emacs-devel
[Top][All Lists]
Advanced

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

Window change functions


From: martin rudalics
Subject: Window change functions
Date: Tue, 25 Dec 2018 10:41:31 +0100

The attached patch should radically change the way we run functions
when window changes occur.  The only hook it does not affect is
'window-scroll-functions'.  For the remainder we now would have the
following four hooks:

(1) 'window-state-change-functions' runs when a window got a new
    buffer or was created or deleted since last redisplay.

(2) 'window-size-change-functions' runs when a window was created or
    got a new buffer, body or total size since last redisplay.

(3) 'window-configuration-change-hook' runs as (1) and (2) together.

(4) 'window-selection-change-functions' run when a window got
    (de-)selected since last redisplay.

In contrast with current behavior (3) does not trigger immediately
when, for example, a window is created, deleted or resized or gets a
another buffer assigned.  Rather, the code now only sets an internal
frame-local flag in these cases.  During redisplay, the code inspects
these flags, checks whether any window of the corresponding frame
really changed and calls the functions on the hooks only in that case.

This means that, for example, running 'save-window-excursion' will
call such hooks only if a redisplay is embedded within that form.  It
also means that any code that changes windows internally won't have to
care about calling `run-window-configuration-change-hook' any more.

In addition, there are now seven functions that give more information
about the state of windows at the last time hooks were run for them.
Please see the documentation in the "Window Hooks" section of the
Emacs manual for these and the new behavior in general.

A number of issues are yet unresolved:

- Some functions on 'window-configuration-change-hook' (notably in
  erc-track.el and rcirc.el) put further code on 'post-command-hook'.
  This concept will be broken since 'post-command-hook' now runs
  before 'window-configuration-change-hook'.

  The solution in the cases I've seen is to run that code right in
  'window-configuration-change-hook'.  xterm.el has a bit more
  convoluted code whose purpose I haven't been able to figure out yet.
  The solution should be similar though.

- It's not entirely clear to me whether the current position where
  change functions are called is good.  The choice was rather
  deliberate - a place where we look whether frame sizes were
  changed externally.  Feel free to propose a better place.

- Currently, there is no hook that runs state, size and selection
  changes in combination.  If such a hook is needed please tell me.

- For efficiency, local and global hooks are run in a somewhat
  intermingled way.  If you see any problems with that, please tell
  me.

- Ideally, we should run 'window-scroll-functions' in the same group
  too.  But currently run_window_scroll_functions returns a value that
  is used by redisplay and I don't know whether changing that could
  have nasty complications.

- Running window change functions generally does not save/restore
  things like the current buffer, selected window, frame or match
  data.  I don't see a real motivation to do that since functions run
  by these hooks could change arbitrary things.  But if someone feels
  strongly about them I can make the necessary provisions.

Please apply the patch, run your Emacs with it and report anomalies.

Thanks for your attention, martin

Attachment: window-change-functions.diff
Description: Text document


reply via email to

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