Tidy load-time specific source block evaluation
This commit is contained in:
parent
ec0210d63f
commit
eeae503add
64
README.org
64
README.org
@ -1816,25 +1816,51 @@ variables in order to export the =info-org-link= types in this document to
|
||||
#+caption: Evaluate specific source blocks at load-time.
|
||||
#+name: lst:load-time-specific-source-block-evaluation
|
||||
#+begin_src emacs-lisp
|
||||
(defun my-org-eval-blocks-named (infix)
|
||||
"Evaluate all source blocks having INFIX in their name."
|
||||
(when (eq major-mode 'org-mode)
|
||||
(let ((blocks
|
||||
(org-element-map
|
||||
(org-element-parse-buffer 'greater-element nil) 'src-block
|
||||
(lambda (block)
|
||||
(let ((name (org-element-property :name block)))
|
||||
(when (and name (string-match-p infix name))
|
||||
block))))))
|
||||
(dolist (block blocks)
|
||||
(goto-char (org-element-property :begin block))
|
||||
(org-babel-execute-src-block)))))
|
||||
(with-eval-after-load 'emacs
|
||||
(defun org-eval-infixed-blocks (infix)
|
||||
"Evaluate all source blocks having INFIX in their name."
|
||||
(when (eq major-mode 'org-mode)
|
||||
(let ((blocks
|
||||
(org-element-map
|
||||
(org-element-parse-buffer 'greater-element nil) 'src-block
|
||||
(lambda (block)
|
||||
(when-let ((name (org-element-property :name block)))
|
||||
(when (string-match-p infix name) block))))))
|
||||
(dolist (block blocks)
|
||||
(goto-char (org-element-property :begin block))
|
||||
(org-babel-execute-src-block)))))
|
||||
|
||||
;; Emacs looks for "Local variables:" after the last "?\n?\f".
|
||||
(add-to-list 'safe-local-eval-forms
|
||||
'(apply 'my-org-eval-blocks-named '("emacs-lisp-setup")))
|
||||
(add-to-list 'safe-local-eval-forms
|
||||
'(apply 'my-org-eval-blocks-named '("python-setup")))
|
||||
(defun org-eval-emacs-lisp-setup-blocks ()
|
||||
"Evaluate all source blocks having \"emacs-lisp-setup\" in their name."
|
||||
(org-eval-infixed-blocks "emacs-lisp-setup"))
|
||||
|
||||
(defun org-eval-python-setup-blocks ()
|
||||
"Evaluate all source blocks having \"python-setup\" in their name."
|
||||
(org-eval-infixed-blocks "python-setup"))
|
||||
|
||||
;; Emacs looks for "Local variables:" after the last "?\n?\f".
|
||||
(add-to-list 'safe-local-eval-forms '(org-eval-emacs-lisp-setup-blocks))
|
||||
(add-to-list 'safe-local-eval-forms '(org-eval-python-setup-blocks)))
|
||||
|
||||
(with-eval-after-load 'emacs
|
||||
(defun my-org-eval-blocks-named (infix)
|
||||
"Evaluate all source blocks having INFIX in their name."
|
||||
(when (eq major-mode 'org-mode)
|
||||
(let ((blocks
|
||||
(org-element-map
|
||||
(org-element-parse-buffer 'greater-element nil) 'src-block
|
||||
(lambda (block)
|
||||
(when-let ((name (org-element-property :name block)))
|
||||
(when (string-match-p infix name) block))))))
|
||||
(dolist (block blocks)
|
||||
(goto-char (org-element-property :begin block))
|
||||
(org-babel-execute-src-block)))))
|
||||
|
||||
;; Emacs looks for "Local variables:" after the last "?\n?\f".
|
||||
(add-to-list 'safe-local-eval-forms
|
||||
'(apply 'my-org-eval-blocks-named '("emacs-lisp-setup")))
|
||||
(add-to-list 'safe-local-eval-forms
|
||||
'(apply 'my-org-eval-blocks-named '("python-setup"))))
|
||||
#+end_src
|
||||
|
||||
*** [[info:org#LaTeX header and sectioning][Easy LaTeX preamble editing]]
|
||||
@ -3596,6 +3622,6 @@ Only the [[info:org#Top][Org]] source file shows the local variables footer.
|
||||
|
||||
# Local Variables:
|
||||
# compile-command: "latexmk -interaction=nonstopmode -lualatex -pvc -shell-escape README.tex"
|
||||
# eval: (apply 'my-org-eval-blocks-named '("emacs-lisp-setup"))
|
||||
# eval: (org-eval-emacs-lisp-setup-blocks)
|
||||
# fill-column: 80
|
||||
# End:
|
||||
|
@ -5,21 +5,22 @@ emacs -Q --batch --eval "
|
||||
(require 'org)
|
||||
(require 'ob-latex)
|
||||
(require 'ox-latex)
|
||||
(defun my-org-eval-blocks-named (infix)
|
||||
(defun org-eval-infixed-blocks (infix)
|
||||
(when (eq major-mode 'org-mode)
|
||||
(let ((blocks
|
||||
(org-element-map
|
||||
(org-element-parse-buffer 'greater-element nil) 'src-block
|
||||
(lambda (block)
|
||||
(let ((name (org-element-property :name block)))
|
||||
(when (and name (string-match-p infix name))
|
||||
block))))))
|
||||
(when-let ((name (org-element-property :name block)))
|
||||
(when (string-match-p infix name) block))))))
|
||||
(dolist (block blocks)
|
||||
(goto-char (org-element-property :begin block))
|
||||
(org-babel-execute-src-block)))))
|
||||
|
||||
(add-to-list 'safe-local-eval-forms
|
||||
'(apply 'my-org-eval-blocks-named '(\"emacs-lisp-setup\")))
|
||||
(defun org-eval-emacs-lisp-setup-blocks ()
|
||||
(org-eval-infixed-blocks \"emacs-lisp-setup\"))
|
||||
|
||||
(add-to-list 'safe-local-eval-forms '(org-eval-emacs-lisp-setup-blocks))
|
||||
|
||||
(setq org-confirm-babel-evaluate nil)
|
||||
(setq python-indent-guess-indent-offset nil)
|
||||
|
Loading…
Reference in New Issue
Block a user