unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Q on after-change-functions
@ 2006-02-22  1:57 Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2006-02-22  1:57 UTC (permalink / raw)


In Emacs 22 or 20 -

I do this:

  (set-buffer (window-buffer (minibuffer-window)))
  (add-hook 'after-change-functions 'foobar nil 'local)

(BTW, is there an easier way to get the minibuffer buffer than via its
window?)

Then I do this:

  (set-buffer (window-buffer (minibuffer-window)))
  (describe-variable 'after-change-functions)

That prints this, showing (I think) that `foobar' is in the minibuffer-local
value of `after-change-functions':

  after-change-functions's value is (foobar t)
  Local in buffer  *Minibuf-0*; global value is nil

I then do this:

(defun foobar (a b c) (message "phooey!"))

When I then do, say, `M-x abcdef' I'm expecting that `foobar' will be called
each time I insert a character in the minibuffer: a b c ... Likewise each
time I delete characters from the minibuffer input. I'm expecting any change
to the text in buffer minibuffer to provoke `foobar'. (I haven't yet started
to wonder how to turn it off for things like prompt insertion!)

However, `foobar' never gets called, as seen by using `debug-on-entry
foobar' (and by the lack of any message from `foobar').

What am I missing? Suggestions? I'm trying to pick up any user changes to
input in the minibuffer. I don't, however, want to trigger `foobar' for
insertion of prompts and such by program.

Currently, I use a different approach, redefining several basic editing keys
(character, word, etc. insertion and deletion) so that they do both 1) their
normal thing and 2) call `foobar'. That works well, but I thought perhaps
`after-change-functions' might provide a simpler, more elegant
implementation. In any case, I'm curious about how it works.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Q on after-change-functions
       [not found] <mailman.1173.1140573492.2856.help-gnu-emacs@gnu.org>
@ 2006-02-23 15:50 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2006-02-23 15:50 UTC (permalink / raw)


>   (set-buffer (window-buffer (minibuffer-window)))
>   (add-hook 'after-change-functions 'foobar nil 'local)

The minibuffer's buffer is refreshed/recreated/reset every time you
enter it.  Maybe it would work if you added (put 'after-change-functions
'permanent-local t), but that would be truly evil.  Also it would still fail
in the case of recursive minibuffers where you may have several minibuffer
buffers active at the same time.

Instead, you want to do your `add-hook' from minibuffer-setup-hook.

See icomplete-mode for an example of a mode that does something similar
(tho it doesn't use after-change-functions but pre/post-command-hook
instead).


        Stefan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-02-23 15:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-22  1:57 Q on after-change-functions Drew Adams
     [not found] <mailman.1173.1140573492.2856.help-gnu-emacs@gnu.org>
2006-02-23 15:50 ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).