GNU bug report logs - #79463
[PATCH] term: Add 'term-other-window' command

Previous Next

Package: emacs;

Reported by: ERIC Frederickson <ericfrederickson68 <at> gmail.com>

Date: Thu, 18 Sep 2025 01:43:02 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: ERIC Frederickson <ericfrederickson68 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: dann <at> ics.uci.edu, per <at> bothner.com, 79463 <at> debbugs.gnu.org
Subject: bug#79463: [PATCH] term: Add 'term-other-window' command
Date: Thu, 18 Sep 2025 13:09:21 -0500
>> 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".

Yes; the "C-x 4 4 M-x term RET" solution is something I found while
exploring the 'term-other-window' idea, and it led me to question
whether a new command like 'term-other-window' was necessary.  I came to
the conclusion that the existence of a stand-alone 'term-other-window'
command would still be beneficial, because it would enable users to bind
the "Term mode buffer in another window" behavior to a key without
needing to write a custom command to bind the key to.  I think it'd be
nice if they could make a binding for this behavior via
"M-x global-set-key RET" for example, especially since this is a behavior
that I've seen to be widely used among programmers.  I'd be worried
about a situation where a user thinks:

  "I like what 'C-x 4 4 M-x term RET' does, and would like to bind that
  to a more convenient key",

and then can't find a way to do so.

Of course, this argument could apply to any command that someone might
want to run after "C-x 4 4", and clearly we should not add a
'*-other-window' variant for any command '*' for which it may be wanted.
However, I feel it's a justified addition to the 'term' package
specifically because the "terminal emulator in another window" behavior
is a common pattern of interaction for terminal emulator users, and
making it more discoverable and more easily bindable via adding a
command like 'term-other-window' seems to make 'term' more friendly.

> 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.

Awesome, thank you very much for providing this feedback.

>> +*** 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.

Adopted.

> Also, the second sentence seems to be unnecessary, because NEWS
> doesn't have to advertise new features, as long as the functionality
> is clear.

Understood.

>> +;;;###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?

Agreed; will do.

I'll take some time to think about the best way to proceed here, and I
hope to send an improved patch within a few days.  I'll assume that it
would be best to send this updated patch to this same thread, unless I
hear otherwise.

Thanks everyone,
And thanks again Eli for your comments,
--
Eric Frederickson

On Thu, Sep 18, 2025 at 12:35 AM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> > Cc: per <at> bothner.com, dann <at> ics.uci.edu
> > From: ERIC Frederickson <ericfrederickson68 <at> gmail.com>
> > 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?




This bug report was last modified 1 day ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.