From mboxrd@z Thu Jan 1 00:00:00 1970 From: Benda Xu Subject: Re: remote plot with local output? Date: Fri, 18 Sep 2015 17:58:58 +0900 Message-ID: <874mis2je5.fsf@gentoo.org> References: <87bnd5gho8.fsf@gentoo.org> <871te0cchw.fsf@gentoo.org> <87mvwn862v.fsf@gentoo.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcrVo-0000KC-UE for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 04:59:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcrVj-0006Cj-Uv for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 04:59:20 -0400 Received: from smtp.gentoo.org ([2001:470:ea4a:1:5054:ff:fec7:86e4]:54670) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcrVj-0006BT-OJ for emacs-orgmode@gnu.org; Fri, 18 Sep 2015 04:59:15 -0400 Received: from proton (www20427ue.sakura.ne.jp [49.212.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: heroxbd) by smtp.gentoo.org (Postfix) with ESMTPSA id B197034097F for ; Fri, 18 Sep 2015 08:59:12 +0000 (UTC) In-Reply-To: <87mvwn862v.fsf@gentoo.org> (Benda Xu's message of "Wed, 16 Sep 2015 11:13:12 +0900") 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: emacs-orgmode@gnu.org Hi, Benda Xu writes: > "Charles C. Berry" writes: > >> 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. > > It successfully extracts the :dir field. Thanks! Python works this way. But babel R has a completely different *this* value. Consider the following example: #+BEGIN_SRC R :results output graphics :file line.png :dir /ipmuap02:/tmp plot(c(1,2,3)) #+END_SRC #+RESULTS: [[file:/scp:ipmuap02:/tmp/line.png]] *this* equals "[[file:/scp:ipmuap02:/tmp/line.png]]", but in babel python *this* equals "line.png". So I come up with #+name: localize #+BEGIN_SRC emacs-lisp :var file="" srcinfo=(org-babel-get-src-block-info) (let ((lang (car srcinfo))) (cond ((string= lang "python") (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)) ((string= lang "R") (let* ((rfile (substring file 7 -2)) (lfile (car (last (split-string rfile ":"))))) (copy-file rfile lfile 1) (concat "[[file:" lfile "]]"))))) #+END_SRC But the result is a string rather than a file link: #+HEADER: :post localize(*this*) #+BEGIN_SRC R :results output graphics :file line.png :dir /ipmuap02:/tmp plot(c(1,2,3)) #+END_SRC #+RESULTS: : [[file:/tmp/line.png]] Any hints? Yours, Benda