On Mon, Oct 1, 2018 at 11:50 AM Ihor Radchenko <
address@hidden> 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
=====