alphapapa / org-sticky-header

Show off-screen Org heading at top of window
144 stars 9 forks source link

Avoid truncating the wrong path element #3

Closed alphapapa closed 7 years ago

alphapapa commented 7 years ago

Carsten Dominik pointed out that, when the path is reversed, the closest heading element is the one that gets truncated, rather than the one farthest to the right of the screen. He sent this patch:

--- org-sticky-header.el.orig   2017-04-19 07:33:26.000000000 +0200
+++ org-sticky-header.el    2017-04-19 08:07:41.000000000 +0200
@@ -42,7 +42,6 @@
 ;;; Code:

 (require 'dash)
-(require 's)

 (defvar org-sticky-header-old-hlf nil
   "Value of the header line when entering org-sticky-header mode.")
@@ -102,14 +101,19 @@
         ('nil (concat org-sticky-header-prefix (org-get-heading t t)))
         ('full (concat org-sticky-header-prefix (org-format-outline-path (org-get-outline-path t) (window-width) nil
                                                                          org-sticky-header-outline-path-separator)))
-        ('reversed (concat org-sticky-header-prefix
-                           ;; Using "🐱" "CAT FACE" as separator character. It needs to be a single character,
-                           ;; otherwise it could get truncated and cause splitting to fail, and the chances of this
-                           ;; character being in a heading is low enough...right?
-                           (->> (org-format-outline-path (org-get-outline-path t) (window-width) nil "🐱")
-                                (s-split "🐱")
-                                (nreverse)
-                                (s-join org-sticky-header-outline-path-reversed-separator))))))))
+        ('reversed
+    (let ((s (mapconcat
+          'identity
+          (org-split-string
+           (concat org-sticky-header-prefix
+               (org-format-outline-path
+                (org-get-outline-path t)
+                1000 nil "🐱"))
+           "🐱")
+          org-sticky-header-outline-path-reversed-separator)))
+      (if (> (length s) (window-width))
+          (concat (substring s 0 (- (window-width) 2)) "..")
+        s)))))))

 ;;;###autoload
 (define-minor-mode org-sticky-header-mode