diff options
author | Dan Davison <davison@stats.ox.ac.uk> | 2010-09-22 21:40:14 +0100 |
---|---|---|
committer | Dan Davison <davison@stats.ox.ac.uk> | 2010-09-22 22:10:13 +0100 |
commit | ec0b3892b9493d7da8f2e88d7d70b7c578eb8d8a (patch) | |
tree | 090989047dd0bb1f1f23de545161ecbc7c0ebf26 | |
parent | 708d0e2da166c6ccc729dadf6edca96acb227241 (diff) | |
download | org-mode-ec0b3892b9493d7da8f2e88d7d70b7c578eb8d8a.tar.gz |
babel: New function to process file names for use in external processes
* ob.el (org-babel-process-file-name): New function
(org-babel-maybe-remote-file): Delete function
* ob-sql.el (org-babel-execute:sql):
Use org-babel-process-file-name
* ob-scheme.el (org-babel-execute:scheme):
Use org-babel-process-file-name
* ob-sass.el (org-babel-execute:sass):
Use org-babel-process-file-name
* ob-ruby.el (org-babel-ruby-evaluate):
Use org-babel-process-file-name
* ob-python.el (org-babel-python-evaluate-external-process):
Use org-babel-process-file-name
(org-babel-python-evaluate-session):
Use org-babel-process-file-name
* ob-plantuml.el (org-babel-execute:plantuml):
Use org-babel-process-file-name
* ob-perl.el (org-babel-perl-evaluate):
Use org-babel-process-file-name
* ob-octave.el (org-babel-octave-evaluate-external-process):
Use org-babel-process-file-name
(org-babel-octave-evaluate-session):
Use org-babel-process-file-name,
don't use org-babel-maybe-remote-file
* ob-lisp.el (org-babel-execute:lisp):
Use org-babel-process-file-name
* ob-ledger.el (org-babel-execute:ledger):
Use org-babel-process-file-name
* ob-js.el (org-babel-execute:js):
Use org-babel-process-file-name
* ob-haskell.el (org-babel-haskell-export-to-lhs):
Use org-babel-process-file-name
* ob-gnuplot.el (org-babel-execute:gnuplot):
Use org-babel-process-file-name
* ob-eval.el (org-babel-eval-read-file): Don't use
org-babel-maybe-remote-file
* ob-dot.el (org-babel-execute:dot):
Use org-babel-process-file-name
* ob-ditaa.el (org-babel-execute:ditaa):
Use org-babel-process-file-name
* ob-clojure.el (org-babel-clojure-evaluate-external-process):
Use org-babel-process-file-name
* ob-asymptote.el (org-babel-execute:asymptote):
Use org-babel-process-file-name
* ob-R.el (org-babel-R-assign-elisp): Don't use
org-babel-maybe-remote-file, use org-babel-process-file-name
(org-babel-R-evaluate-external-process):
Use org-babel-process-file-name
(org-babel-R-evaluate-session):
Use org-babel-process-file-name
* ob-C.el (org-babel-C-execute):
Use org-babel-process-file-name
In addition to passing the file path through `expand-file-name',
tramp-style remote file names are converted to conventional (local)
file paths. The reason is that, if a tramp file name was in use in
emacs, then the shell command will be executing on the remote machine
in question. Further, by default the file name is passed through
`shell-quote-argument'.
-rw-r--r-- | lisp/ob-C.el | 4 | ||||
-rw-r--r-- | lisp/ob-R.el | 8 | ||||
-rw-r--r-- | lisp/ob-asymptote.el | 14 | ||||
-rw-r--r-- | lisp/ob-clojure.el | 8 | ||||
-rw-r--r-- | lisp/ob-ditaa.el | 4 | ||||
-rw-r--r-- | lisp/ob-dot.el | 6 | ||||
-rw-r--r-- | lisp/ob-eval.el | 3 | ||||
-rw-r--r-- | lisp/ob-gnuplot.el | 5 | ||||
-rw-r--r-- | lisp/ob-haskell.el | 4 | ||||
-rw-r--r-- | lisp/ob-js.el | 4 | ||||
-rw-r--r-- | lisp/ob-ledger.el | 9 | ||||
-rw-r--r-- | lisp/ob-lisp.el | 4 | ||||
-rw-r--r-- | lisp/ob-octave.el | 18 | ||||
-rw-r--r-- | lisp/ob-perl.el | 3 | ||||
-rw-r--r-- | lisp/ob-plantuml.el | 6 | ||||
-rw-r--r-- | lisp/ob-python.el | 8 | ||||
-rw-r--r-- | lisp/ob-ruby.el | 19 | ||||
-rw-r--r-- | lisp/ob-sass.el | 4 | ||||
-rw-r--r-- | lisp/ob-scheme.el | 3 | ||||
-rw-r--r-- | lisp/ob-sql.el | 8 | ||||
-rw-r--r-- | lisp/ob.el | 24 |
21 files changed, 104 insertions, 62 deletions
diff --git a/lisp/ob-C.el b/lisp/ob-C.el index 0c1f3c7..0156e5d 100644 --- a/lisp/ob-C.el +++ b/lisp/ob-C.el @@ -100,10 +100,10 @@ or `org-babel-execute:c++'." (cond ((equal org-babel-c-variant 'c) org-babel-C-compiler) ((equal org-babel-c-variant 'cpp) org-babel-c++-compiler)) - tmp-bin-file + (org-babel-process-file-name tmp-bin-file) (mapconcat 'identity (if (listp flags) flags (list flags)) " ") - tmp-src-file) "")))) + (org-babel-process-file-name tmp-src-file)) "")))) ((lambda (results) (org-babel-reassemble-table (if (member "vector" (nth 2 processed-params)) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 64bbba4..c709064 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -144,11 +144,11 @@ This function is called by `org-babel-execute-src-block'." (let ((transition-file (org-babel-temp-file "R-import-"))) ;; ensure VALUE has an orgtbl structure (depth of at least 2) (unless (listp (car value)) (setq value (list value))) - (with-temp-file (org-babel-maybe-remote-file transition-file) + (with-temp-file transition-file (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) (insert "\n")) (format "%s <- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE)" - name transition-file + name (org-babel-process-file-name transition-file 'noquote) (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE") (if rownames-p "1" "NULL"))) (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))) @@ -245,7 +245,7 @@ last statement in BODY, as elisp." (if row-names-p "NA" "TRUE") "FALSE") (format "{function ()\n{\n%s\n}}()" body) - (org-babel-tramp-localname tmp-file))) + (org-babel-process-file-name tmp-file 'noquote))) (org-babel-R-process-value-result (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) (output (org-babel-eval org-babel-R-command body)))) @@ -271,7 +271,7 @@ last statement in BODY, as elisp." (if column-names-p (if row-names-p "NA" "TRUE") "FALSE") - ".Last.value" (org-babel-tramp-localname tmp-file))) + ".Last.value" (org-babel-process-file-name tmp-file 'noquote))) (org-babel-R-process-value-result (org-babel-import-elisp-from-file tmp-file '(16)) column-names-p))) (output diff --git a/lisp/ob-asymptote.el b/lisp/ob-asymptote.el index 49ccc7c..5b3141c 100644 --- a/lisp/ob-asymptote.el +++ b/lisp/ob-asymptote.el @@ -74,11 +74,15 @@ This function is called by `org-babel-execute-src-block'." "pdf")) (cmdline (cdr (assoc :cmdline params))) (in-file (org-babel-temp-file "asymptote-")) - (cmd (concat "asy " - (if out-file - (concat "-globalwrite -f " format " -o " out-file) - "-V") - " " cmdline " " in-file))) + (cmd + (concat "asy " + (if out-file + (concat + "-globalwrite -f " format + " -o " (org-babel-process-file-name out-file)) + "-V") + " " cmdline + " " (org-babel-process-file-name in-file)))) (with-temp-file in-file (insert (org-babel-expand-body:asymptote body params processed-params))) (message cmd) (shell-command cmd) diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el index 4311bb5..67eba74 100644 --- a/lisp/ob-clojure.el +++ b/lisp/ob-clojure.el @@ -262,8 +262,12 @@ repl buffer." (case result-type (output (org-babel-eval cmd body)) (value (let* ((tmp-file (org-babel-temp-file "clojure-results-"))) - (org-babel-eval cmd (format org-babel-clojure-wrapper-method - body tmp-file tmp-file)) + (org-babel-eval + cmd + (format + org-babel-clojure-wrapper-method + body + (org-babel-process-file-name tmp-file 'noquote) tmp-file)) (org-babel-clojure-table-or-string (org-babel-eval-read-file tmp-file))))))) diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el index 20cc192..48917d9 100644 --- a/lisp/ob-ditaa.el +++ b/lisp/ob-ditaa.el @@ -57,7 +57,9 @@ This function is called by `org-babel-execute-src-block'." (cmd (concat "java -jar " (shell-quote-argument (expand-file-name org-ditaa-jar-path)) - " " cmdline " " in-file " " out-file))) + " " cmdline + " " (org-babel-process-file-name in-file) + " " (org-babel-process-file-name out-file)))) (unless (file-exists-p org-ditaa-jar-path) (error "Could not find ditaa.jar at %s" org-ditaa-jar-path)) (with-temp-file in-file (insert body)) diff --git a/lisp/ob-dot.el b/lisp/ob-dot.el index 72cc691..68ddf14 100644 --- a/lisp/ob-dot.el +++ b/lisp/ob-dot.el @@ -74,7 +74,11 @@ This function is called by `org-babel-execute-src-block'." (in-file (org-babel-temp-file "dot-"))) (with-temp-file in-file (insert (org-babel-expand-body:dot body params processed-params))) - (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "") + (org-babel-eval + (concat cmd + " " (org-babel-process-file-name in-file) + " " cmdline + " -o " (org-babel-process-file-name out-file)) "") out-file)) (defun org-babel-prep-session:dot (session params) diff --git a/lisp/ob-eval.el b/lisp/ob-eval.el index ef72ff8..17e2162 100644 --- a/lisp/ob-eval.el +++ b/lisp/ob-eval.el @@ -60,8 +60,7 @@ STDERR with `org-babel-eval-error-notify'." (defun org-babel-eval-read-file (file) "Return the contents of FILE as a string." - (with-temp-buffer (insert-file-contents - (org-babel-maybe-remote-file file)) + (with-temp-buffer (insert-file-contents file) (buffer-string))) (defun org-babel-shell-command-on-region (start end command diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index ff68ad7..81f9295 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -146,7 +146,10 @@ This function is called by `org-babel-execute-src-block'." (insert (concat body "\n"))) (message "gnuplot \"%s\"" script-file) (setq output - (shell-command-to-string (format "gnuplot \"%s\"" script-file))) + (shell-command-to-string + (format + "gnuplot \"%s\"" + (org-babel-process-file-name script-file)))) (message output)) (with-temp-buffer (insert (concat body "\n")) diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el index 9cfda96..bab6f11 100644 --- a/lisp/ob-haskell.el +++ b/lisp/ob-haskell.el @@ -182,7 +182,9 @@ constructs (header arguments, no-web syntax etc...) are ignored." (tmp-tex-file (concat tmp-file ".tex")) (lhs-file (concat base-name ".lhs")) (tex-file (concat base-name ".tex")) - (command (concat org-babel-haskell-lhs2tex-command " " lhs-file " > " tex-file)) + (command (concat org-babel-haskell-lhs2tex-command + " " (org-babel-process-file-name lhs-file) + " > " (org-babel-process-file-name tex-file))) (preserve-indentp org-src-preserve-indentation) indentation) ;; escape haskell source-code blocks diff --git a/lisp/ob-js.el b/lisp/ob-js.el index a59a134..661cd34 100644 --- a/lisp/ob-js.el +++ b/lisp/ob-js.el @@ -100,7 +100,9 @@ This function is called by `org-babel-execute-src-block'" (if (string= result-type "value") (format org-babel-js-function-wrapper full-body) full-body))) - (org-babel-eval (format "%s %s" org-babel-js-cmd script-file) "")))))) + (org-babel-eval + (format "%s %s" org-babel-js-cmd + (org-babel-process-file-name script-file)) "")))))) (defun org-babel-js-read (results) "Convert RESULTS into an appropriate elisp value. diff --git a/lisp/ob-ledger.el b/lisp/ob-ledger.el index 111e3f9..86a008b 100644 --- a/lisp/ob-ledger.el +++ b/lisp/ob-ledger.el @@ -53,9 +53,14 @@ called by `org-babel-execute-src-block'." (out-file (org-babel-temp-file "ledger-output-")) ) (with-temp-file in-file (insert body)) - (message (concat "ledger -f " in-file " " cmdline)) + (message (concat "ledger" + " -f " (org-babel-process-file-name in-file) + " " cmdline)) (with-output-to-string - (shell-command (concat "ledger -f " in-file " " cmdline " > " out-file))) + (shell-command (concat "ledger" + " -f " (org-babel-process-file-name in-file) + " " cmdline + " > " (org-babel-process-file-name out-file)))) (with-temp-buffer (insert-file-contents out-file) (buffer-string)))) (defun org-babel-prep-session:ledger (session params) diff --git a/lisp/ob-lisp.el b/lisp/ob-lisp.el index 4216158..2036fb4 100644 --- a/lisp/ob-lisp.el +++ b/lisp/ob-lisp.el @@ -81,7 +81,9 @@ This function is called by `org-babel-execute-src-block'" (if (string= result-type "value") (format "(print %s)" full-body) full-body))) - (org-babel-eval (format "%s %s" org-babel-lisp-cmd script-file) "")))))) + (org-babel-eval + (format "%s %s" org-babel-lisp-cmd + (org-babel-process-file-name script-file)) "")))))) ;; This function should be used to assign any variables in params in ;; the context of the session environment. diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el index 19174cd..b064ff4 100644 --- a/lisp/ob-octave.el +++ b/lisp/ob-octave.el @@ -181,9 +181,10 @@ value of the last statement in BODY, as elisp." (value (let ((tmp-file (org-babel-temp-file "results-"))) (org-babel-eval cmd - (format org-babel-octave-wrapper-method body tmp-file tmp-file)) - (org-babel-octave-import-elisp-from-file - (org-babel-maybe-remote-file tmp-file))))))) + (format org-babel-octave-wrapper-method body + (org-babel-process-file-name tmp-file 'noquote) + (org-babel-process-file-name tmp-file 'noquote))) + (org-babel-octave-import-elisp-from-file tmp-file)))))) (defun org-babel-octave-evaluate-session (session body result-type &optional matlabp) @@ -200,11 +201,15 @@ value of the last statement in BODY, as elisp." (if (and matlabp org-babel-matlab-with-emacs-link) (concat (format org-babel-matlab-emacs-link-wrapper-method - body tmp-file tmp-file wait-file) "\n") + body + (org-babel-process-file-name tmp-file 'noquote) + (org-babel-process-file-name tmp-file 'noquote) wait-file) "\n") (mapconcat #'org-babel-chomp (list (format org-babel-octave-wrapper-method - body tmp-file tmp-file) + body + (org-babel-process-file-name tmp-file 'noquote) + (org-babel-process-file-name tmp-file 'noquote)) org-babel-octave-eoe-indicator) "\n"))))) (raw (if (and matlabp org-babel-matlab-with-emacs-link) (save-window-excursion @@ -227,8 +232,7 @@ value of the last statement in BODY, as elisp." (insert full-body) (comint-send-input nil t)))) results) (case result-type (value - (org-babel-octave-import-elisp-from-file - (org-babel-maybe-remote-file tmp-file))) + (org-babel-octave-import-elisp-from-file tmp-file)) (output (progn (setq results diff --git a/lisp/ob-perl.el b/lisp/ob-perl.el index 3e4873d..b9c5a86 100644 --- a/lisp/ob-perl.el +++ b/lisp/ob-perl.el @@ -110,7 +110,8 @@ return the value of the last statement in BODY, as elisp." (value (let ((tmp-file (org-babel-temp-file "perl-results-"))) (org-babel-eval org-babel-perl-command - (format org-babel-perl-wrapper-method body tmp-file)) + (format org-babel-perl-wrapper-method body + (org-babel-process-file-name tmp-file 'noquote))) (org-babel-eval-read-file tmp-file))))) (provide 'ob-perl) diff --git a/lisp/ob-plantuml.el b/lisp/ob-plantuml.el index 1b44248..45e099b 100644 --- a/lisp/ob-plantuml.el +++ b/lisp/ob-plantuml.el @@ -66,11 +66,9 @@ This function is called by `org-babel-execute-src-block'." (if (string= (file-name-extension out-file) "svg") "-tsvg" "") " -p " cmdline " < " - (shell-quote-argument - (expand-file-name in-file)) + (org-babel-process-file-name in-file) " > " - (shell-quote-argument - (expand-file-name out-file)))))) + (org-babel-process-file-name out-file))))) (unless (file-exists-p org-plantuml-jar-path) (error "Could not find plantuml.jar at %s" org-plantuml-jar-path)) (with-temp-file in-file (insert (concat "@startuml\n" body "\n@enduml"))) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 1d2e8f5..ae3f2d8 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -222,7 +222,7 @@ last statement in BODY, as elisp." (org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n") - tmp-file)) + (org-babel-process-file-name tmp-file 'noquote))) ((lambda (raw) (if (or (member "code" result-params) (member "pp" result-params)) @@ -243,8 +243,10 @@ last statement in BODY, as elisp." (if pp (list "import pp" - (format "open('%s', 'w').write(pprint.pformat(_))" tmp-file)) - (list (format "open('%s', 'w').write(str(_))" tmp-file))))) + (format "open('%s', 'w').write(pprint.pformat(_))" + (org-babel-process-file-name tmp-file 'noquote))) + (list (format "open('%s', 'w').write(str(_))" + (org-babel-process-file-name tmp-file 'noquote)))))) (input-body (body) (mapc (lambda (statement) (insert statement) (comint-send-input)) (split-string (org-babel-trim body) "[\r\n]+")) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 87df8d1..19e44a1 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -185,12 +185,13 @@ return the value of the last statement in BODY, as elisp." ;; external process evaluation (case result-type (output (org-babel-eval org-babel-ruby-command body)) - (value (let ((tmp-file (org-babel-temp-file "ruby-results-"))) - (org-babel-eval org-babel-ruby-command - (format (if (member "pp" result-params) - org-babel-ruby-pp-wrapper-method - org-babel-ruby-wrapper-method) - body tmp-file)) + (value (let ((tmp-file (org-babel-temp-file "ruby-"))) + (org-babel-eval + org-babel-ruby-command + (format (if (member "pp" result-params) + org-babel-ruby-pp-wrapper-method + org-babel-ruby-wrapper-method) + body (org-babel-process-file-name tmp-file 'noquote))) ((lambda (raw) (if (or (member "code" result-params) (member "pp" result-params)) @@ -232,10 +233,12 @@ return the value of the last statement in BODY, as elisp." (append (list body) (if (not ppp) - (list (format org-babel-ruby-f-write tmp-file)) + (list (format org-babel-ruby-f-write + (org-babel-process-file-name tmp-file 'noquote))) (list "results=_" "require 'pp'" "orig_out = $stdout" - (format org-babel-ruby-pp-f-write tmp-file))) + (format org-babel-ruby-pp-f-write + (org-babel-process-file-name tmp-file 'noquote)))) (list org-babel-ruby-eoe-indicator))) (comint-send-input nil t)) (org-babel-eval-read-file tmp-file))))))) diff --git a/lisp/ob-sass.el b/lisp/ob-sass.el index 2e624f2..196597a 100644 --- a/lisp/ob-sass.el +++ b/lisp/ob-sass.el @@ -54,7 +54,9 @@ This function is called by `org-babel-execute-src-block'." (out-file (or file (org-babel-temp-file "sass-out-"))) (cmdline (cdr (assoc :cmdline params))) (in-file (org-babel-temp-file "sass-in-")) - (cmd (concat "sass " (or cmdline "") in-file " " out-file))) + (cmd (concat "sass " (or cmdline "") + " " (org-babel-process-file-name in-file) + " " (org-babel-process-file-name out-file)))) (with-temp-file in-file (insert (org-babel-expand-body:sass body params))) (shell-command cmd) (or file (with-temp-buffer (insert-file-contents out-file) (buffer-string))))) diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el index 38df35b..ace0b86 100644 --- a/lisp/ob-scheme.el +++ b/lisp/ob-scheme.el @@ -98,7 +98,8 @@ This function is called by `org-babel-execute-src-block'" (format "(display %s)" full-body) full-body))) (org-babel-eval - (format "%s %s" org-babel-scheme-cmd script-file) "")))))) + (format "%s %s" org-babel-scheme-cmd + (org-babel-process-file-name script-file)) "")))))) (defun org-babel-prep-session:scheme (session params) "Prepare SESSION according to the header arguments specified in PARAMS." diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 2636752..ccaae58 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -65,9 +65,13 @@ This function is called by `org-babel-execute-src-block'." (org-babel-temp-file "sql-out-"))) (command (case (intern engine) ('mysql (format "mysql %s -e \"source %s\" > %s" - (or cmdline "") in-file out-file)) + (or cmdline "") + (org-babel-process-file-name in-file) + (org-babel-process-file-name out-file))) ('postgresql (format "psql -A -P footer=off -F \"\t\" -f %s -o %s %s" - in-file out-file (or cmdline ""))) + (org-babel-process-file-name in-file) + (org-babel-process-file-name out-file) + (or cmdline ""))) (t (error "no support for the %s sql engine" engine))))) (with-temp-file in-file (insert (org-babel-expand-body:sql body params))) @@ -1766,18 +1766,7 @@ Fixes a bug in `tramp-handle-call-process-region'." (apply org-babel-call-process-region-original start end program delete buffer display args))) -(defun org-babel-maybe-remote-file (file) - "Conditionally parse information on a remote connnection. -If FILE specifies a remote file, then parse the information on -the remote connection." - (if (file-remote-p default-directory) - (let* ((vec (tramp-dissect-file-name default-directory)) - (user (tramp-file-name-user vec)) - (host (tramp-file-name-host vec))) - (concat "/" user (when user "@") host ":" file)) - file)) - -(defun org-babel-tramp-localname (file) +(defun org-babel-local-file-name (file) "Return the local name component of FILE." (if (file-remote-p file) (let (localname) @@ -1785,6 +1774,17 @@ the remote connection." localname)) file)) +(defun org-babel-process-file-name (name &optional no-quote-p) + "Prepare NAME to be used in an external process. +If NAME specifies a remote location, the remote portion of the +name is removed, since in that case the process will be executing +remotely. The file name is then processed by +`expand-file-name'. Unless second argument NO-QUOTE-P is non-nil, +the file name is additionally processed by +`shell-quote-argument'" + ((lambda (f) (if no-quote-p f (shell-quote-argument f))) + (expand-file-name (org-babel-local-file-name name)))) + ;; (defvar org-babel-temporary-directory ;; (or (and (boundp 'org-babel-temporary-directory) ;; org-babel-temporary-directory) |