TUI中的Emacs所在的终端的类别为何总是dumb

这问题我之前遇到过,当时我要解决的问题是emacs在TUI模式下方向键失灵的问题。我在konsole和xterm里都进行了测试,发现TERM的默认值是xterm-256color。当时有人给出了一个解答:

  TERM=linux emacs -nw # this makes arrow keys work

来源在这里

然而,这也不管用!终端里的TERM环境变量和emacs里的值不一致。当时我以为这是终端的问题,因为对于escape的处理,终端有更高的优先级。然而,在GUI里面它的值也是dumb。

emacs 23 NEWS 提到

** Changes related to multiple-terminal (multi-tty) support *** $TERM is now set to ‘dumb’ for subprocesses. If you want to know the $TERM inherited by Emacs you will have to look inside initial-environment.

对此@Chingyat 已经提到过了。至于是哪里把它设成dumb的,参考startup.el:852

    ;; Subprocesses of Emacs do not have direct access to the terminal, so
    ;; unless told otherwise they should only assume a dumb terminal.
    ;; We are careful to do it late (after term-setup-hook), although the
    ;; new multi-tty code does not use $TERM any more there anyway.
    (setenv "TERM" "dumb")

之前我在坛子里提过一个相关问题如何在emacsclient -e求值的表达式中打印到当前终端的输出流

看起来当前不管是tui还是gui都继承不到父进程的环境变量。关于emacs如何使用TERM变量进行初始化,参考Emacs On Terminal 理论上可以通过修改term/${TERM}.el的方式来进行tweak。