Subject: Re: bug#79463: [PATCH] term: Add 'term-other-window' command

From: Eli Zaretskii <[email-masked]>
Date: Thu, 18 Sep 2025 08:35:20 +0300

> Cc: [email-masked], [email-masked]
> From: ERIC Frederickson <[email-masked]>
> Date: Wed, 17 Sep 2025 20:41:50 -0500
> 
> The patch attached to this message adds a command to lisp/term.el called
> 'term-other-window', which is a sibling command to 'term' but which
> opens the *terminal* buffer in another window.

Thanks.

> I think that the functionality of having a terminal emulator pop to
> another window can be extremely useful to those who use a terminal
> emulator within their text editor, and would hence be a great thing to
> ship with Emacs's built-in 'term' package. Additionally, I think that
> this addition would be especially useful to people coming to Emacs from
> other text/code editing environments such as VS Code, wherein the
> "pop-up terminal" / "split terminal" workflow is very widely used and is
> seen as standard.

It's a no-brainer to have a command that does something we already do,
but in another window.  However, please note that Emacs 31 is already
capable to do this generically with many/most commands, by using the
"C-x 4 4" prefix.  Thus, "C-x 4 4 M-x term RET" already does what you
want, and I'm therefore wondering whether we need a new command for
this, let alone a new keybinding "C-x 4 t".

I'm writing some comments below, both for the case we decide to accept
this patch nonetheless, and for making you aware of our conventions
for your future contributions.

> +*** New command 'term-other-window'.
> +This command is like 'term', but opens the resulting Term mode buffer in
> +another window. With the addition of this command, Emacs now gives users
> +an out-of-the-box way to use the common "pop-up terminal" workflow that
> +many users may be expecting, especially if they're coming from other
> +popular text editing environments in which this workflow is standard.

Our conventions are to leave two spaces between sentences.  Also, the
second sentence seems to be unnecessary, because NEWS doesn't have to
advertise new features, as long as the functionality is clear.

> +;;;###autoload
> +(defun term-other-window (program)
> +  "Start a terminal-emulator in a new buffer, in another window.
> +The buffer is in Term mode; see `term-mode' for the
> +commands to use in that buffer.
> +
> +\\<term-raw-map>Type \\[other-window] to switch back to another window,
> +or \\[switch-to-buffer] to switch to another buffer."
> +  (interactive (list (read-shell-command "Run program in other window: "
> +					 (or explicit-shell-file-name
> +					     (getenv "ESHELL")
> +					     shell-file-name))))
> +  (let ((prog (split-string-shell-command program)))
> +    (set-buffer (apply #'make-term "terminal" (car prog) nil (cdr prog))))
> +  (term-char-mode)
> +  (pop-to-buffer "*terminal*"))

Since this is almost an exact copy of 'term', maybe making them both
use the same subroutine with most of the body would be slightly
better.  E.g., what if someone wants to add term-other-frame?