help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open multiple separate terminal buffers with multi-term in Emacs.


From: Hongyi Zhao
Subject: Re: Open multiple separate terminal buffers with multi-term in Emacs.
Date: Wed, 2 Jun 2021 22:05:26 +0800

On Wed, Jun 2, 2021 at 9:09 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Wed, Jun 2, 2021 at 3:12 PM Joost Kremers <joostkremers@fastmail.fm> wrote:
> >
> >
> > On Wed, Jun 02 2021, Hongyi Zhao wrote:
> > > According to the tricks mentioned here,
> > > <https://iloveemacs.wordpress.com/2014/09/10/emacs-as-an-advanced-terminal-multiplexer/comment-page-1/>,
> > > I installed the following packages from melpa: multi-term,
> > > ace-jump-mode, key-chord, and yasnippet. Then I add the following
> > > configuration into my ~/.emacs.d/init.el:
> >
> > If all you want is to use multiple terminals, you don't need all those 
> > packages.
> > Only multi-term is useful for your purpose. (It's possible to do what you 
> > want
> > without any extra packages, but multi-term makes it easier.)
> >
> > So before you install ace-jump-mode, key-chord and yasnippet, I strongly 
> > suggest
> > you read about what those packages do and consider whether you really 
> > want/need
> > them.
> >
> > Now, about your question:
> >
> > > Now, I can open two new terminals by pressing:
> > >
> > > C-c T
> > > C-x 2
> >
> > This doesn't actually open two terminals. It opens one terminal and then 
> > splits
> > the window in two windows. Both windows show the *same* buffer, however.
> >
> > The description of the multi-term package (see 
> > <https://melpa.org/#/multi-term>)
> > says that you can create a new term buffer with `M-x multi-term`, which you 
> > have
> > bound to `C-c T`. So press it once to create one terminal, press it again to
> > create a second one. If you want to see both terminals at once, open one
> > terminal, split the window (C-x 2 or C-x 3) and then open a new terminal in 
> > the
> > second window.
>
> I want to see all the opened terminals at once, i.e., tiling them in
> the Emacs window. How can I write a function that takes as an argument
> the number of buffers to open to automate this process?

To be more specific, I find the following code snippet from
<https://stackoverflow.com/questions/2785950/more-than-one-emacs-terminal>:

;Here's a super lightweight little function that you can call to
automatically rename the term you're on, and then start a new term:
(defun new-ansi-term ()
  (interactive)
  (if (string= "*ansi-term*" (buffer-name))
      (rename-uniquely))
  (ansi-term "/bin/bash"))

;Then to bind that within ansi-term, I found this works:

(defvar ansi-term-after-hook nil)
(add-hook 'ansi-term-after-hook
          '(lambda ()
             (define-key term-raw-map (kbd "C-t") 'new-ansi-term)))
(defadvice ansi-term (after ansi-term-after-advice (org))
  (run-hooks 'ansi-term-after-hook))
(ad-activate 'ansi-term)


The above code can open multiple new terminals, but they are located
in different windows, and I don't know how to adjust it to let all
terminals opened using a tiling layout.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

[Prev in Thread] Current Thread [Next in Thread]