forked from mirrors/org-mode
org-babel-tangle is collecting blocks by language->session
This commit is contained in:
parent
d9b96acd82
commit
d469181978
|
@ -38,18 +38,35 @@ language, and the cdr should be a list containing the extension
|
|||
and shebang(#!) line to use when writing out the language to
|
||||
file.")
|
||||
|
||||
(defun org-bable-tangle ()
|
||||
(defun org-babel-tangle ()
|
||||
"Extract the bodies of all source code blocks form the current
|
||||
file into their own source-specific files."
|
||||
(interactive)
|
||||
(let (by-lang)
|
||||
(let (blocks)
|
||||
;; blocks will be two nested association lists, first grouped by
|
||||
;; language, then by session, the contents of the second a-list
|
||||
;; will be source-code blocks
|
||||
(org-babel-map-source-blocks (buffer-file-name)
|
||||
(let ((link (progn (org-store-link nil) (pop org-stored-links)))
|
||||
(source-name (intern (org-babel-get-src-block-name)))
|
||||
(info (org-babel-get-src-block-info)))
|
||||
;; once collected these can be added to by-lang and then
|
||||
;; dropped out to buffers
|
||||
))))
|
||||
(let* ((link (progn (org-store-link nil) (pop org-stored-links)))
|
||||
(source-name (intern (org-babel-get-src-block-name)))
|
||||
(info (org-babel-get-src-block-info))
|
||||
(lang (first info))
|
||||
(body (second info))
|
||||
(params (third info))
|
||||
(spec (list link source-name params body))
|
||||
(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 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 "block = %S" blocks)
|
||||
blocks))
|
||||
|
||||
(provide 'org-babel-tangle)
|
||||
;;; org-babel-tangle.el ends here
|
||||
|
|
|
@ -404,6 +404,13 @@ non-nil."
|
|||
(dotimes (n size)
|
||||
(move-beginning-of-line 1) (insert ": ") (forward-line 1))))))
|
||||
|
||||
(defun org-babel-alist-pop (key alist)
|
||||
"Return the `assoc' of KEY in ALIST, and remove all elements of
|
||||
ALIST matching KEY with `assq-delete-all'."
|
||||
(let ((results (assoc key alist)))
|
||||
(setq alist (assq-delete-all key alist))
|
||||
results))
|
||||
|
||||
(defun org-babel-clean-text-properties (text)
|
||||
"Strip all properties from text return."
|
||||
(set-text-properties 0 (length text) nil text) text)
|
||||
|
|
Loading…
Reference in New Issue