Search code examples
bashemacscompletion

emacs + comint-dynamic-complete-filename after '='


Editing a Bash script I want to assign a filename to a variable.

E.g. inputfile=foo.txt

With std. settings I can't complete the filename without first inserting a space after the '='.

Is there any solution to this?


Solution

  • First of all, comint-dynamic-complete has been obsolete since Emacs 24.1. The replacement function is completion-at-point.

    Now, if you starting looking at what completion-at-point actually does in a shell script buffer, you'll eventually end up in comint anyway. In particular, the function comint--match-partial-filename looks promising for an explanation of the behavior you described.

    If I read that correctly, the problem here is that "=" is considered a valid part of a filename, at least on POSIX-like systems (see variable comint-file-name-chars). So, the completion mechanism is trying to complete the filename "inputfile=/..." which it can obviously not find.

    If you never use a "=" in your filenames (or you use it so rarely that the working completion outweighs other downsides), you may want to consider doing something like (setq comint-file-name-chars "[]~/A-Za-z0-9+@:_.$#%,{}-") in the shell script mode hook (if you are on a POSIX system; on Windows it would look slightly different).

    Hope that helps.