diff --git a/doc/org-manual.org b/doc/org-manual.org index aaeed11f8..d66d95a22 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -6009,6 +6009,11 @@ This dynamic block has the following parameters: When non-~nil~, indent each =ITEM= field according to its level. +- =:link= :: + + When non-~nil~, link the =ITEM= headlines in the table to their + origins. + - =:format= :: Specify a column attribute (see [[*Column attributes]]) for the dynamic diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 827701835..c735a67a3 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1104,6 +1104,12 @@ using the new ~:formatter~ parameter on the block's =BEGIN= line. This new feature replicates the ~:formatter~ option already available for =clocktable= dynamic blocks. +*** =colview= dynamic block can link to headlines + +The =colview= dynamic block understands a new ~:link~ parameter, which +when non-~nil~ causes =ITEM= headlines in the table to be linked to +their origins. + *** =ob-tangle.el=: New flag to remove tangle targets before writing When ~org-babel-tangle-remove-file-before-write~ is set to ~t~ the diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 6241fa3ba..64ed8c16a 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1557,6 +1557,10 @@ PARAMS is a property list of parameters: When non-nil, make each column a column group to enforce vertical lines. +`:link' + + Link the item headlines in the table to their origins. + `:formatter' A function to format the data and insert it into the @@ -1599,9 +1603,10 @@ PARAMS is a property list of parameters: TABLE is a table with data as produced by `org-columns--capture-view'. PARAMS is the parameter property list obtained from the dynamic block definition." - (let ((width-specs - (mapcar (lambda (spec) (nth 2 spec)) - org-columns-current-fmt-compiled))) + (let ((link (plist-get params :link)) + (width-specs + (mapcar (lambda (spec) (nth 2 spec)) + org-columns-current-fmt-compiled))) (when table ;; Prune level information from the table. Also normalize ;; headings: remove stars, add indentation entities, if @@ -1625,7 +1630,14 @@ definition." (and (numberp hlines) (<= level hlines)))) (push 'hline new-table)) (when item-index - (let ((item (org-columns--clean-item (nth item-index (cdr row))))) + (let* ((raw (nth item-index (cdr row))) + (cleaned (org-columns--clean-item raw)) + (item (if (not link) cleaned + (let ((search (org-link-heading-search-string raw))) + (org-link-make-string + (if (not (buffer-file-name)) search + (format "file:%s::%s" (buffer-file-name) search)) + cleaned))))) (setf (nth item-index (cdr row)) (if (and indent (> level 1)) (concat "\\_" (make-string (* 2 (1- level)) ?\s) item) diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index bcf4e897f..6b603c31b 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -1723,6 +1723,18 @@ there are 4 parameters "* H\n#+BEGIN: columnview :formatter test-org-colview/dblock-formatter\n#+END:" (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) + (buffer-substring-no-properties (point) (point-max))))) + ;; test headline linkification + (should + (equal + "#+BEGIN: columnview :link t +| ITEM | +|------| +| [[*H][H]] | +#+END:" + (org-test-with-temp-text + "* H\n#+BEGIN: columnview :link t\n#+END:" + (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) (buffer-substring-no-properties (point) (point-max)))))) (provide 'test-org-colview)