From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [RFC] Rewrite `org-entry-properties' using parser
Date: Thu, 21 Aug 2014 02:16:38 +0200 [thread overview]
Message-ID: <87fvgqae8p.fsf@gmail.com> (raw)
In-Reply-To: 8761i525ak.fsf@nicolasgoaziou.fr
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
Hello,
> You may want to read my answer again. There is no "write this, write
> that" in it. I'm pointing out what is missing or flawed and _suggesting_
> alternative approaches.
I appreciate your comments and input, but unfortunately I gave up on the
original idea because I did not want to make another "much more time
consuming than planned" side-project out of this.
>> so I rather leave this to you (or whoever wants to do it).
> Unfortunately, my plate is full at the moment.
Ok, so I simplified the task and wrote
,----[ C-h f org-dp-filter-node-props RET ]
| org-dp-filter-node-props is a Lisp function in `org-dp-lib.el'.
|
| (org-dp-filter-node-props FILTER &optional NEGATE-P SILENT-P)
|
| Return filtered node-properties.
| FILTER should either be the car of one of the cons-pairs in
| `org-dp-prop-filters' or a regexp-string. If NEGATE-P is non-nil,
| the properties not matched by the filter are returned. If
| SILENT-P is non-nil, no message is printed if no property-drawer
| is found.
`----
- this function acts on element-type 'node-property', not 'headline'
- it does not attempt to replace `org-entry-properties' or to be
compatible with its signature, its written from scratch.
but it does what I want - make it easy to filter out application
properties and user defined properties from the usual property-mix found
in property drawers.
It relies on the following constants:
,----[ C-h v org-dp-prop-filters RET ]
| org-dp-prop-filters is a variable defined in `org-dp-lib.el'.
| Its value is ((special . org-special-properties)
| (custom . org-custom-properties)
| (default . org-default-properties)
| (file . org-file-properties)
| (global mapcar 'car org-global-properties)
| (org)
| (user-defined))
|
| Alist of filter-types and associated property-classes.
`----
(do I miss an Org property class here?)
,----[ C-h v org-dp-org-props RET ]
| org-dp-org-props is a variable defined in `org-dp-lib.el'.
| [...]
| Union of special, custom, file and global properties, as well
| as those properties specified by the user in customizable
| variable `org-dp-misc-props'.
`----
Thus given the following Org headline two typical function calls would
be:
#+BEGIN_SRC emacs-lisp :results raw
(save-excursion
(outline-next-heading)
(org-dp-filter-node-props "^foo-."))
#+END_SRC
#+results:
((foo-star . star1) (foo-bar . bar1))
#+BEGIN_SRC emacs-lisp :results raw
(save-excursion
(outline-next-heading)
(org-dp-filter-node-props 'org t))
#+END_SRC
#+results:
((cho-bar . bar2) (foo-star . star1) (foo-bar . bar1))
* ORG SCRATCH
:PROPERTIES:
:CUSTOM_ID: abc123
:CATEGORY: mycat
:foo-bar: bar1
:foo-star: star1
:cho-bar: bar2
:END:
PS
For completeness I attach the code:
#+BEGIN_SRC emacs-lisp
(defun org-dp-filter-node-props (filter &optional negate-p silent-p)
"Return filtered node-properties.
FILTER should either be the car of one of the cons-pairs in
`org-dp-prop-filters' or a regexp-string. If NEGATE-P is non-nil,
the properties not matched by the filter are returned. If
SILENT-P is non-nil, no message is printed if no property-drawer
is found."
(let ((props (save-excursion
(and
(or (org-at-heading-p)
(outline-previous-heading))
(re-search-forward org-property-drawer-re
nil 'NOERROR 1)
(progn
(goto-char (match-beginning 0))
(org-dp-contents)))))
filtered-props)
(if (not props)
(unless silent-p
(message
"Could not find properties at point %d in buffer %s."
(point) (current-buffer)))
(org-element-map props 'node-property
(lambda (--prop)
(let* ((key (org-element-property :key --prop))
(val (org-element-property :value --prop))
(memberp (case filter
((special custom default file global)
(member-ignore-case
key
(eval
(cdr-safe
(assoc filter
org-dp-prop-filters)))))
(org (member-ignore-case
key org-dp-org-props))
(t (if (stringp filter)
(string-match filter key)
(error "Not a valid filter: %s"
filter))))))
(when (or (and negate-p (not memberp))
(and (not negate-p) memberp))
(setq filtered-props
(cons (cons key val) filtered-props))))))
filtered-props)))
#+END_SRC
--
cheers,
Thorsten
next prev parent reply other threads:[~2014-08-21 0:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-31 23:21 [RFC] Rewrite `org-entry-properties' using parser Thorsten Jolitz
2014-08-01 11:44 ` Bastien
2014-08-01 12:44 ` Thorsten Jolitz
2014-08-01 13:28 ` Nicolas Goaziou
2014-08-05 12:52 ` Thorsten Jolitz
2014-08-06 9:59 ` Rasmus
2014-08-06 12:04 ` Nicolas Goaziou
2014-08-21 0:16 ` Thorsten Jolitz [this message]
2014-08-01 18:41 ` Erik Hetzner
2014-08-03 18:59 ` John Kitchin
2014-08-04 3:45 ` Erik Hetzner
2014-08-04 4:07 ` Aaron Ecay
2014-08-04 14:11 ` Erik Hetzner
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fvgqae8p.fsf@gmail.com \
--to=tjolitz@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.