1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2025-01-12 16:24:10 +00:00

now able to generate source files (not really tested or complete)

This commit is contained in:
Eric Schulte 2009-06-26 12:12:23 -07:00
parent 9dd3050ce0
commit fba47f3651

View File

@ -66,34 +66,42 @@ file into their own source-specific files."
blocks))))
;; blocks should contain all source-blocks organized by language
;; and session
(message "block = %S" blocks)
;; (message "block = %S" blocks) ;; debugging
(mapc ;; for every language create a file
(lambda (by-lang)
(let* ((lang (car by-lang))
(lang-f (intern (concat lang "-mode")))
(lang-specs (cdr (assoc lang org-babel-tangle-langs)))
(ext (first lang-specs))
(she-bang (second lang-specs))
(by-session (cdr by-lang)))
;; if there are multiple sessions then break out by session
(if (> (length by-session) 1)
(mapc (lambda (session-pair)
(org-babel-tangle-specs-to-file
(format "%s-%s.%s" base-name (car session-pair) ext) (cdr session-pair) she-bang))
by-session)
(org-babel-tangle-specs-to-file (format "%s.%s" base-name ext) ext she-bang))))
(flet ((to-file (filename specs)
(with-temp-file filename
(funcall lang-f)
(when she-bang (insert she-bang))
(comment-region (point) (progn (insert "generated by org-babel-tangle") (point)))
(message "specs=%s" specs)
(mapc #'org-babel-spec-to-string specs))))
;; (message "lang=%s lang-specs=%s ext=%s she-bang=%s by-session=%s" lang lang-specs ext she-bang by-session) ;; debugging
;; if there are multiple sessions then break out by session
(if (> (length by-session) 1)
(mapc (lambda (session-pair)
(to-file (format "%s-%s.%s" base-name (car session-pair) ext) (cdr session-pair)))
by-session)
(message "by-session=%s" by-session)
(to-file (format "%s.%s" base-name ext) (cdr (car by-session)))))))
blocks)))
(defun org-babel-tangle-specs-to-file (filename specs &optional she-bang)
"Take a list of source-block specifications in SPECS and write
it out to FILENAME."
(with-temp-file filename
(when she-bang (insert she-bang))
(insert (mapconcat #'org-babel-spec-to-string specs "\n"))))
(defun org-babel-spec-to-string (spec)
"Return the string version of spec suitable for inclusion in a
source code file."
(message spec))
source code file. SPEC has the form
(link source-name params body)"
(flet ((insert-comment (text)
(comment-region (point) (progn (insert text) (point)))))
(insert-comment (format "\n\nlink: %s" (first spec)))
(insert-comment (format "\nsource-name: %s" (second spec)))
(insert (format "\n%s\n" (fourth spec)))))
(provide 'org-babel-tangle)
;;; org-babel-tangle.el ends here