Reputation: 113
I am working on a windows 10 machine using Emacs and plink to connect to a Linux development server.
I am able to start a shell in Emacs using M-x shell
and ssh to the server with plink server
When I press enter on my keyboard it's like I have pressed enter twice rather than once
username@server>ls<enter>
file1 file2 file3
username@server>
username@server>
I initially thought this had something to do with extraneous escape characters for the terminal as other questions have indicated. Opening a windows command prompt and ssh'ing to the server with plink output these extraneous characters and I was able to remove them with the following variables in my bashrc:
export PROMPT_COMMAND=""
export PS1="\u@\H:\W>
export TERM=""
The windows command prompt now properly displayed the plink session with no extraneous escape characters. Despite this, the Emacs shell still seemed to press enter twice for one press.
Next, I assumed there was a problem with the characters that were being sent by the enter key.
running showkey -a
seems to explain the problem:
In a real putty window and in the Windows command prompt I got the following showkey output while in a ssh connection to the server:
showkey -a
Press any keys - Ctrl-D will terminate this program
^M 13 0015 0x0d
in the Emacs shell I get this output
showkey -a
Press any keys - Ctrl-D will terminate this program
^M^J 13 0015 0x0d
10 0012 0x0a
It seems that the Emacs shell is sending a carriage return as well as a line feed when I press enter (the DOS line ending format). It makes sense then that enter is "pressed twice." Is there any way to change this behavior in the shell? I have seen the use of set-buffer-file-coding-system
to tell Emacs to use Unix, Windows or Mac line endings. but this doesn't seem to work for me since I am in a shell.
Upvotes: 2
Views: 913
Reputation: 73274
For each inferior process, Emacs applies independent coding systems for the process input and process output.
In your case the coding system for input to the process will be a "dos" system, resulting in the CRLF pair being sent to the process for EOLs.
You can use M-x set-buffer-process-coding-system
to change these input/output coding systems interactively for the current buffer. Bound by default to C-xRETp
You could also use a hook to do so automatically for certain modes. e.g.:
(add-hook 'shell-mode-hook 'my-shell-mode-hook)
(defun my-shell-mode-hook ()
"Custom `shell-mode' behaviours."
(set-buffer-process-coding-system 'utf-8-unix 'iso-latin-1-unix))
As per the interactive prompts, the first argument is "Coding-system for output from the process" and the second is "Coding-system for input to the process".
See C-hig (emacs)Communication Coding
for more information.
Upvotes: 1