From: John Kitchin <jkitchin@andrew.cmu.edu>
To: emacs-orgmode@gnu.org
Subject: Re: getting file properties
Date: Sun, 5 May 2013 12:34:36 -0400 [thread overview]
Message-ID: <CAJ51ETqXqP8k+L_hY6cr=LYNZXXR_Se1B-Zr17S-HXZTfzXtXg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1577 bytes --]
Thanks for the great suggestions (Nick, Nick, and Eric)!
Here are the two functions that finally do what I wanted. I added the
second function to get a specific result.
#+RANDOM: tfjkdsla jfkdsa
#+BEGIN_SRC emacs-lisp :results value
; suggested by Nicolas Goaziou <n.goaziou@gmail.com>
(defun jk-org-kwds ()
(org-element-map (org-element-parse-buffer 'element) 'keyword
(lambda (keyword) (cons (org-element-property :key keyword)
(org-element-property :value keyword)))))
(defun jk-org-kwd (KEYWORD)
"get the value of a KEYWORD in the form of #+KEYWORD: value"
(cdr (assoc KEYWORD (jk-org-kwds))))
(jk-org-kwd "RANDOM")
#+END_SRC
#+RESULTS:
: tfjkdsla jfkdsa
A less orgish way I worked out last night after browsing through org.el is:
#+ANDREWID: jkitchin
#+BEGIN_SRC emacs-lisp :results value
(defun jk-get-file-keyword (KEYWORD)
"get the value from a line like this
#+OPTION: value
in a file."
(interactive)
(let ((case-fold-search t)
(re (format "^#\\+%s:[ \t]+\\([^\t\n]+\\)" KEYWORD)))
(if (not (save-excursion
(or (re-search-forward re nil t)
(re-search-backward re nil t))))
(error (format "No line containing #+%s: value found" KEYWORD)))
(match-string 1)))
(jk-get-file-keyword "ANDREWID")
#+END_SRC
#+RESULTS:
: jkitchin
This is pretty awesome!
John
-----------------------------------
John Kitchin
Associate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu
[-- Attachment #2: Type: text/html, Size: 1986 bytes --]
next reply other threads:[~2013-05-05 16:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-05 16:34 John Kitchin [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-05-04 21:42 getting file properties John Kitchin
2013-05-05 1:51 ` J. David Boyd
2013-05-05 4:36 ` Nick Dokos
2013-05-05 7:36 ` Nicolas Goaziou
2013-05-05 5:11 ` Eric Abrahamsen
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='CAJ51ETqXqP8k+L_hY6cr=LYNZXXR_Se1B-Zr17S-HXZTfzXtXg@mail.gmail.com' \
--to=jkitchin@andrew.cmu.edu \
--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 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).