Hello, Oh, right, I messed the scopes.
Best Regards, Slava Barinov Ihor Radchenko <yanta...@posteo.net> writes: > Slava Barinov <raysl...@gmail.com> writes: > >> Okay, in that case we can just merge two loops into one and filter out the >> #+TBLFM line. This version works for me. >> + (when (and (string-match-p "^#" (substring-no-properties line)) >> + (not (string-match-p "^#\\+TBLFM:" >> (substring-no-properties line)))) >> + (insert line "\n"))) > > What if there is no :tblfm parameter provided?
>From d17a808c373e65f0de5b71d429aca9666dbef8f0 Mon Sep 17 00:00:00 2001 From: Slava Barinov <raysl...@gmail.com> Date: Fri, 21 Feb 2025 20:45:41 +0900 Subject: [PATCH] lisp/org-collector.el (org-dblock-write:propview): Add support for the :tblfm keyword. --- lisp/org-collector.el | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lisp/org-collector.el b/lisp/org-collector.el index b645d3a..b41d311 100644 --- a/lisp/org-collector.el +++ b/lisp/org-collector.el @@ -122,6 +122,7 @@ preceding the dblock, then update the contents of the dblock." (noquote (plist-get params :noquote)) (colnames (plist-get params :colnames)) (defaultval (plist-get params :defaultval)) + (tblfm (plist-get params :tblfm)) (content-lines (org-split-string (plist-get params :content) "\n")) id table line pos idpos stringformat) (save-excursion @@ -141,14 +142,16 @@ preceding the dblock, then update the contents of the dblock." (widen)) (setq pos (point)) (when content-lines - (while (string-match "^#" (car content-lines)) - (insert (pop content-lines) "\n"))) + (dolist (line content-lines) + (when (and (string-prefix-p "#" (substring-no-properties line)) + (not (string-prefix-p "#+TBLFM:" (substring-no-properties line)))) + (insert line "\n")))) (insert table) (insert "\n|--") (org-cycle) (move-end-of-line 1) - (message (format "point-%d" pos)) - (while (setq line (pop content-lines)) - (when (string-match "^#" line) - (insert "\n" line))) - (goto-char pos) + (when tblfm + (unless (looking-back "\n" 1) + (insert "\n")) + (insert (concat "#+TBLFM:" tblfm))) + (goto-char pos) (org-table-recalculate 'all)) (org-collector-error (widen) (error "%s" er)) (error (widen) (error "%s" er)))) -- 2.48.1