From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: creating new #+KEYWORD: variables Date: Thu, 8 Nov 2018 22:32:52 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000e24acf057a32ff09" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gKxXI-00035n-Pt for emacs-orgmode@gnu.org; Thu, 08 Nov 2018 22:32:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gKxXC-0007Fk-4R for emacs-orgmode@gnu.org; Thu, 08 Nov 2018 22:32:40 -0500 Received: from mail-it1-x12c.google.com ([2607:f8b0:4864:20::12c]:38786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gKxX0-0006oo-AC for emacs-orgmode@gnu.org; Thu, 08 Nov 2018 22:32:29 -0500 Received: by mail-it1-x12c.google.com with SMTP id k141-v6so1340705itk.3 for ; Thu, 08 Nov 2018 19:32:24 -0800 (PST) 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: Org Mode --000000000000e24acf057a32ff09 Content-Type: text/plain; charset="UTF-8" I am writing this interface to my university's learning management system: https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. I am only using hte exporting system tangentially and I have not defined a new exporter. However, I would really like to be able to set some variable values in the header section of hte document, e.g.: #+ORG_LMS_COURSE: becomingmodern or #+PROPERTY: org-lms-course hackinghistory I thought the latter might work but (org-entry-get-with-inheritance "org-lms-course) and (org-entry-get-with-inheritance "ORG_LMS_COURSE") both return nil. The former is in any case somewhat cleaner-looking but I am not finding in the manual an instructions on how to add my own keywords. Is it possible to do this? I can of course always set a buffer-local variable in a src block, e.g.: #+begin_src emacs-lisp (setq org-lms-course 'becomingmodern) #+end_src. but I would like to be able to avoid that where possible. Thanks for the help as usual! --000000000000e24acf057a32ff09 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I am writing this interface to my univers= ity's learning management system: https://github.com/= titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. I am onl= y using hte exporting system tangentially and I have not defined a new expo= rter. However, I would really like to be able to set some variable values i= n the header section of hte document, e.g.:

#+ORG_LMS_COURSE: becomingmodern

or

