From 4d69c3407c7c00fe0a1f52c383ced572f3524076 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 | 34 ++++++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index e66e48cda..5e2549f49 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -6007,6 +6007,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 eab181bc3..449487ac0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -1056,6 +1056,12 @@ The global default function can be overridden for any given =colview= dynamic block individually by specifying a custom formatter function using the new ~:formatter~ parameter on the block's =BEGIN= line. +*** =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 5c908affe..1771283f2 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1439,15 +1439,15 @@ and variances (respectively) of the individual estimates." ;;; Dynamic block for Column view -(defun org-columns--capture-view (maxlevel match skip-empty exclude-tags format local) +(defun org-columns--capture-view (maxlevel match skip-empty exclude-tags link 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. When LINK is non-nil, item headlines will be +linked to their origins. FORMAT is a format string for columns, or nil. +When LOCAL is non-nil, only capture headings in current subtree. 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 @@ -1467,12 +1467,21 @@ the columns according to FORMAT." (let (row) (dotimes (i columns) (let* ((col (+ (line-beginning-position) i)) - (p (get-char-property col 'org-columns-key))) - (push (org-quote-vert + (p (get-char-property col 'org-columns-key)) + (cell-content + (org-quote-vert (get-char-property col (if (string= p "ITEM") 'org-columns-value - 'org-columns-value-modified))) + 'org-columns-value-modified))))) + (push (if (and link (string= p "ITEM")) + (let ((search (org-link-heading-search-string + cell-content))) + (org-link-make-string + (if (not (buffer-file-name)) search + (format "file:%s::%s" (buffer-file-name) search)) + cell-content)) + cell-content) row))) (unless (or (and skip-empty @@ -1558,6 +1567,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 buffer." @@ -1587,6 +1600,7 @@ PARAMS is a property list of parameters: (plist-get params :match) (plist-get params :skip-empty-rows) (plist-get params :exclude-tags) + (plist-get params :link) (plist-get params :format) view-pos))))) (formatter (or (plist-get params :formatter) -- 2.39.3 (Apple Git-146)