Skip to content

Commit

Permalink
improve(buffer-identification): no path segments for renamed buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Jun 20, 2024
1 parent ea48c08 commit cb22547
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test/whale-line-segments-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
(ert-deftest buffer-identification--path-segments ()
:tags '(segments buffer)

(bydi ((:mock buffer-file-name :return "/test/one/two/three.el"))
(bydi ((:mock buffer-file-name :return "/test/one/two/three.el")
(:mock buffer-name :return "three.el"))

(let ((whale-line-segments-buffer-identification-path-segments 1))

Expand Down
11 changes: 9 additions & 2 deletions whale-line-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ This pre-pends the path to the buffer if so configured."
(list 'help-echo whale-line-segments--buffer-identification--additional-help)))))

(defun whale-line-segments--buffer-identification--path-segments ()
"Get preceding path segments."
"Get preceding path segments.
This can be disabled by setting
`whale-line-segments-buffer-identification-path-segments' to a
non-positive value.
Buffers that have been renamed will also yield no segments."
(and-let* (((> whale-line-segments-buffer-identification-path-segments 0))
(file (buffer-file-name (current-buffer)))
(file (buffer-file-name))
((string= (buffer-name) (file-name-nondirectory 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)))
Expand Down

0 comments on commit cb22547

Please sign in to comment.