GNU bug report logs -
#38693
27.0.50; tab-bar: automatic tab names should be shortened
Previous Next
Reported by: Gregor Zattler <grfz <at> gmx.de>
Date: Fri, 20 Dec 2019 17:49:01 UTC
Severity: normal
Tags: fixed
Found in version 27.0.50
Fixed in version 27.0.60
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
Message #14 received at 38693 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>>> Please provide an option to dynamically shorten at least
>>> automatic tab labels in order not to overflow the tab bar into
>>> another line OR provide an option with sensible default for the
>>> max length of automatic tab labels (e.g. 23 characters per tab
>>> label would allow for at least 3 tabs on a 80 char terminal) OR
>>> something to such effect.
>>
>> Maybe such a new option:
>>
>> (defcustom tab-bar-tab-name-max 23
>>
>> and using it on the default values of tab-bar-tab-name-current,
>> tab-bar-tab-name-current-with-count, tab-bar-tab-name-all?
>
> yes, this would be helpful for me.
I'm still not sure whether to use the new option in all functions above,
or add a new function that truncates the name. It seems the latter is
better:
[tab-bar-tab-name-truncated.patch (text/x-diff, inline)]
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 0d0197eb6b..d10dd7031f 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -319,6 +319,8 @@ tab-bar-tab-name-function
tab-bar-tab-name-current)
(const :tag "Selected window buffer with window count"
tab-bar-tab-name-current-with-count)
+ (const :tag "Truncated buffer name"
+ tab-bar-tab-name-truncated)
(const :tag "All window buffers"
tab-bar-tab-name-all)
(function :tag "Function"))
@@ -350,6 +352,29 @@ tab-bar-tab-name-all
'nomini)))
", "))
+(defcustom tab-bar-tab-name-truncated-max 20
+ "Maximum length of the tab name from the current buffer.
+Effective when `tab-bar-tab-name-function' is customized
+to `tab-bar-tab-name-truncated'."
+ :type 'integer
+ :group 'tab-bar
+ :version "27.1")
+
+(defvar tab-bar-tab-name-truncated-ellipsis
+ (if (char-displayable-p ?…) "…" "..."))
+
+(defun tab-bar-tab-name-truncated ()
+ "Generate tab name from the buffer of the selected window.
+Truncate it ti the length specified by `tab-bar-tab-name-truncated-max'.
+Append ellipsis `tab-bar-tab-name-truncated-ellipsis' in this case."
+ (let ((tab-name (buffer-name (window-buffer (minibuffer-selected-window)))))
+ (if (< (length tab-name) tab-bar-tab-name-truncated-max)
+ tab-name
+ (propertize (truncate-string-to-width
+ tab-name tab-bar-tab-name-truncated-max nil nil
+ tab-bar-tab-name-truncated-ellipsis)
+ 'help-echo tab-name))))
+
(defvar tab-bar-tabs-function #'tab-bar-tabs
"Function to get a list of tabs to display in the tab bar.
This bug report was last modified 5 years and 119 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.