Skip to content

Commit

Permalink
improve(segments,project): customizable width before truncation
Browse files Browse the repository at this point in the history
Adds new custom variable `whale-line-segments-project-width` that
defaults to 10. If the name of the project exceeds this numer, it is
truncated using `truncate-string-to-width`.

The old behavior can be restored by setting this to `nil`.
  • Loading branch information
Walheimat committed Oct 14, 2024
1 parent 40a17a7 commit 0b3ddd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@
(should (string= "Project (/home/test/project/)\nmouse-1: Open root" (whale-line-segments--project--help)))))

(ert-deftest project--get--for-project ()
(let ((whale-line-segments--project--map nil))
(let ((whale-line-segments--project--map nil)
(whale-line-segments-project-width nil))

(bydi ((:always whale-line-segments--project--display-for-buffer-p)
(:always project-current)
Expand All @@ -699,6 +700,15 @@
mouse-face whale-line-highlight
help-echo "help"
local-map nil))
(whale-line-segments--project)))

(setq whale-line-segments-project-width 3)

(should (equal `("*" " " (:propertize ,(concat "pr" (truncate-string-ellipsis))
face whale-line-emphasis
mouse-face whale-line-highlight
help-echo "help"
local-map nil))
(whale-line-segments--project))))))

(ert-deftest tab-bar ()
Expand Down
14 changes: 13 additions & 1 deletion whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ In project buffers segments are calculated relative to the project root."
:group 'whale-line-segments
:type 'string)

(defcustom whale-line-segments-project-width 10
"The width of the project 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 @@ -845,11 +853,15 @@ Only consider Dired buffers and file buffers."
(when-let* ((candidate (whale-line-segments--project--display-for-buffer-p))
(project (project-current))
(name (project-name project))
(truncated (if (and (numberp whale-line-segments-project-width)
(> (length name) whale-line-segments-project-width))
(truncate-string-to-width name whale-line-segments-project-width 0 nil t)
name))
(help (whale-line-segments--project--help)))

`(,@(when-let ((decorated (whale-line-segments--decorate 'project)))
(list decorated (whale-line--spacer)))
(:propertize ,name
(:propertize ,truncated
face whale-line-emphasis
mouse-face whale-line-highlight
help-echo ,help
Expand Down

0 comments on commit 0b3ddd8

Please sign in to comment.