emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jens Neuhalfen <jens@neuhalfen.name>
To: Karl Voit <news2042@Karl-Voit.at>, emacs-orgmode@gnu.org
Subject: Re: Dynamic block tables: adding prefix of "id:" to %ID
Date: Sun, 25 Jul 2021 17:01:35 +0200	[thread overview]
Message-ID: <8735s2bfow.fsf@neuhalfen.name> (raw)
In-Reply-To: <2021-07-25T08-23-28@devnull.Karl-Voit.at>

 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))) mapping))
          (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)))
                                                                 (raw (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 add-headline)
 #+end_src

 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 there"))
   (("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")))))
  )
 #+end_src

 #+CALL: generate-table-from-sections-mapped(scope='file, mapping=demoprops2, query="+mytag-exclude")

 Regards
 Jens

> 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
>>:PROPERTIES:
>>:ID: [[bar][barheading]]
>>:END:
>>
>> /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/


  parent reply	other threads:[~2021-07-25 15:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  8:46 Dynamic block tables: adding prefix of "id:" to %ID Karl Voit
2021-07-23 10:01 ` Kristian Grönberg
2021-07-23 12:56   ` Karl Voit
2021-07-23 13:24     ` Kristian Grönberg
2021-07-25  6:24       ` Karl Voit
2021-07-25  6:39         ` Kristian Grönberg
2021-07-25 15:01         ` Jens Neuhalfen [this message]
2021-07-25  8:51 ` Ihor Radchenko
2021-07-27 12:07   ` Karl Voit
2021-07-27 12:36     ` Ihor Radchenko
2021-07-28 19:42       ` Karl Voit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735s2bfow.fsf@neuhalfen.name \
    --to=jens@neuhalfen.name \
    --cc=emacs-orgmode@gnu.org \
    --cc=news2042@Karl-Voit.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).