bin/org-tangle: expand #+INCLUDE directives

See 711e68770 for details.
This commit is contained in:
Henrik Lissner 2020-07-25 22:57:22 -04:00
parent 8da31dbbab
commit 4b96039374
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -2,8 +2,9 @@
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*- ":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
;;; bin/org-tangle ;;; bin/org-tangle
;; Tangles source blocks from org files. Debug/info messages are directed to ;; Tangles source blocks from org files. Also expands #+INCLUDE directives,
;; stderr and can be ignored. ;; unlike vanilla `ob-tangle'. Debug/info messages are directed to stderr and
;; can be ignored.
;; ;;
;; -l/--lang LANG ;; -l/--lang LANG
;; Only include blocks in the specified language (e.g. emacs-lisp). ;; Only include blocks in the specified language (e.g. emacs-lisp).
@ -25,6 +26,7 @@
;; org-tangle --and tagA --and tagB my/literate/config.org ;; org-tangle --and tagA --and tagB my/literate/config.org
(require 'cl-lib) (require 'cl-lib)
(require 'ox)
(require 'ob-tangle) (require 'ob-tangle)
(defun usage () (defun usage ()
@ -140,5 +142,18 @@ trees with the :notangle: tag."
(_ (error "Unknown option or file: %s" arg))))) (_ (error "Unknown option or file: %s" arg)))))
(dolist (file srcs) (dolist (file srcs)
(org-babel-tangle-file file nil lang)) (let ((backup (make-temp-file (file-name-base file) nil ".backup.org")))
(unwind-protect
;; Prevent slow hooks from interfering
(let (org-mode-hook)
;; We do the ol' switcheroo because `org-babel-tangle' writes
;; changes to the current file, which would be imposing on the user.
(copy-file file backup t)
(with-current-buffer (find-file-noselect file)
;; Tangling doesn't expand #+INCLUDE directives, so we do it
;; ourselves, since includes are so useful for literate configs!
(org-export-expand-include-keyword)
(org-babel-tangle nil nil lang)))
(ignore-errors (copy-file backup file t))
(ignore-errors (delete-file backup)))))
(kill-emacs 0)) (kill-emacs 0))