[Top][All Lists]

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

Re: How do i say it in emacs lisp

From: tomas
Subject: Re: How do i say it in emacs lisp
Date: Mon, 28 Nov 2016 10:21:00 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

Hash: SHA1

On Sun, Nov 27, 2016 at 09:46:49PM +0100, Matthias Pfeifer wrote:
> Hi there,
> I want to say this in emacs lisp
> Whenever the buffer in the selected window
> Is changed, do something in a certain other window (which displays a
> certain well known buffer)
> Is this possible? How would it be done?


Since your question is pretty unspecific, I'll assume you'd like to
be pointed in a general direction. Here it goes:

Emacs's way of extending functionality "whenever something happens"
is typically called "hooks": you can insert a function of yours
to be called whenever "something" happens. The hooks you are looking
for are described in the Emacs Lisp manual (31.28, Change hooks [1]).

There, you have to decide whether you want to be called before or
after the text change happens (there are two aptly named hooks).

To get the ball rolling, here's minimal code which complains at
every change in a buffer:

(add-hook 'after-change-functions
          (lambda (beg end oldlen)
            (message (format "Ouch: beg=%S end=%S oldlen=%S" beg end oldlen)))
          nil t)

Insert it in a buffer in lisp mode (e.g. your *scratch* buffer, if
your Emacs is set up in a "normal" way, type C-x C-e to get the
hook function inseerted and watch the action whenever you modify
the buffer.

The "t" at the end sets the hook locally, i.e. only for the local

Do come back if you have further questions!


[1] Or online, at

- -- tomás
Version: GnuPG v1.4.12 (GNU/Linux)


reply via email to

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