Lennart Borgman <address@hidden> writes:
The appended patch shows how autocompletion could work for remote file
names. It removes the drive letter from file names to be completed,
because this prevents activation of Tramp file name handlers for
file-name-all-completions in read-file-name-internal.
Exactly why must the drive letter be removed? (Where in the code is it
essential?)
It is in read-file-name-internal (respectively
Fread_file_name_internal) in fileio.c. You can see it when you enable
traces:
(trace-function-background 'read-file-name-internal)
(mapcar 'trace-function-background
(mapcar 'intern
(all-completions "tramp-" obarray 'functionp)))
With unpatched tramp.el, you get:
======================================================================
1 -> read-file-name-internal: string="/pl" dir="~/" action=t
| 2 -> tramp-completion-file-name-handler: operation=substitute-in-file-name
args=("/pl")
| | 3 -> tramp-completion-run-real-handler: operation=substitute-in-file-name
args=("/pl")
| | 3 <- tramp-completion-run-real-handler: "/pl"
| 2 <- tramp-completion-file-name-handler: "/pl"
| 2 -> tramp-completion-file-name-handler: operation=file-name-nondirectory
args=("/pl")
| | 3 -> tramp-completion-run-real-handler: operation=file-name-nondirectory
args=("/pl")
| | 3 <- tramp-completion-run-real-handler: "pl"
| 2 <- tramp-completion-file-name-handler: "pl"
| 2 -> tramp-completion-file-name-handler: operation=file-name-directory
args=("/pl")
| | 3 -> tramp-completion-run-real-handler: operation=file-name-directory
args=("/pl")
| | 3 <- tramp-completion-run-real-handler: "/"
| 2 <- tramp-completion-file-name-handler: "/"
| 2 -> tramp-completion-file-name-handler: operation=expand-file-name args=("/"
"~/")
| | 3 -> tramp-completion-run-real-handler: operation=expand-file-name args=("/"
"~/")
| | 3 <- tramp-completion-run-real-handler: "h:/"
| 2 <- tramp-completion-file-name-handler: "h:/"
1 <- read-file-name-internal: nil
======================================================================
Interesting are the Tramp functions called at trace level 2:
(substitute-in-file-name "/pl") -> "/pl"
(file-name-nondirectory "/pl") -> "pl"
(file-name-directory "/pl") -> "/"
(expand-file-name "/" "~/") -> "h:/"
In read-file-name-internal, these calls are related to the following
code sequence:
orig_string = string;
string = Fsubstitute_in_file_name (string);
changed = NILP (Fstring_equal (string, orig_string));
name = Ffile_name_nondirectory (string);
val = Ffile_name_directory (string);
if (! NILP (val))
realdir = Fexpand_file_name (val, realdir);
Finally, there is the call:
Lisp_Object all = Ffile_name_all_completions (name, realdir);