Fix org-babel-tangle-file usage

This commit is contained in:
Gerard Vermeulen 2021-11-30 11:57:07 +01:00
parent f56531b7bc
commit 2aba64cf76
3 changed files with 55 additions and 7 deletions

View File

@ -5,10 +5,29 @@
job="$(git diff-tree -r --name-only --no-commit-id HEAD^ HEAD -- README.org)"
if [ -n "$job" ]; then
emacs --batch \
--eval "(add-to-list 'safe-local-eval-forms '(apply 'my-org-eval-blocks-named '(\"emacs-lisp-setup\")))" \
--eval "(require 'org)" \
--eval "(org-babel-tangle-file \"$job\")"
emacs -Q --batch --eval "
(progn
(require 'org)
(defun my-org-eval-blocks-named (name)
(when (eq major-mode 'org-mode)
(let ((blocks
(org-element-map
(org-element-parse-buffer 'greater-element nil) 'src-block
(lambda (block)
(when (string= name (org-element-property :name block))
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\")))
(setq org-confirm-babel-evaluate nil)
(setq python-indent-guess-indent-offset nil)
(org-babel-tangle-file \"$job\"))
"
fi
# Local Variables:

View File

@ -3,6 +3,4 @@
# https://emacs.stackexchange.com/questions/27126/is-it-possible-to-org-bable-tangle-an-org-file-from-the-command-line
init:
git config core.hooksPath .githooks
emacs --batch \
--eval "(add-to-list 'safe-local-eval-forms '(apply 'my-org-eval-blocks-named '(\"emacs-lisp-setup\")))" \
--eval "(require 'org)" --eval '(org-babel-tangle-file "README.org")'
sh org-babel-tangle-file README.org

31
org-babel-tangle-file Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env sh
emacs -Q --batch --eval "
(progn
(require 'org)
(defun my-org-eval-blocks-named (name)
(when (eq major-mode 'org-mode)
(let ((blocks
(org-element-map
(org-element-parse-buffer 'greater-element nil) 'src-block
(lambda (block)
(when (string= name (org-element-property :name block))
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\")))
(setq org-confirm-babel-evaluate nil)
(setq python-indent-guess-indent-offset nil)
(org-babel-tangle-file \"$1\"))
"
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# sh-basic-offset: 2
# End: