* lisp/org-colview.el (org-columns--pad-line-for-overlays): New
function extracted from `org-columns--display-here'.  The docstring
documents that this buffer mutation is a kludge -- display code should
not modify the buffer -- and adds a FIXME for replacing it with a
non-mutating display approach.
(org-columns--display-here): Use the new helper.

No behavior change.
---
 lisp/org-colview.el | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 463962493..cbd50907a 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -395,6 +395,24 @@ ORIGINAL is the real string, i.e., before it is modified by
 This is needed to later remove this relative remapping.")
 
 (defvar org-columns--read-only-string nil)
+
+(defun org-columns--pad-line-for-overlays ()
+  "Pad current line with spaces, one per column if needed.
+Kludge: column display modifies the buffer here, which it should not.
+Each column is rendered as an overlay anchored on a character, so the
+underlying line must contain at least as many characters as there are
+columns in `org-columns-current-fmt-compiled'.  Short lines (e.g.
+empty headlines) are padded with trailing spaces under
+`inhibit-read-only' so the overlays have something to attach to.
+FIXME: find a way to display columns without inserting characters."
+  (let ((columns (length org-columns-current-fmt-compiled))
+       (chars (- (line-end-position) (line-beginning-position))))
+    (when (> columns chars)
+      (save-excursion
+       (end-of-line)
+       (let ((inhibit-read-only t))
+         (insert (make-string (- columns chars) ?\s)))))))
+
 (defun org-columns--display-here (columns &optional dateline)
   "Overlay the current line with column display.
 COLUMNS is an alist (SPEC VALUE DISPLAYED).  Optional argument
@@ -417,16 +435,7 @@ DATELINE is non-nil when the face used should be
           (font (list :family (face-attribute 'default :family)))
           (face (list color font 'org-column ref-face))
           (face1 (list color font 'org-agenda-column-dateline ref-face)))
-      ;; Each column is an overlay on top of a character.  So there has
-      ;; to be at least as many characters available on the line as
-      ;; columns to display.
-      (let ((columns (length org-columns-current-fmt-compiled))
-           (chars (- (line-end-position) (line-beginning-position))))
-       (when (> columns chars)
-         (save-excursion
-           (end-of-line)
-           (let ((inhibit-read-only t))
-             (insert (make-string (- columns chars) ?\s))))))
+      (org-columns--pad-line-for-overlays)
       ;; Display columns.  Create and install the overlay for the
       ;; current column on the next character.
       (let ((i 0)
-- 
2.39.5


Reply via email to