Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force emacs update frame title?

Tags:

emacs

elisp

I customized variable frame-title-format to change frame title. However, Emacs only updates frame title when he/she wants to. Can I force Emacs to update (i.e. refresh) the title, say, after evaluating some custom functions? Here is the frame-title-format:

(setq frame-title-format "%b  %*  %n")

I want %n (display if narrowing) to take effect right after narrowing the buffer.

like image 685
Yi Wang Avatar asked Dec 02 '12 08:12

Yi Wang


2 Answers

According to https://www.gnu.org/software/emacs/manual/html_node/elisp/Mode-Line-Basics.html

(force-mode-line-update)

also forces menu bar and frame title updates.

I can confirm that a frame title containing "%*" doesn't immediately update when I first modify a buffer and (force-mode-line-update) helps. [emacs 24.5.1 on fedora 23 linux]

like image 102
Beni Cherniavsky-Paskin Avatar answered Sep 29 '22 05:09

Beni Cherniavsky-Paskin


One way in elisp to force a redisplay is to use (sit-for 0). You can define your own functions like the following:

(defun my-narrow-to-region (start end)
  (interactive "r")
  (narrow-to-region start end)
  (sit-for 0))

Note: I can't verify that this solves your problem, as I use Mac OS X, where the frame title is properly updated even without this.

Update: In an earlier version of this answer I suggested using defadvice. I realized that this wasn't a good idea as it affects all uses of the function, as it gives rise to unwanted side effects.

like image 35
Lindydancer Avatar answered Sep 29 '22 05:09

Lindydancer