From cb2254719f2c5743e96aa682c82100827617d9f7 Mon Sep 17 00:00:00 2001 From: Walheimat Date: Thu, 20 Jun 2024 20:07:03 +0200 Subject: [PATCH] improve(buffer-identification): no path segments for renamed buffers --- test/whale-line-segments-test.el | 3 ++- whale-line-segments.el | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/whale-line-segments-test.el b/test/whale-line-segments-test.el index d6c5d92..cbf1957 100644 --- a/test/whale-line-segments-test.el +++ b/test/whale-line-segments-test.el @@ -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)) diff --git a/whale-line-segments.el b/whale-line-segments.el index 7e19db5..ccaee92 100644 --- a/whale-line-segments.el +++ b/whale-line-segments.el @@ -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)))