Emacs buttons – an introduction for the somewhat impatient

May 14, 2008 at 7:08 pm 3 comments

Working out how to make buttons work in emacs took rather too much effort – I suspect I was just being slow. However, I thought I’d write a tiny how-to for anyone else who tries to do this:

Below is a prototypical emacs lisp function call to create a new button in your text between characters beg and end is:

(defun f (button)
    (call-interactively 'find-file))

(make-button beg end 'action 'f 'follow-link t)

Note the following:

  • The properties are defined via a variable number of arguments . It does does not take a list.
  • Removing the follow-link property would cause left mouse-clicks on the link to have no effects
  • f must take a single argument otherwise this will fail.

For more on emacs buttons see:


If you want to make your button more anonymous (so that changing the function value associated with f has no deleterious results) you can use the following

(make-button beg end 'action
    (lambda (button) (call-interactively 'find-file))
    'follow-link t)

Entry filed under: Uncategorized. Tags: , , .

Sending mail through gmail Using Emacs Searching multiple buffers emacs

3 Comments Add your own

  • 1. clay  |  November 26, 2008 at 6:22 pm

    Could you please include some non-prototype examples of creating buttons. Even just one or two that makes something happen on the screen would be great.


  • 2. existentiality  |  November 26, 2008 at 8:03 pm

    Hi clay,

    I probably should have been a bit clearer. If you go to the scratch
    buffer and enter and execute the following code:

    (defun f (button) ‘find-file)
    (make-button 1 10 ‘action ‘f ‘follow-link t)

    then the first 10 characters of that buffer should become a button.
    Clicking this button should cause the mini-buffer to try to find a

    Alternatively, if you have

    (defun f (button) (insert “hey”))

    then clicking this button will write “hey” where you clicked this button.

    Hope this helps – say if it doesn’t.

  • […] are posts on searching multiple buffers, emacs version control and emacs buttons within the same […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

May 2008
« Apr   Jul »

%d bloggers like this: