DONE singe-function tangling and loading elisp from literate org-mode file [3/3]

This commit is contained in:
Eric Schulte 2009-07-14 20:16:51 -07:00
parent 77c7fc81cc
commit d37d148d3f
3 changed files with 51 additions and 31 deletions

View File

@ -43,13 +43,26 @@ file.")
org-mode formatted FILE. This function will first export the
source code using `org-babel-tangle' and then load the resulting
file using `load-file'."
(mapc #'load-file (org-babel-tangle-file "emacs-lisp")))
(let ((loadable-file (first (org-babel-tangle-file file "emacs-lisp"))))
(message "loading %s" loadable-file)
(unless (file-exists-p loadable-file)
(error "can't load file that doesn't exist"))
(load-file loadable-file)
(message "loaded %s" loadable-file)))
(defun org-babel-tangle-file (file &optional lang)
"Extract the bodies of all source code blocks in FILE with
`org-babel-tangle'. Optional argument LANG can be used to limit
the exported source code blocks by language."
(save-window-excursion (find-file file) (org-babel-tangle lang)))
(flet ((age (file)
(time-to-seconds
(time-subtract (current-time)
(sixth (file-attributes file))))))
(let ((target-file (concat (file-name-sans-extension file) "."
(second (assoc lang org-babel-tangle-langs)))))
(if (and lang (file-exists-p target-file) (> (age file) (age target-file)))
(list target-file)
(save-window-excursion (find-file file) (org-babel-tangle lang))))))
(defun org-babel-tangle (&optional lang)
"Extract the bodies of all source code blocks from the current

View File

@ -199,34 +199,7 @@ would then be [[#sandbox][the sandbox]].
#+end_src
* Tasks [27/44]
** TODO singe-function tangling and loading elisp from literate org-mode file [2/3]
This function should tangle the org-mode file for elisp, and then call
`load-file' on the resulting tangled file.
#+srcname: test-loading-embedded-emacs-lisp
#+begin_src emacs-lisp
(org-babel-load-file "test-tangle.org")
(list test-tangle-loading test-tangle-advert)
#+end_src
*** DONE add optional language limiter to org-babel-tangle
This should check to see if there is any need to re-export
*** DONE ensure that org-babel-tangle returns the path to the tangled file(s)
#+srcname: test-return-value-of-org-babel-tangle
#+begin_src emacs-lisp :results replace
(mapcar #'file-name-nondirectory (org-babel-tangle-file "test-tangle.org" "emacs-lisp"))
#+end_src
#+resname:
| "test-tangle.el" |
*** TODO only tangle the file if it's actually necessary
compare the ages of the files
* Tasks [28/44]
** TODO support for working with =*Org Edit Src Example*= buffers [2/4]
*** TODO optionally evaluate header references when we switch to =*Org Edit Src*= buffer
That seems to imply that the header references need to be evaluated
@ -870,6 +843,41 @@ $0
[[file:snippets/org-mode/sb][sb -- snippet]]
waiting for guidance from those more familiar with yasnippets
** DONE singe-function tangling and loading elisp from literate org-mode file [3/3]
This function should tangle the org-mode file for elisp, and then call
`load-file' on the resulting tangled file.
#+srcname: test-loading-embedded-emacs-lisp
#+begin_src emacs-lisp :results replace
(setq test-tangle-advert nil)
(setq test-tangle-loading nil)
(setq results (list :before test-tangle-loading test-tangle-advert))
(org-babel-load-file "test-tangle.org")
(setq results (list (list :after test-tangle-loading test-tangle-advert) results))
(delete-file "test-tangle.el")
(reverse results)
#+end_src
#+resname: test-loading-embedded-emacs-lisp
| :before | nil | nil |
| :after | "org-babel tangles" | "use org-babel-tangle for all your emacs initialization files!!" |
*** DONE add optional language limiter to org-babel-tangle
This should check to see if there is any need to re-export
*** DONE ensure that org-babel-tangle returns the path to the tangled file(s)
#+srcname: test-return-value-of-org-babel-tangle
#+begin_src emacs-lisp :results replace
(mapcar #'file-name-nondirectory (org-babel-tangle-file "test-tangle.org" "emacs-lisp"))
#+end_src
#+resname:
| "test-tangle.el" |
*** DONE only tangle the file if it's actually necessary
compare the ages of the files
** DONE add a function to jump to a source-block by name
I've had an initial stab at that in org-babel-find-named-block
(library-of-babel branch).

View File

@ -84,5 +84,4 @@ plus_two(holder)
#+begin_src emacs-lisp
(setq test-tangle-loading "org-babel tangles")
(setq test-tangle-advert "use org-babel-tangle for all your emacs initialization files!!")
(setq test-tangle-file-path (expand-file-name (buffer-file-name)))
#+end_src