From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Charles C. Berry" Subject: Re: remote plot with local output? Date: Tue, 15 Sep 2015 09:19:04 -0700 Message-ID: References: <87bnd5gho8.fsf@gentoo.org> <871te0cchw.fsf@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zbswq-0005jj-3F for emacs-orgmode@gnu.org; Tue, 15 Sep 2015 12:19:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zbswl-00025x-0l for emacs-orgmode@gnu.org; Tue, 15 Sep 2015 12:19:11 -0400 Received: from iport-acv3-out.ucsd.edu ([132.239.0.4]:9635) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zbswk-00025m-NI for emacs-orgmode@gnu.org; Tue, 15 Sep 2015 12:19:06 -0400 In-Reply-To: <871te0cchw.fsf@gentoo.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Benda Xu Cc: emacs-orgmode@gnu.org On Tue, 15 Sep 2015, Benda Xu wrote: > Hi Charles, > > "Charles C. Berry" writes: > >> Look at the :post header arg >> >> (info "(org) post") >> >> You write a src block that extracts the remote file name from *this*, >> creates a local file name from it, copies the remote file to the local >> host, then substitutes the local file name in *this* and uses it as >> the return value. >> >> Use the name of that src block as the argument to :post > > Thanks for your hint. I come up with the following example: > > #+NAME: line > | 1 | > | 2 | > | 3 | > > #+name: localize > #+BEGIN_SRC emacs-lisp :var file="" dir="" > (let ((rfile (concat (file-name-as-directory dir) file))) > (let ((lfile (car (last (split-string rfile ":"))))) > (copy-file rfile lfile 1) > lfile)) > #+END_SRC > > #+HEADER: :post localize(*this*, "/ipmuap02:/tmp") > #+BEGIN_SRC python :results file :var dt=line :dir /ipmuap02:/tmp > from matplotlib import pylab as plt > plt.plot(dt) > plt.savefig("line.png") > return "line.png" > #+END_SRC > > #+RESULTS: > [[file:/tmp/line.png]] > > *this* only returns the resulting file name, without :dir. I have to > set the same remote directory again in the :post call. Is there a > smarter way to achieve it without duplication? > Untested, but try this : #+name: localize #+BEGIN_SRC emacs-lisp :var file="" srcinfo=(org-babel-get-src-block-info) (let* ((dir (cdr (assoc :dir (nth 2 srcinfo)))) (rfile (concat (file-name-as-directory dir) file)) (lfile (car (last (split-string rfile ":"))))) (copy-file rfile lfile 1) lfile) #+END_SRC then use #+HEADER: :post localize(*this*) in your python src block. HTH, Chuck