From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: creating new #+KEYWORD: variables Date: Sat, 10 Nov 2018 19:58:41 +0100 Message-ID: <87r2fsbvz2.fsf@nicolasgoaziou.fr> References: <87h8gpcs86.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33799) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLYT4-0002FV-UZ for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 13:58:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLYT1-0005hS-Jb for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 13:58:50 -0500 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:49139) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLYT0-0005Wy-Lt for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 13:58:47 -0500 In-Reply-To: (John Kitchin's message of "Sat, 10 Nov 2018 12:11:36 -0500") 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" To: John Kitchin Cc: org-mode-email Hello, John Kitchin writes: > You can retrieve keywords in the org-file like this: > > (defun get-keyword (key) > (org-element-map (org-element-parse-buffer) 'keyword > (lambda (k) > (when (string= key (org-element-property :key k)) > (org-element-property :value k))) > nil t)) As a minor addendum, (org-element-parse-buffer 'element) is more efficient in this case. An even more efficient way to retrieve keywords, assuming buffer is not already parsed, would be: (org-with-point-at 1 (let ((case-fold-search t) (regexp (format "^[ \t]*#\\+%s:" key)) (result nil)) (while (re-search-forward regexp nil t) (let ((element (org-element-at-point))) (when (eq 'keyword (org-element-type element)) (push (org-element-property :value element) result)))) result)) Regards, -- Nicolas Goaziou