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--