Ihor Radchenko <[email protected]> writes: >> - (org-columns (not local) columns-format) >> - (goto-char org-columns-top-level-marker) >> - (let ((columns (length org-columns-current-fmt-compiled)) >> - (has-item (assoc "ITEM" org-columns-current-fmt-compiled)) >> - table) >> + (org-columns-remove-overlays) > > Do you need to remove the overlays here?
Yes. This preserves the same-buffer cleanup that used to happen through `org-columns', for the case where column view is already active and columnview capture is invoked in the same source buffer. The old implementation called `org-columns', which starts with `org-columns-remove-overlays'. After switching capture to call `org-columns--prepare-rows' directly, this cleanup would otherwise be lost. Without it, `org-columns--prepare-rows' would reuse and move the existing buffer-local `org-columns-begin-marker' and `org-columns-top-level-marker', while the old overlays would remain in `org-columns-overlays'. That would leave stale overlays with marker/format state modified by capture. >> + (setq-local org-columns-global (not local)) >> + (let* ((rows (save-excursion >> + (org-columns--prepare-rows (not local) columns-format))) >> + (has-item (assoc "ITEM" org-columns-current-fmt-compiled)) >> + table) >> + (goto-char org-columns-top-level-marker) > > You moved goto-char *after* columns computation "(not local)". Not sure > if this is right. The old code did not move to `org-columns-top-level-marker' before computing columns either. It first called `org-columns', and `org-columns' computed the scope and set `org-columns-top-level-marker'. Only after that did `org-columns--capture-view' move to the marker. > It might be that org-columns-quit becomes unnecessary if you do not have > overlays. Unless you rely on some specific side effects of org-columns-quit. Yes, I agree. The final `org-columns-quit' is no longer needed. I replaced it with explicit cleanup of the temporary state created by `org-columns--prepare-rows': row markers, `org-columns-begin-marker', `org-columns-top-level-marker', and `org-columns-current-fmt'. Best, -- Slawomir Grochowski
>From 351e3880fe13aeb20afc229a6e6e2c62b70523a8 Mon Sep 17 00:00:00 2001 From: Slawomir Grochowski <[email protected]> Date: Mon, 15 Jun 2026 07:00:53 +0200 Subject: [PATCH v3] org-colview: Capture column view without rendering overlays * lisp/org-colview.el (org-columns--capture-view): Prepare rows directly instead of enabling column view. Read captured values from collected rows and clear row markers once consumed. Dynamic block capture only needs collected row data. Preserve cleanup of an existing column view and temporary preparation state without rendering column overlays. --- lisp/org-colview.el | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 0de4b3bd7..8c93f9d91 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1698,23 +1698,27 @@ to COLUMNS-FORMAT. All subsequent lists each represent a body row as a list whose first element is an integer indicating the outline level of the entry, and whose remaining elements are strings with the contents for the columns according to COLUMNS-FORMAT." - (org-columns (not local) columns-format) - (goto-char org-columns-top-level-marker) - (let ((columns (length org-columns-current-fmt-compiled)) - (has-item (assoc "ITEM" org-columns-current-fmt-compiled)) - table) + (org-columns-remove-overlays) + (let* ((rows (save-excursion + (org-columns--prepare-rows (not local) columns-format))) + (has-item (assoc "ITEM" org-columns-current-fmt-compiled)) + table) + (goto-char org-columns-top-level-marker) (org-map-entries (lambda () - (when (get-char-property (point) 'org-columns-key) - (let (row) - (dotimes (i columns) - (let* ((col (+ (line-beginning-position) i)) - (p (get-char-property col 'org-columns-key))) - (push (get-char-property col - (if (string= p "ITEM") - 'org-columns-value - 'org-columns-value-modified)) - row))) + (while (and rows (< (caar rows) (point))) + (set-marker (caar rows) nil) + (pop rows)) + (when-let* ((triplets (and rows + (= (caar rows) (point)) + (cdar rows)))) + (let ((row + (mapcar + (pcase-lambda (`(,spec ,value ,displayed-value)) + (if (string= (org-columns--spec-property spec) "ITEM") + value + displayed-value)) + triplets))) (unless (or (and skip-empty (let ((r (delete-dups (remove "" row)))) @@ -1722,14 +1726,19 @@ for the columns according to COLUMNS-FORMAT." (and exclude-tags (cl-some (lambda (tag) (member tag exclude-tags)) (org-get-tags)))) - (push (cons (org-reduced-level (org-current-level)) (nreverse row)) + (push (cons (org-reduced-level (org-current-level)) row) table))))) (if match (concat match (and maxlevel (format "+LEVEL<=%d" maxlevel))) (and maxlevel (format "LEVEL<=%d" maxlevel))) (and local 'tree) 'archive 'comment) - (org-columns-quit) + (dolist (row rows) (set-marker (car row) nil)) + (when (markerp org-columns-begin-marker) + (set-marker org-columns-begin-marker nil)) + (when (markerp org-columns-top-level-marker) + (set-marker org-columns-top-level-marker nil)) + (setq org-columns-current-fmt nil) ;; Add column titles and a horizontal rule in front of the table. (cons (mapcar #'org-columns--spec-title org-columns-current-fmt-compiled) (cons 'hline (nreverse table))))) -- 2.39.5
