[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: py-execute-region temporary buffers
From: |
Michael Albinus |
Subject: |
Re: py-execute-region temporary buffers |
Date: |
Wed, 28 Sep 2011 11:29:54 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Paul Northug <address@hidden> writes:
> Hi Michael.
Hi Paul,
> 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?
Every buffer has a buffer-local variable default-directory. You can
check whether this is a remote directory with the function
file-remote-p. If this returns non-nil, it is remote.
Even better, file-remote-p returns exactly the remote part of a file
name. Like this:
(file-remote-p "/tmp") => nil
(file-remote-p "/ssh:address@hidden:/tmp") => "/ssh:address@hidden:"
Let's also simplify and assume that the temp directory is always the
same on all involved hosts, for example "/tmp". py-temp-directory shall
keep this value.
In this case, you could replace all occurences of py-temp-directory by
(concat (file-remote-p default-directory) py-temp-directory)
Best regards, Michael.