Skip to content

Commit

Permalink
improve(segments,tab-bar): truncate long tab names
Browse files Browse the repository at this point in the history
Adds new custom variable `whale-line-segments-tab-bar-width` and sets
it to 10 by default. Works the same as for projects.

To get the old behavior back this can be set to `nil`.
  • Loading branch information
Walheimat committed Oct 17, 2024
1 parent 0b3ddd8 commit 7eb0c29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 8 additions & 3 deletions test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,18 @@
(whale-line-segments--project))))))

(ert-deftest tab-bar ()
(let ((tab '((explicit-name . t) (name . "test-tab")))
(tab-bar-mode t))
(let ((tab '((explicit-name . t) (name . "test-tab-long-name")))
(tab-bar-mode t)
(whale-line-segments-tab-bar-width 10))

(bydi ((:mock tab-bar--current-tab :return tab)
(:risky-mock fboundp :with always))

(should (string= "test-tab" (whale-line-segments--tab-bar--identifier))))))
(should (string= (concat "test-tab-" (truncate-string-ellipsis)) (whale-line-segments--tab-bar--identifier)))

(setq whale-line-segments-tab-bar-width nil)

(should (string= "test-tab-long-name" (whale-line-segments--tab-bar--identifier))))))

;;;; VC

Expand Down
14 changes: 13 additions & 1 deletion whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ If this is a number, a name exceeding it will be truncated."
:type '(choice (integer :tag "The (padded) width")
(const :tag "Full name" nil)))

(defcustom whale-line-segments-tab-bar-width 10
"The width of the tab-bar name.
If this is a number, a name exceeding it will be truncated."
:group 'whale-line-segments
:type '(choice (integer :tag "The (padded) width")
(const :tag "Full name" nil)))

;;;; Utility

(defun whale-line-segments--decorate (_symbol &rest _args)
Expand Down Expand Up @@ -879,7 +887,11 @@ Only consider Dired buffers and file buffers."
(when-let* ((tab (tab-bar--current-tab))
(name (alist-get 'name tab)))

name))
(if (numberp whale-line-segments-tab-bar-width)
(truncate-string-to-width
name whale-line-segments-tab-bar-width nil nil
(truncate-string-ellipsis))
name)))

(defvar whale-line-segments--tab-bar
'((tab-bar-mode
Expand Down

0 comments on commit 7eb0c29

Please sign in to comment.