فهرست منبع

DONE re-work tangling system

  the tangling header arguments are now working along the new NuWeb
  inspired schema
Eric Schulte 16 سال پیش
والد
کامیت
bfdc0bbb35
3فایلهای تغییر یافته به همراه19 افزوده شده و 14 حذف شده
  1. 15 9
      lisp/org-babel-tangle.el
  2. 2 3
      org-babel.org
  3. 2 2
      test-tangle.org

+ 15 - 9
lisp/org-babel-tangle.el

@@ -49,7 +49,7 @@ file using `load-file'."
                               (sixth (file-attributes file))))))
     (let* ((base-name (file-name-sans-extension file))
            (exported-file (concat base-name ".el")))
-      (message "building %s" exported-file) ;; debugging
+      ;; (message "building %s" exported-file) ;; debugging
       ;; tangle if the org-mode file is newer than the elisp file
       (unless (and (file-exists-p exported-file) (> (age file) (age exported-file)))
         (org-babel-tangle-file file base-name "emacs-lisp"))
@@ -72,8 +72,7 @@ source blocks.  Optional argument LANG can be used to limit the
 exported source code blocks by language."
   (interactive)
   (save-excursion
-    (let ((base-name (file-name-sans-extension (buffer-file-name)))
-          (block-counter 0)
+    (let ((block-counter 0)
           path-collector)
       (mapc ;; for every language create a file
        (lambda (by-lang)
@@ -85,14 +84,18 @@ exported source code blocks by language."
                 (she-bang (second lang-specs)))
            (mapc
             (lambda (spec)
-              (let* ((tangle (cdr (assoc :tangle params)))
-                     (base-name (or (when (not (or (string= tangle "yes")
-                                                   (string= tangle "no")))
-                                      (when (> (length tangle) 0) tangle))
+              (let* ((tangle (cdr (assoc :tangle (third spec))))
+                     (base-name (or (cond
+                                     ((string= "yes" tangle)
+                                      (file-name-sans-extension (buffer-file-name)))
+                                     ((string= "no" tangle) nil)
+                                     ((> (length tangle) 0) tangle))
                                     target-file))
                      (file-name (when base-name
                                   (concat base-name "." ext))))
-                (message "tangle=%S base-name=%S file-name=%S" tangle base-name file-name)
+                ;; ;; debugging
+                ;; (message "tangle=%S base-name=%S file-name=%S"
+                ;;          tangle base-name file-name)
                 (when file-name
                   ;; delete any old versions of file
                   (when (and (file-exists-p file-name)
@@ -106,10 +109,13 @@ exported source code blocks by language."
                      (point) (progn (insert "generated by org-babel-tangle") (point)))
                     (org-babel-spec-to-string spec)
                     (append-to-file nil nil file-name))
+                  ;; update counter
+                  (setq block-counter (+ 1 block-counter))
                   (add-to-list 'path-collector file-name))))
             specs)))
        (org-babel-tangle-collect-blocks lang))
-      (message "tangled %d source-code blocks" block-counter)
+      (message "tangled %d source-code block%s" block-counter
+               (if (> block-counter 1) "s" ""))
       path-collector)))
 
 (defun org-babel-tangle-collect-blocks (&optional lang)

+ 2 - 3
org-babel.org

@@ -207,7 +207,7 @@ would then be [[#sandbox][the sandbox]].
 #+end_src
 
   
-* Tasks [38/61]
+* Tasks [39/61]
 ** TODO new reference syntax *inside* source code blocks
 This is from an email discussion on the org-mode mailing list with
 Sébastien.  The goal here is to mimic the source-block reference style
@@ -240,7 +240,7 @@ being generated at =ruby-nuweb.rb= with the following contents
 : puts "                            Ruby                            "
 : puts "---------------------------footer---------------------------"
 
-** STARTED re-work tangling system
+** DONE re-work tangling system
 Sometimes when tangling a file (e.g. when extracting elisp from a
 org-mode file) we want to get nearly every source-code block.
 
@@ -273,7 +273,6 @@ can happen in two ways...
 #+resname:
 : succeed
 
-
 ** PROPOSED raise elisp error when source-blocks return errors
 Not sure how/if this would work, but it may be desirable.
 

+ 2 - 2
test-tangle.org

@@ -13,7 +13,7 @@ echo "line 2"
 more text
 
 #+srcname: ruby-no-session
-#+begin_src ruby 
+#+begin_src ruby :tangle yes
   def hello
     puts "hello world"
   end
@@ -21,7 +21,7 @@ more text
 
 
 #+srcname: first-ruby-block
-#+begin_src ruby :session special
+#+begin_src ruby :session special :tangle trivial-symbol
 :block_the_first
 #+end_src