help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Can't add bookmarks for help pages


From: Drew Adams
Subject: RE: Can't add bookmarks for help pages
Date: Sat, 9 Jun 2012 13:48:50 -0700

> Emacs lets me add bookmarks for man and info pages, but not 
> for help pages (it says "Buffer not visiting a file or 
> directory"). Not letting me bookmark help pages isn't user-friendly.

What do you mean by a help page?  Do you mean the output, in buffer *Help*, from
a help command/key such as `C-h f' or `C-h v'?

If so, then no, normally you cannot bookmark that - but see below.

With Bookmark+ [*] you can bookmark a buffer that is not associated with a file,
but except for certain predefined buffer types, such as Info and Dired, to jump
to the bookmark later that buffer must already be present (live).  And it must
already have the text that you expect.

So that won't help you here, not right out of the box.

But it's easy enough to do.  You just need to define your own new bookmark type
for it.  To do that you need to define two functions:

1. A function that creates the bookmark record for that type.
2. A handler function the DTRT when you "jump" to the bookmark.

Here's how:

(defun my-make-help-record ()
  "Create and return a `*Help*' bookmark record."
  (unless (car help-xref-stack-item)
    (error "Cannot create bookmark - help command not known"))
  `(,@(bookmark-make-record-default 'NO-FILE 'NO-CONTEXT)
      (filename    . ,bmkp-non-file-filename)
      (buffer-name . "*Help*")
      (help-fn     . ,(car help-xref-stack-item))
      (help-arg    . ,(cadr help-xref-stack-item))
      (handler     . my-jump-help-bookmark)))

(defun my-jump-help-bookmark (bookmark)
  "Jump to `*Help*' bookmark BOOKMARK.
Handler function for record returned by `my-make-help-record'.
BOOKMARK is a bookmark name or a bookmark record."
  (let ((help-fn   (bookmark-prop-get bookmark 'help-fn))
        (help-arg  (bookmark-prop-get bookmark 'help-arg)))
    (funcall help-fn help-arg)))

(add-hook 'help-mode-hook
          #'(lambda () (set (make-local-variable
                             'bookmark-make-record-function)
                       'my-make-help-record)))

Then, whenever you are in buffer `*Help*', the normal bookmark-setting key, `C-x
r m', creates a bookmark that will show that same help text in `*Help*' when you
jump to it.  It just calls the same help command with the same argument.

E.g., if you used `C-h f forward-char' and you then set a bookmark in `*Help*',
then jumping to it later would show again the help for function `forward-char',
with the cursor at the same spot.

But why would you want such a bookmark type (assuming this was what you had in
mind)?  Why not just use the help commands?  Why would you want a bookmark for a
specific bit of help text (e.g. for a specific variable), rather than just use a
general command that works for any argument (e.g. any variable name)?

Probably I'm missing what you really want to do.

[*] http://www.emacswiki.org/cgi-bin/wiki/BookmarkPlus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]