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