[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Share] collect some idea about auto eval code when TAB expand headline
From: |
stardiviner |
Subject: |
[Share] collect some idea about auto eval code when TAB expand headline |
Date: |
Fri, 16 Oct 2020 13:01:21 +0800 |
User-agent: |
mu4e 1.5.5; emacs 28.0.50 |
I write an elisp config for Org Mode to auto evaluate inline source block in
property "EVAL".
#+begin_src emacs-lisp
(defcustom org-property-eval-keywords-list '("EVAL")
"A list of property keywords for evaluate code."
:type 'list
:safe #'listp
:group 'org)
(defun org-property-eval-code (&optional state)
"Evaluate Org inline source block in property value."
(when (memq state '(children subtree))
(if-let ((inline-src-block (org-entry-get nil "EVAL" nil)))
(with-temp-buffer
(insert inline-src-block)
(goto-char (point-min))
(require 'ob-async nil t)
(setq-local org-babel-default-inline-header-args
'((:results . "silent") (:async . t)))
(let* ((context (org-element-context))
(src-block-info (org-babel-get-src-block-info nil context))
(type (org-element-type context)))
(when (eq type 'inline-src-block)
;; ob-async: `org-babel-execute-src-block:async'
(org-babel-execute-src-block nil src-block-info)))))))
(add-hook 'org-cycle-hook #'org-property-eval-code)
#+end_src
A question:
How to get all property keywords under headline? I want to use ~member~ to
detect
whether property keywords has member in defined custom list
~org-property-eval-keywords-list~.
Second question:
Do you have any good idea or suggest about this?
Thanks for sharing your idea.
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
- [Share] collect some idea about auto eval code when TAB expand headline,
stardiviner <=