Compare commits
3 Commits
f124b616d9
...
fbf613ece9
Author | SHA1 | Date |
---|---|---|
Alexander Adolf | fbf613ece9 | |
Alexander Adolf | 4e6fa96e26 | |
Alexander Adolf | 5a98b4c563 |
|
@ -6009,11 +6009,23 @@ 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
|
||||
block.
|
||||
|
||||
- =:formatter= ::
|
||||
|
||||
#+cindex: @samp{formatter}, dynamic block parameter
|
||||
#+vindex: org-columns-dblock-formatter
|
||||
A function to format column view data and insert it into the buffer.
|
||||
See the option ~org-columns-dblock-formatter~.
|
||||
|
||||
The following commands insert or update the dynamic block:
|
||||
|
||||
- ~org-columns-insert-dblock~ ::
|
||||
|
|
35
etc/ORG-NEWS
35
etc/ORG-NEWS
|
@ -1027,6 +1027,16 @@ When using =biblatex= to export bibliographies, you can use the format
|
|||
as specified in the =biblatex= package documentation as
|
||||
=key=val,key=val,...=
|
||||
|
||||
*** New option ~org-columns-dblock-formatter~
|
||||
|
||||
=colview= dynamic blocks now understand a new ~:formatter~ parameter
|
||||
to use a specific function for formatting and inserting the contents
|
||||
of the dynamic block. This new option can be used to set the global
|
||||
default formatting function that will be used for =colview= dynamic
|
||||
blocks that do not specify any ~:formatter~ parameter. Its default
|
||||
value (the new function ~org-columns-dblock-write-default~) yields the
|
||||
previous (fixed) formatting behaviour.
|
||||
|
||||
** New features
|
||||
*** =ob-lua=: Support all types and multiple values in results
|
||||
|
||||
|
@ -1075,6 +1085,31 @@ Example:
|
|||
: | PROYECTO EMACS |
|
||||
: #+END:
|
||||
|
||||
*** =colview= dynamic block supports custom formatting function
|
||||
|
||||
The =colview= dynamic block understands a new ~:formatter~ parameter,
|
||||
which specifies a user-supplied function to format and insert the data
|
||||
in the dynamic block.
|
||||
|
||||
A global default formatting function for =colview= dynamic blocks can
|
||||
be set via the new option ~org-columns-dblock-formatter~ which
|
||||
defaults to the new function ~org-columns-dblock-write-default~, that
|
||||
implements the previous (fixed) formatting behaviour. Hence, the
|
||||
default behaviour is identical to previous versions.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
|
|
@ -123,6 +123,12 @@ in `org-columns-summary-types-default', which see."
|
|||
(function :tag "Summarize")
|
||||
(function :tag "Collect")))))
|
||||
|
||||
(defcustom org-columns-dblock-formatter #'org-columns-dblock-write-default
|
||||
"Function to format data in column view dynamic blocks.
|
||||
For more information, see `org-columns-dblock-write-default'."
|
||||
:group 'org-properties
|
||||
:package-version '(Org . "9.7")
|
||||
:type 'function)
|
||||
|
||||
|
||||
;;; Column View
|
||||
|
@ -1442,9 +1448,13 @@ 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.
|
||||
|
||||
This function returns a list containing the title row and all
|
||||
other rows. Each row is a list of fields, as strings, or
|
||||
`hline'."
|
||||
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
|
||||
is the heading row as a list of strings with the column titles according
|
||||
to FORMAT. All subsequent lists each represent a body row as a list
|
||||
whose first element is an integer indicating the outline level of the
|
||||
entry, and whose remaining elements are strings with the contents for
|
||||
the columns according to FORMAT."
|
||||
(org-columns (not local) format)
|
||||
(goto-char org-columns-top-level-marker)
|
||||
(let ((columns (length org-columns-current-fmt-compiled))
|
||||
|
@ -1457,11 +1467,10 @@ other rows. Each row is a list of fields, as strings, or
|
|||
(dotimes (i columns)
|
||||
(let* ((col (+ (line-beginning-position) i))
|
||||
(p (get-char-property col 'org-columns-key)))
|
||||
(push (org-quote-vert
|
||||
(get-char-property col
|
||||
(if (string= p "ITEM")
|
||||
'org-columns-value
|
||||
'org-columns-value-modified)))
|
||||
(push (get-char-property col
|
||||
(if (string= p "ITEM")
|
||||
'org-columns-value
|
||||
'org-columns-value-modified))
|
||||
row)))
|
||||
(unless (or
|
||||
(and skip-empty
|
||||
|
@ -1493,7 +1502,9 @@ an inline src-block."
|
|||
'(footnote-reference inline-babel-call inline-src-block target
|
||||
radio-target statistics-cookie)
|
||||
#'org-element-extract)
|
||||
(org-no-properties (org-element-interpret-data data))))
|
||||
(org-quote-vert
|
||||
(org-no-properties
|
||||
(org-element-interpret-data data)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-dblock-write:columnview (params)
|
||||
|
@ -1545,7 +1556,17 @@ PARAMS is a property list of parameters:
|
|||
`:vlines'
|
||||
|
||||
When non-nil, make each column a column group to enforce
|
||||
vertical lines."
|
||||
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. Overrides the default formatting function set in
|
||||
`org-columns-dblock-formatter'."
|
||||
(let ((table
|
||||
(let ((id (plist-get params :id))
|
||||
view-file view-pos)
|
||||
|
@ -1573,9 +1594,20 @@ PARAMS is a property list of parameters:
|
|||
(plist-get params :exclude-tags)
|
||||
(plist-get params :format)
|
||||
view-pos)))))
|
||||
(width-specs
|
||||
(mapcar (lambda (spec) (nth 2 spec))
|
||||
org-columns-current-fmt-compiled)))
|
||||
(formatter (or (plist-get params :formatter)
|
||||
org-columns-dblock-formatter
|
||||
#'org-columns-dblock-write-default)))
|
||||
(funcall formatter (point) table params)))
|
||||
|
||||
(defun org-columns-dblock-write-default (ipos table params)
|
||||
"Write out a columnview table at position IPOS in the current buffer.
|
||||
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 ((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
|
||||
|
@ -1599,7 +1631,14 @@ PARAMS is a property list of parameters:
|
|||
(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)
|
||||
|
@ -1616,6 +1655,8 @@ PARAMS is a property list of parameters:
|
|||
;; to the resulting table, adding alignment field as the first
|
||||
;; row.
|
||||
(push (mapcar (lambda (width) (when width (format "<%d>" width))) width-specs) table))
|
||||
;; now insert the table into the buffer
|
||||
(goto-char ipos)
|
||||
(let ((content-lines (org-split-string (plist-get params :content) "\n"))
|
||||
recalc)
|
||||
;; Insert affiliated keywords before the table.
|
||||
|
|
|
@ -1398,6 +1398,13 @@
|
|||
|
||||
;;; Dynamic block
|
||||
|
||||
(defun test-org-colview/dblock-formatter (ipos table params)
|
||||
"User-defined columnview dblock formatting function."
|
||||
(goto-char ipos)
|
||||
(insert-before-markers "Hello columnview!" "\n")
|
||||
(insert-before-markers (format "table has %d rows" (length table)) "\n")
|
||||
(insert-before-markers (format "there are %d parameters" (/ (length params) 2))))
|
||||
|
||||
(ert-deftest test-org-colview/dblock ()
|
||||
"Test the column view table."
|
||||
(should
|
||||
|
@ -1703,6 +1710,31 @@ SCHEDULED: <2020-05-11 Mon> DEADLINE: <2020-05-14 Thu>
|
|||
(let ((org-columns-default-format
|
||||
"%ITEM %DEADLINE(d) %SCHEDULED(s) %TIMESTAMP(t)"))
|
||||
(org-update-dblock))
|
||||
(buffer-substring-no-properties (point) (point-max)))))
|
||||
;; custom formatting function
|
||||
(should
|
||||
(equal
|
||||
"#+BEGIN: columnview :formatter test-org-colview/dblock-formatter
|
||||
Hello columnview!
|
||||
table has 3 rows
|
||||
there are 4 parameters
|
||||
#+END:"
|
||||
(org-test-with-temp-text
|
||||
"* 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)
|
||||
|
|
Loading…
Reference in New Issue