org-sticky-header icon indicating copy to clipboard operation
org-sticky-header copied to clipboard

Error during redisplay if org-sticky-header-always-show-header is nil

Open kings2u opened this issue 1 year ago • 2 comments

My messages buffer was constantly filling up with redisplay errors like this:

Error during redisplay: (eval (progn (setq org-sticky-header-stickyline (propertize (org-sticky-header--fetch-stickyline) 'keymap org-sticky-header-keymap)) (list (propertize " " 'display '((space :align-to 0))) 'org-sticky-header-stickyline))) signaled (wrong-type-argument stringp nil) [5 times]

https://github.com/alphapapa/org-sticky-header/issues/19#issuecomment-684128927 led me to a solution. I too had org-sticky-header-always-show-header set to nil, which caused org-sticky-header--fetch-stickyline to sometimes return nil instead of an empty string.

The below seems to solve it:

(defun org-sticky-header--fetch-stickyline ()
  "Return string of Org heading or outline path for display in header line."
  (org-with-wide-buffer
   (goto-char (window-start))
   (if (org-before-first-heading-p)
       ""
     ;; No non-header lines above top displayed header
     (if (or org-sticky-header-always-show-header
             (not (org-at-heading-p)))
         ;; Header should be shown
         (progn 
           (when (fboundp 'org-inlinetask-in-task-p)
             ;; Skip inline tasks
             (while (and (org-back-to-heading)
                         (org-inlinetask-in-task-p))
               (forward-line -1)))
           (cond
            ;; TODO: Update minimum Emacs version and use `pcase'.
            ((null org-sticky-header-full-path)
             (concat (org-sticky-header--get-prefix)
                     (org-sticky-header--heading-string)))
            ((eq org-sticky-header-full-path 'full)
             (concat (org-sticky-header--get-prefix)
                     (mapconcat 'identity
                                (nreverse
                                 (save-excursion
                                   (cl-loop collect (org-sticky-header--heading-string)
                                            while (org-up-heading-safe))))
                                org-sticky-header-outline-path-separator)))
            ((eq org-sticky-header-full-path 'reversed)
             (let ((s (concat
                       (org-sticky-header--get-prefix)
                       (mapconcat 'identity
                                  (save-excursion
                                    (cl-loop collect (org-sticky-header--heading-string)
                                             while (org-up-heading-safe)))
                                  org-sticky-header-outline-path-reversed-separator))))
               (if (> (string-width s) (window-width))
                   (concat (substring s 0 (- (window-width) 2))
                           "..")
                 s)))
            (t "")))
       ""))))

kings2u avatar Nov 06 '23 05:11 kings2u