lisp/org-colview.el: Add link parameter to colview dynamic block

* lisp/org-colview.el (org-columns--capture-view): Add new link
parameter, which when non-nil causes ITEM headlines to be linked to
their origins.
(org-dblock-write:columnview): Pass new link parameter to
`org-columns--capture-view', and explain its use in the docstring.
* testing/lisp/test-org-colview.el (test-org-colview/dblock): Add
new test for link feature.
* doc/org-manual.org (Capturing column view): Describe new :link
parameter.
* etc/ORG-NEWS (=colview= dynamic block can link to headlines):
Describe new link feature.
This commit is contained in:
Alexander Adolf 2024-04-15 18:01:40 +02:00 committed by Ihor Radchenko
parent 5a98b4c563
commit 4e6fa96e26
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
4 changed files with 39 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -1723,6 +1723,18 @@ there are 4 parameters
"* H\n<point>#+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<point>#+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)