tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: py-execute-region temporary buffers


From: Paul Northug
Subject: Re: py-execute-region temporary buffers
Date: Wed, 28 Sep 2011 10:39:54 +0200

On Mon, Sep 26, 2011 at 10:31 PM, Michael Albinus
<address@hidden> wrote:
> Paul Northug <address@hidden> writes:
>
>> I am using ipython shell through tramp through multi-hop ssh. It works
>> very well (thank you developers!)
>>
>> I am missing the py-execute-region functionality. When I mark a region
>> and do C-c |, a temporary local file of the region is created that is
>> passed on to the running python interpreter and executed. Through
>> tramp, a local file is created rather than a remote file and the
>> remote python shell complains for example:
>>
>> IOError: [Errno 2] No such file or directory:
>> '/var/folders/0l/rbzbq01d1yz3ysh8dbhgrl5h0000gn/T/python-35908Jta.py'
>>
>> I was wondering if this functionality could be added somehow.
>
> First, I have no experience with python/ipython at all.
>
> Looking at python.el from Emacs 24.0.90, the following change might do
> the trick:
>
> --8<---------------cut here---------------start------------->8---
> *** /home/albinus/src/emacs/lisp/progmodes/python.el.~105925~   2011-09-26 
> 22:09:16.993851430 +0200
> --- /home/albinus/src/emacs/lisp/progmodes/python.el    2011-09-26 
> 22:09:03.783832044 +0200
> ***************
> *** 1616,1622 ****
>    ;; Fixme: Write a `coding' header to the temp file if the region is
>    ;; non-ASCII.
>    (interactive "r")
> !   (let* ((f (make-temp-file "py"))
>         (command
>            ;; IPython puts the FakeModule module into __main__ so
>            ;; emacs.eexecfile becomes useless.
> --- 1616,1622 ----
>    ;; Fixme: Write a `coding' header to the temp file if the region is
>    ;; non-ASCII.
>    (interactive "r")
> !   (let* ((f (concat (file-remote-p default-directory) (make-temp-file 
> "py")))
>         (command
>            ;; IPython puts the FakeModule module into __main__ so
>            ;; emacs.eexecfile becomes useless.
> --8<---------------cut here---------------end--------------->8---
>
> However, this could not be a final solution. make-temp-file should be
> enhanced to work also on remote hosts, checking for the existence of a
> temporary file etc.
>
> If you use python-mode.el, it might be sufficient to customize
> py-temp-directory.
>
> Best regards, Michael.
>

Hi Michael. Thanks for your tip! It works great in principle. My
solution is not elegant as I don't know emacs lisp.

python-mode.el uses py-temp-directory to define a filename for writing
the region, as you pointed out:

(file (concat (expand-file-name temp py-temp-directory) ".py"))

I added a line below:

(tramp-file (concat (expand-file-name temp (concat tramp-py-prefix
py-temp-directory)) ".py"))

and hard-coded tramp-py-prefix in my .emacs: (setq tramp-py-prefix
"/ssh:address@hidden:")

And I used 'tramp-file' in the places where the buffer was being
written and 'file' where it was being executed.

Can you point to any example code on how to detect I if am using tramp
and modify the filenames accordingly?

(Sorry, I first replied to you directly rather than the list. Reposting).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]