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

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

Re: how to add button to emacs that play a elisp code


From: Pascal J. Bourguignon
Subject: Re: how to add button to emacs that play a elisp code
Date: Thu, 11 Sep 2014 18:00:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Renato Pontefice <renato.pontefice@gmail.com> writes:

> Hi,
> is it possible to add a button on my emacs that run a piece of code?
> Or a combination of button.
>
> I mean: I want to run a little elisp procedure, while I'm editing a file.

So you've seen global-set-key to configure a key or combination of keys
(key chord) to call up an elisp command.

But you can also insert buttons in buffers to run some elisp code:

(let ((start (point)))
  (insert "Hello")
  (let ((end (point)))
    (make-button start end 'action (lambda (&rest args) (message "world!")))))

When you evaluate this expression, it inserts the text Hello as a
button.  If you move to this button and type RET, or middle-click on it,
then the action function is called, which in this case will display
world! in the minibuffer.

-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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