mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-26 17:02:53 +00:00
languages are now able to specify that they don't support comments for tangling
This commit is contained in:
parent
6a9cd84440
commit
5d4ac21aca
|
@ -34,7 +34,7 @@
|
|||
|
||||
(org-babel-add-interpreter "css")
|
||||
|
||||
(add-to-list 'org-babel-tangle-langs '("css" "css"))
|
||||
(add-to-list 'org-babel-tangle-langs '("css" "css" nil t))
|
||||
|
||||
(defun org-babel-execute:css (body params)
|
||||
"Execute a block of CSS code with org-babel. This function is
|
||||
|
|
|
@ -35,8 +35,9 @@
|
|||
"Association list matching source-block languages. The car of
|
||||
each element should be a string indicating the source block
|
||||
language, and the cdr should be a list containing the extension
|
||||
and shebang(#!) line to use when writing out the language to
|
||||
file.")
|
||||
shebang(#!) line to use when writing out the language to file,
|
||||
and an optional flag indicating that the language is not
|
||||
commentable.")
|
||||
|
||||
(defun org-babel-load-file (file)
|
||||
"Load the contents of the Emacs Lisp source code blocks in the
|
||||
|
@ -80,7 +81,8 @@ exported source code blocks by language."
|
|||
(lang-f (intern (concat lang "-mode")))
|
||||
(lang-specs (cdr (assoc lang org-babel-tangle-langs)))
|
||||
(ext (first lang-specs))
|
||||
(she-bang (second lang-specs)))
|
||||
(she-bang (second lang-specs))
|
||||
(commentable (not (third lang-specs))))
|
||||
(mapc
|
||||
(lambda (spec)
|
||||
(let* ((tangle (cdr (assoc :tangle (third spec))))
|
||||
|
@ -104,8 +106,9 @@ exported source code blocks by language."
|
|||
(with-temp-buffer
|
||||
(funcall lang-f)
|
||||
(when she-bang (insert (concat she-bang "\n")))
|
||||
(when commentable
|
||||
(comment-region
|
||||
(point) (progn (insert "generated by org-babel-tangle") (point)))
|
||||
(point) (progn (insert "generated by org-babel-tangle") (point))))
|
||||
(org-babel-spec-to-string spec)
|
||||
(append-to-file nil nil file-name))
|
||||
;; update counter
|
||||
|
@ -134,7 +137,7 @@ code blocks by language."
|
|||
(src-lang (first info))
|
||||
(body (org-babel-expand-noweb-references info))
|
||||
(params (third info))
|
||||
(spec (list link source-name params body))
|
||||
(spec (list link source-name params body (third (cdr (assoc src-lang org-babel-tangle-langs)))))
|
||||
by-lang)
|
||||
(unless (string= (cdr (assoc :tangle params)) "no") ;; maybe skip
|
||||
(unless (and lang (not (string= lang src-lang))) ;; maybe limit by language
|
||||
|
@ -146,7 +149,7 @@ code blocks by language."
|
|||
(setq blocks
|
||||
(mapcar (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang)))) blocks))
|
||||
;; blocks should contain all source-blocks organized by language
|
||||
(message "blocks=%S" blocks) ;; debugging
|
||||
;; (message "blocks=%S" blocks) ;; debugging
|
||||
blocks))
|
||||
|
||||
(defun org-babel-spec-to-string (spec)
|
||||
|
@ -157,10 +160,12 @@ form
|
|||
|
||||
(link source-name params body)"
|
||||
(flet ((insert-comment (text)
|
||||
(comment-region (point) (progn (insert text) (point)))))
|
||||
(when commentable
|
||||
(comment-region (point) (progn (insert text) (point))))))
|
||||
(let ((link (first spec))
|
||||
(source-name (second spec))
|
||||
(body (fourth spec)))
|
||||
(body (fourth spec))
|
||||
(commentable (not (fifth spec))))
|
||||
(insert "\n\n")
|
||||
(insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
|
||||
(insert (format "\n%s\n" (org-babel-chomp body)))
|
||||
|
|
Loading…
Reference in a new issue