#+PROPERTY: org-lms-course hackinghistory
<= br>
I thought the latter might work but (org-entry-get-with-inher= itance "org-lms-course) and (org-entry-get-with-inheritance "ORG_= LMS_COURSE") both return nil.=C2=A0 The former is in any case somewhat= cleaner-looking but I am not finding in the manual an instructions on how = to add my own keywords.=C2=A0 Is it possible to do this? I can of course al= ways set a buffer-local variable in a src block, e.g.:
#+begin_sr= c emacs-lisp
(setq org-lms-course 'becomingmodern)
= #+end_src.

but I would like to be able to avoid t= hat where possible.

Thanks for the help as us= ual!


--000000000000e24acf057a32ff09-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: creating new #+KEYWORD: variables Date: Fri, 9 Nov 2018 10:29:47 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000b51db9057a37fe9e" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL373-0006mv-U5 for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 04:30:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL372-0004ki-Le for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 04:30:01 -0500 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]:42347) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gL372-0004i4-8U for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 04:30:00 -0500 Received: by mail-ed1-x529.google.com with SMTP id h21-v6so1192076edq.9 for ; Fri, 09 Nov 2018 01:29:59 -0800 (PST) In-Reply-To: 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: moptop99@gmail.com Cc: Org-mode --000000000000b51db9057a37fe9e Content-Type: text/plain; charset="UTF-8" Hi Matt, I found a solution for this, which I am using with my (still in development) setup for exporting from org-mode to LeanPub. I found a function for extracting document global properties at https://emacs.stackexchange.com/a/21715, which you could use to support your first example. After defining =org-global-prop-value=, you could call it like this: (org-global-prop-value "ORG_LMS_COURSE") You can see my setup, including the two functions, here: https://github.com/zzamboni/dot-emacs/blob/master/init.org#publishing-to-leanpub Hope this helps! --Diego On Fri, Nov 9, 2018 at 4:33 AM Matt Price wrote: > I am writing this interface to my university's learning management system: > https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. > I am only using hte exporting system tangentially and I have not defined a > new exporter. However, I would really like to be able to set some variable > values in the header section of hte document, e.g.: > > #+ORG_LMS_COURSE: becomingmodern > > or > > #+PROPERTY: org-lms-course hackinghistory > > I thought the latter might work but (org-entry-get-with-inheritance > "org-lms-course) and (org-entry-get-with-inheritance "ORG_LMS_COURSE") both > return nil. The former is in any case somewhat cleaner-looking but I am > not finding in the manual an instructions on how to add my own keywords. > Is it possible to do this? I can of course always set a buffer-local > variable in a src block, e.g.: > #+begin_src emacs-lisp > (setq org-lms-course 'becomingmodern) > #+end_src. > > but I would like to be able to avoid that where possible. > > Thanks for the help as usual! > > > --000000000000b51db9057a37fe9e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <= /div>
On Fri, Nov 9, 2018 at= 4:33 AM Matt Price <moptop99@gmai= l.com> wrote:
I am writing this interface to my university's lear= ning management system: https://github.= com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. I am= only using hte exporting system tangentially and I have not defined a new = exporter. However, I would really like to be able to set some variable valu= es in the header section of hte document, e.g.:

<= /div>
#+ORG_LMS_COURSE: becomingmodern

or
=

#+PROPERTY: org-lms-course hackinghistory

I thought the latter might work but (org-entry-get-with-i= nheritance "org-lms-course) and (org-entry-get-with-inheritance "= ORG_LMS_COURSE") both return nil.=C2=A0 The former is in any case some= what cleaner-looking but I am not finding in the manual an instructions on = how to add my own keywords.=C2=A0 Is it possible to do this? I can of cours= e always set a buffer-local variable in a src block, e.g.:
#+begi= n_src emacs-lisp
(setq org-lms-course 'becomingmodern)
<= div>#+end_src.

but I would like to be able to avo= id that where possible.

Thanks for the help a= s usual!


--000000000000b51db9057a37fe9e-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: creating new #+KEYWORD: variables Date: Fri, 9 Nov 2018 21:24:02 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000009c417a057a4627a4" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLJ7U-0003Vk-PJ for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 21:35:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLIw8-0007kf-FD for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 21:23:49 -0500 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:40589) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLIw8-0007fV-7y for emacs-orgmode@gnu.org; Fri, 09 Nov 2018 21:23:48 -0500 Received: by mail-io1-xd2e.google.com with SMTP id r7-v6so2533978iog.7 for ; Fri, 09 Nov 2018 18:23:35 -0800 (PST) In-Reply-To: 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: diego@zzamboni.org Cc: Org Mode --0000000000009c417a057a4627a4 Content-Type: text/plain; charset="UTF-8" ah, thank you Diego, I wil ltry it out and report back. On Fri, Nov 9, 2018 at 4:29 AM Diego Zamboni wrote: > Hi Matt, > > I found a solution for this, which I am using with my (still in > development) setup for exporting from org-mode to LeanPub. I found a > function for extracting document global properties at > https://emacs.stackexchange.com/a/21715, which you could use to support > your first example. After defining =org-global-prop-value=, you could call > it like this: > > (org-global-prop-value "ORG_LMS_COURSE") > > You can see my setup, including the two functions, here: > https://github.com/zzamboni/dot-emacs/blob/master/init.org#publishing-to-leanpub > > Hope this helps! > > --Diego > > > > On Fri, Nov 9, 2018 at 4:33 AM Matt Price wrote: > >> I am writing this interface to my university's learning management >> system: >> https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. >> I am only using hte exporting system tangentially and I have not defined a >> new exporter. However, I would really like to be able to set some variable >> values in the header section of hte document, e.g.: >> >> #+ORG_LMS_COURSE: becomingmodern >> >> or >> >> #+PROPERTY: org-lms-course hackinghistory >> >> I thought the latter might work but (org-entry-get-with-inheritance >> "org-lms-course) and (org-entry-get-with-inheritance "ORG_LMS_COURSE") both >> return nil. The former is in any case somewhat cleaner-looking but I am >> not finding in the manual an instructions on how to add my own keywords. >> Is it possible to do this? I can of course always set a buffer-local >> variable in a src block, e.g.: >> #+begin_src emacs-lisp >> (setq org-lms-course 'becomingmodern) >> #+end_src. >> >> but I would like to be able to avoid that where possible. >> >> Thanks for the help as usual! >> >> >> --0000000000009c417a057a4627a4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
ah, thank you Diego, I wil ltry it out and report back.=C2= =A0

On Fri, Nov 9, 201= 8 at 4:29 AM Diego Zamboni <diego@= zzamboni.org> wrote:
Hi Matt,
<= br>
I found a solution for this, which I am using with my (still = in development) setup for exporting from org-mode to LeanPub. I found a fun= ction for extracting document global properties at https://emacs.stackexchange.c= om/a/21715, which you could use to support your first example. After de= fining =3Dorg-global-prop-value=3D, you could call it like this:
=
(org-global-prop-value "ORG_LMS_COURSE")

You can see my setup, including the two functions, here:=C2= =A0https://github.com/zzamboni/dot-emac= s/blob/master/init.org#publishing-to-leanpub

H= ope this helps!

--Diego

<= br>

On Fri, Nov 9, 2018 at 4:33 AM Matt Price <moptop99@gmail.com> wrote:
I am writ= ing this interface to my university's learning management system: https://github.com/titaniumbones/Org-Marking= -Mode/tree/use-structured-course-def. I am only using hte exporting sys= tem tangentially and I have not defined a new exporter. However, I would re= ally like to be able to set some variable values in the header section of h= te document, e.g.:

#+ORG_LMS_COURSE: b= ecomingmodern

or

#+P= ROPERTY: org-lms-course hackinghistory

I thought t= he latter might work but (org-entry-get-with-inheritance "org-lms-cour= se) and (org-entry-get-with-inheritance "ORG_LMS_COURSE") both re= turn nil.=C2=A0 The former is in any case somewhat cleaner-looking but I am= not finding in the manual an instructions on how to add my own keywords.= =C2=A0 Is it possible to do this? I can of course always set a buffer-local= variable in a src block, e.g.:
#+begin_src emacs-lisp
= (setq org-lms-course 'becomingmodern)
#+end_src.
but I would like to be able to avoid that where possible.

Thanks for the help as usual!

=

--0000000000009c417a057a4627a4-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: creating new #+KEYWORD: variables Date: Sat, 10 Nov 2018 08:22:01 +0100 Message-ID: <87h8gpcs86.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:57291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLNar-0008Lq-Rb for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 02:22:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLNan-0004lz-T5 for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 02:22:09 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:38497) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLNan-0004ji-MW for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 02:22:05 -0500 In-Reply-To: (Matt Price's message of "Thu, 8 Nov 2018 22:32:52 -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: Matt Price Cc: Org Mode Hello, Matt Price writes: > I am writing this interface to my university's learning management system: > https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def. > I am only using hte exporting system tangentially and I have not defined a > new exporter. However, I would really like to be able to set some variable > values in the header section of hte document, e.g.: > > #+ORG_LMS_COURSE: becomingmodern You can add keywords specific to a given export back-end in its definition, more precisely in :options-alist value. For example, in "ox-texinfo", there is (org-export-define-backend 'texinfo '((bold . org-texinfo-bold)) ... :options-alist '((:texinfo-filename "TEXINFO_FILENAME" nil nil t) ...)) which means `texinfo' back-end should recognize the "#+TEXINFO_FILENAME" keyword, and store its value in the :texinfo-filename property from "info" paramater, which is passed to each function. You can write a derived back-end using this new keyword, along with a template function that actually uses it. Look at the definition of `beamer' back-end for an example. HTH, -- Nicolas Goaziou From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: creating new #+KEYWORD: variables Date: Sat, 10 Nov 2018 11:17:47 -0500 Message-ID: References: <87h8gpcs86.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000328821057a51cd00" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLVwp-00047f-L5 for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 11:17:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLVwn-0001yL-Od for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 11:17:23 -0500 Received: from mail-it1-x129.google.com ([2607:f8b0:4864:20::129]:50804) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLVwk-0001t3-AI for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 11:17:19 -0500 Received: by mail-it1-x129.google.com with SMTP id k206-v6so7199454ite.0 for ; Sat, 10 Nov 2018 08:17:18 -0800 (PST) In-Reply-To: <87h8gpcs86.fsf@nicolasgoaziou.fr> 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: Org Mode --000000000000328821057a51cd00 Content-Type: text/plain; charset="UTF-8" On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou wrote: > Hello, > > Matt Price writes: > > > I am writing this interface to my university's learning management > system: > > > https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def > . > > I am only using hte exporting system tangentially and I have not defined > a > > new exporter. However, I would really like to be able to set some > variable > > values in the header section of hte document, e.g.: > > > > #+ORG_LMS_COURSE: becomingmodern > > You can add keywords specific to a given export back-end in its > definition, more precisely in :options-alist value. For example, in > "ox-texinfo", there is > > (org-export-define-backend 'texinfo > '((bold . org-texinfo-bold)) > ... > :options-alist > '((:texinfo-filename "TEXINFO_FILENAME" nil nil t) > ...)) > > which means `texinfo' back-end should recognize the "#+TEXINFO_FILENAME" > keyword, and store its value in the :texinfo-filename property from > "info" paramater, which is passed to each function. > > You can write a derived back-end using this new keyword, along with > a template function that actually uses it. Look at the definition of > `beamer' back-end for an example. > > Thank you as always, Nicolas. I have not written a derived backend for this, though I guess many of the functions are export-like and in osme ways thatwould make a lot of sense. But I also need to use the course id to receive data from the courseware server, so for instance, right now I have this code: ------ (defun org-lms-get-students (&optional course) (unless course (setq course org-lms-course)) (let* ((courseid (plist-get course :id)) (result (org-lms-canvas-request (format "courses/%s/users" courseid) "GET" '(("enrollment_type[]" . "student") ("include[]" . "email"))))) (message "RESULTS") ;;(with-temp-file "students-canvas.json" (insert result)) (loop for student in-ref result do (if (string-match "," (plist-get student :sortable_name)) (let ((namelist (split-string (plist-get student :sortable_name) ", "))) (plist-put student :lastname (car namelist) ) (plist-put student :firstname (cadr namelist))))) result)) --- Is there aclever way to extract the value of ~org-lms-course~ from the exporter even if what I'm doing really isn't an export? I'm actually harvesting JSON data from the server, rather than producing an export file. > HTH, > > -- > Nicolas Goaziou > --000000000000328821057a51cd00 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
Hello,

Matt Price <mopt= op99@gmail.com> writes:

> I am writing this interface to my university's learning management= system:
> https://github.= com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def.
> I am only using hte exporting system tangentially and I have not defin= ed a
> new exporter. However, I would really like to be able to set some vari= able
> values in the header section of hte document, e.g.:
>
> #+ORG_LMS_COURSE: becomingmodern

You can add keywords specific to a given export back-end in its
definition, more precisely in :options-alist value. For example, in
"ox-texinfo", there is

=C2=A0 =C2=A0 (org-export-define-backend 'texinfo
=C2=A0 =C2=A0 =C2=A0 '((bold . org-texinfo-bold))
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0 :options-alist
=C2=A0 =C2=A0 =C2=A0 '((:texinfo-filename "TEXINFO_FILENAME" = nil nil t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ...))

which means `texinfo' back-end should recognize the "#+TEXINFO_FIL= ENAME"
keyword, and store its value in the :texinfo-filename property from
"info" paramater, which is passed to each function.

You can write a derived back-end using this new keyword, along with
a template function that actually uses it. Look at the definition of
`beamer' back-end for an example.

Thank you as always, Nicolas. I have not written a de= rived backend for this, though I guess many of the functions are export-lik= e and in osme ways thatwould make a lot of sense. But I also need to use th= e course id to receive data from the courseware server, so for instance, ri= ght now I have this code:=C2=A0

------
<= div>(defun org-lms-get-students (&optional course)
=C2=A0 (un= less course
=C2=A0 =C2=A0 (setq course org-lms-course))
=C2=A0 (let* ((courseid (plist-get course :id))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(result
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or= g-lms-canvas-request (format "courses/%s/users" courseid) "G= ET"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'(("= enrollment_type[]" . "student")
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0("include[]" . "email"= ;)))))
=C2=A0 =C2=A0 (message "RESULTS")
=C2= =A0 =C2=A0 ;;(with-temp-file "students-canvas.json" (insert resul= t))
=C2=A0 =C2=A0 (loop for student in-ref result
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (if (string-match "," (plist-get student :sortable_name))<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((namelist= =C2=A0 (split-string (plist-get student :sortable_name) ", ")))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (plist-put= student :lastname (car namelist) )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 (plist-put student :firstname (cadr namelist)))= ))
=C2=A0 =C2=A0 result))

---

Is there aclever way to extract the value of ~org-lms-= course~ from the exporter even if what I'm doing really isn't an ex= port? I'm actually harvesting JSON data=C2=A0 from the server, rather t= han producing an export file.=C2=A0=C2=A0
=C2=A0
HTH,

--
Nicolas Goaziou
--000000000000328821057a51cd00-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: creating new #+KEYWORD: variables Date: Sat, 10 Nov 2018 12:11:36 -0500 Message-ID: References: <87h8gpcs86.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004c00a2057a529062" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLWne-0004T8-3E for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 12:11:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLWnb-0007kj-U3 for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 12:11:57 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:54779) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLWnZ-0007eO-W5 for emacs-orgmode@gnu.org; Sat, 10 Nov 2018 12:11:55 -0500 Received: by mail-wm1-x32f.google.com with SMTP id r63-v6so4716532wma.4 for ; Sat, 10 Nov 2018 09:11:51 -0800 (PST) In-Reply-To: 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: Matt Price Cc: org-mode-email --0000000000004c00a2057a529062 Content-Type: text/plain; charset="UTF-8" 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)) (get-keyword "ORG_LMS_COURSE") John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Sat, Nov 10, 2018 at 11:17 AM Matt Price wrote: > > > On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou > wrote: > >> Hello, >> >> Matt Price writes: >> >> > I am writing this interface to my university's learning management >> system: >> > >> https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def >> . >> > I am only using hte exporting system tangentially and I have not >> defined a >> > new exporter. However, I would really like to be able to set some >> variable >> > values in the header section of hte document, e.g.: >> > >> > #+ORG_LMS_COURSE: becomingmodern >> >> You can add keywords specific to a given export back-end in its >> definition, more precisely in :options-alist value. For example, in >> "ox-texinfo", there is >> >> (org-export-define-backend 'texinfo >> '((bold . org-texinfo-bold)) >> ... >> :options-alist >> '((:texinfo-filename "TEXINFO_FILENAME" nil nil t) >> ...)) >> >> which means `texinfo' back-end should recognize the "#+TEXINFO_FILENAME" >> keyword, and store its value in the :texinfo-filename property from >> "info" paramater, which is passed to each function. >> >> You can write a derived back-end using this new keyword, along with >> a template function that actually uses it. Look at the definition of >> `beamer' back-end for an example. >> >> Thank you as always, Nicolas. I have not written a derived backend for > this, though I guess many of the functions are export-like and in osme ways > thatwould make a lot of sense. But I also need to use the course id to > receive data from the courseware server, so for instance, right now I have > this code: > > ------ > (defun org-lms-get-students (&optional course) > (unless course > (setq course org-lms-course)) > (let* ((courseid (plist-get course :id)) > (result > (org-lms-canvas-request (format "courses/%s/users" courseid) "GET" > '(("enrollment_type[]" . "student") > ("include[]" . "email"))))) > (message "RESULTS") > ;;(with-temp-file "students-canvas.json" (insert result)) > (loop for student in-ref result > do > (if (string-match "," (plist-get student :sortable_name)) > (let ((namelist (split-string (plist-get student > :sortable_name) ", "))) > (plist-put student :lastname (car namelist) ) > (plist-put student :firstname (cadr namelist))))) > result)) > > --- > > Is there aclever way to extract the value of ~org-lms-course~ from the > exporter even if what I'm doing really isn't an export? I'm actually > harvesting JSON data from the server, rather than producing an export > file. > > >> HTH, >> >> -- >> Nicolas Goaziou >> > --0000000000004c00a2057a529062 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You can retrieve keywords in the org-file= like this:

(defun get-keyword (key)
=C2= =A0 (org-element-map (org-element-parse-buffer) 'keyword
=C2= =A0 =C2=A0 (lambda (k)
=C2=A0 =C2=A0 =C2=A0 (when (string=3D key = (org-element-property :key k))
<= /span>(org-element-property :value k)))=C2=A0
=C2=A0 =C2=A0 nil t= ))

(get-keyword "ORG_LMS_COURSE")
<= div>

John

----------------------= -------------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Depa= rtment of Chemical Engineering
Carnegie Mellon University
Pittsburgh,= PA 15213
412-268-7803

=
On Sat, Nov 10, 2018 at 11:= 17 AM Matt Price <moptop99@gmail.c= om> wrote:
=


On Sat= , Nov 10, 2018 at 2:22 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
Hello,

Matt Price <mopt= op99@gmail.com> writes:

> I am writing this interface to my university's learning management= system:
> https://github.= com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def.
> I am only using hte exporting system tangentially and I have not defin= ed a
> new exporter. However, I would really like to be able to set some vari= able
> values in the header section of hte document, e.g.:
>
> #+ORG_LMS_COURSE: becomingmodern

You can add keywords specific to a given export back-end in its
definition, more precisely in :options-alist value. For example, in
"ox-texinfo", there is

=C2=A0 =C2=A0 (org-export-define-backend 'texinfo
=C2=A0 =C2=A0 =C2=A0 '((bold . org-texinfo-bold))
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0 :options-alist
=C2=A0 =C2=A0 =C2=A0 '((:texinfo-filename "TEXINFO_FILENAME" = nil nil t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ...))

which means `texinfo' back-end should recognize the "#+TEXINFO_FIL= ENAME"
keyword, and store its value in the :texinfo-filename property from
"info" paramater, which is passed to each function.

You can write a derived back-end using this new keyword, along with
a template function that actually uses it. Look at the definition of
`beamer' back-end for an example.

Thank you as always, Nicolas. I have not written a de= rived backend for this, though I guess many of the functions are export-lik= e and in osme ways thatwould make a lot of sense. But I also need to use th= e course id to receive data from the courseware server, so for instance, ri= ght now I have this code:=C2=A0

------
<= div>(defun org-lms-get-students (&optional course)
=C2=A0 (un= less course
=C2=A0 =C2=A0 (setq course org-lms-course))
=C2=A0 (let* ((courseid (plist-get course :id))
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0(result
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(or= g-lms-canvas-request (format "courses/%s/users" courseid) "G= ET"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'(("= enrollment_type[]" . "student")
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0("include[]" . "email"= ;)))))
=C2=A0 =C2=A0 (message "RESULTS")
=C2= =A0 =C2=A0 ;;(with-temp-file "students-canvas.json" (insert resul= t))
=C2=A0 =C2=A0 (loop for student in-ref result
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (if (string-match "," (plist-get student :sortable_name))<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((namelist= =C2=A0 (split-string (plist-get student :sortable_name) ", ")))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (plist-put= student :lastname (car namelist) )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 (plist-put student :firstname (cadr namelist)))= ))
=C2=A0 =C2=A0 result))

---

Is there aclever way to extract the value of ~org-lms-= course~ from the exporter even if what I'm doing really isn't an ex= port? I'm actually harvesting JSON data=C2=A0 from the server, rather t= han producing an export file.=C2=A0=C2=A0
=C2=A0
HTH,

--
Nicolas Goaziou
--0000000000004c00a2057a529062-- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Diego Zamboni Subject: Re: creating new #+KEYWORD: variables Date: Mon, 12 Nov 2018 10:11:38 +0100 Message-ID: References: <87h8gpcs86.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000005f7b1b057a7419e8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gM8Gy-0004Bl-Bj for emacs-orgmode@gnu.org; Mon, 12 Nov 2018 04:12:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gM8Gs-0005wR-84 for emacs-orgmode@gnu.org; Mon, 12 Nov 2018 04:12:44 -0500 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]:40719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gM8Gh-0005dK-Om for emacs-orgmode@gnu.org; Mon, 12 Nov 2018 04:12:30 -0500 Received: by mail-ed1-x535.google.com with SMTP id d3so6139985edx.7 for ; Mon, 12 Nov 2018 01:12:25 -0800 (PST) In-Reply-To: <87h8gpcs86.fsf@nicolasgoaziou.fr> 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: Org-mode --0000000000005f7b1b057a7419e8 Content-Type: text/plain; charset="UTF-8" Hi Nicolas, Thank you for this pointer! I have modified my own leanpub-multifile backend (derived from leanpub) to use this instead of manually extracting the keywords. In case anyone is interested, my code is here: https://github.com/zzamboni/dot-emacs/blob/master/init.org#publishing-to-leanpub Best, --Diego On Sat, Nov 10, 2018 at 8:22 AM Nicolas Goaziou wrote: > Hello, > > Matt Price writes: > > > I am writing this interface to my university's learning management > system: > > > https://github.com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def > . > > I am only using hte exporting system tangentially and I have not defined > a > > new exporter. However, I would really like to be able to set some > variable > > values in the header section of hte document, e.g.: > > > > #+ORG_LMS_COURSE: becomingmodern > > You can add keywords specific to a given export back-end in its > definition, more precisely in :options-alist value. For example, in > "ox-texinfo", there is > > (org-export-define-backend 'texinfo > '((bold . org-texinfo-bold)) > ... > :options-alist > '((:texinfo-filename "TEXINFO_FILENAME" nil nil t) > ...)) > > which means `texinfo' back-end should recognize the "#+TEXINFO_FILENAME" > keyword, and store its value in the :texinfo-filename property from > "info" paramater, which is passed to each function. > > You can write a derived back-end using this new keyword, along with > a template function that actually uses it. Look at the definition of > `beamer' back-end for an example. > > HTH, > > -- > Nicolas Goaziou > > --0000000000005f7b1b057a7419e8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Nicolas,

Thank you = for this pointer! I have modified my own leanpub-multifile backend (derived= from leanpub) to use this instead of manually extracting the keywords.

In case anyone is interested, my code is here:=C2=A0<= a href=3D"https://github.com/zzamboni/dot-emacs/blob/master/init.org#publis= hing-to-leanpub">https://github.com/zzamboni/dot-emacs/blob/master/init.org= #publishing-to-leanpub

Best,
--Diego=


On Sat, Nov = 10, 2018 at 8:22 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
Hello,

Matt Price <mopt= op99@gmail.com> writes:

> I am writing this interface to my university's learning management= system:
> https://github.= com/titaniumbones/Org-Marking-Mode/tree/use-structured-course-def.
> I am only using hte exporting system tangentially and I have not defin= ed a
> new exporter. However, I would really like to be able to set some vari= able
> values in the header section of hte document, e.g.:
>
> #+ORG_LMS_COURSE: becomingmodern

You can add keywords specific to a given export back-end in its
definition, more precisely in :options-alist value. For example, in
"ox-texinfo", there is

=C2=A0 =C2=A0 (org-export-define-backend 'texinfo
=C2=A0 =C2=A0 =C2=A0 '((bold . org-texinfo-bold))
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0 :options-alist
=C2=A0 =C2=A0 =C2=A0 '((:texinfo-filename "TEXINFO_FILENAME" = nil nil t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 ...))

which means `texinfo' back-end should recognize the "#+TEXINFO_FIL= ENAME"
keyword, and store its value in the :texinfo-filename property from
"info" paramater, which is passed to each function.

You can write a derived back-end using this new keyword, along with
a template function that actually uses it. Look at the definition of
`beamer' back-end for an example.

HTH,

--
Nicolas Goaziou

--0000000000005f7b1b057a7419e8-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: creating new #+KEYWORD: variables Date: Thu, 15 Nov 2018 07:15:16 -0500 Message-ID: References: <87h8gpcs86.fsf@nicolasgoaziou.fr> <87r2fsbvz2.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000066e66c057ab2ffc4" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNGXv-0000Ig-PY for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 07:14:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNGXs-00037X-RU for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 07:14:55 -0500 Received: from mail-it1-x134.google.com ([2607:f8b0:4864:20::134]:33292) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNGXs-000373-Dq for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 07:14:52 -0500 Received: by mail-it1-x134.google.com with SMTP id p11-v6so18801602itf.0 for ; Thu, 15 Nov 2018 04:14:51 -0800 (PST) In-Reply-To: <87r2fsbvz2.fsf@nicolasgoaziou.fr> 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 , Org Mode --00000000000066e66c057ab2ffc4 Content-Type: text/plain; charset="UTF-8" On Sat, Nov 10, 2018 at 1:58 PM Nicolas Goaziou wrote: > 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)) > > This is very helpful, Nicolas and John. What about *setting* a global keyword? I would like to write something like this: (defun org-lms-set-global-prop-value (key value) "Add or update keyword KEY in the org file header." (save-excursion (goto-char (point-min)) (insert (format "#+%s: %" (upcase key) value)))) But (a) insert the value at the *end* of the headers section, not the beginning. (b) preferably replace any existing values of the keyword rather than write a whole new line. (b) I guess could be achieved with something like (replace-regexp (format "\(^[ \t]*#\\+%s: \)\(.*\)" key) (concat "\1" value)) But what about (a)? I thought org already had a couple of functions that performed this kind of serach but now I'm not so sure. > Regards, > > -- > Nicolas Goaziou > --00000000000066e66c057ab2ffc4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Sat, Nov 10, 2018 at 1:58 PM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
Hello,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> You can retrieve keywords in the org-file like this:
>
> (defun get-keyword (key)
>=C2=A0 =C2=A0(org-element-map (org-element-parse-buffer) 'keyword >=C2=A0 =C2=A0 =C2=A0(lambda (k)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(when (string=3D key (org-element-property := key k))
> (org-element-property :value k)))
>=C2=A0 =C2=A0 =C2=A0nil t))

As a minor addendum,

=C2=A0 =C2=A0 (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:

=C2=A0 =C2=A0 (org-with-point-at 1
=C2=A0 =C2=A0 =C2=A0 (let ((case-fold-search t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (regexp (format "^[ \t]*#\\+= %s:" key))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (result nil))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (while (re-search-forward regexp nil t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((element (org-element-at-point)))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (eq 'keyword (org-eleme= nt-type element))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push (org-element-propert= y :value element) result))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 result))

This is very helpful, Nicolas and John.=C2=A0

What about *setting* a global keyword? I would like = to write something like this:

(defun org-lms-= set-global-prop-value (key value)
=C2=A0 "Add or update keyword KEY= in the org file header."
=C2=A0 (save-excursion
=C2=A0=C2=A0=C2= =A0 (goto-char (point-min))
=C2=A0=C2=A0=C2=A0 (insert (format "#+%= s: %" (upcase key) value))))

But
(a) insert the value at the *end* of the headers section, not the beginn= ing.
(b) preferably replace any existing values of the keywo= rd rather than write a whole new line.

(b) I guess= could be achieved with something like

(repla= ce-regexp (format "\(^[ \t]*#\\+%s: \)\(.*\)" key) (concat "= \1" value))
But what about (a)? I thought org already h= ad a couple of functions that performed this kind of serach but now I'm= not so sure.=C2=A0


=C2=A0
Regards,

--
Nicolas Goaziou
--00000000000066e66c057ab2ffc4-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: creating new #+KEYWORD: variables Date: Thu, 15 Nov 2018 14:51:55 -0500 Message-ID: References: <87h8gpcs86.fsf@nicolasgoaziou.fr> <87r2fsbvz2.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000c597f7057ab96263" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNgR-00008R-FY for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 14:52:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNNgQ-0004Vd-73 for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 14:52:11 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:45270) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNNgP-0004VD-NA for emacs-orgmode@gnu.org; Thu, 15 Nov 2018 14:52:10 -0500 Received: by mail-wr1-x433.google.com with SMTP id v6so635785wrr.12 for ; Thu, 15 Nov 2018 11:52:09 -0800 (PST) In-Reply-To: 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: Matt Price Cc: org-mode-email --000000000000c597f7057ab96263 Content-Type: text/plain; charset="UTF-8" I have used something like this: (defun gb-set-filetag (tag value) "Set filetag TAG to VALUE. If VALUE is nil, remove the filetag." (save-excursion (goto-char (point-min)) (if (re-search-forward (format "#\\+%s:" tag) (point-max) 'end) ;; replace existing filetag (progn (beginning-of-line) (kill-line) (when value (insert (format "#+%s: %s" tag value)))) ;; add new filetag (if (looking-at "^$") ;empty line ;; at beginning of line (when value (insert (format "#+%s: %s" tag value))) ;; at end of some line, so add a new line (when value (insert (format "\n#+%s: %s" tag value))))))) I am not sure what you mean by the end of the headers. This code ends up putting new keywords at the end of the file. You could add some code I guess that jumps back to the top, and puts it at the next line after the last #+ or something. John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Thu, Nov 15, 2018 at 7:14 AM Matt Price wrote: > > > On Sat, Nov 10, 2018 at 1:58 PM Nicolas Goaziou > wrote: > >> 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)) >> >> This is very helpful, Nicolas and John. > > What about *setting* a global keyword? I would like to write something > like this: > > (defun org-lms-set-global-prop-value (key value) > "Add or update keyword KEY in the org file header." > (save-excursion > (goto-char (point-min)) > (insert (format "#+%s: %" (upcase key) value)))) > > But > (a) insert the value at the *end* of the headers section, not the > beginning. > (b) preferably replace any existing values of the keyword rather than > write a whole new line. > > (b) I guess could be achieved with something like > > (replace-regexp (format "\(^[ \t]*#\\+%s: \)\(.*\)" key) (concat "\1" > value)) > But what about (a)? I thought org already had a couple of functions that > performed this kind of serach but now I'm not so sure. > > > > >> Regards, >> >> -- >> Nicolas Goaziou >> > --000000000000c597f7057ab96263 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I have used something like this:

=
= (defun gb-set-f= iletag (tag value)
"Set filetag TAG to VALUE.
If VALUE is nil, remove the filetag.&q= uot;
(save-excursion
(goto-char (point-min= ))
(if = (re-search-forward (format "#\\+%s:" tag) (point-max= ) 'end)
;; replace existing fileta= g
(progn
(beginnin= g-of-line)
(kill-line)
(when value
(insert (format "#+%s: %s" tag value))))
= ;; add new filetag
(if (looking-at &qu= ot;^$") ;empty line
;; at beginning of line
(when value
(insert (format "#+%s: %s" tag value)= ))
;; at end of some line, so add a new line
(when value
(insert (format "\n#+%s: %s" tag = value)))))))
I am not sure what you mean by the end of t= he headers. This code ends up putting new keywords at the end of the file. = You could add some code I guess that jumps back to the top, and puts it at = the next line after the last #+ or something.

John

--= ---------------------------------
Professor John Kitchin=C2=A0
Dohert= y Hall A207F
Department of Chemical Engineering
Carnegie Mellon Unive= rsity
Pittsburgh, PA 15213
412-268-7803

On Thu, Nov 1= 5, 2018 at 7:14 AM Matt Price <moptop99@gmail.com> wrote:


On Sat, Nov 10, 2018 at 1:58 PM Nicolas Goaziou &l= t;mail@nicolasg= oaziou.fr> wrote:
Hello,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> You can retrieve keywords in the org-file like this:
>
> (defun get-keyword (key)
>=C2=A0 =C2=A0(org-element-map (org-element-parse-buffer) 'keyword >=C2=A0 =C2=A0 =C2=A0(lambda (k)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0(when (string=3D key (org-element-property := key k))
> (org-element-property :value k)))
>=C2=A0 =C2=A0 =C2=A0nil t))

As a minor addendum,

=C2=A0 =C2=A0 (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:

=C2=A0 =C2=A0 (org-with-point-at 1
=C2=A0 =C2=A0 =C2=A0 (let ((case-fold-search t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (regexp (format "^[ \t]*#\\+= %s:" key))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (result nil))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (while (re-search-forward regexp nil t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((element (org-element-at-point)))<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (eq 'keyword (org-eleme= nt-type element))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (push (org-element-propert= y :value element) result))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 result))

This is very helpful, Nicolas and John.=C2=A0

What about *setting* a global keyword? I would like = to write something like this:

(defun org-lms-= set-global-prop-value (key value)
=C2=A0 "Add or update keyword KEY= in the org file header."
=C2=A0 (save-excursion
=C2=A0=C2=A0=C2= =A0 (goto-char (point-min))
=C2=A0=C2=A0=C2=A0 (insert (format "#+%= s: %" (upcase key) value))))

But
(a) insert the value at the *end* of the headers section, not the beginn= ing.
(b) preferably replace any existing values of the keywo= rd rather than write a whole new line.

(b) I guess= could be achieved with something like

(repla= ce-regexp (format "\(^[ \t]*#\\+%s: \)\(.*\)" key) (concat "= \1" value))
But what about (a)? I thought org already h= ad a couple of functions that performed this kind of serach but now I'm= not so sure.=C2=A0


=C2=A0
Regards,

--
Nicolas Goaziou
--000000000000c597f7057ab96263--