1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-25 07:27:57 +00:00

languages are now able to specify that they don't support comments for tangling

This commit is contained in:
Eric Schulte 2009-08-04 13:23:23 -06:00
parent 6a9cd84440
commit 5d4ac21aca
2 changed files with 15 additions and 10 deletions

View File

@ -34,7 +34,7 @@
(org-babel-add-interpreter "css") (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) (defun org-babel-execute:css (body params)
"Execute a block of CSS code with org-babel. This function is "Execute a block of CSS code with org-babel. This function is

View File

@ -35,8 +35,9 @@
"Association list matching source-block languages. The car of "Association list matching source-block languages. The car of
each element should be a string indicating the source block each element should be a string indicating the source block
language, and the cdr should be a list containing the extension language, and the cdr should be a list containing the extension
and shebang(#!) line to use when writing out the language to shebang(#!) line to use when writing out the language to file,
file.") and an optional flag indicating that the language is not
commentable.")
(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
@ -80,7 +81,8 @@ exported source code blocks by language."
(lang-f (intern (concat lang "-mode"))) (lang-f (intern (concat lang "-mode")))
(lang-specs (cdr (assoc lang org-babel-tangle-langs))) (lang-specs (cdr (assoc lang org-babel-tangle-langs)))
(ext (first lang-specs)) (ext (first lang-specs))
(she-bang (second lang-specs))) (she-bang (second lang-specs))
(commentable (not (third lang-specs))))
(mapc (mapc
(lambda (spec) (lambda (spec)
(let* ((tangle (cdr (assoc :tangle (third spec)))) (let* ((tangle (cdr (assoc :tangle (third spec))))
@ -104,8 +106,9 @@ exported source code blocks by language."
(with-temp-buffer (with-temp-buffer
(funcall lang-f) (funcall lang-f)
(when she-bang (insert (concat she-bang "\n"))) (when she-bang (insert (concat she-bang "\n")))
(comment-region (when commentable
(point) (progn (insert "generated by org-babel-tangle") (point))) (comment-region
(point) (progn (insert "generated by org-babel-tangle") (point))))
(org-babel-spec-to-string spec) (org-babel-spec-to-string spec)
(append-to-file nil nil file-name)) (append-to-file nil nil file-name))
;; update counter ;; update counter
@ -134,7 +137,7 @@ code blocks by language."
(src-lang (first info)) (src-lang (first info))
(body (org-babel-expand-noweb-references info)) (body (org-babel-expand-noweb-references info))
(params (third 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) by-lang)
(unless (string= (cdr (assoc :tangle params)) "no") ;; maybe skip (unless (string= (cdr (assoc :tangle params)) "no") ;; maybe skip
(unless (and lang (not (string= lang src-lang))) ;; maybe limit by language (unless (and lang (not (string= lang src-lang))) ;; maybe limit by language
@ -146,7 +149,7 @@ code blocks by language."
(setq blocks (setq blocks
(mapcar (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang)))) blocks)) (mapcar (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang)))) blocks))
;; blocks should contain all source-blocks organized by language ;; blocks should contain all source-blocks organized by language
(message "blocks=%S" blocks) ;; debugging ;; (message "blocks=%S" blocks) ;; debugging
blocks)) blocks))
(defun org-babel-spec-to-string (spec) (defun org-babel-spec-to-string (spec)
@ -157,10 +160,12 @@ form
(link source-name params body)" (link source-name params body)"
(flet ((insert-comment (text) (flet ((insert-comment (text)
(comment-region (point) (progn (insert text) (point))))) (when commentable
(comment-region (point) (progn (insert text) (point))))))
(let ((link (first spec)) (let ((link (first spec))
(source-name (second spec)) (source-name (second spec))
(body (fourth spec))) (body (fourth spec))
(commentable (not (fifth spec))))
(insert "\n\n") (insert "\n\n")
(insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name)) (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
(insert (format "\n%s\n" (org-babel-chomp body))) (insert (format "\n%s\n" (org-babel-chomp body)))