all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Andrea Cardaci <cyrus.and@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: Zoom: a window management minor mode -- best practices and questions
Date: Wed, 09 May 2018 09:00:45 +0200	[thread overview]
Message-ID: <5AF29C9D.4090902@gmx.at> (raw)
In-Reply-To: <CACMsj9OvBq_xP0m7-Mtkbw4ZU8vHQnS2qici7jQCDxs6NKn_nw@mail.gmail.com>

 > There's one problem with `buffer-list-update-hook` though, it gets
 > called (multiple times) even wen the buffer list is not changed, e.g.,
 > simply by clicking in the buffer. Is this the expected behaviour?

Yes and no.  Some users accumulate several hundred entries in their
buffer lists.  For them, checking the buffer list every time a buffer
is recorded could create an unnecessary performance burden.  So it's
expected that the function on the hook remembers the old buffer list
and compares it against the new one if this is of any importance (I
suppose that in many cases checking the head of the list is all that's
needed).

 > Besides this, if there's no way to get rid of false positives in event
 > handling (i.e., a relayout is triggered but no actual change happened)
 > I guess I need a way to decide if a relayout is *really* needed. A
 > naive way would be saving the current window and buffer but I'm not
 > sure if we can do better.

For example 'switch-to-buffer' does

(select-window (selected-window)))

in order to record the buffer it displays to make sure that a "false
positive" is made when the selected window already displays the
buffer.  So saving the selected window and the buffer it displays is
the best thing one can do.

The Elisp manual mentions this as follows:

    However, when its NORECORD argument is `nil', `select-window'
updates the buffer list and thus indirectly runs the normal hook
`buffer-list-update-hook' (*note Buffer List::).  Consequently, that
hook provides a reasonable way to run a function whenever a window gets
selected more "permanently".

    Since `buffer-list-update-hook' is also run by functions that are
not related to window management, it will usually make sense to save the
value of the selected window somewhere and compare it with the value of
`selected-window' while running that hook.  Also, to avoid false
positives when using `buffer-list-update-hook', it is good practice
that every `select-window' call supposed to select a window only
temporarily passes a non-`nil' NORECORD argument.  If possible, the
macro `with-selected-window' (see below) should be used in such cases.

martin



  parent reply	other threads:[~2018-05-09  7:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-02 16:31 Zoom: a window management minor mode -- best practices and questions Andrea Cardaci
2018-05-02 17:32 ` Eli Zaretskii
2018-05-02 18:41   ` Andrea Cardaci
2018-05-02 18:58     ` Eli Zaretskii
2018-05-03  7:11       ` martin rudalics
2018-05-03  9:50         ` Andrea Cardaci
2018-05-03  9:46       ` Andrea Cardaci
2018-05-03  7:11     ` martin rudalics
2018-05-03  9:47       ` Andrea Cardaci
2018-05-07 12:32         ` Andrea Cardaci
2018-05-07 18:19           ` Eli Zaretskii
2018-05-08 10:40             ` Andrea Cardaci
2018-05-08 14:53               ` Noam Postavsky
2018-05-08 15:03                 ` Andrea Cardaci
2018-05-09 12:33                 ` Stefan Monnier
2018-05-08 17:52               ` Eli Zaretskii
2018-05-09  7:00           ` martin rudalics [this message]
2018-05-09 16:06             ` Andrea Cardaci
2018-05-10  6:27               ` martin rudalics
2018-05-10 10:11                 ` Andrea Cardaci
2018-05-10 10:27                   ` martin rudalics
2018-05-10 10:34                     ` Andrea Cardaci
2018-05-10 10:37                       ` martin rudalics

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=5AF29C9D.4090902@gmx.at \
    --to=rudalics@gmx.at \
    --cc=cyrus.and@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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.