emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] frame.c: focus hooks


From: martin rudalics
Subject: Re: [PATCH] frame.c: focus hooks
Date: Sun, 12 Jan 2014 10:54:42 +0100

> I originally interpreted your mention of it as additional evidence that
> deciding whether or not to call a new select-window-hook from
> Fselect_window based on its NORECORD argument would be a
> reasonable approach.  It sounds like I misunderstood, and that you
> were suggesting simply using the existing b-l-u-h for code that should
> run when the selected window changes non-ephemerally.  Is that right?

Both interpretations are valid:

(1) The first interpretation means (implicitly) that we could replace
    the call to `buffer-list-update-hook' by calling instead something
    we could name `record-buffer-hook'.

(2) The second interpretation means that your function would have to
    filter the calls of `buffer-list-update-hook' appropriately.

> As an experiment, I just evaluated this form with `eval-expression':
>
>   (progn
>     (setq bluh-hist nil)
>     (add-hook 'buffer-list-update-hook
>               (lambda (&rest args)
>                 (push (format "%s: %s" (buffer-name) args)
>                       bluh-hist))))
>
> A few seconds later bluh-hist had grown to contain several hundred
> elements, even though I did not interact with Emacs at all during the
> interim.  All of my open buffers appear to be represented in that list,
> including ERC buffers, source code buffers, *scratch*, *Backtrace*,
> etc.  I have not yet tried this experiment with -q/-Q so it's possible
> this behavior is being caused by some of my own code or a library,
> but if this expected behavior then b-l-u-h doesn't seem well-suited
> to the problem I'd like to solve.

You didn't explain _what_ you want to solve.  Adding the name of the
current buffer whenever a hook is run doesn't sound very reasonable to
me.

Consider the following construct:

(defvar my-window nil)

(defun foo ()
  (unless (eq (selected-window) my-window)
    (setq my-window (selected-window))
    (ding)))

(add-hook 'buffer-list-update-hook 'foo)

Here it beeps whenever the selected window visibly changes.  What
more/less do you want/need?  If you give me an example where you cannot
apply (2), that is, filter the changes of which window is selected from
the `buffer-list-update-hook'-run function we can always add a new hook
as sketched in (1) above.  But obviously not adding a new hook would be
the cheaper solution.

martin



reply via email to

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