Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs lisp: how to add to link/hyperlink to another file just like that in *H e l p*

Tags:

emacs

elisp

we can get help with "C-h ..." and emacs show a Help buffer,and jump to other place with the link . How can I make something like that with elisp, link to another buffer or show something else?

like image 255
Eric.Q Avatar asked Oct 08 '11 10:10

Eric.Q


1 Answers

The builtin Button package provides a convenient way. For example,

(require 'button)
(insert-button "foo" 'action (lambda (x) (find-file user-init-file)))

will insert a button/link labeled "foo" that when activated (by pressing Enter while point is over the label or middle clicking) will bring up the init file.

Here is another example that mimics a www link,

(insert-button "fsf"
               'action (lambda (x) (browse-url (button-get x 'url)))
               'url "http://www.fsf.org")

See Elisp Reference Manual 38.17 Buttons.

like image 176
huaiyuan Avatar answered Sep 24 '22 17:09

huaiyuan