Rewrite bin/org-tangle
This commit is contained in:
parent
2516a123d6
commit
075b4557f6
1 changed files with 19 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!emacs --script
|
#!/usr/bin/env bash
|
||||||
;;; bin/org-tangle -*- lexical-binding: t; -*-
|
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*-
|
||||||
|
;;; bin/org-tangle
|
||||||
|
|
||||||
;; Extracts source blocks from org files and prints them to stdout. Debug/info
|
;; Extracts source blocks from org files and prints them to stdout. Debug/info
|
||||||
;; messages are directed to stderr and can be ignored. -l/--lang can be used to
|
;; messages are directed to stderr and can be ignored. -l/--lang can be used to
|
||||||
|
@ -24,9 +25,20 @@
|
||||||
(apply orig-fn args)))
|
(apply orig-fn args)))
|
||||||
(advice-add #'org-babel-tangle :around #'*org-babel-tangle)
|
(advice-add #'org-babel-tangle :around #'*org-babel-tangle)
|
||||||
|
|
||||||
(let ((lang (when (member (car command-line-args-left) '("--lang" "-l"))
|
(let (lang srcs)
|
||||||
(pop command-line-args-left)
|
(pop argv)
|
||||||
(pop command-line-args-left)))
|
(while argv
|
||||||
(srcs (cl-remove-if-not 'file-exists-p command-line-args-left)))
|
(let ((arg (pop argv)))
|
||||||
|
(pcase arg
|
||||||
|
((or "--lang" "-l")
|
||||||
|
(setq lang (pop argv)))
|
||||||
|
((guard (string-match-p "^--lang=" arg))
|
||||||
|
(setq lang (cadr (split-string arg "=" t t))))
|
||||||
|
((guard (file-exists-p arg))
|
||||||
|
(push arg srcs))
|
||||||
|
(_
|
||||||
|
(error "Unknown option or file: %s" arg)))))
|
||||||
|
|
||||||
(dolist (file srcs)
|
(dolist (file srcs)
|
||||||
(org-babel-tangle-file file nil lang)))
|
(org-babel-tangle-file file nil lang))
|
||||||
|
(kill-emacs 0))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue