I'm working on emacs support for export-completions and I've
encountered an issue.  Directories in 'export-completions' output do
not include trailing slashes.

```
bash-5.3$ ls test
testdir/      testfile.txt
bash-5.3$ ls test
3
test
3:7
test
testdir
testfile.txt
```

When using tab completion in emacs, instead of the expected behavior
of automatically appending a / after completing a path to a directory,
it only completes the directory name itself. Instead of

```
$ mydirectory/subdi
<TAB>
$ mydirectory/subdir/
```

You get

```
$ mydirectory/subdi
<TAB>
$ mydirectory/subdir
```

And have to manually append a / before continuing. Emacs can't figure
out whether a given completion is a directory or not becuase it
doesn't know the value of 'rl_filename_completion_desired'.

>From looking through the completions display code, it seems like
'print_filename' is what adds these slashes when displaying
completions. Changing '_rl_export_completions' to use that instead of
fprintf seems to solve the problem after some quick testing. See below
diff.

diff --git a/lib/readline/complete.c b/lib/readline/complete.c
index 473f04db..4b8e30d2 100644
--- a/lib/readline/complete.c
+++ b/lib/readline/complete.c
@@ -3065,8 +3065,10 @@ _rl_export_completions (char **matches, char
*text, int start, int end)
   fprintf (rl_outstream, "%zd\n", len);
   fprintf (rl_outstream, "%s\n", text);
   fprintf (rl_outstream, "%d:%d\n", start, end); /* : because it's
not a radix character */
-  for (i = 0; i < len; i++)
-    fprintf (rl_outstream, "%s\n", matches[i]);
+  for (i = 0; i < len; i++) {
+    print_filename (matches[i], matches[i], 0);
+    fprintf (rl_outstream, "\n");
+  }
   fflush (rl_outstream);
 }

Reply via email to