summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien <bzg@gnu.org>2020-02-12 22:40:45 +0100
committerBastien <bzg@gnu.org>2020-02-12 22:40:45 +0100
commitbe93859c78e26c0f33f6c9d459b34a3945734283 (patch)
treecc4c9e8037c632e7883492f1bc3d64b07d9c4a51
parentcc38fdc7f0bee4c6673e966a8a24e7db1d36a954 (diff)
downloadorg-mode-be93859c78e26c0f33f6c9d459b34a3945734283.tar.gz
org.el (org-babel-load-file): Load emacs-lisp and elisp src blocks
* lisp/org.el (org-babel-load-file): Load both "emacs-lisp" and "elisp" source blocks. * lisp/ob-tangle.el (org-babel-tangle-file) (org-babel-tangle, org-babel-tangle-collect-blocks): Use a regular expression to match the language(s) to tangle. Thanks to Troy Hinckley for reporting this.
-rw-r--r--lisp/ob-tangle.el31
-rw-r--r--lisp/org.el2
2 files changed, 18 insertions, 15 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 9460398..1195e89 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -166,13 +166,14 @@ evaluating BODY."
(def-edebug-spec org-babel-with-temp-filebuffer (form body))
;;;###autoload
-(defun org-babel-tangle-file (file &optional target-file lang)
+(defun org-babel-tangle-file (file &optional target-file lang-re)
"Extract the bodies of source code blocks in FILE.
Source code blocks are extracted with `org-babel-tangle'.
Optional argument TARGET-FILE can be used to specify a default
-export file for all source blocks. Optional argument LANG can be
-used to limit the exported source code blocks by language.
-Return a list whose CAR is the tangled file name."
+export file for all source blocks. Optional argument LANG-RE can
+be used to limit the exported source code blocks by languages
+matching a regular expression. Return a list whose CAR is the
+tangled file name."
(interactive "fFile to tangle: \nP")
(let ((visited-p (find-buffer-visiting (expand-file-name file)))
to-be-removed)
@@ -180,7 +181,7 @@ Return a list whose CAR is the tangled file name."
(save-window-excursion
(find-file file)
(setq to-be-removed (current-buffer))
- (mapcar #'expand-file-name (org-babel-tangle nil target-file lang)))
+ (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re)))
(unless visited-p
(kill-buffer to-be-removed)))))
@@ -192,7 +193,7 @@ Return a list whose CAR is the tangled file name."
(mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
;;;###autoload
-(defun org-babel-tangle (&optional arg target-file lang)
+(defun org-babel-tangle (&optional arg target-file lang-re)
"Write code blocks to source-specific files.
Extract the bodies of all source code blocks from the current
file into their own source-specific files.
@@ -200,8 +201,9 @@ With one universal prefix argument, only tangle the block at point.
When two universal prefix arguments, only tangle blocks for the
tangle file of the block at point.
Optional argument TARGET-FILE can be used to specify a default
-export file for all source blocks. Optional argument LANG can be
-used to limit the exported source code blocks by language."
+export file for all source blocks. Optional argument LANG-RE can
+be used to limit the exported source code blocks by languages
+matching a regular expression."
(interactive "P")
(run-hooks 'org-babel-pre-tangle-hook)
;; Possibly Restrict the buffer to the current code block
@@ -286,7 +288,7 @@ used to limit the exported source code blocks by language."
specs)))
(if (equal arg '(4))
(org-babel-tangle-single-block 1 t)
- (org-babel-tangle-collect-blocks lang tangle-file)))
+ (org-babel-tangle-collect-blocks lang-re tangle-file)))
(message "Tangled %d code block%s from %s" block-counter
(if (= block-counter 1) "" "s")
(file-name-nondirectory
@@ -364,13 +366,14 @@ that the appropriate major-mode is set. SPEC has the form:
(org-fill-template
org-babel-tangle-comment-format-end link-data)))))
-(defun org-babel-tangle-collect-blocks (&optional language tangle-file)
+(defun org-babel-tangle-collect-blocks (&optional lang-re tangle-file)
"Collect source blocks in the current Org file.
Return an association list of source-code block specifications of
the form used by `org-babel-spec-to-string' grouped by language.
-Optional argument LANGUAGE can be used to limit the collected
-source code blocks by language. Optional argument TANGLE-FILE
-can be used to limit the collected code blocks by target file."
+Optional argument LANG-RE can be used to limit the collected
+source code blocks by languages matching a regular expression.
+Optional argument TANGLE-FILE can be used to limit the collected
+code blocks by target file."
(let ((counter 0) last-heading-pos blocks)
(org-babel-map-src-blocks (buffer-file-name)
(let ((current-heading-pos
@@ -385,7 +388,7 @@ can be used to limit the collected code blocks by target file."
(src-tfile (cdr (assq :tangle (nth 2 info)))))
(unless (or (string= src-tfile "no")
(and tangle-file (not (equal tangle-file src-tfile)))
- (and language (not (string= language src-lang))))
+ (and lang-re (not (string-match-p lang-re src-lang))))
;; Add the spec for this block to blocks under its
;; language.
(let ((by-lang (assoc src-lang blocks))
diff --git a/lisp/org.el b/lisp/org.el
index ef2c7b9..b39ccc7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -224,7 +224,7 @@ byte-compiled before it is loaded."
(unless (org-file-newer-than-p
tangled-file
(file-attribute-modification-time (file-attributes file)))
- (org-babel-tangle-file file tangled-file "emacs-lisp"))
+ (org-babel-tangle-file file tangled-file "emacs-lisp\\|elisp"))
(if compile
(progn
(byte-compile-file tangled-file 'load)