tramp-devel
[Top][All Lists]
Advanced

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

Re: extracting remote directory without depending on tramp


From: Michael Albinus
Subject: Re: extracting remote directory without depending on tramp
Date: Fri, 07 Jul 2017 09:56:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

chris warth <address@hidden> writes:

Hi Chris,

> Is there a correct way to extract just the directory path of a file
> buffer that may be a remote tramp file?  I''m trying to fix up the
> `goimport` handling in go-mode.

In Emacs 26.1, there is the new function `file-local-name'. It extracts
the local part of a remote file name:

(file-local-name "/ssh::/etc/hosts") => "/etc/hosts"

For older Emacsen, you could use `file-remote-p' with the `localname' argument:

(file-remote-p "/ssh::/etc/hosts" 'localname) => "/etc/hosts"

The disadvantage of `file-remote-p' is, that it returns nil in case of
local file names. `file-local-name' returns always what you want.

> Current code uses
>
> (file-name-directory (file-truename buffer-file-name))
>
> which leaves "/ssh:remote:" on the front of the directory name., e.g.
> "/ssh:remote:/mnt2/source/go/src/github.com/username/"
>
> Is there a blessed way to do this type of thing?

For backward compatibility, `file-remote-p' is the better choice. So you
could try

(let ((dir (file-name-directory (file-truename buffer-file-name))))
  (or (file-remote-p dir 'localname) dir))

> Thanks in advance,
>
> - Chris

Best regrds, Michael.



reply via email to

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