I noticed this yesterday. If we have the following:

#+TITLE: Test
* Top
** Sub

`org-display-outline-path' will return Test//Top/Sub if we ask it to
include the "file-or-title" and we choose a seperator. This simple fix
just means `org-display-outline-path' will return Test/Top/Sub if we
ask it to include the "file-or-title" and we choose a separator.
From 34d4a9f2cc6adc14789c06c30790751e95984c04 Mon Sep 17 00:00:00 2001
From: ApollonDeParnasse <[email protected]>
Date: Thu, 18 Jun 2026 07:55:28 -0500
Subject: [PATCH] lisp/org.el: Fix `org-display-outline-path' double separator

* lisp/org.el (org-display-outline-path): Don't append the separator
to the title or filename of an outline path.

* testing/lisp/test-org.el (test-org/org-display-outline-path):
New tests for `org-display-outline-path'.
---
 lisp/org.el              |  8 +++-----
 testing/lisp/test-org.el | 41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 04eed3088..80ad8375b 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7938,7 +7938,8 @@ If JUST-RETURN-STRING is non-nil, return a string, don't display a message."
   (interactive "P" org-mode)
   (let* (case-fold-search
 	 (bfn (buffer-file-name (buffer-base-buffer)))
-         (title-prop (when (eq file-or-title 'title) (org-get-title)))
+         (prefix (when (eq file-or-title 'title)
+                   (or (org-get-title) (file-name-nondirectory bfn))))
 	 (path (and (derived-mode-p 'org-mode) (org-get-outline-path)))
 	 res)
     (when current (setq path (append path
@@ -7950,10 +7951,7 @@ If JUST-RETURN-STRING is non-nil, return a string, don't display a message."
 	  (org-format-outline-path
 	   path
 	   (1- (frame-width))
-	   (and file-or-title bfn (concat (if (and (eq file-or-title 'title) title-prop)
-					      title-prop
-					    (file-name-nondirectory bfn))
-				 separator))
+	   prefix
 	   separator))
     (add-face-text-property 0 (length res)
 			    `(:height ,(face-attribute 'default :height))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index aabf18bfa..162c5a775 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2843,6 +2843,47 @@ test <point>
 				     ">>>>>>>>>>")
 	    ">>>>>>>>..")))
 
+(ert-deftest test-org/org-display-outline-path ()
+  "Test `org-display-outline-path' specifications."
+  ;; basic
+  (org-test-with-temp-text-in-file "* Test\n* Path\n** <point>Sub"
+    (should (equal (org-display-outline-path nil nil "/" t) "Path")))
+
+  ;; current heading included
+  (org-test-with-temp-text-in-file "* Path\n* To\n** <point>Sub"
+    (should (equal (org-display-outline-path nil t "/" t) "To/Sub")))
+
+  ;; basic, ignoring title
+  (org-test-with-temp-text-in-file "#+TITLE: Test\n* Top\n** <point>Sub"
+    (should (equal (org-display-outline-path nil nil "/" t) "Top")))
+
+
+  (org-test-with-temp-text-in-file "#+TITLE: Top\n* To\n** <point>Bottom"
+    (should (equal (org-display-outline-path nil t "/" t) "To/Bottom")))
+
+  ;; with title property in file
+  (org-test-with-temp-text-in-file "#+TITLE: Test\n* Top\n** <point>Sub"
+    (should (equal (org-display-outline-path 'title nil "/" t) "Test/Top")))
+
+  ;; current heading and title
+  (org-test-with-temp-text-in-file "#+TITLE: All\n* The way\n** <point>Down"
+    (should (equal (org-display-outline-path 'title t "/" t) "All/The way/Down")))
+
+  (org-test-with-temp-text-in-file "#+TITLE: Test\n* Top\n** Sub\n* Another Top\n** <point>Another Sub"
+    (should (equal (org-display-outline-path 'title t "/" t) "Test/Another Top/Another Sub")))
+
+  ;; with filename
+  (org-test-with-temp-text-in-file "* Level 1\n** Level 2\n*** <point>Level 3"
+    (let* ((expected-file-name (file-name-base (buffer-file-name)))
+           (expected-path (format "%s/Level 1/Level 2/Level 3" expected-file-name)))
+      (should (equal (org-display-outline-path 'title t "/" t) expected-path))))
+
+  ;; custom separator
+  (org-test-with-temp-text-in-file "* Foo\n** Bar\n*** <point>Baz\n*** Foo"
+    (let* ((expected-file-name (file-name-base (buffer-file-name)))
+           (expected-path (format "%s > Foo > Bar > Baz" expected-file-name)))
+      (should (equal (org-display-outline-path 'title t " > " t) expected-path)))))
+
 (ert-deftest test-org/org-find-olp ()
   "Test `org-find-olp' specifications."
   (org-test-with-temp-text
-- 
2.54.0

Reply via email to