diff options
| author | Martin Rudalics | 2014-03-16 10:26:58 +0100 |
|---|---|---|
| committer | Martin Rudalics | 2014-03-16 10:26:58 +0100 |
| commit | b92631bf71bb029af7a5b4bcf3acd6b4484a4afa (patch) | |
| tree | 3c9770441c520b285461935751643fcc8aa5e43c | |
| parent | d939cbea79c40740333cf779296d94ee265eceb5 (diff) | |
| download | emacs-b92631bf71bb029af7a5b4bcf3acd6b4484a4afa.tar.gz emacs-b92631bf71bb029af7a5b4bcf3acd6b4484a4afa.zip | |
Fix behavior of with-temp-buffer-window (Bug#16816, Bug#17007).
* window.el (with-temp-buffer-window): Don't make BUFFER-OR-NAME
current (Bug#16816, Bug#17007).
(with-current-buffer-window): New macro doing the same as
`with-temp-buffer-window' but with BUFFER-OR-NAME current.
* help.el (help-print-return-message): Warn in doc-string to not
use this in `with-help-window'.
(describe-bindings-internal): Call `describe-buffer-bindings'
from within help buffer. See Juanma's scenario in (Bug#16816).
(with-help-window): Update doc-string.
* dired.el (dired-mark-pop-up):
* files.el (save-buffers-kill-emacs):
* register.el (register-preview): Use `with-current-buffer-window'
instead of `with-temp-buffer-window'.
* display.texi (Temporary Displays): Rewrite descriptions of
`with-output-to-temp-buffer' and `with-temp-buffer-window'.
* help.texi (Help Functions): Rewrite description of
`with-help-window'.
| -rw-r--r-- | doc/lispref/ChangeLog | 9 | ||||
| -rw-r--r-- | doc/lispref/display.texi | 74 | ||||
| -rw-r--r-- | doc/lispref/help.texi | 17 | ||||
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/dired.el | 2 | ||||
| -rw-r--r-- | lisp/files.el | 2 | ||||
| -rw-r--r-- | lisp/help.el | 36 | ||||
| -rw-r--r-- | lisp/register.el | 2 | ||||
| -rw-r--r-- | lisp/window.el | 40 |
9 files changed, 127 insertions, 72 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index 13b96b4ba5e..6e89c0d489b 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2014-03-16 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | * display.texi (Temporary Displays): Rewrite descriptions of | ||
| 4 | `with-output-to-temp-buffer' and `with-temp-buffer-window'. | ||
| 5 | * help.texi (Help Functions): Rewrite description of | ||
| 6 | `with-help-window'. | ||
| 7 | |||
| 1 | 2014-03-15 Dmitry Gutov <dgutov@yandex.ru> | 8 | 2014-03-15 Dmitry Gutov <dgutov@yandex.ru> |
| 2 | 9 | ||
| 3 | * display.texi (Blinking): Update WRT to the new | 10 | * display.texi (Blinking): Update WRT to the new |
| @@ -6,7 +13,7 @@ | |||
| 6 | 2014-03-14 Martin Rudalics <rudalics@gmx.at> | 13 | 2014-03-14 Martin Rudalics <rudalics@gmx.at> |
| 7 | 14 | ||
| 8 | * display.texi (Temporary Displays): Say that | 15 | * display.texi (Temporary Displays): Say that |
| 9 | with-temp-buffer-window makes its buffer current. | 16 | `with-temp-buffer-window' makes its buffer current. |
| 10 | * frames.texi (Size and Position): Describe new option | 17 | * frames.texi (Size and Position): Describe new option |
| 11 | `frame-resize-pixelwise'. Rewrite descriptions of | 18 | `frame-resize-pixelwise'. Rewrite descriptions of |
| 12 | `set-frame-size', `set-frame-height' and `set-frame-width'. | 19 | `set-frame-size', `set-frame-height' and `set-frame-width'. |
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 27f002fe5fe..8bd657b5a9b 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -1094,29 +1094,29 @@ You can use a display table to substitute other text for the ellipsis | |||
| 1094 | buffer and then present it to the user for perusal rather than for | 1094 | buffer and then present it to the user for perusal rather than for |
| 1095 | editing. Many help commands use this feature. | 1095 | editing. Many help commands use this feature. |
| 1096 | 1096 | ||
| 1097 | @defmac with-output-to-temp-buffer buffer-name forms@dots{} | 1097 | @defmac with-output-to-temp-buffer buffer-name body@dots{} |
| 1098 | This function executes @var{forms} while arranging to insert any output | 1098 | This function executes the forms in @var{body} while arranging to insert |
| 1099 | they print into the buffer named @var{buffer-name}, which is first | 1099 | any output they print into the buffer named @var{buffer-name}, which is |
| 1100 | created if necessary, and put into Help mode. Finally, the buffer is | 1100 | first created if necessary, and put into Help mode. (See the similar |
| 1101 | displayed in some window, but not selected. (See the similar | 1101 | form @code{with-temp-buffer-window} below.) Finally, the buffer is |
| 1102 | form @code{with-temp-buffer-window} below.) | 1102 | displayed in some window, but that window is not selected. |
| 1103 | 1103 | ||
| 1104 | If the @var{forms} do not change the major mode in the output buffer, | 1104 | If the forms in @var{body} do not change the major mode in the output |
| 1105 | so that it is still Help mode at the end of their execution, then | 1105 | buffer, so that it is still Help mode at the end of their execution, |
| 1106 | @code{with-output-to-temp-buffer} makes this buffer read-only at the | 1106 | then @code{with-output-to-temp-buffer} makes this buffer read-only at |
| 1107 | end, and also scans it for function and variable names to make them | 1107 | the end, and also scans it for function and variable names to make them |
| 1108 | into clickable cross-references. @xref{Docstring hyperlinks, , Tips | 1108 | into clickable cross-references. @xref{Docstring hyperlinks, , Tips for |
| 1109 | for Documentation Strings}, in particular the item on hyperlinks in | 1109 | Documentation Strings}, in particular the item on hyperlinks in |
| 1110 | documentation strings, for more details. | 1110 | documentation strings, for more details. |
| 1111 | 1111 | ||
| 1112 | The string @var{buffer-name} specifies the temporary buffer, which | 1112 | The string @var{buffer-name} specifies the temporary buffer, which need |
| 1113 | need not already exist. The argument must be a string, not a buffer. | 1113 | not already exist. The argument must be a string, not a buffer. The |
| 1114 | The buffer is erased initially (with no questions asked), and it is | 1114 | buffer is erased initially (with no questions asked), and it is marked |
| 1115 | marked as unmodified after @code{with-output-to-temp-buffer} exits. | 1115 | as unmodified after @code{with-output-to-temp-buffer} exits. |
| 1116 | 1116 | ||
| 1117 | @code{with-output-to-temp-buffer} binds @code{standard-output} to the | 1117 | @code{with-output-to-temp-buffer} binds @code{standard-output} to the |
| 1118 | temporary buffer, then it evaluates the forms in @var{forms}. Output | 1118 | temporary buffer, then it evaluates the forms in @var{body}. Output |
| 1119 | using the Lisp output functions within @var{forms} goes by default to | 1119 | using the Lisp output functions within @var{body} goes by default to |
| 1120 | that buffer (but screen display and messages in the echo area, although | 1120 | that buffer (but screen display and messages in the echo area, although |
| 1121 | they are ``output'' in the general sense of the word, are not affected). | 1121 | they are ``output'' in the general sense of the word, are not affected). |
| 1122 | @xref{Output Functions}. | 1122 | @xref{Output Functions}. |
| @@ -1124,7 +1124,7 @@ they are ``output'' in the general sense of the word, are not affected). | |||
| 1124 | Several hooks are available for customizing the behavior | 1124 | Several hooks are available for customizing the behavior |
| 1125 | of this construct; they are listed below. | 1125 | of this construct; they are listed below. |
| 1126 | 1126 | ||
| 1127 | The value of the last form in @var{forms} is returned. | 1127 | The value of the last form in @var{body} is returned. |
| 1128 | 1128 | ||
| 1129 | @example | 1129 | @example |
| 1130 | @group | 1130 | @group |
| @@ -1174,28 +1174,34 @@ displaying the temporary buffer. When the hook runs, the temporary buffer | |||
| 1174 | is current, and the window it was displayed in is selected. | 1174 | is current, and the window it was displayed in is selected. |
| 1175 | @end defvar | 1175 | @end defvar |
| 1176 | 1176 | ||
| 1177 | @defmac with-temp-buffer-window buffer-or-name action quit-function forms@dots{} | 1177 | @defmac with-temp-buffer-window buffer-or-name action quit-function body@dots{} |
| 1178 | This macro is similar to @code{with-output-to-temp-buffer}. Like that | 1178 | This macro is similar to @code{with-output-to-temp-buffer}. Like that |
| 1179 | construct, it executes @var{forms} while arranging to insert any output | 1179 | construct, it executes @var{body} while arranging to insert any output |
| 1180 | they print into the buffer named @var{buffer-or-name} and displays the | 1180 | it prints into the buffer named @var{buffer-or-name} and displays that |
| 1181 | buffer in some window. Unlike @code{with-output-to-temp-buffer}, | 1181 | buffer in some window. Unlike @code{with-output-to-temp-buffer}, |
| 1182 | however, this makes the buffer current and does not switch to Help mode. | 1182 | however, it does not automatically switch that buffer to Help mode. |
| 1183 | 1183 | ||
| 1184 | The argument @var{buffer-or-name} specifies the temporary buffer. | 1184 | Like @code{with-output-to-temp-buffer} it neither makes the buffer |
| 1185 | It can be either a buffer, which must already exist, or a string, | 1185 | specified by @var{buffer-or-name} current when executing @var{body}. |
| 1186 | in which case a buffer of that name is created if necessary. | 1186 | @findex with-current-buffer-window |
| 1187 | The buffer is marked as unmodified and read-only when | 1187 | The otherwise identical macro @code{with-current-buffer-window} can be |
| 1188 | @code{with-temp-buffer-window} exits. | 1188 | used to execute @var{body} with that buffer current. |
| 1189 | |||
| 1190 | The argument @var{buffer-or-name} specifies the temporary buffer. It | ||
| 1191 | can be either a buffer, which must already exist, or a string, in which | ||
| 1192 | case a buffer of that name is created, if necessary. The buffer is | ||
| 1193 | marked as unmodified and read-only when @code{with-temp-buffer-window} | ||
| 1194 | exits. | ||
| 1189 | 1195 | ||
| 1190 | This macro does not call @code{temp-buffer-show-function}. Rather, it | 1196 | This macro does not call @code{temp-buffer-show-function}. Rather, it |
| 1191 | passes the @var{action} argument to @code{display-buffer} in order to | 1197 | passes the @var{action} argument to @code{display-buffer} in order to |
| 1192 | display the buffer. | 1198 | display the buffer. |
| 1193 | 1199 | ||
| 1194 | The value of the last form in @var{forms} is returned, unless the | 1200 | The value of the last form in @var{body} is returned, unless the |
| 1195 | argument @var{quit-function} is specified. In that case, | 1201 | argument @var{quit-function} is specified. In that case, it is called |
| 1196 | it is called with two arguments: the window showing the buffer | 1202 | with two arguments: the window showing the buffer and the result of |
| 1197 | and the result of @var{forms}. The final return value is then | 1203 | @var{body}. The final return value is then whatever |
| 1198 | whatever @var{quit-function} returns. | 1204 | @var{quit-function} returns. |
| 1199 | 1205 | ||
| 1200 | @vindex temp-buffer-window-setup-hook | 1206 | @vindex temp-buffer-window-setup-hook |
| 1201 | @vindex temp-buffer-window-show-hook | 1207 | @vindex temp-buffer-window-show-hook |
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index 50103d3a8b3..9a763b60938 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi | |||
| @@ -649,14 +649,17 @@ This function returns the name of the help buffer, which is normally | |||
| 649 | @file{*Help*}; if such a buffer does not exist, it is first created. | 649 | @file{*Help*}; if such a buffer does not exist, it is first created. |
| 650 | @end defun | 650 | @end defun |
| 651 | 651 | ||
| 652 | @vindex help-window-select | ||
| 652 | @defmac with-help-window buffer-name body@dots{} | 653 | @defmac with-help-window buffer-name body@dots{} |
| 653 | This macro evaluates the @var{body} forms, inserting any output they | 654 | This macro evaluates @var{body} like @code{with-output-to-temp-buffer} |
| 654 | produce into a buffer named @var{buffer-name} like | 655 | (@pxref{Temporary Displays}), inserting any output produced by its forms |
| 655 | @code{with-output-to-temp-buffer} (@pxref{Temporary Displays}). | 656 | into a buffer named @var{buffer-name}. (Usually, @var{buffer-name} |
| 656 | (Usually, @var{buffer-name} should be the value returned by the | 657 | should be the value returned by the function @code{help-buffer}.) It |
| 657 | function @code{help-buffer}.) It also puts the specified buffer into | 658 | also puts the specified buffer into Help mode and displays a message |
| 658 | Help mode and displays a message telling the user how to quit and | 659 | telling the user how to quit and scroll the help window. It selects the |
| 659 | scroll the help window. | 660 | help window if the current value of the user option |
| 661 | @code{help-window-select} has been set accordingly. It returns the last | ||
| 662 | value in @var{body}. | ||
| 660 | @end defmac | 663 | @end defmac |
| 661 | 664 | ||
| 662 | @defun help-setup-xref item interactive-p | 665 | @defun help-setup-xref item interactive-p |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f800d0f24af..cf42e8ccef6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,20 @@ | |||
| 1 | 2014-03-16 Martin Rudalics <rudalics@gmx.at> | ||
| 2 | |||
| 3 | Fix behavior of with-temp-buffer-window (Bug#16816, Bug#17007). | ||
| 4 | * window.el (with-temp-buffer-window): Don't make BUFFER-OR-NAME | ||
| 5 | current (Bug#16816, Bug#17007). | ||
| 6 | (with-current-buffer-window): New macro doing the same as | ||
| 7 | `with-temp-buffer-window' but with BUFFER-OR-NAME current. | ||
| 8 | * help.el (help-print-return-message): Warn in doc-string to not | ||
| 9 | use this in `with-help-window'. | ||
| 10 | (describe-bindings-internal): Call `describe-buffer-bindings' | ||
| 11 | from within help buffer. See Juanma's scenario in (Bug#16816). | ||
| 12 | (with-help-window): Update doc-string. | ||
| 13 | * dired.el (dired-mark-pop-up): | ||
| 14 | * files.el (save-buffers-kill-emacs): | ||
| 15 | * register.el (register-preview): Use `with-current-buffer-window' | ||
| 16 | instead of `with-temp-buffer-window'. | ||
| 17 | |||
| 1 | 2014-03-16 Juanma Barranquero <lekktu@gmail.com> | 18 | 2014-03-16 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 19 | ||
| 3 | * textmodes/rst.el (rst-arabic-to-roman, rst-roman-to-arabic): | 20 | * textmodes/rst.el (rst-arabic-to-roman, rst-roman-to-arabic): |
diff --git a/lisp/dired.el b/lisp/dired.el index 2bf9f7456fe..162c9beb0c0 100644 --- a/lisp/dired.el +++ b/lisp/dired.el | |||
| @@ -3087,7 +3087,7 @@ argument or confirmation)." | |||
| 3087 | (apply function args) | 3087 | (apply function args) |
| 3088 | (let ((buffer (get-buffer-create (or buffer-or-name " *Marked Files*")))) | 3088 | (let ((buffer (get-buffer-create (or buffer-or-name " *Marked Files*")))) |
| 3089 | (with-current-buffer buffer | 3089 | (with-current-buffer buffer |
| 3090 | (with-temp-buffer-window | 3090 | (with-current-buffer-window |
| 3091 | buffer | 3091 | buffer |
| 3092 | (cons 'display-buffer-below-selected | 3092 | (cons 'display-buffer-below-selected |
| 3093 | '((window-height . fit-window-to-buffer))) | 3093 | '((window-height . fit-window-to-buffer))) |
diff --git a/lisp/files.el b/lisp/files.el index 029872506e3..6d0be9234e6 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -6534,7 +6534,7 @@ if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." | |||
| 6534 | (setq active t)) | 6534 | (setq active t)) |
| 6535 | (setq processes (cdr processes))) | 6535 | (setq processes (cdr processes))) |
| 6536 | (or (not active) | 6536 | (or (not active) |
| 6537 | (with-temp-buffer-window | 6537 | (with-current-buffer-window |
| 6538 | (get-buffer-create "*Process List*") nil | 6538 | (get-buffer-create "*Process List*") nil |
| 6539 | #'(lambda (window _value) | 6539 | #'(lambda (window _value) |
| 6540 | (with-selected-window window | 6540 | (with-selected-window window |
diff --git a/lisp/help.el b/lisp/help.el index 46094e9f6b0..14dda6456cf 100644 --- a/lisp/help.el +++ b/lisp/help.el | |||
| @@ -133,7 +133,9 @@ This function assumes that `standard-output' is the help buffer. | |||
| 133 | It computes a message, and applies the optional argument FUNCTION to it. | 133 | It computes a message, and applies the optional argument FUNCTION to it. |
| 134 | If FUNCTION is nil, it applies `message', thus displaying the message. | 134 | If FUNCTION is nil, it applies `message', thus displaying the message. |
| 135 | In addition, this function sets up `help-return-method', which see, that | 135 | In addition, this function sets up `help-return-method', which see, that |
| 136 | specifies what to do when the user exits the help buffer." | 136 | specifies what to do when the user exits the help buffer. |
| 137 | |||
| 138 | Do not call this in the scope of `with-help-window'." | ||
| 137 | (and (not (get-buffer-window standard-output)) | 139 | (and (not (get-buffer-window standard-output)) |
| 138 | (let ((first-message | 140 | (let ((first-message |
| 139 | (cond ((or | 141 | (cond ((or |
| @@ -498,7 +500,10 @@ The optional argument PREFIX, if non-nil, should be a key sequence; | |||
| 498 | then we display only bindings that start with that prefix." | 500 | then we display only bindings that start with that prefix." |
| 499 | (let ((buf (current-buffer))) | 501 | (let ((buf (current-buffer))) |
| 500 | (with-help-window (help-buffer) | 502 | (with-help-window (help-buffer) |
| 501 | (describe-buffer-bindings buf prefix menus)))) | 503 | ;; Be aware that `describe-buffer-bindings' puts its output into |
| 504 | ;; the current buffer. | ||
| 505 | (with-current-buffer (help-buffer) | ||
| 506 | (describe-buffer-bindings buf prefix menus))))) | ||
| 502 | 507 | ||
| 503 | (defun where-is (definition &optional insert) | 508 | (defun where-is (definition &optional insert) |
| 504 | "Print message listing key sequences that invoke the command DEFINITION. | 509 | "Print message listing key sequences that invoke the command DEFINITION. |
| @@ -1180,28 +1185,25 @@ Return VALUE." | |||
| 1180 | ;; providing the following additional twists: | 1185 | ;; providing the following additional twists: |
| 1181 | 1186 | ||
| 1182 | ;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and | 1187 | ;; (1) It puts the buffer in `help-mode' (via `help-mode-setup') and |
| 1183 | ;; adds cross references (via `help-mode-finish'). | 1188 | ;; adds cross references (via `help-mode-finish'). |
| 1184 | 1189 | ||
| 1185 | ;; (2) It issues a message telling how to scroll and quit the help | 1190 | ;; (2) It issues a message telling how to scroll and quit the help |
| 1186 | ;; window (via `help-window-setup'). | 1191 | ;; window (via `help-window-setup'). |
| 1187 | 1192 | ||
| 1188 | ;; (3) An option (customizable via `help-window-select') to select the | 1193 | ;; (3) An option (customizable via `help-window-select') to select the |
| 1189 | ;; help window automatically. | 1194 | ;; help window automatically. |
| 1190 | 1195 | ||
| 1191 | ;; (4) A marker (`help-window-point-marker') to move point in the help | 1196 | ;; (4) A marker (`help-window-point-marker') to move point in the help |
| 1192 | ;; window to an arbitrary buffer position. | 1197 | ;; window to an arbitrary buffer position. |
| 1193 | |||
| 1194 | ;; Note: It's usually always wrong to use `help-print-return-message' in | ||
| 1195 | ;; the body of `with-help-window'. | ||
| 1196 | (defmacro with-help-window (buffer-name &rest body) | 1198 | (defmacro with-help-window (buffer-name &rest body) |
| 1197 | "Display buffer with name BUFFER-NAME in a help window. | 1199 | "Display buffer named BUFFER-NAME in a help window. |
| 1198 | Evaluate the forms in BODY with the buffer specified by | 1200 | Evaluate the forms in BODY with standard output bound to a buffer |
| 1199 | BUFFER-NAME current, put that buffer in `help-mode', display the | 1201 | called BUFFER-NAME (creating it if it does not exist), put that |
| 1200 | buffer in a window (see `with-temp-buffer-window' for details) | 1202 | buffer in `help-mode', display the buffer in a window (see |
| 1201 | and issue a message how to deal with that \"help\" window when | 1203 | `with-temp-buffer-window' for details) and issue a message how to |
| 1202 | it's no more needed. Select the help window if the current value | 1204 | deal with that \"help\" window when it's no more needed. Select |
| 1203 | of the user option `help-window-select' says so. Return last | 1205 | the help window if the current value of the user option |
| 1204 | value in BODY." | 1206 | `help-window-select' says so. Return last value in BODY." |
| 1205 | (declare (indent 1) (debug t)) | 1207 | (declare (indent 1) (debug t)) |
| 1206 | `(progn | 1208 | `(progn |
| 1207 | ;; Make `help-window-point-marker' point nowhere. The only place | 1209 | ;; Make `help-window-point-marker' point nowhere. The only place |
diff --git a/lisp/register.el b/lisp/register.el index bfe3e35223f..1c64a9a8e64 100644 --- a/lisp/register.el +++ b/lisp/register.el | |||
| @@ -134,7 +134,7 @@ Returns a string.") | |||
| 134 | If SHOW-EMPTY is non-nil show the window even if no registers. | 134 | If SHOW-EMPTY is non-nil show the window even if no registers. |
| 135 | Format of each entry is controlled by the variable `register-preview-function'." | 135 | Format of each entry is controlled by the variable `register-preview-function'." |
| 136 | (when (or show-empty (consp register-alist)) | 136 | (when (or show-empty (consp register-alist)) |
| 137 | (with-temp-buffer-window | 137 | (with-current-buffer-window |
| 138 | buffer | 138 | buffer |
| 139 | (cons 'display-buffer-below-selected | 139 | (cons 'display-buffer-below-selected |
| 140 | '((window-height . fit-window-to-buffer))) | 140 | '((window-height . fit-window-to-buffer))) |
diff --git a/lisp/window.el b/lisp/window.el index fc2accebba8..60f13e65c4e 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -143,21 +143,22 @@ to `display-buffer'." | |||
| 143 | window)))) | 143 | window)))) |
| 144 | 144 | ||
| 145 | (defmacro with-temp-buffer-window (buffer-or-name action quit-function &rest body) | 145 | (defmacro with-temp-buffer-window (buffer-or-name action quit-function &rest body) |
| 146 | "Evaluate BODY in a buffer BUFFER-OR-NAME and show that buffer. | 146 | "Bind `standard-output' to BUFFER-OR-NAME, eval BODY, show the buffer. |
| 147 | BUFFER-OR-NAME must specify either a live buffer, or the name of | 147 | BUFFER-OR-NAME must specify either a live buffer, or the name of |
| 148 | a buffer (if it does not exist, this macro creates it). | 148 | a buffer (if it does not exist, this macro creates it). |
| 149 | 149 | ||
| 150 | Make the buffer specified by BUFFER-OR-NAME empty before running | 150 | Make the buffer specified by BUFFER-OR-NAME empty before running |
| 151 | BODY and make that buffer current for running the forms in BODY. | 151 | BODY and bind `standard-output' to that buffer, so that output |
| 152 | In addition, bind `standard-output' to that buffer, so that | 152 | generated with `prin1' and similar functions in BODY goes into |
| 153 | output generated with `prin1' and similar functions in BODY goes | 153 | that buffer. Do not make that buffer current for running the |
| 154 | into that buffer. | 154 | forms in BODY. Use `with-current-buffer-window' instead if you |
| 155 | need to run BODY with that buffer current. | ||
| 155 | 156 | ||
| 156 | At the end of BODY, mark the specified buffer unmodified and | 157 | At the end of BODY, mark the specified buffer unmodified and |
| 157 | read-only, and display it in a window (but do not select it). | 158 | read-only, and display it in a window (but do not select it). |
| 158 | The display happens by calling `display-buffer' passing it the | 159 | The display happens by calling `display-buffer' passing it the |
| 159 | ACTION argument. If `temp-buffer-resize-mode' is enabled, the | 160 | ACTION argument. If `temp-buffer-resize-mode' is enabled, the |
| 160 | corresponding window may shrink automatically. | 161 | corresponding window may be resized automatically. |
| 161 | 162 | ||
| 162 | Return the value returned by BODY, unless QUIT-FUNCTION specifies | 163 | Return the value returned by BODY, unless QUIT-FUNCTION specifies |
| 163 | a function. In that case, run that function with two arguments - | 164 | a function. In that case, run that function with two arguments - |
| @@ -177,10 +178,29 @@ that buffer temporarily current, and the window that was used to | |||
| 177 | display it temporarily selected. | 178 | display it temporarily selected. |
| 178 | 179 | ||
| 179 | This construct is similar to `with-output-to-temp-buffer' but, | 180 | This construct is similar to `with-output-to-temp-buffer' but, |
| 180 | unlike that, makes BUFFER-OR-NAME current when running BODY. | 181 | neither runs `temp-buffer-setup-hook' which usually puts the |
| 181 | Also, it neither runs `temp-buffer-setup-hook' which usually puts | 182 | buffer in Help mode, nor `temp-buffer-show-function' (the ACTION |
| 182 | the buffer in Help mode, nor `temp-buffer-show-function' (the | 183 | argument replaces this)." |
| 183 | ACTION argument replaces this)." | 184 | (declare (debug t)) |
| 185 | (let ((buffer (make-symbol "buffer")) | ||
| 186 | (window (make-symbol "window")) | ||
| 187 | (value (make-symbol "value"))) | ||
| 188 | `(let* ((,buffer (temp-buffer-window-setup ,buffer-or-name)) | ||
| 189 | (standard-output ,buffer) | ||
| 190 | ,window ,value) | ||
| 191 | (setq ,value (progn ,@body)) | ||
| 192 | (with-current-buffer ,buffer | ||
| 193 | (setq ,window (temp-buffer-window-show ,buffer ,action))) | ||
| 194 | |||
| 195 | (if (functionp ,quit-function) | ||
| 196 | (funcall ,quit-function ,window ,value) | ||
| 197 | ,value)))) | ||
| 198 | |||
| 199 | (defmacro with-current-buffer-window (buffer-or-name action quit-function &rest body) | ||
| 200 | "Evaluate BODY with a buffer BUFFER-OR-NAME current and show that buffer. | ||
| 201 | This construct is like `with-temp-buffer-window' but unlike that | ||
| 202 | makes the buffer specified by BUFFER-OR-NAME current for running | ||
| 203 | BODY." | ||
| 184 | (declare (debug t)) | 204 | (declare (debug t)) |
| 185 | (let ((buffer (make-symbol "buffer")) | 205 | (let ((buffer (make-symbol "buffer")) |
| 186 | (window (make-symbol "window")) | 206 | (window (make-symbol "window")) |