4

I have a directory with the file a file name with spaces and in Emacs I have a bash in a shell buffer. Rhen I type

ls a<TAB>

and shell mode completes to

a\ file\ name\ with\ space

However I would like the completion to look like

'a file name with space'

How can I achieve this? What function do I have modify?

2

An interesting question. It's not configurable at all, so I recommend looking at pcomplete-insert-entry. This is where the completed text is inserted, and it's what calls comint-quote-filename. Note that it handles some fun edge cases that you'll also have to handle. In particular, if there's already a backslash in the buffer then it handles the insertion a little differently so as to avoid ending up with an extra backslash. You'll want to add something similar for quote characters, I'm sure.

You'll also probably want to make sure that your changes don't break anything when pcomplete is used in other modes. It's mostly used by eshell, but in principle it can be used with anything that uses comint-mode.

4
  • AFAICT, it should be pcomplete-quote-argument which in my version of emacs is an obsolete alias to comint-quite-filename.
    – NickD
    Sep 30 '20 at 1:13
  • I recommend changing pcomplete-insert-entry instead, since it also needs to handle the edge cases. Have it call a new function pcomplete-quote-filename-with-actual-quotes instead of comint-quote-filename; that's less likely to break anything.
    – db48x
    Sep 30 '20 at 2:00
  • That's exactly what I was after. Thanks. Detail question: When I look at pcomplete.el I can see that pcomplete-insert-entry calls comint-quote-filename not pcomplete-quote-filename.
    – halloleo
    Sep 30 '20 at 5:31
  • Oops, just a typo.
    – db48x
    Sep 30 '20 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.