all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: <tomas@tuxteam.de>
To: Matthias Pfeifer <mpfeifer77@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How do i say it in emacs lisp
Date: Mon, 28 Nov 2016 10:21:00 +0100	[thread overview]
Message-ID: <20161128092100.GA23484@tuxteam.de> (raw)
In-Reply-To: <CAPzsW6gzPnpPbgAW2PUJ=nRbuuzX+hPG4S-yMyjSD+Omg=k1mQ@mail.gmail.com>

-----BEGIN PGP SIGNED MESSAGE-----
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?

Yes.

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
buffer.

Do come back if you have further questions!

regards

[1] Or online, at
    https://www.gnu.org/software/emacs/manual/html_node/elisp/Change-Hooks.html

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

iEYEARECAAYFAlg79vwACgkQBcgs9XrR2kZofACfdhy4Lr6bB88PgToGEZr3Bcg1
La4Anij3GKm97u6y+FpadyBgV/HfZxEN
=xwDi
-----END PGP SIGNATURE-----



  reply	other threads:[~2016-11-28  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPzsW6jZpzKKfy3u0tghOQgeZM9qOoLBH3U5EDpjOFB9GwNHXQ@mail.gmail.com>
     [not found] ` <CAPzsW6i3UHiAyWFGKrf=pa3B91ZFqgnAT2+vmg=S-agCRi7vZg@mail.gmail.com>
     [not found]   ` <CAPzsW6j+8W+i0t_CvDz0BEa6diG+z7YiDi7rJfsiknbLYmK3=A@mail.gmail.com>
     [not found]     ` <CAPzsW6jdmQkqQwA7wPaPNEA4Ayef7Vm+s1jxVH_Z4zHCWKLyMg@mail.gmail.com>
     [not found]       ` <CAPzsW6hrvFGVyodjd5Zg83-8ZE3s94EDfv28NQRWoRszOoUPKg@mail.gmail.com>
     [not found]         ` <CAPzsW6j2iip9LbqC4zs2g39yvS-VpT-bm0cnhUL3arxC1va7_Q@mail.gmail.com>
     [not found]           ` <CAPzsW6jx0LcsPaTmdoLBjgJSAOw_ytk7e4YqGpo+UwA7+Ou7mA@mail.gmail.com>
     [not found]             ` <CAPzsW6gvO4jExpo=V5vyu+Zw+04nL808sJwLwVnOrFKkj16zWQ@mail.gmail.com>
2016-11-27 20:46               ` How do i say it in emacs lisp Matthias Pfeifer
2016-11-28  9:21                 ` tomas [this message]
2016-11-28 11:50                   ` Matthias Pfeifer
2016-11-28 20:12                     ` tomas
2016-12-21 18:19                     ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161128092100.GA23484@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mpfeifer77@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.