emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] creating new #+KEYWORD: variables


From: John Kitchin
Subject: Re: [O] creating new #+KEYWORD: variables
Date: Sat, 10 Nov 2018 12:11:36 -0500

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


On Sat, Nov 10, 2018 at 11:17 AM Matt Price <address@hidden> wrote:


On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou <address@hidden> wrote:
Hello,

Matt Price <address@hidden> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]