From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: getting file properties Date: Sat, 4 May 2013 17:42:30 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8f647a43306dc904dbeb5873 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:40436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYkDy-0005f4-Ch for emacs-orgmode@gnu.org; Sat, 04 May 2013 17:42:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYkDv-0002S1-WC for emacs-orgmode@gnu.org; Sat, 04 May 2013 17:42:34 -0400 Received: from mail-da0-x233.google.com ([2607:f8b0:400e:c00::233]:44750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYkDv-0002Rv-O6 for emacs-orgmode@gnu.org; Sat, 04 May 2013 17:42:31 -0400 Received: by mail-da0-f51.google.com with SMTP id h15so1248520dan.10 for ; Sat, 04 May 2013 14:42:30 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --e89a8f647a43306dc904dbeb5873 Content-Type: text/plain; charset=ISO-8859-1 Hi everyone, if I have an org-file with this in it: #+EMAIL: jkitchin@cmu.edu is there an org lisp command to get the email address after I have opened the file? I am looping through many files to generate a report, and would like to do this in emacs-lisp. I had hoped org-entry-get would do it, but it does not (it will retrieve it from #+PROPERTY: EMAIL jkitchin@cmu.edu). Is it possible to define other keywords similar to that? E.g. #+ANDREWID: jkitchin and then to be able to read them from a lisp command (without writing the parsing code myself)? something like (org-entry-get-keyword "ANDREWID"). I could not find anything like this in the property API ( http://orgmode.org/manual/Using-the-property-API.html) which is where i thought it would be. Thanks! 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 --e89a8f647a43306dc904dbeb5873 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi everyone,

if I have an org-file with this in it:

#+EMAIL: = jkitchin@cmu.edu

is there an= org lisp command to get the email address after I have opened the file? I = am looping through many files to generate a report, and would like to do th= is in emacs-lisp. I had hoped org-entry-get would do it, but it does not (i= t will retrieve it from #+PROPERTY: EMAIL jkitchin@cmu.edu).

Is it possible to define other keywords similar to that? E.g.

#+= ANDREWID: jkitchin

and then to be able to read them from a lisp comm= and (without writing the parsing code myself)? something like (org-entry-ge= t-keyword "ANDREWID").

I could not find anything like this in the property API (http://orgmode.org/manu= al/Using-the-property-API.html) which is where i thought it would be.
Thanks!

John

-------------------------= ----------
John Kitchin
Associate Professor
Doherty Hall A207F
= Department of Chemical Engineering
Carnegie Mellon University
Pittsbu= rgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

--e89a8f647a43306dc904dbeb5873-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: david@adboyd.com (J. David Boyd) Subject: Re: getting file properties Date: Sat, 04 May 2013 21:51:06 -0400 Message-ID: <878v3utcs5.fsf@adboyd.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:45462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYo6p-0003qq-Hi for emacs-orgmode@gnu.org; Sat, 04 May 2013 21:51:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYo6o-0000IB-Bw for emacs-orgmode@gnu.org; Sat, 04 May 2013 21:51:27 -0400 Received: from plane.gmane.org ([80.91.229.3]:42728) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYo6o-0000I7-5h for emacs-orgmode@gnu.org; Sat, 04 May 2013 21:51:26 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UYo6k-0004Ac-Ug for emacs-orgmode@gnu.org; Sun, 05 May 2013 03:51:22 +0200 Received: from 72.185.97.240 ([72.185.97.240]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 03:51:22 +0200 Received: from david by 72.185.97.240 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 03:51:22 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org John Kitchin writes: > Hi everyone, > > if I have an org-file with this in it: > > #+EMAIL: jkitchin@cmu.edu > > is there an org lisp command to get the email address after I have > opened the file? I am looping through many files to generate a report, > and would like to do this in emacs-lisp. I had hoped org-entry-get > would do it, but it does not (it will retrieve it from #+PROPERTY: > EMAIL jkitchin@cmu.edu). > > Is it possible to define other keywords similar to that? E.g. > > #+ANDREWID: jkitchin > > and then to be able to read them from a lisp command (without writing > the parsing code myself)? something like (org-entry-get-keyword > "ANDREWID"). > > I could not find anything like this in the property API > (http://orgmode.org/manual/Using-the-property-API.html) which is where > i thought it would be. > > Thanks! > > 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 I'm interested in an answer to this as well... From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: getting file properties Date: Sun, 05 May 2013 00:36:04 -0400 Message-ID: <87vc6ym4az.fsf@pierrot.dokosmarshall.org> References: <878v3utcs5.fsf@adboyd.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYqgM-00060X-IC for emacs-orgmode@gnu.org; Sun, 05 May 2013 00:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYqgJ-0000i4-Kr for emacs-orgmode@gnu.org; Sun, 05 May 2013 00:36:18 -0400 Received: from plane.gmane.org ([80.91.229.3]:47303) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYqgJ-0000ho-Db for emacs-orgmode@gnu.org; Sun, 05 May 2013 00:36:15 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UYqgI-0001Sn-NM for emacs-orgmode@gnu.org; Sun, 05 May 2013 06:36:14 +0200 Received: from pool-108-7-96-134.bstnma.fios.verizon.net ([108.7.96.134]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 06:36:14 +0200 Received: from ndokos by pool-108-7-96-134.bstnma.fios.verizon.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 06:36:14 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org david@adboyd.com (J. David Boyd) writes: > John Kitchin writes: > >> Hi everyone, >> >> if I have an org-file with this in it: >> >> #+EMAIL: jkitchin@cmu.edu >> >> is there an org lisp command to get the email address after I have >> opened the file? I am looping through many files to generate a report, >> and would like to do this in emacs-lisp. I had hoped org-entry-get >> would do it, but it does not (it will retrieve it from #+PROPERTY: >> EMAIL jkitchin@cmu.edu). >> >> Is it possible to define other keywords similar to that? E.g. >> >> #+ANDREWID: jkitchin >> >> and then to be able to read them from a lisp command (without writing >> the parsing code myself)? something like (org-entry-get-keyword >> "ANDREWID"). >> >> I could not find anything like this in the property API >> (http://orgmode.org/manual/Using-the-property-API.html) which is where >> i thought it would be. >> >> Thanks! >> >> 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 > > > I'm interested in an answer to this as well... > > > Here's one way: --8<---------------cut here---------------start------------->8--- (defun jk-org-kwds () (let* ((parse-tree (org-element-parse-buffer)) (keys (org-element-map parse-tree 'keyword (function identity)))) (mapcar (function (lambda (x) (cons (org-element-property :key x) (org-element-property :value x)))) keys))) --8<---------------cut here---------------end--------------->8--- This returns a list of (KEY. VALUE) pairs. I'm sure there are other (better, cheaper) ways, but I'm going through org-element.el, and having that hammer in hand, everything looks like a nail to me :-) -- Nick From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: getting file properties Date: Sat, 04 May 2013 22:11:43 -0700 Message-ID: <877gjeovsg.fsf@ericabrahamsen.net> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:42991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYr8e-000698-3C for emacs-orgmode@gnu.org; Sun, 05 May 2013 01:05:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYr8a-0008IJ-8I for emacs-orgmode@gnu.org; Sun, 05 May 2013 01:05:32 -0400 Received: from plane.gmane.org ([80.91.229.3]:45472) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYr8a-0008I8-1d for emacs-orgmode@gnu.org; Sun, 05 May 2013 01:05:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UYr8Y-0000IJ-FW for emacs-orgmode@gnu.org; Sun, 05 May 2013 07:05:26 +0200 Received: from c-76-28-195-250.hsd1.wa.comcast.net ([76.28.195.250]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 07:05:26 +0200 Received: from eric by c-76-28-195-250.hsd1.wa.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 05 May 2013 07:05:26 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org John Kitchin writes: > Hi everyone, > > if I have an org-file with this in it: > > #+EMAIL: jkitchin@cmu.edu > > is there an org lisp command to get the email address after I have > opened the file? I am looping through many files to generate a report, > and would like to do this in emacs-lisp. I had hoped org-entry-get > would do it, but it does not (it will retrieve it from #+PROPERTY: > EMAIL jkitchin@cmu.edu). > > Is it possible to define other keywords similar to that? E.g. > > #+ANDREWID: jkitchin > > and then to be able to read them from a lisp command (without writing > the parsing code myself)? something like (org-entry-get-keyword > "ANDREWID"). > > I could not find anything like this in the property API > (http://orgmode.org/manual/Using-the-property-API.html) which is where > i thought it would be. > > Thanks! > > John If you mean file-level properties (ie not properties on headlines), `org-export-get-environment' is one place to look. It runs `org-export--get-inbuffer-options', which parses options at the top of the file. I don't think it will read arbitrary properties, though... From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: getting file properties Date: Sun, 05 May 2013 09:36:24 +0200 Message-ID: <87r4hlg9on.fsf@gmail.com> References: <878v3utcs5.fsf@adboyd.com> <87vc6ym4az.fsf@pierrot.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:36602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYtUh-0005AJ-No for emacs-orgmode@gnu.org; Sun, 05 May 2013 03:36:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UYtUg-0006Oj-Qi for emacs-orgmode@gnu.org; Sun, 05 May 2013 03:36:27 -0400 Received: from mail-wg0-x22c.google.com ([2a00:1450:400c:c00::22c]:37785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UYtUg-0006OR-AZ for emacs-orgmode@gnu.org; Sun, 05 May 2013 03:36:26 -0400 Received: by mail-wg0-f44.google.com with SMTP id z12so2685182wgg.35 for ; Sun, 05 May 2013 00:36:25 -0700 (PDT) In-Reply-To: <87vc6ym4az.fsf@pierrot.dokosmarshall.org> (Nick Dokos's message of "Sun, 05 May 2013 00:36:04 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Nick Dokos Cc: emacs-orgmode@gnu.org Hello, Nick Dokos writes: > Here's one way: > > (defun jk-org-kwds () > (let* ((parse-tree (org-element-parse-buffer)) > (keys (org-element-map parse-tree 'keyword (function identity)))) > (mapcar (function (lambda (x) (cons (org-element-property :key x) > (org-element-property :value x)))) keys))) > > This returns a list of (KEY. VALUE) pairs. > > I'm sure there are other (better, cheaper) ways, but I'm going through > org-element.el, and having that hammer in hand, everything looks like > a nail to me :-) I suggest the slightly more efficient variation: (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))))) The optional argument `element' prevents `org-element-parse-buffer' from diving too deep and `org-element-map' does the job of `mapcar'. Regards, -- Nicolas Goaziou From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: getting file properties Date: Sun, 5 May 2013 12:34:36 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff24377f36de704dbfb28b7 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:47187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZ1tZ-0008QG-Bp for emacs-orgmode@gnu.org; Sun, 05 May 2013 12:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZ1tW-0001iU-Lr for emacs-orgmode@gnu.org; Sun, 05 May 2013 12:34:41 -0400 Received: from mail-da0-x236.google.com ([2607:f8b0:400e:c00::236]:44076) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZ1tW-0001iG-EY for emacs-orgmode@gnu.org; Sun, 05 May 2013 12:34:38 -0400 Received: by mail-da0-f54.google.com with SMTP id u36so1479246dak.41 for ; Sun, 05 May 2013 09:34:37 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --e89a8ff24377f36de704dbfb28b7 Content-Type: text/plain; charset=ISO-8859-1 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 (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 --e89a8ff24377f36de704dbfb28b7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks for the great suggestions (Nick, Nick, and Eric)!

Here are t= he 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 ()
=A0 (org-element-map= (org-element-parse-buffer 'element) 'keyword
=A0=A0=A0 =A0=A0= =A0 =A0=A0 (lambda (keyword) (cons (org-element-property :key keyword)
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 (org-element-prope= rty :value keyword)))))

(defun jk-org-kwd (KEYWORD)
=A0 "get= the value of a KEYWORD in the form of #+KEYWORD: value"
=A0 (cdr (= assoc KEYWORD (jk-org-kwds))))

(jk-org-kwd "RANDOM")
#+END_SRC

#+RESULTS:
: tfj= kdsla jfkdsa

A less orgish way I worked out last night after browsin= g through org.el is:

#+ANDREWID: jkitchin

#+BEGIN_SRC emacs-l= isp :results value
(defun jk-get-file-keyword (KEYWORD)
=A0 "get the value from a line= like this
#+OPTION: value
in a file."
=A0 (interactive)
= =A0 (let ((case-fold-search t)
=A0=A0=A0 (re (format "^#\\+%s:[ \t]= +\\([^\t\n]+\\)" KEYWORD)))
=A0=A0=A0 (if (not (save-excursion
=A0=A0=A0 =A0=A0=A0=A0=A0=A0 (or (re-= search-forward re nil t)
=A0=A0=A0 =A0=A0=A0 =A0=A0 (re-search-backward = re nil t))))
=A0=A0=A0 (error (format "No line containing #+%s: val= ue found" KEYWORD)))
=A0=A0=A0 (match-string 1)))

(jk-get-file-keyword "ANDREWID")
#+END_SRC

#+RESULT= S:
: jkitchin


This is pretty awesome!

John

-----------------------------------
John Kitchin
Assoc= iate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon= University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.e= du

--e89a8ff24377f36de704dbfb28b7--