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

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

bug#57848: 29.0.50; Problems with private tab-line-tab-name-function


From: Juri Linkov
Subject: bug#57848: 29.0.50; Problems with private tab-line-tab-name-function
Date: Sun, 30 Oct 2022 09:24:00 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

> (1) When using `tab-line-mode' together with
>
> #+begin_src emacs-lisp
> (setq-local tab-line-tab-name-function
>             (lambda (_b &optional _bs) "%b"))
> #+end_src
>
> I get tabs that are all named equally - all named after the currently
> active tab's buffer.
>
> I didn't know that mode-line format sequences are valid.  Are they?  If
> they are (would be nice), could we document this, fix the behavior (I
> guess the interpretation is done in the context of a wrong current
> buffer), and maybe allow all kinds of mode-line-format values, like
> lists?

All mode-line format sequences are valid, but only in the context
of the right buffer.  So you can use such tab-name function:

#+begin_src emacs-lisp
(setq tab-line-tab-name-function
      (lambda (b &optional _bs)
        (format-mode-line "%b" 'tab-line-tab nil b)))
#+end_src

This confirms that all mode-line format sequences can be used:

#+begin_src emacs-lisp
(setq tab-line-tab-name-function
      (lambda (b &optional _bs)
        (format-mode-line mode-line-format 'tab-line-tab nil b)))
#+end_src

> (2) What I actually had tried was to get nicely named tabs for Info
> buffers (including the clones created with M-n).
>
> I tried with something like this:
>
> #+begin_src emacs-lisp
> (add-hook 'Info-mode-hook
>           (defun my-setup-tab-line-for-Info-mode ()
>             (tab-line-mode +1)
>             (setq-local
>              tab-line-tab-name-function
>              (lambda (b &optional _bs)
>                (with-current-buffer b
>                  (apply
>                   #'concat
>                   (cdr mode-line-buffer-identification)))))))
> #+end_src

Using the same as above, this could look like:

#+begin_src emacs-lisp
(add-hook 'Info-mode-hook
          (defun my-setup-tab-line-for-Info-mode ()
            (tab-line-mode +1)
            (setq-local
             tab-line-tab-name-function
             (lambda (b &optional _bs)
               (with-current-buffer b
                 (if (derived-mode-p 'Info-mode)
                     (format-mode-line
                      (apply
                       #'concat
                       (cdr mode-line-buffer-identification))
                      'tab-line-tab nil b)
                   (buffer-name b)))))))
#+end_src

> but with that the tab names are not updated while browsing Info pages.
>
> The problem here seems to be related to the caching mechanism that
> doesn't recognize the need to update; invalidating the cache explicitly
> like with this very ugly hack:
>
> #+begin_src emacs-lisp
> (add-variable-watcher
>  'mode-line-buffer-identification
>  (defun my-Info-mode-line-buffer-identification-watcher
>      (_symbol _newval _operation where)
>    (when (and (eq where (current-buffer))
>               (derived-mode-p 'Info-mode))
>      (set-window-parameter nil 'tab-line-cache nil))))
> #+end_src
>
> makes it work.
>
> It would be nice to provide a way to get cases like this work , e.g. by
> allowing to specify buffer-local cache key returning functions.

A user-defined cache key function is a good idea.
Please send an example of such function for Info,
so I could test the implementation.





reply via email to

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