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.
This commit is contained in:
Bastien 2020-02-12 22:40:45 +01:00
parent cc38fdc7f0
commit be93859c78
2 changed files with 18 additions and 15 deletions

View File

@ -166,13 +166,14 @@ evaluating BODY."
(def-edebug-spec org-babel-with-temp-filebuffer (form body)) (def-edebug-spec org-babel-with-temp-filebuffer (form body))
;;;###autoload ;;;###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. "Extract the bodies of source code blocks in FILE.
Source code blocks are extracted with `org-babel-tangle'. Source code blocks are extracted with `org-babel-tangle'.
Optional argument TARGET-FILE can be used to specify a default Optional argument TARGET-FILE can be used to specify a default
export file for all source blocks. Optional argument LANG can be export file for all source blocks. Optional argument LANG-RE can
used to limit the exported source code blocks by language. be used to limit the exported source code blocks by languages
Return a list whose CAR is the tangled file name." matching a regular expression. Return a list whose CAR is the
tangled file name."
(interactive "fFile to tangle: \nP") (interactive "fFile to tangle: \nP")
(let ((visited-p (find-buffer-visiting (expand-file-name file))) (let ((visited-p (find-buffer-visiting (expand-file-name file)))
to-be-removed) to-be-removed)
@ -180,7 +181,7 @@ Return a list whose CAR is the tangled file name."
(save-window-excursion (save-window-excursion
(find-file file) (find-file file)
(setq to-be-removed (current-buffer)) (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 (unless visited-p
(kill-buffer to-be-removed))))) (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))) (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
;;;###autoload ;;;###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. "Write code blocks to source-specific files.
Extract the bodies of all source code blocks from the current Extract the bodies of all source code blocks from the current
file into their own source-specific files. 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 When two universal prefix arguments, only tangle blocks for the
tangle file of the block at point. tangle file of the block at point.
Optional argument TARGET-FILE can be used to specify a default Optional argument TARGET-FILE can be used to specify a default
export file for all source blocks. Optional argument LANG can be export file for all source blocks. Optional argument LANG-RE can
used to limit the exported source code blocks by language." be used to limit the exported source code blocks by languages
matching a regular expression."
(interactive "P") (interactive "P")
(run-hooks 'org-babel-pre-tangle-hook) (run-hooks 'org-babel-pre-tangle-hook)
;; Possibly Restrict the buffer to the current code block ;; Possibly Restrict the buffer to the current code block
@ -286,7 +288,7 @@ used to limit the exported source code blocks by language."
specs))) specs)))
(if (equal arg '(4)) (if (equal arg '(4))
(org-babel-tangle-single-block 1 t) (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 (message "Tangled %d code block%s from %s" block-counter
(if (= block-counter 1) "" "s") (if (= block-counter 1) "" "s")
(file-name-nondirectory (file-name-nondirectory
@ -364,13 +366,14 @@ that the appropriate major-mode is set. SPEC has the form:
(org-fill-template (org-fill-template
org-babel-tangle-comment-format-end link-data))))) 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. "Collect source blocks in the current Org file.
Return an association list of source-code block specifications of Return an association list of source-code block specifications of
the form used by `org-babel-spec-to-string' grouped by language. the form used by `org-babel-spec-to-string' grouped by language.
Optional argument LANGUAGE can be used to limit the collected Optional argument LANG-RE can be used to limit the collected
source code blocks by language. Optional argument TANGLE-FILE source code blocks by languages matching a regular expression.
can be used to limit the collected code blocks by target file." Optional argument TANGLE-FILE can be used to limit the collected
code blocks by target file."
(let ((counter 0) last-heading-pos blocks) (let ((counter 0) last-heading-pos blocks)
(org-babel-map-src-blocks (buffer-file-name) (org-babel-map-src-blocks (buffer-file-name)
(let ((current-heading-pos (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))))) (src-tfile (cdr (assq :tangle (nth 2 info)))))
(unless (or (string= src-tfile "no") (unless (or (string= src-tfile "no")
(and tangle-file (not (equal tangle-file src-tfile))) (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 ;; Add the spec for this block to blocks under its
;; language. ;; language.
(let ((by-lang (assoc src-lang blocks)) (let ((by-lang (assoc src-lang blocks))

View File

@ -224,7 +224,7 @@ byte-compiled before it is loaded."
(unless (org-file-newer-than-p (unless (org-file-newer-than-p
tangled-file tangled-file
(file-attribute-modification-time (file-attributes 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 (if compile
(progn (progn
(byte-compile-file tangled-file 'load) (byte-compile-file tangled-file 'load)