From 6c3fd68419ac2be705f29bd56dcd23b01b6da86b Mon Sep 17 00:00:00 2001 From: Alexander Adolf Date: Mon, 15 Apr 2024 18:01:40 +0200 Subject: [PATCH 2/2] 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. * 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 | 33 +++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 000783772..a77492971 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 84ea7cde9..b4aea10b8 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1064,6 +1064,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 7a6471377..74f7a8f58 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1441,12 +1441,12 @@ and variances (respectively) of the individual estimates." (defun org-columns--capture-view (maxlevel match skip-empty exclude-tags format local) "Get the column view of the current buffer. -MAXLEVEL sets the level limit. SKIP-EMPTY tells whether to skip -empty rows, an empty row being one where all the column view -specifiers but ITEM are empty. EXCLUDE-TAGS is a list of tags -that will be excluded from the resulting view. FORMAT is a -format string for columns, or nil. When LOCAL is non-nil, only -capture headings in current subtree. +MAXLEVEL sets the level limit. SKIP-EMPTY tells whether to skip empty +rows, an empty row being one where all the column view specifiers but +ITEM are empty. EXCLUDE-TAGS is a list of tags that will be excluded +from the resulting view. FORMAT is a format string for columns, or nil. +When LOCAL is non-nil, only capture headings in current subtree. When +LINK is non-nil, item headlines will be linked to their origins. This function returns a list containing the title row and all other rows. Each row is either a list, or the symbol `hline'. The first list @@ -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 @@ -1600,9 +1604,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 @@ -1626,7 +1631,15 @@ 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 link + (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)) + cleaned))) (setf (nth item-index (cdr row)) (if (and indent (> level 1)) (concat "\\_" (make-string (* 2 (1- level)) ?\s) item) -- 2.39.3 (Apple Git-146)