all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Gregor Zattler <grfz@gmx.de>
Cc: 38693@debbugs.gnu.org
Subject: bug#38693: 27.0.50; tab-bar: automatic tab names should be shortened
Date: Wed, 25 Dec 2019 23:45:39 +0200	[thread overview]
Message-ID: <87a77ghyf0.fsf@mail.linkov.net> (raw)
In-Reply-To: <87sglalrwm.fsf@len.workgroup> (Gregor Zattler's message of "Mon,  23 Dec 2019 21:15:53 +0100")

[-- Attachment #1: Type: text/plain, Size: 760 bytes --]

>>> 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:


[-- Attachment #2: tab-bar-tab-name-truncated.patch --]
[-- Type: text/x-diff, Size: 1862 bytes --]

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))))
+
 \f
 (defvar tab-bar-tabs-function #'tab-bar-tabs
   "Function to get a list of tabs to display in the tab bar.

  reply	other threads:[~2019-12-25 21:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-20 17:48 bug#38693: 27.0.50; tab-bar: automatic tab names should be shortened Gregor Zattler
2019-12-21 23:36 ` Juri Linkov
2019-12-23 20:15   ` Gregor Zattler
2019-12-25 21:45     ` Juri Linkov [this message]
2020-01-20  0:36       ` Juri Linkov
2020-01-20 23:03         ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a77ghyf0.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=38693@debbugs.gnu.org \
    --cc=grfz@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.