diff options
author | Juri Linkov <juri@linkov.net> | 2020-01-21 01:03:37 +0200 |
---|---|---|
committer | Juri Linkov <juri@linkov.net> | 2020-01-21 01:03:37 +0200 |
commit | 3ba0db41e3fcfdc47368e9e6fd7cbe45230ba88b (patch) | |
tree | f6deb0eb40f22956805ffe1335d037220eb57a12 /lisp/tab-bar.el | |
parent | 7dd065fc7bd561b09f79142974b8ada052dfa7d1 (diff) | |
download | emacs-3ba0db41e3fcfdc47368e9e6fd7cbe45230ba88b.tar.gz |
Allow optional truncation of tab names in tab-bar and tab-line (bug#38693)
* lisp/tab-line.el (tab-line-tab-name-truncated-max): New defcustom.
(tab-line-tab-name-truncated-buffer): Use tab-line-tab-name-truncated-max
consistently with similar options in tab-bar.el.
(tab-line-tabs-limit): Remove variable.
(tab-line-tabs-window-buffers): Remove use of tab-line-tabs-limit
that was an experimental feature before horizontal scrolling was implemented.
(tab-line-close-tab-function): Rename from tab-line-close-tab-action
and allow a customizaed function as option.
(tab-line-close-tab): Call function if tab-line-close-tab-function
is customized to a function.
* lisp/tab-bar.el (tab-bar-tab-name-function): Add option
tab-bar-tab-name-truncated.
(tab-bar-tab-name-truncated-max): New defcustom.
(tab-bar-tab-name-truncated-ellipsis): New variable.
(tab-bar-tab-name-truncated): New function.
Diffstat (limited to 'lisp/tab-bar.el')
-rw-r--r-- | lisp/tab-bar.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index e4ff7325844..f70fb6baeee 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -319,6 +319,8 @@ from all windows in the window configuration." 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 @@ Also add the number of windows in the window configuration." '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 to 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. |