Browse Source

now better at inserting wrapping comments, and using org-src-lang-modes

Eric Schulte 16 years ago
parent
commit
937e1aa981
1 changed files with 13 additions and 5 deletions
  1. 13 5
      lisp/org-babel-tangle.el

+ 13 - 5
lisp/org-babel-tangle.el

@@ -78,7 +78,11 @@ exported source code blocks by language."
        (lambda (by-lang)
          (let* ((lang (car by-lang))
                 (specs (cdr by-lang))
-                (lang-f (intern (concat lang "-mode")))
+                (lang-f (intern (concat
+                                 (or (plist-get org-src-lang-modes
+                                                (intern (concat ":" lang)))
+                                     lang)
+                                 "-mode")))
                 (lang-specs (cdr (assoc lang org-babel-tangle-langs)))
                 (ext (first lang-specs))
                 (she-bang (second lang-specs))
@@ -108,7 +112,8 @@ exported source code blocks by language."
                     (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)))
+                      (move-end-of-line nil))
                     (org-babel-spec-to-string spec)
                     (append-to-file nil nil file-name))
                   ;; update counter
@@ -161,7 +166,8 @@ form
   (link source-name params body)"
   (flet ((insert-comment (text)
                          (when commentable
-                           (comment-region (point) (progn (insert text) (point))))))
+                           (comment-region (point) (progn (insert text) (point)))
+                           (move-end-of-line nil))))
     (let ((link (first spec))
           (source-name (second spec))
           (body (fourth spec))
@@ -193,12 +199,14 @@ the source-code block which holds BODY."
                    (setq new-body (concat new-body text))))
       (with-temp-buffer
         (insert body) (goto-char (point-min))
-        (funcall (intern (concat lang "-mode")))
+        (funcall (intern (concat (or (plist-get org-src-lang-modes
+                                                (intern (concat ":" lang)))
+                                     lang) "-mode")))
         (setq index (point))
         (while (and (re-search-forward "<<\\(.+\\)>>" nil t))
           (save-match-data (setf source-name (match-string 1)))
           ;; add interval to new-body
-          (goto-char (match-end 0))
+          (goto-char (match-end 0)) (move-end-of-line nil)
           (nb-add (buffer-substring index (point)))
           (setq index (point))
           ;; if found, add body of referenced source-block