Eric Schulte %!s(int64=16) %!d(string=hai) anos
pai
achega
50abb08479
Modificáronse 1 ficheiros con 8 adicións e 4 borrados
  1. 8 4
      lisp/org-babel-tangle.el

+ 8 - 4
lisp/org-babel-tangle.el

@@ -51,7 +51,10 @@ file into their own source-specific files."
       (org-babel-map-source-blocks (buffer-file-name)
         (let* ((link (progn (call-interactively 'org-store-link)
                             (org-babel-clean-text-properties (car (pop org-stored-links)))))
-               (source-name (intern (org-babel-get-src-block-name)))
+               (counter 0)
+               (source-name (intern (or (org-babel-get-src-block-name)
+                                        (progn (setq counter (+ 1 counter))
+                                               (format "block-%d" counter)))))
                (info (org-babel-get-src-block-info))
                (lang (first info))
                (body (second info))
@@ -60,14 +63,15 @@ file into their own source-specific files."
                (session (cdr (assoc :session params)))
                by-lang by-session)
           ;; add the spec for this block to blocks under it's lang and session
-          (setq by-lang (org-babel-alist-pop lang blocks))
-          (setq by-session (org-babel-alist-pop session by-lang))
+          (setq by-lang (cdr (org-babel-alist-pop lang blocks)))
+          (setq by-session (cdr (org-babel-alist-pop session by-lang)))
           (setq blocks (cons ;; by-language
                         (cons lang (cons ;; by-session
                                     (cons session (cons spec by-session)) by-lang))
                         blocks))))
       ;; blocks should contain all source-blocks organized by language
       ;; and session
+      (message "blocks=%S" blocks) ;; debugging
       (mapc ;; for every language create a file
        (lambda (by-lang)
          (let* ((lang (car by-lang))
@@ -79,7 +83,7 @@ file into their own source-specific files."
            (flet ((to-file (filename specs)
                            (with-temp-file filename
                              (funcall lang-f)
-                             (when she-bang (insert she-bang))
+                             (when she-bang (insert (concat she-bang "\n")))
                              (comment-region (point) (progn (insert "generated by org-babel-tangle") (point)))
                              (mapc #'org-babel-spec-to-string specs))))
              ;; if there are multiple sessions then break out by session