aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2014-03-16 10:26:58 +0100
committerMartin Rudalics2014-03-16 10:26:58 +0100
commitb92631bf71bb029af7a5b4bcf3acd6b4484a4afa (patch)
tree3c9770441c520b285461935751643fcc8aa5e43c
parentd939cbea79c40740333cf779296d94ee265eceb5 (diff)
downloademacs-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/ChangeLog9
-rw-r--r--doc/lispref/display.texi74
-rw-r--r--doc/lispref/help.texi17
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/dired.el2
-rw-r--r--lisp/files.el2
-rw-r--r--lisp/help.el36
-rw-r--r--lisp/register.el2
-rw-r--r--lisp/window.el40
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 @@
12014-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
12014-03-15 Dmitry Gutov <dgutov@yandex.ru> 82014-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 @@
62014-03-14 Martin Rudalics <rudalics@gmx.at> 132014-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
1094buffer and then present it to the user for perusal rather than for 1094buffer and then present it to the user for perusal rather than for
1095editing. Many help commands use this feature. 1095editing. 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{}
1098This function executes @var{forms} while arranging to insert any output 1098This function executes the forms in @var{body} while arranging to insert
1099they print into the buffer named @var{buffer-name}, which is first 1099any output they print into the buffer named @var{buffer-name}, which is
1100created if necessary, and put into Help mode. Finally, the buffer is 1100first created if necessary, and put into Help mode. (See the similar
1101displayed in some window, but not selected. (See the similar 1101form @code{with-temp-buffer-window} below.) Finally, the buffer is
1102form @code{with-temp-buffer-window} below.) 1102displayed in some window, but that window is not selected.
1103 1103
1104If the @var{forms} do not change the major mode in the output buffer, 1104If the forms in @var{body} do not change the major mode in the output
1105so that it is still Help mode at the end of their execution, then 1105buffer, 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 1106then @code{with-output-to-temp-buffer} makes this buffer read-only at
1107end, and also scans it for function and variable names to make them 1107the end, and also scans it for function and variable names to make them
1108into clickable cross-references. @xref{Docstring hyperlinks, , Tips 1108into clickable cross-references. @xref{Docstring hyperlinks, , Tips for
1109for Documentation Strings}, in particular the item on hyperlinks in 1109Documentation Strings}, in particular the item on hyperlinks in
1110documentation strings, for more details. 1110documentation strings, for more details.
1111 1111
1112The string @var{buffer-name} specifies the temporary buffer, which 1112The string @var{buffer-name} specifies the temporary buffer, which need
1113need not already exist. The argument must be a string, not a buffer. 1113not already exist. The argument must be a string, not a buffer. The
1114The buffer is erased initially (with no questions asked), and it is 1114buffer is erased initially (with no questions asked), and it is marked
1115marked as unmodified after @code{with-output-to-temp-buffer} exits. 1115as 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
1118temporary buffer, then it evaluates the forms in @var{forms}. Output 1118temporary buffer, then it evaluates the forms in @var{body}. Output
1119using the Lisp output functions within @var{forms} goes by default to 1119using the Lisp output functions within @var{body} goes by default to
1120that buffer (but screen display and messages in the echo area, although 1120that buffer (but screen display and messages in the echo area, although
1121they are ``output'' in the general sense of the word, are not affected). 1121they 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).
1124Several hooks are available for customizing the behavior 1124Several hooks are available for customizing the behavior
1125of this construct; they are listed below. 1125of this construct; they are listed below.
1126 1126
1127The value of the last form in @var{forms} is returned. 1127The 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
1174is current, and the window it was displayed in is selected. 1174is 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{}
1178This macro is similar to @code{with-output-to-temp-buffer}. Like that 1178This macro is similar to @code{with-output-to-temp-buffer}. Like that
1179construct, it executes @var{forms} while arranging to insert any output 1179construct, it executes @var{body} while arranging to insert any output
1180they print into the buffer named @var{buffer-or-name} and displays the 1180it prints into the buffer named @var{buffer-or-name} and displays that
1181buffer in some window. Unlike @code{with-output-to-temp-buffer}, 1181buffer in some window. Unlike @code{with-output-to-temp-buffer},
1182however, this makes the buffer current and does not switch to Help mode. 1182however, it does not automatically switch that buffer to Help mode.
1183 1183
1184The argument @var{buffer-or-name} specifies the temporary buffer. 1184Like @code{with-output-to-temp-buffer} it neither makes the buffer
1185It can be either a buffer, which must already exist, or a string, 1185specified by @var{buffer-or-name} current when executing @var{body}.
1186in which case a buffer of that name is created if necessary. 1186@findex with-current-buffer-window
1187The buffer is marked as unmodified and read-only when 1187The otherwise identical macro @code{with-current-buffer-window} can be
1188@code{with-temp-buffer-window} exits. 1188used to execute @var{body} with that buffer current.
1189
1190The argument @var{buffer-or-name} specifies the temporary buffer. It
1191can be either a buffer, which must already exist, or a string, in which
1192case a buffer of that name is created, if necessary. The buffer is
1193marked as unmodified and read-only when @code{with-temp-buffer-window}
1194exits.
1189 1195
1190This macro does not call @code{temp-buffer-show-function}. Rather, it 1196This macro does not call @code{temp-buffer-show-function}. Rather, it
1191passes the @var{action} argument to @code{display-buffer} in order to 1197passes the @var{action} argument to @code{display-buffer} in order to
1192display the buffer. 1198display the buffer.
1193 1199
1194The value of the last form in @var{forms} is returned, unless the 1200The value of the last form in @var{body} is returned, unless the
1195argument @var{quit-function} is specified. In that case, 1201argument @var{quit-function} is specified. In that case, it is called
1196it is called with two arguments: the window showing the buffer 1202with two arguments: the window showing the buffer and the result of
1197and the result of @var{forms}. The final return value is then 1203@var{body}. The final return value is then whatever
1198whatever @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{}
653This macro evaluates the @var{body} forms, inserting any output they 654This macro evaluates @var{body} like @code{with-output-to-temp-buffer}
654produce 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}). 656into a buffer named @var{buffer-name}. (Usually, @var{buffer-name}
656(Usually, @var{buffer-name} should be the value returned by the 657should be the value returned by the function @code{help-buffer}.) It
657function @code{help-buffer}.) It also puts the specified buffer into 658also puts the specified buffer into Help mode and displays a message
658Help mode and displays a message telling the user how to quit and 659telling the user how to quit and scroll the help window. It selects the
659scroll the help window. 660help window if the current value of the user option
661@code{help-window-select} has been set accordingly. It returns the last
662value 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 @@
12014-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
12014-03-16 Juanma Barranquero <lekktu@gmail.com> 182014-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.
133It computes a message, and applies the optional argument FUNCTION to it. 133It computes a message, and applies the optional argument FUNCTION to it.
134If FUNCTION is nil, it applies `message', thus displaying the message. 134If FUNCTION is nil, it applies `message', thus displaying the message.
135In addition, this function sets up `help-return-method', which see, that 135In addition, this function sets up `help-return-method', which see, that
136specifies what to do when the user exits the help buffer." 136specifies what to do when the user exits the help buffer.
137
138Do 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;
498then we display only bindings that start with that prefix." 500then 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.
1198Evaluate the forms in BODY with the buffer specified by 1200Evaluate the forms in BODY with standard output bound to a buffer
1199BUFFER-NAME current, put that buffer in `help-mode', display the 1201called BUFFER-NAME (creating it if it does not exist), put that
1200buffer in a window (see `with-temp-buffer-window' for details) 1202buffer in `help-mode', display the buffer in a window (see
1201and issue a message how to deal with that \"help\" window when 1203`with-temp-buffer-window' for details) and issue a message how to
1202it's no more needed. Select the help window if the current value 1204deal with that \"help\" window when it's no more needed. Select
1203of the user option `help-window-select' says so. Return last 1205the help window if the current value of the user option
1204value 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.")
134If SHOW-EMPTY is non-nil show the window even if no registers. 134If SHOW-EMPTY is non-nil show the window even if no registers.
135Format of each entry is controlled by the variable `register-preview-function'." 135Format 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.
147BUFFER-OR-NAME must specify either a live buffer, or the name of 147BUFFER-OR-NAME must specify either a live buffer, or the name of
148a buffer (if it does not exist, this macro creates it). 148a buffer (if it does not exist, this macro creates it).
149 149
150Make the buffer specified by BUFFER-OR-NAME empty before running 150Make the buffer specified by BUFFER-OR-NAME empty before running
151BODY and make that buffer current for running the forms in BODY. 151BODY and bind `standard-output' to that buffer, so that output
152In addition, bind `standard-output' to that buffer, so that 152generated with `prin1' and similar functions in BODY goes into
153output generated with `prin1' and similar functions in BODY goes 153that buffer. Do not make that buffer current for running the
154into that buffer. 154forms in BODY. Use `with-current-buffer-window' instead if you
155need to run BODY with that buffer current.
155 156
156At the end of BODY, mark the specified buffer unmodified and 157At the end of BODY, mark the specified buffer unmodified and
157read-only, and display it in a window (but do not select it). 158read-only, and display it in a window (but do not select it).
158The display happens by calling `display-buffer' passing it the 159The display happens by calling `display-buffer' passing it the
159ACTION argument. If `temp-buffer-resize-mode' is enabled, the 160ACTION argument. If `temp-buffer-resize-mode' is enabled, the
160corresponding window may shrink automatically. 161corresponding window may be resized automatically.
161 162
162Return the value returned by BODY, unless QUIT-FUNCTION specifies 163Return the value returned by BODY, unless QUIT-FUNCTION specifies
163a function. In that case, run that function with two arguments - 164a 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
177display it temporarily selected. 178display it temporarily selected.
178 179
179This construct is similar to `with-output-to-temp-buffer' but, 180This construct is similar to `with-output-to-temp-buffer' but,
180unlike that, makes BUFFER-OR-NAME current when running BODY. 181neither runs `temp-buffer-setup-hook' which usually puts the
181Also, it neither runs `temp-buffer-setup-hook' which usually puts 182buffer in Help mode, nor `temp-buffer-show-function' (the ACTION
182the buffer in Help mode, nor `temp-buffer-show-function' (the 183argument replaces this)."
183ACTION 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.
201This construct is like `with-temp-buffer-window' but unlike that
202makes the buffer specified by BUFFER-OR-NAME current for running
203BODY."
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"))