5

On Ubuntu, I usually open more than one Emacs instances in the same time (for frontend and back development). These instances always by default take the name "Terminal" as a title as shown on this screenshot:

enter image description here

Is there a handy way to change that title?

Emacs is running inside a Gnome terminal.

Billal Begueradj
  • 345
  • 1
  • 5
  • 18
  • The variable you want to change is `frame-title-format`. See https://www.emacswiki.org/emacs/FrameTitle for some examples that one should be able to adapt to do what you want. – andrej Dec 24 '18 at 08:39
  • 1
    See also https://emacs.stackexchange.com/questions/41309/how-to-make-frame-title-format-persistent/41318#41318 – andrej Dec 24 '18 at 08:52
  • 1
    @andrej can you add these as an answer to your question? –  Dec 24 '18 at 11:30
  • @andrej thank you but `M-x set-frame-name` does not change that "Terminal" title (I do not know the right appellation for it). It is useful for me to control the name of that title so that when I press `Tab``+ `Alt`, it will be easy for me to pick the Emacs instance I need – Billal Begueradj Dec 24 '18 at 11:46
  • 1
    @BillalBegueradj Is this what we see in the screenshot emacs in the Terminal? Then emacs doesn't seem to be the right place to look at. Then this https://askubuntu.com/questions/636944/how-to-change-the-title-of-the-current-terminal-tab-using-only-the-command-line seems to be more relevant. – andrej Dec 24 '18 at 14:04
  • 1
    @andrej You might still want to have Emacs set the terminal title, for example to show the current file name. – Gilles 'SO- stop being evil' Dec 24 '18 at 14:30
  • 2
    Why not run a GUI Emacs? More things work out of the box with a GUI Emacs, including the window title. – Gilles 'SO- stop being evil' Dec 24 '18 at 14:30
  • I never use Emacs with its graphical interface – Billal Begueradj Dec 24 '18 at 14:45
  • @Gilles Yes, but in this case I don't know how to do it. I'm using GUI Emacs. Hope the answer below solves OP's question. – andrej Dec 24 '18 at 15:57

2 Answers2

5

A bit of terminology that can help you find help and documentation: for historical reasons, what the rest of the world calls a window is called frame in Emacs. What Emacs calls a window is what the rest of the world sometimes calls a pane. The same metaphor grew in different directions.

Emacs automatically sets its operating system window title (i.e. the title of the Emacs frame) to emacs@darkstar (where darkstar is the host name of the machine it's runnning on) if there's a single Emacs window, and to the buffer name if there are multiple windows. (That's multiple windows in the same instance.) However, this only applies to the title of Emacs windows, i.e. when running a GUI instance of Emacs. If you run Emacs inside a terminal, Emacs doesn't set the terminal's title out of the box.

The Emacs wiki gives a solution when Emacs is running in an xterm-like terminal. Most Unix terminal emulators, including Gnome Terminal, are xterm-like. Install the packages xterm-frobs.el and xterm-title.el (not available from a package repository that I can find) and put the following code in your init file:

(require 'xterm-title)
(xterm-title-mode 1)

Then when Emacs is running in a terminal, it will try to set the terminal emulator's title.

To configure the text that goes into the title, configure the variable frame-title-format. For example, to always show Emacs: buffer name regardless of whether there are multiple frames, use

(setq frame-title-format "Emacs: %b")

If you want to give a specific title to a specific window, use the command set-frame-name.

2

xterm-title doesn't work on Emacs 28, and has been removed from MELPA due to being unmaintained and served over insecure HTTP.

I created a simple replacement:

https://github.com/CyberShadow/term-title

  • If using `term-title`, how does one restore the old terminal title after quitting Emacs? – sam Jul 18 '23 at 02:53
  • The simple terminal protocol used by `term-title` does not allow querying the title, only setting it. The pragmatic solution is to let your shell set the title to what makes sense at the time, such as the current working directory. – Vladimir Panteleev Jul 18 '23 at 05:06