Motivation / Background
- I use the
ffapcounterparts of common file- and directory-finding commands, i.e.
dired-at-pointet al. in place of
diredet al., respectively.
- I want to set
ffap-file-finder(the file-finding subroutine defaulting to
ffapuses behind the scenes) to
counsel-find-filereturns a plain, non-TRAMP-qualified filename, in contrast with
find-fileet al. which return the buffer visiting the given file.
- I thus want to write a function suitable as a value for
ffap-file-finder(i.e. one that returns a buffer object) using
counsel-find-file(which returns a plain filename).
I have tried calling
find-buffer-visiting on the filename returned by
counsel-find-file, but this approach breaks down when the file in question has been opened with TRAMP
sudo syntax. Using the file
/etc/pam.conf with inode
123 and device number
456 on host
foo as an example, I have made the following observations in such cases:
;; This actually calls `(find-file "/sudo:root@foo:/etc/pam.conf")' internally (counsel-find-file) ; => "/etc/pam.conf" ;; These follow the call to `counsel-find-file' (get-buffer "pam.conf") ; => #<buffer pam.conf> (get-file-buffer "pam.conf") ; => nil (get-file-buffer "/etc/pam.conf") ; => nil (find-buffer-visiting "pam.conf") ; => nil (find-buffer-visiting "/etc/pam.conf") ; => nil (nthcdr 10 (file-attributes "/etc/pam.conf")) ; => (123 456)
Inside the buffer of the
buffer-file-name ; => #("/sudo:root@foo:/etc/pam.conf" 6 10 (tramp-default t)) buffer-file-number ; => (123 (-1 . 1))
(find-buffer-visiting "/etc/pam.conf") fails when
"/etc/pam.conf" has been opened via TRAMP because
- compares the given plain filename with the TRAMP-syntax values of
- compares both inode and device numbers to determine file equality, but TRAMP seems to modify the device number.
- Is it necessary for TRAMP to change the
file-attribute-device-numberof visited files? If so, why?
- How does TRAMP compare files for equality in such cases?
- Given a plain, non-TRAMP-qualified filename, how do I lookup a TRAMP buffer visiting it?
- How do I make
find-buffer-visitingwork with TRAMP buffers?
(These questions overlap, but I would like to cover all bases.)
I realise that I can call
(get-buffer (counsel-find-file)) in my example, but I fear this is not a robust approach in the face of multiple buffers with uniquified names visiting the same file. I am also curious as to whether there is a more general and "correct" TRAMP solution to my questions.