2

The frame title I can see in an emacs window on my computer running Windows 11 is "emacs@NEYMAN", where "Neyman" is the computer name. Is it possible to make the frame title more informative and reflect the contents of the file? Ideally, I would like to be able to specify the frame title in one of the first lines of the text file.

The reason I am asking is that I am accustomed to never combining taskbar buttons in Windows 10, but Windows 11 has removed this option. When I hover over a combined emacs button on the taskbar, I am shown the frame titles of all open emacs files, and those titles don't give me any idea of the files' contents.

There is a section (C.11 in my version) about frame titles in "GNU Emacs Manual", but I can't see how I can customize the frame title for an individual file.

Drew
  • 75,699
  • 9
  • 109
  • 225
Vlad
  • 23
  • 4
  • 1
    You can also use `frame-title-format` to specify what is displayed in the title bar. I have the following in my .emacs file `(setq-default frame-title-format '("%& %b [%m] %f - " invocation-name "@" system-name))` – rsp Nov 30 '21 at 18:07
  • @rsp: Thank you, I like the option `(setq-default frame-title-format '("%b"))` a lot. – Vlad Nov 30 '21 at 20:44

1 Answers1

2

You can use a file-variable for this, at the start or at the end of your file (as explained in the manual).

For example in a bash file, where # is used for comments, you can set the frame title statically, e.g. by adding the following line at the beginning of the file

# -*- frame-title-format: "new title" -*-

Or you can set it dynamically using e.g.

# -*- eval : (setq frame-title-format (buffer-file-name)) -*-

In a .c file, you can use

/* -*- frame-title-format: "new title" -*- */

etc.

dalanicolai
  • 6,108
  • 7
  • 23
  • Works perfectly. – Vlad Nov 30 '21 at 11:59
  • You can see that I am not knowledgeable in emacs (despite using it all the time). It would be great not to be asked to confirm that I do want to set the risky local variable "frame-title-format" every time I open the file. However, I am not given the "!" option (only "y" and "n"). Is there a simple way of achieving this? – Vlad Nov 30 '21 at 16:30
  • You can find that answer [here](https://emacs.stackexchange.com/a/18785/26163), and read more about it [here](https://www.gnu.org/software/emacs/manual/html_node/emacs/Safe-File-Variables.html) – dalanicolai Nov 30 '21 at 20:56
  • 1
    Thank you; the first link is particularly useful for non-expert readers like me. – Vlad Dec 01 '21 at 11:30
  • The answer in the comment by @rsp seems a generally more elegant solution to me (I was not aware of that option as I actually never have wanted to change the frame title, yet) – dalanicolai Dec 01 '21 at 12:14