|
@@ -58,7 +58,8 @@ file using `load-file'."
|
|
(let* ((base-name (file-name-sans-extension file))
|
|
(let* ((base-name (file-name-sans-extension file))
|
|
(exported-file (concat base-name ".el")))
|
|
(exported-file (concat base-name ".el")))
|
|
;; tangle if the org-mode file is newer than the elisp file
|
|
;; tangle if the org-mode file is newer than the elisp file
|
|
- (unless (and (file-exists-p exported-file) (> (age file) (age exported-file)))
|
|
|
|
|
|
+ (unless (and (file-exists-p exported-file)
|
|
|
|
+ (> (age file) (age exported-file)))
|
|
(org-babel-tangle-file file exported-file "emacs-lisp"))
|
|
(org-babel-tangle-file file exported-file "emacs-lisp"))
|
|
(load-file exported-file)
|
|
(load-file exported-file)
|
|
(message "loaded %s" exported-file))))
|
|
(message "loaded %s" exported-file))))
|
|
@@ -91,12 +92,13 @@ exported source code blocks by language."
|
|
(lambda (by-lang)
|
|
(lambda (by-lang)
|
|
(let* ((lang (car by-lang))
|
|
(let* ((lang (car by-lang))
|
|
(specs (cdr by-lang))
|
|
(specs (cdr by-lang))
|
|
- (lang-f (intern (concat
|
|
|
|
- (or (and (cdr (assoc lang org-src-lang-modes))
|
|
|
|
- (symbol-name
|
|
|
|
- (cdr (assoc lang org-src-lang-modes))))
|
|
|
|
- lang)
|
|
|
|
- "-mode")))
|
|
|
|
|
|
+ (lang-f (intern
|
|
|
|
+ (concat
|
|
|
|
+ (or (and (cdr (assoc lang org-src-lang-modes))
|
|
|
|
+ (symbol-name
|
|
|
|
+ (cdr (assoc lang org-src-lang-modes))))
|
|
|
|
+ lang)
|
|
|
|
+ "-mode")))
|
|
(lang-specs (cdr (assoc lang org-babel-tangle-langs)))
|
|
(lang-specs (cdr (assoc lang org-babel-tangle-langs)))
|
|
(ext (first lang-specs))
|
|
(ext (first lang-specs))
|
|
(she-bang (second lang-specs))
|
|
(she-bang (second lang-specs))
|
|
@@ -112,7 +114,8 @@ exported source code blocks by language."
|
|
she-bang))
|
|
she-bang))
|
|
(base-name (or (cond
|
|
(base-name (or (cond
|
|
((string= "yes" tangle)
|
|
((string= "yes" tangle)
|
|
- (file-name-sans-extension (buffer-file-name)))
|
|
|
|
|
|
+ (file-name-sans-extension
|
|
|
|
+ (buffer-file-name)))
|
|
((string= "no" tangle) nil)
|
|
((string= "no" tangle) nil)
|
|
((> (length tangle) 0) tangle))
|
|
((> (length tangle) 0) tangle))
|
|
target-file))
|
|
target-file))
|
|
@@ -120,10 +123,6 @@ exported source code blocks by language."
|
|
;; decide if we want to add ext to base-name
|
|
;; decide if we want to add ext to base-name
|
|
(if (and ext (string= "yes" tangle))
|
|
(if (and ext (string= "yes" tangle))
|
|
(concat base-name "." ext) base-name))))
|
|
(concat base-name "." ext) base-name))))
|
|
- ;; ;; debugging
|
|
|
|
- ;; (message
|
|
|
|
- ;; "tangle=%S base-name=%S file-name=%S she-bang=%S commentable=%s"
|
|
|
|
- ;; tangle base-name file-name she-bang commentable)
|
|
|
|
(when file-name
|
|
(when file-name
|
|
;; delete any old versions of file
|
|
;; delete any old versions of file
|
|
(when (and (file-exists-p file-name)
|
|
(when (and (file-exists-p file-name)
|
|
@@ -178,7 +177,8 @@ code blocks by language."
|
|
(org-babel-map-source-blocks (buffer-file-name)
|
|
(org-babel-map-source-blocks (buffer-file-name)
|
|
(setq block-counter (+ 1 block-counter))
|
|
(setq block-counter (+ 1 block-counter))
|
|
(let* ((link (progn (call-interactively 'org-store-link)
|
|
(let* ((link (progn (call-interactively 'org-store-link)
|
|
- (org-babel-clean-text-properties (car (pop org-stored-links)))))
|
|
|
|
|
|
+ (org-babel-clean-text-properties
|
|
|
|
+ (car (pop org-stored-links)))))
|
|
(info (org-babel-get-src-block-info))
|
|
(info (org-babel-get-src-block-info))
|
|
(source-name (intern (or (fifth info)
|
|
(source-name (intern (or (fifth info)
|
|
(format "block-%d" block-counter))))
|
|
(format "block-%d" block-counter))))
|
|
@@ -186,8 +186,8 @@ code blocks by language."
|
|
(expand-cmd (intern (concat "org-babel-expand-body:" src-lang)))
|
|
(expand-cmd (intern (concat "org-babel-expand-body:" src-lang)))
|
|
(params (third info))
|
|
(params (third info))
|
|
by-lang)
|
|
by-lang)
|
|
- (unless (string= (cdr (assoc :tangle params)) "no") ;; maybe skip
|
|
|
|
- (unless (and lang (not (string= lang src-lang))) ;; maybe limit by language
|
|
|
|
|
|
+ (unless (string= (cdr (assoc :tangle params)) "no") ;; skip
|
|
|
|
+ (unless (and lang (not (string= lang src-lang))) ;; limit by language
|
|
;; add the spec for this block to blocks under it's language
|
|
;; add the spec for this block to blocks under it's language
|
|
(setq by-lang (cdr (assoc src-lang blocks)))
|
|
(setq by-lang (cdr (assoc src-lang blocks)))
|
|
(setq blocks (delq (assoc src-lang blocks) blocks))
|
|
(setq blocks (delq (assoc src-lang blocks) blocks))
|
|
@@ -199,18 +199,27 @@ code blocks by language."
|
|
(if (assoc :no-expand params)
|
|
(if (assoc :no-expand params)
|
|
body
|
|
body
|
|
(funcall
|
|
(funcall
|
|
- (if (fboundp expand-cmd) expand-cmd 'org-babel-expand-body:generic)
|
|
|
|
|
|
+ (if (fboundp expand-cmd)
|
|
|
|
+ expand-cmd
|
|
|
|
+ 'org-babel-expand-body:generic)
|
|
body
|
|
body
|
|
params)))
|
|
params)))
|
|
(if (and (cdr (assoc :noweb params))
|
|
(if (and (cdr (assoc :noweb params))
|
|
- (string= "yes" (cdr (assoc :noweb params))))
|
|
|
|
- (org-babel-expand-noweb-references info) (second info)))
|
|
|
|
- (third (cdr (assoc
|
|
|
|
- src-lang org-babel-tangle-langs))))
|
|
|
|
|
|
+ (string=
|
|
|
|
+ "yes"
|
|
|
|
+ (cdr (assoc :noweb params))))
|
|
|
|
+ (org-babel-expand-noweb-references
|
|
|
|
+ info)
|
|
|
|
+ (second info)))
|
|
|
|
+ (third
|
|
|
|
+ (cdr (assoc src-lang
|
|
|
|
+ org-babel-tangle-langs))))
|
|
by-lang)) blocks))))))
|
|
by-lang)) blocks))))))
|
|
;; ensure blocks in the correct order
|
|
;; ensure blocks in the correct order
|
|
(setq blocks
|
|
(setq blocks
|
|
- (mapcar (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang)))) blocks))
|
|
|
|
|
|
+ (mapcar
|
|
|
|
+ (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang))))
|
|
|
|
+ blocks))
|
|
;; blocks should contain all source-blocks organized by language
|
|
;; blocks should contain all source-blocks organized by language
|
|
;; (message "blocks=%S" blocks) ;; debugging
|
|
;; (message "blocks=%S" blocks) ;; debugging
|
|
blocks))
|
|
blocks))
|
|
@@ -226,14 +235,17 @@ form
|
|
(when (and commentable
|
|
(when (and commentable
|
|
org-babel-tangle-w-comments)
|
|
org-babel-tangle-w-comments)
|
|
(insert "\n")
|
|
(insert "\n")
|
|
- (comment-region (point) (progn (insert text) (point)))
|
|
|
|
|
|
+ (comment-region (point)
|
|
|
|
+ (progn (insert text) (point)))
|
|
(end-of-line nil)
|
|
(end-of-line nil)
|
|
(insert "\n"))))
|
|
(insert "\n"))))
|
|
(let ((link (first spec))
|
|
(let ((link (first spec))
|
|
(source-name (second spec))
|
|
(source-name (second spec))
|
|
(body (fourth spec))
|
|
(body (fourth spec))
|
|
- (commentable (not (if (> (length (cdr (assoc :comments (third spec)))) 0)
|
|
|
|
- (string= (cdr (assoc :comments (third spec))) "no")
|
|
|
|
|
|
+ (commentable (not (if (> (length (cdr (assoc :comments (third spec))))
|
|
|
|
+ 0)
|
|
|
|
+ (string= (cdr (assoc :comments (third spec)))
|
|
|
|
+ "no")
|
|
(fifth spec)))))
|
|
(fifth spec)))))
|
|
(insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
|
|
(insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
|
|
(insert (format "%s" (org-babel-chomp body)))
|
|
(insert (format "%s" (org-babel-chomp body)))
|