开发者

^M in file names & find-file

开发者 https://www.devze.com 2022-12-16 19:22 出处:网络
Update: This only occurs when I access the particular server from a Windows machine With emacs tramp (plink) I\'m logging on to 2 different servers, and am experiencing a problem in one of them with

Update: This only occurs when I access the particular server from a Windows machine

With emacs tramp (plink) I'm logging on to 2 different servers, and am experiencing a problem in one of them with find-file.

If I do tab completion in a directory, all file names have ^M appended to them, e.g.:

Click <mouse-2> on a completion to select it.
In this buffer, type RET to select the completion near point.

Possible completions are:
-name^M       ../^M
./^M         .bash_history^M
.git/^M       .gitconfig^M
.gitignore^M  .lesshst^M
.ssh/^M       .subversion/^M

and when I tab-complete the file name, it completes with the ^M suffix, which is the filename of a nonexistent file:

/plink:user@myserver.com:/home/me/.gitignore^M

Any开发者_如何学Cone experience a similar problem? ^M is ungoogleable!


^M really is the carriage return part of a carriage return/line feed (hex 0x0d, oct 015). You probably need to configure your server to use linefeeds as line endings. There might be a way to fix this in emacs, but I don't know offhand.

In a way, it's MS Windows (carriage return/line feed) vs. Linux (line feed) issue. However, it's not really that simple and boths types of line endings are there for a historically good reason.


As mentioned elsewhere, ^M is the CR character, which makes up the first half of a CR LF pair used as a line terminator in DOS. Unix/Linux just uses the LF, so the ^M is displayed as an extra character.

When I see this in vim, I remove it by searching for ^M and replacing it with nothing. To specify ^M I press ctrl-V then M

I'm sure emacs has some way to do the same thing.


Try

    (add-hook 'comint-output-filter-functions
        'shell-strip-ctrl-m nil t)
    (add-hook 'comint-output-filter-functions
        'comint-watch-for-password-prompt nil t)

or maybe even

'(ansi-color-for-comint-mode-on)
'(ansi-color-for-comint-mode-filter)


^M is Enter.

It could has to do with DOS vs. Unix line break.

DOS: (13, 10)
Unix: (10)

So when you want to write lines using DOS style, a Unix style renderer will say:

your like(char13)
another line

Check your terminal and stuff like that...

And... if you are writing a batch file for Unix in DOS happens the same. You have to convert it using dos2unix filename to remove the extra 13's in your file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号