forked from mirrors/org-mode
babel: simplifying handling of tangle langs
- Removed the org-babel-tangle-langs variable. - Added the org-babel-tangle-lang-exts alist for associating languages with file extensions - Comments now only added when the :comments header argument is set to yes * lisp/babel/ob-tangle.el (org-babel-tangle-w-comments): this is now a defcustom (org-babel-tangle-lang-exts): alist associating languages with file extension, this is also a defcustom (org-babel-spec-to-string): no longer using the complex tangle-lang variables
This commit is contained in:
parent
cab1e23d61
commit
c981f6d697
|
@ -33,19 +33,25 @@
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(require 'cl))
|
(require 'cl))
|
||||||
|
|
||||||
(defvar org-babel-tangle-langs nil
|
(defcustom org-babel-tangle-w-comments nil
|
||||||
"List of languages supported by `org-babel-tangle'. The first
|
|
||||||
element of each language's list is a string indicating the name
|
|
||||||
of the language, the second element should be the file extension
|
|
||||||
of the language, an optional third element the shebang(#!) line
|
|
||||||
to use when writing out the language to file, and an optional
|
|
||||||
fourth element is a flag which when true indicates that the
|
|
||||||
language does not support comments.")
|
|
||||||
|
|
||||||
(defvar org-babel-tangle-w-comments nil
|
|
||||||
"Control the insertion of comments into tangled code. Non-nil
|
"Control the insertion of comments into tangled code. Non-nil
|
||||||
value will result in the insertion of comments for those
|
value will result in the insertion of comments for those
|
||||||
languages with comment support.")
|
languages with comment support."
|
||||||
|
:group 'org-babel-tangle
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
|
(defcustom org-babel-tangle-lang-exts
|
||||||
|
'(("emacs-lisp" . "el"))
|
||||||
|
"Alist mapping languages to their file extensions.
|
||||||
|
The key is the language name, the value is the string that should
|
||||||
|
be inserted as the extension commonly used to identify files
|
||||||
|
written in this language. If no entry is found in this list,
|
||||||
|
then the name of the language is used."
|
||||||
|
:group 'org-babel-tangle
|
||||||
|
:type '(repeat
|
||||||
|
(cons
|
||||||
|
(string "Language name")
|
||||||
|
(string "File Extension"))))
|
||||||
|
|
||||||
(defun org-babel-load-file (file)
|
(defun org-babel-load-file (file)
|
||||||
"Load the contents of the Emacs Lisp source code blocks in the
|
"Load the contents of the Emacs Lisp source code blocks in the
|
||||||
|
@ -101,6 +107,7 @@ exported source code blocks by language."
|
||||||
(lambda (by-lang)
|
(lambda (by-lang)
|
||||||
(let* ((lang (car by-lang))
|
(let* ((lang (car by-lang))
|
||||||
(specs (cdr by-lang))
|
(specs (cdr by-lang))
|
||||||
|
(ext (or (cdr (assoc lang org-babel-tangle-lang-exts)) lang))
|
||||||
(lang-f (intern
|
(lang-f (intern
|
||||||
(concat
|
(concat
|
||||||
(or (and (cdr (assoc lang org-src-lang-modes))
|
(or (and (cdr (assoc lang org-src-lang-modes))
|
||||||
|
@ -108,19 +115,14 @@ exported source code blocks by language."
|
||||||
(cdr (assoc lang org-src-lang-modes))))
|
(cdr (assoc lang org-src-lang-modes))))
|
||||||
lang)
|
lang)
|
||||||
"-mode")))
|
"-mode")))
|
||||||
(lang-specs (cdr (assoc lang org-babel-tangle-langs)))
|
|
||||||
(ext (nth 0 lang-specs))
|
|
||||||
(she-bang (nth 1 lang-specs))
|
|
||||||
(commentable (and (fboundp lang-f) (not (nth 2 lang-specs))))
|
|
||||||
she-banged)
|
she-banged)
|
||||||
(mapc
|
(mapc
|
||||||
(lambda (spec)
|
(lambda (spec)
|
||||||
(flet ((get-spec (name)
|
(flet ((get-spec (name)
|
||||||
(cdr (assoc name (nth 2 spec)))))
|
(cdr (assoc name (nth 2 spec)))))
|
||||||
(let* ((tangle (get-spec :tangle))
|
(let* ((tangle (get-spec :tangle))
|
||||||
(she-bang (if (> (length (get-spec :shebang)) 0)
|
(she-bang ((lambda (sheb) (when (> (length sheb) 0) sheb))
|
||||||
(get-spec :shebang)
|
(get-spec :shebang)))
|
||||||
she-bang))
|
|
||||||
(base-name (or (cond
|
(base-name (or (cond
|
||||||
((string= "yes" tangle)
|
((string= "yes" tangle)
|
||||||
(file-name-sans-extension
|
(file-name-sans-extension
|
||||||
|
@ -219,18 +221,13 @@ code blocks by language."
|
||||||
(cdr (assoc :noweb params))))
|
(cdr (assoc :noweb params))))
|
||||||
(org-babel-expand-noweb-references
|
(org-babel-expand-noweb-references
|
||||||
info)
|
info)
|
||||||
(nth 1 info)))
|
(nth 1 info))))
|
||||||
(nth 2
|
|
||||||
(cdr (assoc src-lang
|
|
||||||
org-babel-tangle-langs))))
|
|
||||||
by-lang)) blocks))))))
|
by-lang)) blocks))))))
|
||||||
;; ensure blocks in the correct order
|
;; ensure blocks in the correct order
|
||||||
(setq blocks
|
(setq blocks
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang))))
|
(lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang))))
|
||||||
blocks))
|
blocks))
|
||||||
;; blocks should contain all source-blocks organized by language
|
|
||||||
;; (message "blocks=%S" blocks) ;; debugging
|
|
||||||
blocks))
|
blocks))
|
||||||
|
|
||||||
(defun org-babel-spec-to-string (spec)
|
(defun org-babel-spec-to-string (spec)
|
||||||
|
@ -243,11 +240,7 @@ form
|
||||||
(let ((link (nth 0 spec))
|
(let ((link (nth 0 spec))
|
||||||
(source-name (nth 1 spec))
|
(source-name (nth 1 spec))
|
||||||
(body (nth 3 spec))
|
(body (nth 3 spec))
|
||||||
(commentable (not (if (> (length (cdr (assoc :comments (nth 2 spec))))
|
(commentable (string= (cdr (assoc :comments (nth 2 spec))) "yes")))
|
||||||
0)
|
|
||||||
(string= (cdr (assoc :comments (nth 2 spec)))
|
|
||||||
"no")
|
|
||||||
(nth 4 spec)))))
|
|
||||||
(flet ((insert-comment (text)
|
(flet ((insert-comment (text)
|
||||||
(when (and commentable
|
(when (and commentable
|
||||||
org-babel-tangle-w-comments)
|
org-babel-tangle-w-comments)
|
||||||
|
|
Loading…
Reference in New Issue