[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamic block tables: adding prefix of "id:" to %ID

From: Jens Neuhalfen
Subject: Re: Dynamic block tables: adding prefix of "id:" to %ID
Date: Sun, 25 Jul 2021 17:01:35 +0200

 Hi Karl,

 I use a wrapper around org-map-entries to create custom tables.

 Calling the wrapper takes a configuration for each table column. This is quite 
nice for other use cases as well, to e.g. convert properties (":TASK_PROGRESS: 
75") into graphical representations like harvey balls.

 Each column takes the following configuration values:

 - colname :: The name of the column
 - entry :: the property value of the column
 - map :: a lambda function called with the value (optional)
 - default :: default value if nothing yields a non nil value (optional)

 (defun neuhalje/org-generate-table-from-sections-mapped (query default scope 
mapping add-headline)
   "See my library of Babel."
   (let* (
          (org-use-tag-inheritance nil)
          (title-row (mapcar '(lambda (cfg) (cdr (assoc "colname" cfg))) 
          (rows (org-map-entries #'(lambda ()
                                     (mapcar '(lambda (column) (let* 
((default-value (or (cdr (assoc "default" column)) default))
                                                                 (entry (cdr 
(assoc "entry" column)))
                                                                 (mapping (cdr 
(assoc "map" column)))
(org-entry-get nil entry))
                                                                 (mapped (if 
mapping (funcall mapping raw) raw)))
                                                            (or  mapped 
default-value))) mapping)) query scope)))
     (if add-headline (append  `(,title-row hline) rows) rows)))

 #+NAME: generate-table-from-sections-mapped
 #+BEGIN_SRC emacs-lisp :exports results :results table :var query='() :var 
default="N/A" scope='file :var mapping='() :var add-headline='t  :cache no
 (neuhalje/org-generate-table-from-sections-mapped query default scope mapping 

 I call it from my org files like this:

 #+name: demoprops2
 #+begin_src emacs-lisp
   (("colname" . "ROW") ("entry" . "ITEM"))
   (("colname" . "default") ("entry" . "x-prop-xxx"))
   (("colname" . "custom default") ("entry" . "x-prop-b") ("default" . "not 
   (("colname" . "link") ("entry" . "CUSTOM_ID") ("map" . (lambda (value) (if 
value (format "[[#%s][%s]]" value value) "<default>"))))
   (("colname" . "linked item") ("entry" . "CUSTOM_ID") ("map" . (lambda 
(value) (if value (format "[[#%s][%s]]" value (org-entry-get nil "ITEM")) 
(org-entry-get nil "ITEM")))))

 #+CALL: generate-table-from-sections-mapped(scope='file, mapping=demoprops2, 


> Hi,
> * Kristian Grönberg <kristian@gronberg.org> wrote:
>> I didn't read your question properly.
>> Would it work for you to use the "<<id-link>>"?
>> *** <<bar>> barheading
>>:ID: [[bar][barheading]]
>> /Kris
> I'm afraid not because the dynamic block would duplicate the
> target definition and not generating a link.
> --
> get mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML into Org-mode:
>        > get Memacs from https://github.com/novoid/Memacs <
> Personal Information Management > http://Karl-Voit.at/tags/pim/
> Emacs-related > http://Karl-Voit.at/tags/emacs/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]