From 64ea1a178c6cb3a436eeb6783237bd603be4f5e4 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sun, 12 Dec 2021 15:50:28 +0800 Subject: [PATCH 1/5] Fix eshell for systems that do not have subprocesses * lisp/eshell/esh-cmd.el (eshell-eval-command): Use `eshell-processp' instead of `processp'. --- lisp/eshell/esh-cmd.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index a2464ad4a98..213b7ab2893 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -945,12 +945,12 @@ at the moment are: ;; In that case, unwrap the value before checking the delimiter ;; value. (if (and val - (not (processp val)) + (not (eshell-processp val)) (not (eq val t))) (error "Unmatched delimiter: %S" val) ;; Eshell-command expect a list like () to know if the ;; command should be async or not. - (or (and (processp val) delim) val))))) + (or (and (eshell-processp val) delim) val))))) (defun eshell-resume-command (proc status) "Resume the current command when a process ends." From b5354e989d8ec590ef6160f9241333a7d73628e3 Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Tue, 7 Dec 2021 23:35:31 -0500 Subject: [PATCH 2/5] Rewrite the "Quitting Windows" section of Emacs Lisp Reference * doc/lispref/windows.texi (Quitting Windows): Rewrite for clarity. (Bug#52328) --- doc/lispref/functions.texi | 7 +- doc/lispref/windows.texi | 210 +++++++++++++++++++++---------------- 2 files changed, 124 insertions(+), 93 deletions(-) diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index afb9dfcb9ec..c8f3b12080a 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -1648,9 +1648,10 @@ function will be interactive and will use the interactive spec of @var{function}. One exception: if the interactive spec of @var{function} is a function (i.e., a @code{lambda} expression or an @code{fbound} symbol rather than an expression or a string), then the interactive -spec of the combined function will be a call to that function with as sole -argument the interactive spec of the original function. To interpret the spec -received as argument, use @code{advice-eval-interactive-spec}. +spec of the combined function will be a call to that function with +the interactive spec of the original function as sole argument. To +interpret the spec received as argument, use +@code{advice-eval-interactive-spec}. Note: The interactive spec of @var{function} will apply to the combined function and should hence obey the calling convention of the combined function diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 54a5bce96c1..d988a0ff118 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -4185,97 +4185,48 @@ action alist entry (@pxref{Buffer Display Action Alists}). @node Quitting Windows @section Quitting Windows +@cindex quitting windows -When you want to get rid of a window used for displaying a buffer, you -can call @code{delete-window} or @code{delete-windows-on} -(@pxref{Deleting Windows}) to remove that window from its frame. If the -buffer is shown on a separate frame, you might want to call -@code{delete-frame} (@pxref{Deleting Frames}) instead. If, on the other -hand, a window has been reused for displaying the buffer, you might -prefer showing the buffer previously shown in that window, by calling the -function @code{switch-to-prev-buffer} (@pxref{Window History}). -Finally, you might want to either bury (@pxref{Buffer List}) or kill -(@pxref{Killing Buffers}) the window's buffer. +After a command uses @code{display-buffer} to put a buffer on the +screen, the user may decide to hide it and return to the previous +configuration of the Emacs display. We call that @dfn{quitting the +window}. The way to do this is to call @code{quit-window} while the +window used by @code{display-buffer} is the selected window. - The following command uses information on how the window for -displaying the buffer was obtained in the first place, thus attempting -to automate the above decisions for you. +The right way to restore the previous configuration of the display +depends on what was done to the window where the buffer now appears. +It might be right to delete that window, or delete its frame, or just +display another buffer in that window. One complication is that the +user may have changed the window configuration since the act of +displaying that buffer, and it would be undesirable to undo the user's +explicitly requested changes. + +To enable @code{quit-window} to do the right thing, +@code{display-buffer} saves information about what it did in the +window's @code{quit-restore} parameter (@pxref{Window Parameters}). @deffn Command quit-window &optional kill window This command quits @var{window} and buries its buffer. The argument @var{window} must be a live window and defaults to the selected one. With prefix argument @var{kill} non-@code{nil}, it kills the buffer -instead of burying it. It calls the function @code{quit-restore-window} -described next to deal with the window and its buffer. +instead of burying it. @vindex quit-window-hook -The functions in @code{quit-window-hook} are run before doing anything -else. +The function @code{quit-window} first runs @code{quit-window-hook}. +Then it calls the function @code{quit-restore-window}, described next, +which does the hard work. @end deffn +You can get more control by calling @code{quit-restore-window} instead. + @defun quit-restore-window &optional window bury-or-kill This function handles @var{window} and its buffer after quitting. The optional argument @var{window} must be a live window and defaults to -the selected one. The function's behavior is determined by the four -elements of the list specified by @var{window}'s @code{quit-restore} -parameter (@pxref{Window Parameters}). - -The first element of the @code{quit-restore} parameter is one of the -symbols @code{window}, meaning that the window has been specially -created by @code{display-buffer}; @code{frame}, a separate frame has -been created; @code{same}, the window has only ever displayed this -buffer; or @code{other}, the window showed another buffer before. -@code{frame} and @code{window} affect how the window is quit, while -@code{same} and @code{other} affect the redisplay of buffers -previously shown in @var{window}. - -The parameter's second element is either one of the symbols -@code{window} or @code{frame}, or a list whose elements are the buffer -shown in @var{window} before, that buffer's window start and window -point positions, and @var{window}'s height at that time. If that -buffer is still live when @var{window} is quit, then this function may -reuse @var{window} to display it. - -The third element is the window selected at the time the parameter was -created. If this function deletes @var{window}, it subsequently tries -to reselect the window named by that element. - -The fourth element is the buffer whose display caused the creation of -this parameter. This function may delete @var{window} if and only if -it still shows that buffer. - -This function will try to delete @var{window} if and only if (1) the -first element of its @code{quit-restore} parameter is either -@code{window} or @code{frame}, (2) the window has no history of -previously-displayed buffers and (3) the fourth element of the -@code{quit-restore} parameter specifies the buffer currently displayed -in @var{window}. If @var{window} is part of an atomic window -(@pxref{Atomic Windows}), it will try to delete the root of that -atomic window instead. In either case, it tries to avoid signaling an -error when @var{window} cannot be deleted. - -If @var{window} shall be deleted, is the only window on its frame and -there are other frames on that frame's terminal, the value of the -optional argument @var{bury-or-kill} determines how to proceed with -the window. If @var{bury-or-kill} equals @code{kill}, the frame is -deleted unconditionally. Otherwise, the fate of the frame is -determined by calling @code{frame-auto-hide-function} (see below) with -that frame as sole argument. - -If the second element of the @code{quit-restore} parameter is a list -of a buffer, a window start (@pxref{Window Start and End}) and a -window point (@pxref{Window Point}), and that buffer is still live, -the buffer will be displayed, and start and point set accordingly. -If, in addition, @var{window}'s buffer was temporarily resized, this -function will also try to restore the original height of @var{window}. - -Otherwise, if @var{window} was previously used for displaying other -buffers (@pxref{Window History}), the most recent buffer in that -history will be displayed. In either case, if @var{window} is not -deleted, its @code{quit-restore} parameter is reset to @code{nil}. +the selected one. The function takes account of the @var{window}'s +@code{quit-restore} parameter. The optional argument @var{bury-or-kill} specifies how to deal with -@var{window}'s buffer. The following values are handled: +@var{window}'s buffer. The following values are meaningful: @table @code @item nil @@ -4285,25 +4236,106 @@ consequence, if @var{window} is not deleted, invoking @item append This means that if @var{window} is not deleted, its buffer is moved to -the end of @var{window}'s list of previous buffers, so it's less likely -that a future invocation of @code{switch-to-prev-buffer} will switch to -it. Also, it moves the buffer to the end of the frame's buffer list. +the end of @var{window}'s list of previous buffers (@pxref{Window +History}), so it's less likely that future invocations of +@code{switch-to-prev-buffer} will switch to it. Also, it moves the +buffer to the end of the frame's buffer list (@pxref{Buffer List}). @item bury This means that if @var{window} is not deleted, its buffer is removed -from @var{window}'s list of previous buffers. Also, it moves the buffer -to the end of the frame's buffer list. This value provides the most -reliable remedy to not have @code{switch-to-prev-buffer} switch to this -buffer again without killing the buffer. +from @var{window}'s list of previous buffers. Also, it moves the +buffer to the end of the frame's buffer list. This is the most +reliable way to prevent @code{switch-to-prev-buffer} from switching to +this buffer again, short of killing the buffer. @item kill This means to kill @var{window}'s buffer. @end table +The argument @var{bury-or-kill} also specifies what to do with +@var{window}'s frame when @var{window} should be deleted, if it is the +only window on its frame, and there are other frames on that frame's +terminal. If @var{bury-or-kill} equals @code{kill}, it means to +delete the frame. Otherwise, the fate of the frame is determined by +calling @code{frame-auto-hide-function} (see below) with that frame as +sole argument. + +This function always sets @var{window}'s @code{quit-restore} parameter +to @code{nil} unless it deletes the window. +@end defun + +The window @var{window}'s @code{quit-restore} parameter (@pxref{Window +Parameters}) should be @code{nil} or a list of four elements: +@c FIXME: describe what quit-restore-window does if this is nil. + +@lisp +(@var{method} @var{obuffer} @var{owindow} @var{this-buffer}) +@end lisp + +The first element, @var{method}, is one of the four symbols +@code{window}, @code{frame}, @code{same} and @code{other}. +@code{frame} and @code{window} control how to delete @var{window}, +while @code{same} and @code{other} control displaying some other +buffer in it. + +Specifically, @code{window} means that the window has been specially +created by @code{display-buffer}; @code{frame} means that a separate +frame has been created; @code{same}, that the window has only ever +displayed this buffer; @code{other}, that the window showed another +buffer before. + +The second element, @var{obuffer}, is either one of the symbols +@code{window} or @code{frame}, or a list of the form + +@lisp +(@var{prev-buffer} @var{prev-window-start} @var{prev-window-point} @var{height}) +@end lisp + +@noindent +which says which buffer was shown in @var{window} before, that +buffer's window start (@pxref{Window Start and End}) and window point +(@pxref{Window Point}) positions at that time, and +@var{window}'s height at that time. If @var{prev-buffer} is still +live when quitting @var{window}, quitting the window may reuse +@var{window} to display @var{prev-buffer}. + +The third element, @var{owindow}, is the window that was selected +just before the displaying was done. If quitting deletes +@var{window}, it tries to select @var{owindow}. + +The fourth element, @var{this-buffer}, is the buffer whose displaying +set the @code{quit-restore} parameter. Quitting @var{window} may delete +that window only if it still shows that buffer. + +Quitting @var{window} tries to delete it if and only if (1) +@var{method} is either @code{window} or @code{frame}, (2) the window +has no history of previously-displayed buffers and (3) +@var{this-buffer} equals the buffer currently displayed in +@var{window}. If @var{window} is part of an atomic window +(@pxref{Atomic Windows}), quitting will try to delete the root of that +atomic window instead. In either case, it tries to avoid signaling an +error when @var{window} cannot be deleted. + +If @var{obuffer} is a list, and @var{prev-buffer} is still live, +quitting displays @var{prev-buffer} in @var{window} according to the +rest of the elements of @var{obuffer}. This includes resizing the +window to @var{height} if it was temporarily resized to display +@var{this-buffer}. + +Otherwise, if @var{window} was previously used for displaying other +buffers (@pxref{Window History}), the most recent buffer in that +history will be displayed. + +@ignore +@c FIXME: Should we document display-buffer-reuse-window? +If we document display-buffer-record-window, it should be with @defun. +And maybe not here. + + Typically, the display routines run by @code{display-buffer} will set -the @code{quit-restore} window parameter correctly. It's also -possible to set it manually, using the following code for displaying -@var{buffer} in @var{window}: +the @code{quit-restore} window parameter correctly. You can also set +it manually, using the following code for displaying @var{buffer} in +@var{window}: @example @group @@ -4317,11 +4349,10 @@ possible to set it manually, using the following code for displaying Setting the window history to @code{nil} ensures that a future call to @code{quit-window} can delete the window altogether. +@end ignore -@end defun - -The following option specifies how to deal with a frame containing just -one window that should be either quit, or whose buffer should be buried. +The following option specifies a function to do the right thing with a +frame containing one window when quitting that window. @defopt frame-auto-hide-function The function specified by this option is called to automatically hide @@ -4350,7 +4381,6 @@ that frame's @code{auto-hide-function} frame parameter (@pxref{Frame Interaction Parameters}). @end defopt - @node Side Windows @section Side Windows @cindex side windows From ea8422204f1fbd354e4d25b8c99fd4916db87296 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 12 Dec 2021 20:20:51 +0200 Subject: [PATCH 3/5] * make-dist (manifest): Filter out msdos/autogen/* files. --- make-dist | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/make-dist b/make-dist index eb040150d9d..b069130ca61 100755 --- a/make-dist +++ b/make-dist @@ -392,9 +392,11 @@ manifest=MANIFEST # other way when adding or deleting a distributed file while not using Git. # TODO: maybe this should ignore $update, and always update MANIFEST # if .git is present. +# Filter out the files in msdos/autogen/, as they aren't useful in the +# tarball, and get in the way during the build of the MSDOS port. if ( [ $update = yes ] || [ ! -f $manifest ] ) && [ -r .git ]; then echo "Updating $manifest" - git ls-files > $manifest || exit + git ls-files | sed -e '/^msdos\/autogen\//d' > $manifest || exit printf '%s\n' $possibly_non_vc_files $info_files >>$manifest || exit sort -u -o $manifest $manifest || exit fi From 62139aeb42e286b51afe7dd6045ba7f5519593fc Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 12 Dec 2021 20:25:54 +0200 Subject: [PATCH 4/5] * lisp/tab-bar.el (tab-bar-switch-to-last-tab): Add 'abs' for precautions. https://lists.gnu.org/archive/html/emacs-devel/2021-11/msg01149.html --- lisp/tab-bar.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index cfd766d5495..68d28306dd9 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1175,7 +1175,7 @@ which means the last tab on the tab bar. For example, `C-u 2 -9' selects the tab before the last tab." (interactive "p") (tab-bar-select-tab (- (length (funcall tab-bar-tabs-function)) - (1- (or arg 1))))) + (1- (abs (or arg 1)))))) (defun tab-bar-switch-to-recent-tab (&optional arg) "Switch to ARGth most recently visited tab. From 9bd3f78645e14fdbaf3a569df5e0a52249c4f90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= Date: Mon, 13 Dec 2021 05:17:00 +0100 Subject: [PATCH 5/5] Make `M-x run-python' select the window again Interactively, we want M-x run-python to focus the interpreter buffer. The previous code failed in two ways: - the call to 'display-buffer' was not reached if an interpreter was already running, - set-buffer is ineffectual if the interpreter's window is not selected: once Emacs returns to the command loop, the current buffer will revert back to what the selected window contains. * lisp/progmodes/python.el (python-shell-make-comint): Handle the SHOW argument regardless of whether an interpreter buffer exists, and use pop-to-buffer to select the window. (run-python): Delegate buffer management to 'python-shell-make-comint'. * test/lisp/progmodes/python-tests.el (python-tests--run-python-selects-window): Rename from 'python-tests--bug31398', and adjust assertions (bug#52380). --- lisp/progmodes/python.el | 4 ++-- test/lisp/progmodes/python-tests.el | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index f1c3e75bb73..6357c4f2d3e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -2994,8 +2994,9 @@ killed." (mapconcat #'identity args " "))) (with-current-buffer buffer (inferior-python-mode)) - (when show (display-buffer buffer)) (and internal (set-process-query-on-exit-flag process nil)))) + (when show + (pop-to-buffer proc-buffer-name)) proc-buffer-name)))) ;;;###autoload @@ -3027,7 +3028,6 @@ process buffer for a list of commands.)" (python-shell-make-comint (or cmd (python-shell-calculate-command)) (python-shell-get-process-name dedicated) show))) - (set-buffer buffer) (get-buffer-process buffer))) (defun run-python-internal () diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 6ab9c62746e..752a4f0113f 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -5448,15 +5448,21 @@ buffer with overlapping strings." (python-nav-end-of-statement))) (should (eolp)))) -;; After call `run-python' the buffer running the python process is current. -(ert-deftest python-tests--bug31398 () - "Test for https://debbugs.gnu.org/31398 ." +;; Interactively, `run-python' focuses the buffer running the +;; interpreter. +(ert-deftest python-tests--run-python-selects-window () + "Test for bug#31398. See also bug#44421 and bug#52380." (skip-unless (executable-find python-tests-shell-interpreter)) - (let ((buffer (process-buffer (run-python nil nil 'show)))) - (should (eq buffer (current-buffer))) + (let* ((buffer (process-buffer (run-python nil nil 'show))) + (window (get-buffer-window buffer))) + ;; We look at `selected-window' rather than `current-buffer' + ;; because as `(elisp)Current buffer' says, the latter will only + ;; be synchronized with the former when returning to the "command + ;; loop"; until then, `current-buffer' can change arbitrarily. + (should (eq window (selected-window))) (pop-to-buffer (other-buffer)) (run-python nil nil 'show) - (should (eq buffer (current-buffer))))) + (should (eq window (selected-window))))) (ert-deftest python-tests--fill-long-first-line () (should