diff options
author | Bastien Guerry <bzg@gnu.org> | 2018-03-02 08:52:42 +0000 |
---|---|---|
committer | Gogs <gogs@fake.local> | 2018-03-02 08:52:42 +0000 |
commit | 0c96d5066f6947adb9cd0efffbf2f7141dc6eb06 (patch) | |
tree | 027b72b91d8041f874175251b7c86643dd790912 | |
parent | a1659053d51357ef7d7dc096c8687c730e4cc9ef (diff) | |
parent | 39bd69b08d22dc734c9cb8b8f03445ee6eb76baa (diff) | |
download | org-mode-0c96d5066f6947adb9cd0efffbf2f7141dc6eb06.tar.gz |
Merge branch 'develop' of stardiviner/org-mode into master
-rw-r--r-- | contrib/lisp/ob-clojure-literate.el | 55 | ||||
-rw-r--r-- | lisp/ob-core.el | 13 |
2 files changed, 63 insertions, 5 deletions
diff --git a/contrib/lisp/ob-clojure-literate.el b/contrib/lisp/ob-clojure-literate.el index 1a0ce31..b6fedee 100644 --- a/contrib/lisp/ob-clojure-literate.el +++ b/contrib/lisp/ob-clojure-literate.el @@ -223,6 +223,61 @@ Don't auto jack in by default for not rude." (cdr pair))) (org-babel--get-vars params))) +;;; Support header arguments :results graphics :file "image.png" by inject Clojure code. +(defun ob-clojure-literate-inject-code (args) + "Inject Clojure code into `BODY' in `ARGS'. +It is used to change Clojure currently working directory in a FAKE way. +And generate inline graphics image file link result. +Use header argument like this: + +:results graphics :file \"incanter-plot.png\" + +Then you need to assign image variable to this :file value like: +(def incanter-plot (histogram (sample-normal 1000))) + +*NOTE*: Currently only support Incanter's `save' function. +" + (let* ((body (nth 0 args)) + (params (nth 1 args)) + (dir (cdr (assq :dir params))) + (default-directory (and (buffer-file-name) (file-name-directory (buffer-file-name)))) + (directory (and dir (file-name-as-directory (expand-file-name dir)))) + (result-type (cdr (assq :results params))) + (file (cdr (assq :file params))) + (file-name (file-name-base file)) + ;; TODO: future support `:graphics-file' to avoid collision. + (graphics-result (member "graphics" (cdr (assq :result-params params)))) + ;; (graphics-file (cdr (assq :graphics-file params))) + ;; (graphics-name (file-name-base graphics-file)) + (prepend-to-body (lambda (code) + (setq body (concat code "\n" body)))) + (append-to-body (lambda (code) + (setq body (concat body "\n" code "\n")))) + ) + (when directory + (unless (file-directory-p (expand-file-name directory)) + (warn (format "Target directory %s does not exist, please create it." dir)))) + (when file + (funcall append-to-body + (format "(save %s \"%s\")" file-name (concat directory file))) + ) + (list body params) ; return modified argument list + )) + +(advice-add 'org-babel-expand-body:clojure :filter-args #'ob-clojure-literate-inject-code) + +;;; support :results graphics :dir "data/image" :file "incanter-plot.png" +(defun ob-clojure-literate-support-graphics-result (result) + "Support :results graphics :dir \"data/images\" :file \"incanter-plot.png\" +reset `RESULT' to `nil'." + (let* ((params (nth 2 info)) + (graphics-result (member "graphics" (cdr (assq :result-params params))))) + (if graphics-result + (setq result nil)) + result)) + +(advice-add 'org-babel-execute:clojure :filter-return #'ob-clojure-literate-support-graphics-result) + (defvar ob-clojure-literate-mode-map (let ((map (make-sparse-keymap))) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 6af10dc..a948ea7 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -702,13 +702,16 @@ block." (not (listp r))) (list (list r)) r))) - (let ((file (cdr (assq :file params)))) + (let ((file (cdr (assq :file params))) + (result-graphics (member "graphics" (cdr (assq :result-params params))))) ;; If non-empty result and :file then write to :file. (when file - (when result - (with-temp-file file - (insert (org-babel-format-result - result (cdr (assq :sep params)))))) + ;; handle :results graphics :file case. don't write result to file if result is graphics. + (unless result-graphics + (when result + (with-temp-file file + (insert (org-babel-format-result + result (cdr (assq :sep params))))))) (setq result file)) ;; Possibly perform post process provided its ;; appropriate. Dynamically bind "*this*" to the |