diff options
| author | Juri Linkov | 2020-03-30 01:57:36 +0300 |
|---|---|---|
| committer | Juri Linkov | 2020-03-30 01:57:36 +0300 |
| commit | 3273e2ace788a58bef77cef936021d151815ea94 (patch) | |
| tree | 0bb97e42c356ba9fee04879fc9f439634819252a | |
| parent | 7a6f5a5167037cdc3a0e9e312393781daedec085 (diff) | |
| download | emacs-3273e2ace788a58bef77cef936021d151815ea94.tar.gz emacs-3273e2ace788a58bef77cef936021d151815ea94.zip | |
Deprecate with-displayed-buffer-window, use body-function instead (bug#39822)
* doc/lispref/display.texi (Temporary Displays):
Remove defmac with-displayed-buffer-window.
* doc/lispref/windows.texi (Buffer Display Action Alists):
Add body-function.
* lisp/window.el (with-displayed-buffer-window): Declare macro obsolete.
(window--display-buffer): Call 'body-function' after displaying the buffer.
* lisp/dired.el (dired-mark-pop-up):
* lisp/files.el (save-buffers-kill-emacs):
* lisp/minibuffer.el (minibuffer-completion-help):
Replace with-displayed-buffer-window with with-current-buffer-window
and add action alist entry 'body-function' with former macro body.
| -rw-r--r-- | doc/lispref/display.texi | 6 | ||||
| -rw-r--r-- | doc/lispref/windows.texi | 9 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/dired.el | 29 | ||||
| -rw-r--r-- | lisp/files.el | 14 | ||||
| -rw-r--r-- | lisp/minibuffer.el | 116 | ||||
| -rw-r--r-- | lisp/window.el | 10 |
7 files changed, 105 insertions, 83 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 2b25d6023cd..9fbf995d7e4 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -1318,12 +1318,6 @@ the buffer specified by @var{buffer-or-name} current for running | |||
| 1318 | @var{body}. | 1318 | @var{body}. |
| 1319 | @end defmac | 1319 | @end defmac |
| 1320 | 1320 | ||
| 1321 | @defmac with-displayed-buffer-window buffer-or-name action quit-function &rest body | ||
| 1322 | This macro is like @code{with-current-buffer-window} but unlike that | ||
| 1323 | displays the buffer specified by @var{buffer-or-name} @emph{before} | ||
| 1324 | running @var{body}. | ||
| 1325 | @end defmac | ||
| 1326 | |||
| 1327 | A window showing a temporary buffer can be fitted to the size of that | 1321 | A window showing a temporary buffer can be fitted to the size of that |
| 1328 | buffer using the following mode: | 1322 | buffer using the following mode: |
| 1329 | 1323 | ||
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index d0791d40196..00142d87dcc 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -3048,6 +3048,15 @@ since there is no guarantee that an arbitrary caller of | |||
| 3048 | @code{display-buffer} will be able to handle the case that no window | 3048 | @code{display-buffer} will be able to handle the case that no window |
| 3049 | will display the buffer. @code{display-buffer-no-window} is the only | 3049 | will display the buffer. @code{display-buffer-no-window} is the only |
| 3050 | action function that cares about this entry. | 3050 | action function that cares about this entry. |
| 3051 | |||
| 3052 | @vindex body-function@r{, a buffer display action alist entry} | ||
| 3053 | @item body-function | ||
| 3054 | The value must be a function taking one argument (a displayed window). | ||
| 3055 | This function can be used to fill the displayed window's body with | ||
| 3056 | some contents. It is called @emph{after} the buffer is displayed, and | ||
| 3057 | @emph{before} the entries @code{window-height}, @code{window-width} | ||
| 3058 | and @code{preserve-size} are applied that could resize the window | ||
| 3059 | to fit it to the inserted contents. | ||
| 3051 | @end table | 3060 | @end table |
| 3052 | 3061 | ||
| 3053 | By convention, the entries @code{window-height}, @code{window-width} | 3062 | By convention, the entries @code{window-height}, @code{window-width} |
| @@ -266,6 +266,10 @@ It was used to allow loading Lisp libraries compiled by XEmacs, a | |||
| 266 | modified version of Emacs which is no longer actively maintained. | 266 | modified version of Emacs which is no longer actively maintained. |
| 267 | This is no longer supported, and setting this variable has no effect. | 267 | This is no longer supported, and setting this variable has no effect. |
| 268 | 268 | ||
| 269 | +++ | ||
| 270 | ** The macro 'with-displayed-buffer-window' is now obsolete. | ||
| 271 | Use macro 'with-current-buffer-window' with action alist entry 'body-function'. | ||
| 272 | |||
| 269 | 273 | ||
| 270 | * Lisp Changes in Emacs 28.1 | 274 | * Lisp Changes in Emacs 28.1 |
| 271 | 275 | ||
diff --git a/lisp/dired.el b/lisp/dired.el index 72d1cc250a3..b66bb034712 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -3521,26 +3521,27 @@ argument or confirmation)." | |||
| 3521 | ;; Mark *Marked Files* window as softly-dedicated, to prevent | 3521 | ;; Mark *Marked Files* window as softly-dedicated, to prevent |
| 3522 | ;; other buffers e.g. *Completions* from reusing it (bug#17554). | 3522 | ;; other buffers e.g. *Completions* from reusing it (bug#17554). |
| 3523 | (display-buffer-mark-dedicated 'soft)) | 3523 | (display-buffer-mark-dedicated 'soft)) |
| 3524 | (with-displayed-buffer-window | 3524 | (with-current-buffer-window |
| 3525 | buffer | 3525 | buffer |
| 3526 | (cons 'display-buffer-below-selected | 3526 | `(display-buffer-below-selected |
| 3527 | '((window-height . fit-window-to-buffer) | 3527 | (window-height . fit-window-to-buffer) |
| 3528 | (preserve-size . (nil . t)))) | 3528 | (preserve-size . (nil . t)) |
| 3529 | (body-function | ||
| 3530 | . ,#'(lambda (_window) | ||
| 3531 | ;; Handle (t FILE) just like (FILE), here. That value is | ||
| 3532 | ;; used (only in some cases), to mean just one file that was | ||
| 3533 | ;; marked, rather than the current line file. | ||
| 3534 | (dired-format-columns-of-files | ||
| 3535 | (if (eq (car files) t) (cdr files) files)) | ||
| 3536 | (remove-text-properties (point-min) (point-max) | ||
| 3537 | '(mouse-face nil help-echo nil)) | ||
| 3538 | (setq tab-line-exclude nil)))) | ||
| 3529 | #'(lambda (window _value) | 3539 | #'(lambda (window _value) |
| 3530 | (with-selected-window window | 3540 | (with-selected-window window |
| 3531 | (unwind-protect | 3541 | (unwind-protect |
| 3532 | (apply function args) | 3542 | (apply function args) |
| 3533 | (when (window-live-p window) | 3543 | (when (window-live-p window) |
| 3534 | (quit-restore-window window 'kill))))) | 3544 | (quit-restore-window window 'kill))))))))) |
| 3535 | ;; Handle (t FILE) just like (FILE), here. That value is | ||
| 3536 | ;; used (only in some cases), to mean just one file that was | ||
| 3537 | ;; marked, rather than the current line file. | ||
| 3538 | (with-current-buffer buffer | ||
| 3539 | (dired-format-columns-of-files | ||
| 3540 | (if (eq (car files) t) (cdr files) files)) | ||
| 3541 | (remove-text-properties (point-min) (point-max) | ||
| 3542 | '(mouse-face nil help-echo nil)) | ||
| 3543 | (setq tab-line-exclude nil)))))) | ||
| 3544 | 3545 | ||
| 3545 | (defun dired-format-columns-of-files (files) | 3546 | (defun dired-format-columns-of-files (files) |
| 3546 | (let ((beg (point))) | 3547 | (let ((beg (point))) |
diff --git a/lisp/files.el b/lisp/files.el index 8ce0187f5b7..1f5fae95023 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -7253,10 +7253,15 @@ if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." | |||
| 7253 | (setq active t)) | 7253 | (setq active t)) |
| 7254 | (setq processes (cdr processes))) | 7254 | (setq processes (cdr processes))) |
| 7255 | (or (not active) | 7255 | (or (not active) |
| 7256 | (with-displayed-buffer-window | 7256 | (with-current-buffer-window |
| 7257 | (get-buffer-create "*Process List*") | 7257 | (get-buffer-create "*Process List*") |
| 7258 | '(display-buffer--maybe-at-bottom | 7258 | `(display-buffer--maybe-at-bottom |
| 7259 | (dedicated . t)) | 7259 | (dedicated . t) |
| 7260 | (window-height . fit-window-to-buffer) | ||
| 7261 | (preserve-size . (nil . t)) | ||
| 7262 | (body-function | ||
| 7263 | . ,#'(lambda (_window) | ||
| 7264 | (list-processes t)))) | ||
| 7260 | #'(lambda (window _value) | 7265 | #'(lambda (window _value) |
| 7261 | (with-selected-window window | 7266 | (with-selected-window window |
| 7262 | (unwind-protect | 7267 | (unwind-protect |
| @@ -7264,8 +7269,7 @@ if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." | |||
| 7264 | (setq confirm nil) | 7269 | (setq confirm nil) |
| 7265 | (yes-or-no-p "Active processes exist; kill them and exit anyway? ")) | 7270 | (yes-or-no-p "Active processes exist; kill them and exit anyway? ")) |
| 7266 | (when (window-live-p window) | 7271 | (when (window-live-p window) |
| 7267 | (quit-restore-window window 'kill))))) | 7272 | (quit-restore-window window 'kill))))))))) |
| 7268 | (list-processes t))))) | ||
| 7269 | ;; Query the user for other things, perhaps. | 7273 | ;; Query the user for other things, perhaps. |
| 7270 | (run-hook-with-args-until-failure 'kill-emacs-query-functions) | 7274 | (run-hook-with-args-until-failure 'kill-emacs-query-functions) |
| 7271 | (or (null confirm) | 7275 | (or (null confirm) |
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 7f5b597542a..9e0e6339c6f 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el | |||
| @@ -1973,7 +1973,7 @@ variables.") | |||
| 1973 | ;; minibuffer-hide-completions will know whether to | 1973 | ;; minibuffer-hide-completions will know whether to |
| 1974 | ;; delete the window or not. | 1974 | ;; delete the window or not. |
| 1975 | (display-buffer-mark-dedicated 'soft)) | 1975 | (display-buffer-mark-dedicated 'soft)) |
| 1976 | (with-displayed-buffer-window | 1976 | (with-current-buffer-window |
| 1977 | "*Completions*" | 1977 | "*Completions*" |
| 1978 | ;; This is a copy of `display-buffer-fallback-action' | 1978 | ;; This is a copy of `display-buffer-fallback-action' |
| 1979 | ;; where `display-buffer-use-some-window' is replaced | 1979 | ;; where `display-buffer-use-some-window' is replaced |
| @@ -1991,62 +1991,64 @@ variables.") | |||
| 1991 | '(window-height . resize-temp-buffer-window) | 1991 | '(window-height . resize-temp-buffer-window) |
| 1992 | '(window-height . fit-window-to-buffer)) | 1992 | '(window-height . fit-window-to-buffer)) |
| 1993 | ,(when temp-buffer-resize-mode | 1993 | ,(when temp-buffer-resize-mode |
| 1994 | '(preserve-size . (nil . t)))) | 1994 | '(preserve-size . (nil . t))) |
| 1995 | nil | 1995 | (body-function |
| 1996 | ;; Remove the base-size tail because `sort' requires a properly | 1996 | . ,#'(lambda (_window) |
| 1997 | ;; nil-terminated list. | 1997 | ;; Remove the base-size tail because `sort' requires a properly |
| 1998 | (when last (setcdr last nil)) | 1998 | ;; nil-terminated list. |
| 1999 | (setq completions | 1999 | (when last (setcdr last nil)) |
| 2000 | ;; FIXME: This function is for the output of all-completions, | 2000 | (setq completions |
| 2001 | ;; not completion-all-completions. Often it's the same, but | 2001 | ;; FIXME: This function is for the output of all-completions, |
| 2002 | ;; not always. | 2002 | ;; not completion-all-completions. Often it's the same, but |
| 2003 | (let ((sort-fun (completion-metadata-get | 2003 | ;; not always. |
| 2004 | all-md 'display-sort-function))) | 2004 | (let ((sort-fun (completion-metadata-get |
| 2005 | (if sort-fun | 2005 | all-md 'display-sort-function))) |
| 2006 | (funcall sort-fun completions) | 2006 | (if sort-fun |
| 2007 | (sort completions 'string-lessp)))) | 2007 | (funcall sort-fun completions) |
| 2008 | (when afun | 2008 | (sort completions 'string-lessp)))) |
| 2009 | (setq completions | 2009 | (when afun |
| 2010 | (mapcar (lambda (s) | 2010 | (setq completions |
| 2011 | (let ((ann (funcall afun s))) | 2011 | (mapcar (lambda (s) |
| 2012 | (if ann (list s ann) s))) | 2012 | (let ((ann (funcall afun s))) |
| 2013 | completions))) | 2013 | (if ann (list s ann) s))) |
| 2014 | 2014 | completions))) | |
| 2015 | (with-current-buffer standard-output | 2015 | |
| 2016 | (set (make-local-variable 'completion-base-position) | 2016 | (with-current-buffer standard-output |
| 2017 | (list (+ start base-size) | 2017 | (set (make-local-variable 'completion-base-position) |
| 2018 | ;; FIXME: We should pay attention to completion | 2018 | (list (+ start base-size) |
| 2019 | ;; boundaries here, but currently | 2019 | ;; FIXME: We should pay attention to completion |
| 2020 | ;; completion-all-completions does not give us the | 2020 | ;; boundaries here, but currently |
| 2021 | ;; necessary information. | 2021 | ;; completion-all-completions does not give us the |
| 2022 | end)) | 2022 | ;; necessary information. |
| 2023 | (set (make-local-variable 'completion-list-insert-choice-function) | 2023 | end)) |
| 2024 | (let ((ctable minibuffer-completion-table) | 2024 | (set (make-local-variable 'completion-list-insert-choice-function) |
| 2025 | (cpred minibuffer-completion-predicate) | 2025 | (let ((ctable minibuffer-completion-table) |
| 2026 | (cprops completion-extra-properties)) | 2026 | (cpred minibuffer-completion-predicate) |
| 2027 | (lambda (start end choice) | 2027 | (cprops completion-extra-properties)) |
| 2028 | (unless (or (zerop (length prefix)) | 2028 | (lambda (start end choice) |
| 2029 | (equal prefix | 2029 | (unless (or (zerop (length prefix)) |
| 2030 | (buffer-substring-no-properties | 2030 | (equal prefix |
| 2031 | (max (point-min) | 2031 | (buffer-substring-no-properties |
| 2032 | (- start (length prefix))) | 2032 | (max (point-min) |
| 2033 | start))) | 2033 | (- start (length prefix))) |
| 2034 | (message "*Completions* out of date")) | 2034 | start))) |
| 2035 | ;; FIXME: Use `md' to do quoting&terminator here. | 2035 | (message "*Completions* out of date")) |
| 2036 | (completion--replace start end choice) | 2036 | ;; FIXME: Use `md' to do quoting&terminator here. |
| 2037 | (let* ((minibuffer-completion-table ctable) | 2037 | (completion--replace start end choice) |
| 2038 | (minibuffer-completion-predicate cpred) | 2038 | (let* ((minibuffer-completion-table ctable) |
| 2039 | (completion-extra-properties cprops) | 2039 | (minibuffer-completion-predicate cpred) |
| 2040 | (result (concat prefix choice)) | 2040 | (completion-extra-properties cprops) |
| 2041 | (bounds (completion-boundaries | 2041 | (result (concat prefix choice)) |
| 2042 | result ctable cpred ""))) | 2042 | (bounds (completion-boundaries |
| 2043 | ;; If the completion introduces a new field, then | 2043 | result ctable cpred ""))) |
| 2044 | ;; completion is not finished. | 2044 | ;; If the completion introduces a new field, then |
| 2045 | (completion--done result | 2045 | ;; completion is not finished. |
| 2046 | (if (eq (car bounds) (length result)) | 2046 | (completion--done result |
| 2047 | 'exact 'finished))))))) | 2047 | (if (eq (car bounds) (length result)) |
| 2048 | 2048 | 'exact 'finished))))))) | |
| 2049 | (display-completion-list completions)))) | 2049 | |
| 2050 | (display-completion-list completions)))) | ||
| 2051 | nil))) | ||
| 2050 | nil)) | 2052 | nil)) |
| 2051 | 2053 | ||
| 2052 | (defun minibuffer-hide-completions () | 2054 | (defun minibuffer-hide-completions () |
diff --git a/lisp/window.el b/lisp/window.el index b54f1633f5e..0121a78191a 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -226,7 +226,9 @@ BODY." | |||
| 226 | "Show a buffer BUFFER-OR-NAME and evaluate BODY in that buffer. | 226 | "Show a buffer BUFFER-OR-NAME and evaluate BODY in that buffer. |
| 227 | This construct is like `with-current-buffer-window' but unlike that, | 227 | This construct is like `with-current-buffer-window' but unlike that, |
| 228 | displays the buffer specified by BUFFER-OR-NAME before running BODY." | 228 | displays the buffer specified by BUFFER-OR-NAME before running BODY." |
| 229 | (declare (debug t) (indent 3)) | 229 | (declare (debug t) (indent 3) |
| 230 | (obsolete "use `with-current-buffer-window' with action alist entry `body-function'." | ||
| 231 | "28.1")) | ||
| 230 | (let ((buffer (make-symbol "buffer")) | 232 | (let ((buffer (make-symbol "buffer")) |
| 231 | (window (make-symbol "window")) | 233 | (window (make-symbol "window")) |
| 232 | (value (make-symbol "value"))) | 234 | (value (make-symbol "value"))) |
| @@ -7070,6 +7072,12 @@ Return WINDOW if BUFFER and WINDOW are live." | |||
| 7070 | (set-window-dedicated-p window display-buffer-mark-dedicated)))) | 7072 | (set-window-dedicated-p window display-buffer-mark-dedicated)))) |
| 7071 | (when (memq type '(window frame tab)) | 7073 | (when (memq type '(window frame tab)) |
| 7072 | (set-window-prev-buffers window nil)) | 7074 | (set-window-prev-buffers window nil)) |
| 7075 | |||
| 7076 | (when (functionp (cdr (assq 'body-function alist))) | ||
| 7077 | (let ((inhibit-read-only t) | ||
| 7078 | (inhibit-modification-hooks t)) | ||
| 7079 | (funcall (cdr (assq 'body-function alist)) window))) | ||
| 7080 | |||
| 7073 | (let ((quit-restore (window-parameter window 'quit-restore)) | 7081 | (let ((quit-restore (window-parameter window 'quit-restore)) |
| 7074 | (height (cdr (assq 'window-height alist))) | 7082 | (height (cdr (assq 'window-height alist))) |
| 7075 | (width (cdr (assq 'window-width alist))) | 7083 | (width (cdr (assq 'window-width alist))) |