diff options
| author | Alan Mackenzie | 2018-10-03 10:45:59 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2018-10-03 10:45:59 +0000 |
| commit | 51f0cccdde9bd1679e20f35d30e39e872ce6513a (patch) | |
| tree | d0d88b4ca9f6b5b575e1f88904a56c6a99ada9b9 | |
| parent | 3eedabaef37ecbcf30144ab9efa2441bbfc950e0 (diff) | |
| download | emacs-51f0cccdde9bd1679e20f35d30e39e872ce6513a.tar.gz emacs-51f0cccdde9bd1679e20f35d30e39e872ce6513a.zip | |
Put follow-mode's engine on pre-redisplay-hook instead of post-command-hook
This fixes bug #32874.
* lisp/follow.el (follow-mode): Put follow-pre-redisplay-function onto
pre-redisplay-function instead of putting follow-post-command-hook onto
post-command-hook. Amend the removal operation analogously.
(follow-pre-redisplay-function): New function.
| -rw-r--r-- | lisp/follow.el | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lisp/follow.el b/lisp/follow.el index 7aa7b514739..e2d3a11b654 100644 --- a/lisp/follow.el +++ b/lisp/follow.el | |||
| @@ -187,8 +187,8 @@ | |||
| 187 | ;; Implementation: | 187 | ;; Implementation: |
| 188 | ;; | 188 | ;; |
| 189 | ;; The main method by which Follow mode aligns windows is via the | 189 | ;; The main method by which Follow mode aligns windows is via the |
| 190 | ;; function `follow-post-command-hook', which is run after each | 190 | ;; function `follow-pre-redisplay-function', which is run before each |
| 191 | ;; command. This "fixes up" the alignment of other windows which are | 191 | ;; redisplay. This "fixes up" the alignment of other windows which are |
| 192 | ;; showing the same Follow mode buffer, on the same frame as the | 192 | ;; showing the same Follow mode buffer, on the same frame as the |
| 193 | ;; selected window. It does not try to deal with buffers other than | 193 | ;; selected window. It does not try to deal with buffers other than |
| 194 | ;; the buffer of the selected frame, or windows on other frames. | 194 | ;; the buffer of the selected frame, or windows on other frames. |
| @@ -418,7 +418,7 @@ Keys specific to Follow mode: | |||
| 418 | (if follow-mode | 418 | (if follow-mode |
| 419 | (progn | 419 | (progn |
| 420 | (add-hook 'compilation-filter-hook 'follow-align-compilation-windows t t) | 420 | (add-hook 'compilation-filter-hook 'follow-align-compilation-windows t t) |
| 421 | (add-hook 'post-command-hook 'follow-post-command-hook t) | 421 | (add-function :before pre-redisplay-function 'follow-pre-redisplay-function) |
| 422 | (add-hook 'window-size-change-functions 'follow-window-size-change t) | 422 | (add-hook 'window-size-change-functions 'follow-window-size-change t) |
| 423 | (add-hook 'after-change-functions 'follow-after-change nil t) | 423 | (add-hook 'after-change-functions 'follow-after-change nil t) |
| 424 | (add-hook 'isearch-update-post-hook 'follow-post-command-hook nil t) | 424 | (add-hook 'isearch-update-post-hook 'follow-post-command-hook nil t) |
| @@ -445,7 +445,7 @@ Keys specific to Follow mode: | |||
| 445 | (setq following (buffer-local-value 'follow-mode (car buffers)) | 445 | (setq following (buffer-local-value 'follow-mode (car buffers)) |
| 446 | buffers (cdr buffers))) | 446 | buffers (cdr buffers))) |
| 447 | (unless following | 447 | (unless following |
| 448 | (remove-hook 'post-command-hook 'follow-post-command-hook) | 448 | (remove-function pre-redisplay-function 'follow-pre-redisplay-function) |
| 449 | (remove-hook 'window-size-change-functions 'follow-window-size-change))) | 449 | (remove-hook 'window-size-change-functions 'follow-window-size-change))) |
| 450 | 450 | ||
| 451 | (kill-local-variable 'move-to-window-group-line-function) | 451 | (kill-local-variable 'move-to-window-group-line-function) |
| @@ -1260,10 +1260,27 @@ non-first windows in Follow mode." | |||
| 1260 | (not (eq win top)))) ;; Loop while this is true. | 1260 | (not (eq win top)))) ;; Loop while this is true. |
| 1261 | (set-buffer orig-buffer)))) | 1261 | (set-buffer orig-buffer)))) |
| 1262 | 1262 | ||
| 1263 | ;;; Post Command Hook | 1263 | ;;; Pre Display Function |
| 1264 | |||
| 1265 | ;; This function is added to `pre-display-function' and is thus called | ||
| 1266 | ;; before each redisplay operation. It supersedes (2018-09) the | ||
| 1267 | ;; former use of the post command hook, and now does the right thing | ||
| 1268 | ;; when a program calls `redisplay' or `sit-for'. | ||
| 1269 | |||
| 1270 | (defun follow-pre-redisplay-function (wins) | ||
| 1271 | (if (or (eq wins t) | ||
| 1272 | (null wins) | ||
| 1273 | (and (listp wins) | ||
| 1274 | (memq (selected-window) wins))) | ||
| 1275 | (follow-post-command-hook))) | ||
| 1264 | 1276 | ||
| 1265 | ;; The magic little box. This function is called after every command. | 1277 | ;;; Post Command Hook |
| 1266 | 1278 | ||
| 1279 | ;; The magic little box. This function was formerly called after every | ||
| 1280 | ;; command. It is now called before each redisplay operation (see | ||
| 1281 | ;; `follow-pre-redisplay-function' above), and at the end of several | ||
| 1282 | ;; search/replace commands. It retains its historical name. | ||
| 1283 | ;; | ||
| 1267 | ;; This is not as complicated as it seems. It is simply a list of common | 1284 | ;; This is not as complicated as it seems. It is simply a list of common |
| 1268 | ;; display situations and the actions to take, plus commands for redrawing | 1285 | ;; display situations and the actions to take, plus commands for redrawing |
| 1269 | ;; the screen if it should be unaligned. | 1286 | ;; the screen if it should be unaligned. |
| @@ -1284,6 +1301,12 @@ non-first windows in Follow mode." | |||
| 1284 | (setq follow-windows-start-end-cache nil)) | 1301 | (setq follow-windows-start-end-cache nil)) |
| 1285 | (follow-adjust-window win))))) | 1302 | (follow-adjust-window win))))) |
| 1286 | 1303 | ||
| 1304 | ;; NOTE: to debug follow-mode with edebug, it is helpful to add | ||
| 1305 | ;; `follow-post-command-hook' to `post-command-hook' temporarily. Do | ||
| 1306 | ;; this locally to the target buffer with, say,: | ||
| 1307 | ;; M-: (add-hook 'post-command-hook 'follow-post-command-hook t t) | ||
| 1308 | ;; . | ||
| 1309 | |||
| 1287 | (defun follow-adjust-window (win) | 1310 | (defun follow-adjust-window (win) |
| 1288 | ;; Adjust the window WIN and its followers. | 1311 | ;; Adjust the window WIN and its followers. |
| 1289 | (cl-assert (eq (window-buffer win) (current-buffer))) | 1312 | (cl-assert (eq (window-buffer win) (current-buffer))) |