branch: externals/org
commit 4e6fa96e2659be1f8ec5189bbce661e99aeeb466
Author: Alexander Adolf <alexander.ad...@condition-alpha.com>
Commit: Ihor Radchenko <yanta...@posteo.net>

    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.
---
 doc/org-manual.org               |  5 +++++
 etc/ORG-NEWS                     |  6 ++++++
 lisp/org-colview.el              | 20 ++++++++++++++++----
 testing/lisp/test-org-colview.el | 12 ++++++++++++
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index aaeed11f88..d66d95a22b 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 827701835d..c735a67a35 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 6241fa3ba0..64ed8c16a1 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 bcf4e897fa..6b603c31b7 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<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)

Reply via email to