emacs shell 模式(Mx shell)

emacs shell 模式(Mx shell)

当我使用 emacs Mx 时模式 我在屏幕上看到奇怪的字符,我认为这些字符与我的提示(包括行尾)和颜色的使用有关。

所以,这是我在终端上看到的内容:

mperdikeas@thorin:~#
$ 

这是我在 Emacs 中看到的内容缓冲:

^[]0;mperdikeas@thorin: ~^Gmperdikeas@thorin:~#
$  

这是我的相关部分.bashrc:

if [ "$color_prompt" = yes ]; then
  PS1='${debian_chroot:+($debian_chroot)}\[\033[1;32m\]\u@\h\[\033[00m\]:\[\033[1;33m\]\w\[\033[00m\]#\n$'
else
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w#\n$ '
fi 

如何配置 emacs 以正确显示提示符缓冲?

答案1

可能有一个更优雅的解决方案,但这对我有用。在 .bashrc 中任何与提示相关的行之后,插入以下内容,并调整 PS1 的值以适应:

# Keep it simple if running in emacs.
case "$TERM" in
  dumb)
    PROMPT_COMMAND=
    PS1="\u@\h:\W$ "
esac

答案2

我认为你最好在 shell 模式设置中启用 ansi-color 。

 (eval-after-load 'shell
   '(progn
      (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
      (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on t)
      t))

答案3

进一步建立在戴夫·埃米的回答.bashrc为了让事情简单起见,我最后放入了以下内容:

case "$EMACS" in
    t)
    PROMPT_COMMAND=
    PS1="[\u@\h:\w]$ "
esac

依赖 的值$TERM在我的情况下不起作用,而 Emacs需要将 $EMACS 环境变量设置为 true对于它产生的任何贝壳。

答案4

尝试通过将以下内容放入 init 文件并重新启动 Emacs 来启用对 OSC(操作系统代码)的支持:

(add-hook 'comint-output-filter-functions 'comint-osc-process-output)

欲了解更多信息,请参阅外壳模式Emacs 手册的部分,C-h i后跟m Shell Mode <RET>

默认情况下,Shell 模式处理常见的 ANSI 转义码(例如,用于更改文本的颜色)。如果您将以下内容放入 init 文件中,Emacs 还可以选择支持一些扩展转义代码,例如某些 OSC(操作系统代码):

(add-hook 'comint-output-filter-functions 'comint-osc-process-output)

相关内容