Search code examples
emacselisp

How to force emacs update frame title?


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.


Solution

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