Skip to content

Commit

Permalink
improve(buffer-ident): allow truncating additional segments
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Oct 6, 2024
1 parent 8c53da4 commit bd2c3d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ the change.

;; Buffer identification.
(whale-line-segments-buffer-identification-path-segments 1)
(whale-line-segments-buffer-identification-path-segments-length 'full)

;; Org.
(whale-line-segments-org-separator ">")
Expand Down
10 changes: 8 additions & 2 deletions test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,21 @@
(:othertimes project-current)
(:mock project-root :return "/test"))

(let ((whale-line-segments-buffer-identification-path-segments 1))
(let ((whale-line-segments-buffer-identification-path-segments 1)
(whale-line-segments-buffer-identification-path-segments-length 'full))

(should (string= "two/" (whale-line-segments--buffer-identification--path-segments)))

(setq whale-line-segments-buffer-identification-path-segments 12)

(should (string= "/test/one/two/" (whale-line-segments--buffer-identification--path-segments)))

(setq whale-line-segments-buffer-identification-path-segments 0)
(setq whale-line-segments-buffer-identification-path-segments-length 1)

(should (string= "/t/o/two/" (whale-line-segments--buffer-identification--path-segments)))

(setq whale-line-segments-buffer-identification-path-segments 0
whale-line-segments-buffer-identification-path-segments-length 'full)

(should-not (whale-line-segments--buffer-identification--path-segments))

Expand Down
17 changes: 16 additions & 1 deletion whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ In project buffers segments are calculated relative to the project root."
:group 'whale-line-segments
:type 'integer)

(defcustom whale-line-segments-buffer-identification-path-segments-length 'full
"The length of path segments beyond the final one."
:group 'whale-line-segments
:type '(choice (symbol :tag "Show full length")
(integer :tag "Length of other segments")))

(defcustom whale-line-segments-window-status-separator "·"
"Separator between multiple window statuses."
:group 'whale-line-segments
Expand Down Expand Up @@ -151,7 +157,16 @@ Project buffers will only show segments deeper than root."
file))
(path (file-name-split file))
(count (min (1- (length path)) whale-line-segments-buffer-identification-path-segments))
(segments (seq-take (cdr (reverse path)) count)))
(segments (seq-take (cdr (reverse path)) count))
(max-len whale-line-segments-buffer-identification-path-segments-length)
(segments (if (and (numberp max-len)
(> (length segments) 1))

(append
(list (car segments))
(mapcar (lambda (it) (substring it 0 (min (length it) max-len))) (cdr-safe segments)))

segments)))

(concat (string-join (reverse segments) "/") "/")))

Expand Down

0 comments on commit bd2c3d8

Please sign in to comment.