* creating new #+KEYWORD: variables @ 2018-11-09 3:32 Matt Price 2018-11-09 9:29 ` Diego Zamboni 2018-11-10 7:22 ` Nicolas Goaziou 0 siblings, 2 replies; 10+ messages in thread From: Matt Price @ 2018-11-09 3:32 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 993 bytes --] 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! [-- Attachment #2: Type: text/html, Size: 1386 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-09 3:32 creating new #+KEYWORD: variables Matt Price @ 2018-11-09 9:29 ` Diego Zamboni 2018-11-10 2:24 ` Matt Price 2018-11-10 7:22 ` Nicolas Goaziou 1 sibling, 1 reply; 10+ messages in thread From: Diego Zamboni @ 2018-11-09 9:29 UTC (permalink / raw) To: moptop99; +Cc: Org-mode [-- Attachment #1: Type: text/plain, Size: 1683 bytes --] 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 <moptop99@gmail.com> 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! > > > [-- Attachment #2: Type: text/html, Size: 2653 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-09 9:29 ` Diego Zamboni @ 2018-11-10 2:24 ` Matt Price 0 siblings, 0 replies; 10+ messages in thread From: Matt Price @ 2018-11-10 2:24 UTC (permalink / raw) To: diego; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1880 bytes --] ah, thank you Diego, I wil ltry it out and report back. On Fri, Nov 9, 2018 at 4:29 AM Diego Zamboni <diego@zzamboni.org> 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 <moptop99@gmail.com> 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! >> >> >> [-- Attachment #2: Type: text/html, Size: 3074 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-09 3:32 creating new #+KEYWORD: variables Matt Price 2018-11-09 9:29 ` Diego Zamboni @ 2018-11-10 7:22 ` Nicolas Goaziou 2018-11-10 16:17 ` Matt Price 2018-11-12 9:11 ` Diego Zamboni 1 sibling, 2 replies; 10+ messages in thread From: Nicolas Goaziou @ 2018-11-10 7:22 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode Hello, Matt Price <moptop99@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 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-10 7:22 ` Nicolas Goaziou @ 2018-11-10 16:17 ` Matt Price 2018-11-10 17:11 ` John Kitchin 2018-11-12 9:11 ` Diego Zamboni 1 sibling, 1 reply; 10+ messages in thread From: Matt Price @ 2018-11-10 16:17 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 2674 bytes --] On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote: > Hello, > > Matt Price <moptop99@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 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 > [-- Attachment #2: Type: text/html, Size: 3982 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-10 16:17 ` Matt Price @ 2018-11-10 17:11 ` John Kitchin 2018-11-10 18:58 ` Nicolas Goaziou 0 siblings, 1 reply; 10+ messages in thread From: John Kitchin @ 2018-11-10 17:11 UTC (permalink / raw) To: Matt Price; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 3377 bytes --] 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 <moptop99@gmail.com> wrote: > > > On Sat, Nov 10, 2018 at 2:22 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> > wrote: > >> Hello, >> >> Matt Price <moptop99@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 >> 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 >> > [-- Attachment #2: Type: text/html, Size: 5278 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-10 17:11 ` John Kitchin @ 2018-11-10 18:58 ` Nicolas Goaziou 2018-11-15 12:15 ` Matt Price 0 siblings, 1 reply; 10+ messages in thread From: Nicolas Goaziou @ 2018-11-10 18:58 UTC (permalink / raw) To: John Kitchin; +Cc: org-mode-email Hello, John Kitchin <jkitchin@andrew.cmu.edu> 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-10 18:58 ` Nicolas Goaziou @ 2018-11-15 12:15 ` Matt Price 2018-11-15 19:51 ` John Kitchin 0 siblings, 1 reply; 10+ messages in thread From: Matt Price @ 2018-11-15 12:15 UTC (permalink / raw) To: John Kitchin, Org Mode [-- Attachment #1: Type: text/plain, Size: 1839 bytes --] 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) > > (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 > [-- Attachment #2: Type: text/html, Size: 2851 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-15 12:15 ` Matt Price @ 2018-11-15 19:51 ` John Kitchin 0 siblings, 0 replies; 10+ messages in thread From: John Kitchin @ 2018-11-15 19:51 UTC (permalink / raw) To: Matt Price; +Cc: org-mode-email [-- Attachment #1: Type: text/plain, Size: 3059 bytes --] 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 <moptop99@gmail.com> wrote: > > > 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) >> > (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 >> > [-- Attachment #2: Type: text/html, Size: 28061 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: creating new #+KEYWORD: variables 2018-11-10 7:22 ` Nicolas Goaziou 2018-11-10 16:17 ` Matt Price @ 2018-11-12 9:11 ` Diego Zamboni 1 sibling, 0 replies; 10+ messages in thread From: Diego Zamboni @ 2018-11-12 9:11 UTC (permalink / raw) To: Org-mode [-- Attachment #1: Type: text/plain, Size: 1655 bytes --] 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 <mail@nicolasgoaziou.fr> wrote: > Hello, > > Matt Price <moptop99@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 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 > > [-- Attachment #2: Type: text/html, Size: 2529 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-11-15 19:52 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-11-09 3:32 creating new #+KEYWORD: variables Matt Price 2018-11-09 9:29 ` Diego Zamboni 2018-11-10 2:24 ` Matt Price 2018-11-10 7:22 ` Nicolas Goaziou 2018-11-10 16:17 ` Matt Price 2018-11-10 17:11 ` John Kitchin 2018-11-10 18:58 ` Nicolas Goaziou 2018-11-15 12:15 ` Matt Price 2018-11-15 19:51 ` John Kitchin 2018-11-12 9:11 ` Diego Zamboni
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).