Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using emacs to work on linux, windows, osx and everything is fine except one annoying problem with shell buffers under windows.

Autocompleting filenames would work great (better than standard windows) but is completely useless because it generates paths with forward slash separator for directories. This with windows doesn't work so I've to force myself to avoid tabbing and type everything in command prompt or I've to give up with emacs and use the broken command window of windows (where for example it's hard to even copy'n paste reasonably because of the splitting line problems).

Is there a way to tell emacs to use "\" instead of "/" for pathname completion for windows?

share|improve this question
    
Have you looked into EmacsW32 ? –  harrymc Mar 20 '11 at 7:31
    
I'll give it a try even if using a different emacs just for this problem looks scary to me. For now I'm surviving using toggle-backslash-line.el that flips between '\' and '/' when in comint-mode and that I bound to ctrl-\. It sucks but it's better than nothing... –  6502 Mar 23 '11 at 10:27
    
Do the forward slashes not actually work for the paths? I know the windows command shell will let you use forward slashes just like they were backslashes without complaint. –  Zach Mar 24 '11 at 18:28
    
@Zach: no, surely doesn't work with every command. The command that doesn't work with fw slash that I miss most is "cd". While a program compiled for windows can actually use "/" for example for fopen still the command prompt cannot use "/" for paths because the decision was to use forward slash for options. –  6502 Mar 24 '11 at 20:34
    
I'm on Windows 7, so it may vary between versions but something like cd Desktop/Books works for me. –  Zach Mar 28 '11 at 20:05

2 Answers 2

up vote 4 down vote accepted
+50

Short answer: Use the variable comint-completion-addsuffix.

Longer answer: Googling for "emacs shell completion windows" got me to http://www.gnu.org/software/emacs/windows/Sub_002dprocesses.html, which says the variable comint-completion-addsuffix controls the completion characters. Setting it to a cons of \ and SPACE does what you want. You can do this with

  1. M-x customize-variable RET comint-completion-addsuffix RET
  2. select Value Menu
  3. select Suffix pair
  4. enter \ after Directory suffix:
  5. enter a space character after File suffix:
  6. select Save for Future Sessions (or Save for current session)

Doing that adds the line

'(comint-completion-addsuffix (quote ("\\" . " ")))

to the correct place in your ~/.emacs file.

(Tested with Emacs 22.3.)

Update:

I see what you mean in your comment that with Emacs 23.3 the leading backslash is changed to a slash. comint-dynamic-complete-filename has been broken so the part of the description except that it won't change parts of the filename already entered in the buffer is no longer true.

Replacing 23.3's lisp/comint.el with 22.3's seems to work. So does replacing the three lines of that file starting at line 3062:

     (delete-region filename-beg filename-end)
     (if filedir (insert (comint-quote-filename filedir)))
     (insert (comint-quote-filename (directory-file-name completion)))

with these lines (from 22.3):

     (insert (comint-quote-filename
          (substring (directory-file-name completion)
             (length filenondir))))

and doing M-x byte-recompile-directory.

share|improve this answer
    
Close, but still useless. The problem is that while it's true that using this variable I'll get an ending "\" on previous directories emacs will flip all "\" to "/" when doing completions. For example typing "cd \check (TAB)" i get emacs changing to "cd /checkout\" (ending is "\" -good- but the initial got transformed into "/" -bad-). –  6502 Mar 24 '11 at 9:15
    
When I type "cd \windo(TAB)" Emacs changes the input to "cd \windoWS\". What Emacs are you using? I'm using Emacs 22.3.1. Its shell mode binds TAB to comint-dynamic-complete which uses comint-dynamic-complete-functions whose value includes comint-dynamic-complete-filename, which "is similar to `comint-replace-by-expanded-filename', except that it won't change parts of the filename already entered in the buffer; it just adds completion characters to the end of the filename." Maybe your Emacs is using comint-replace-by-expanded-filename instead (though for me that changes to c:/windoWS)? –  Larry Engholm Mar 25 '11 at 3:08
    
After writing my previous comment I edited my answer to include a fix to 23.3's comint.el. –  Larry Engholm Mar 25 '11 at 5:16
    
YAY! thanks a lot... this solved the issue. I tried looking everywhere (including #emacs) but only found dumbies that said that I should drop windows or that "\" was indeed a typo done long ago and that I should use "/" anyway instead. –  6502 Mar 25 '11 at 7:22
    
comint.el is drastically changed in v24. The DIRSUFFIX is now ignored. It appears that expand-file-name (from fileio.c) builds the path (including the directory separator). I don't know if there's a way to customize it. –  Jubjub Bandersnatch Jan 21 at 19:17

(setq comint-completion-addsuffix (quote ("\\" . " "))) in my ~\.emacs did the trick for me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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