From: Kaushal Modi <kaushal.modi@gmail.com>
To: yantar92@gmail.com
Cc: emacs-org list <emacs-orgmode@gnu.org>, mwe012008@gmx.net
Subject: Re: Concatenating Org property values from parent subtrees
Date: Mon, 1 Oct 2018 17:00:32 -0400 [thread overview]
Message-ID: <CAFyQvY3HOwN7idzwQPWS3Oh+8LUC+OryqV0epZHezLPXnMorBQ@mail.gmail.com> (raw)
In-Reply-To: <87ftxpu0rb.fsf@yantar92-laptop.i-did-not-set--mail-host-address--so-tickle-me>
[-- Attachment #1: Type: text/plain, Size: 2630 bytes --]
On Mon, Oct 1, 2018 at 11:50 AM Ihor Radchenko <yantar92@gmail.com> wrote:
> Hi,
>
> Check out the following code:
>
> ````
> (defvar org-concatenated-properties '("AA")
> "A list of property names (strings), which should be computed via
> concatenation with the parent properties.")
>
> (define-advice org-entry-get (:around (oldfun pom property &optional
> inherit literal-nil) concatenate-parents-maybe)
>
Hello Ihor,
That code is perfect!
I was able to get what I want with minor refactoring. Thanks!
Refactored code:
=====
(defvar org-concatenated-properties '("AA")
"List of property names whose values are allowed to be concatenated.
The list is of type '(PROP1 PROP2 ..) where each element is a string.")
(defvar org-property-concat-string "/"
"String use to concat the `org-concatenated-properties' properties.")
(defun org-get-parent-property (property inherit literal-nil)
"Get the value of PROPERTY from the parent relative to current point."
(org-with-wide-buffer
(if (org-up-heading-safe)
(or (org-entry-get nil property inherit literal-nil) "")
"")))
(defun org/advice-concatenate-properties-maybe (orig-fun &rest args)
"Concatenate an Org Property value with its inherited value.
The concatenation happens only if the Org Property is in
`org-concatenated-properties' list."
(let* ((value-orig (apply orig-fun args))
(property (nth 1 args))
(dont-concat (not (member property org-concatenated-properties))))
;; (message "dbg: args:%S value-orig:%S property:%S" args value-orig
property)
(if dont-concat
value-orig
(let* ((pom (nth 0 args))
(inherit (nth 2 args))
(literal-nil (nth 3 args))
(value-here-no-inherit (apply orig-fun `(,pom ,property nil
,literal-nil)))
(value-parent (apply #'org-get-parent-property `(,property
,inherit ,literal-nil))))
;; (message "dbg advice: value-here-no-inherit: %S"
value-here-no-inherit)
(if value-here-no-inherit
(format "%s%s%s"
value-parent
(if (org-string-nw-p value-parent)
org-property-concat-string
"")
value-orig)
value-parent)))))
(advice-add 'org-entry-get :around
#'org/advice-concatenate-properties-maybe)
;; (advice-remove 'org-entry-get #'org/advice-concatenate-properties-maybe)
=====
Example Org file:
=====
* heading 1
:PROPERTIES:
:FOO: abc
:END:
asdf
** heading 1
:PROPERTIES:
:FOO: def
:AA: pqr
:END:
*** heading 2
:PROPERTIES:
:FOO: 123
:AA: 456
:END:
**** heading 3
=====
[-- Attachment #2: Type: text/html, Size: 3761 bytes --]
prev parent reply other threads:[~2018-10-01 21:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-26 22:57 Concatenating Org property values from parent subtrees Kaushal Modi
2018-09-29 18:38 ` Michael Welle
2018-09-29 19:01 ` Kaushal Modi
2018-09-29 19:23 ` Michael Welle
2018-09-29 19:26 ` Michael Welle
2018-10-01 15:47 ` Ihor Radchenko
2018-10-01 21:00 ` Kaushal Modi [this message]
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=CAFyQvY3HOwN7idzwQPWS3Oh+8LUC+OryqV0epZHezLPXnMorBQ@mail.gmail.com \
--to=kaushal.modi@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mwe012008@gmx.net \
--cc=yantar92@gmail.com \
/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).