chris warth <[email protected]> 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. _______________________________________________ Tramp-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/tramp-devel
