emacs shell 模式下的 Gnu 屏幕:如何修复颜色转义代码
我想在 shell 模式下在 emacs 中附加 screen 或 tmux。我经常发现自己在远程服务器上运行 emacs,但屏幕内的进程较差;如果我可以将工作流程转移到本地 emacs + TRAMP 就好了;然而,重新连接持久会话的能力是必须的。 (这样的工作流程对于 R [1] 中的分析特别有用)
Shell 模式是相当理想的,因为在使用 Mx term 或 Mx ansiterm + screen + R 的组合时,我不断遇到各种故障甚至崩溃。但是,我可以在 Mx shell 下运行时,似乎无法摆脱在屏幕中呈现为转义码的 ansi 颜色。当我使用 ansi-color-for-comint-mode-on 时,它们很好 - 但一旦屏幕出现,它就会变得一团糟。
有没有人弄清楚使用 shell + screen 或 tmux 正确解释 ansi 颜色的条件集?完全摆脱颜色怎么样?.. 在运行持久远程进程并将它们附加到本地 emacs 方面还有其他选择吗?..
[1] http://blog.nguyenvq.com/2010/07/11/using-r-ess-远程与屏幕在 emacs/
I would like to attach screen or tmux inside emacs, in shell mode. I often find myself running emacs with inferior processes inside screen on remote servers; it would be nice if I could shift the workflow to local emacs + TRAMP; ability to reattach persistent sessions is a must, however. (Such workflow is particularly useful for analysis in R [1])
Shell-mode is rather desirable because I keep encountering miscellaneous glitches and even crashes when using the combination of M-x term or M-x ansi-term + screen + R. However, I can't seem to get rid of ansi colored rendered as escape codes in screen when run under M-x shell. When I use ansi-color-for-comint-mode-on
, they are fine -- but as soon as screen comes on, it becomes a horrible mess.
Has anyone figured out the set of conditions for proper interpretation of ansi color with shell + screen or tmux? What about getting rid of color altogether?.. Are there any other alternatives in terms of running persistent remote processes and attaching them to local emacs?..
[1] http://blog.nguyenvq.com/2010/07/11/using-r-ess-remote-with-screen-in-emacs/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,Screen 需要终端的功能,而 Emacs 的 shell 模式根本没有也无法提供这些功能,因为它不是像 VT100 这样的传统字符终端。因此,问题不在于摆脱或尝试解释颜色代码 - Screen 需要更多终端功能才能正常运行。
据我所知,默认情况下 Screen 甚至不会在 Emacs 的 shell 模式下启动(它错误地指出它需要清晰的屏幕功能)。网络上的一些帖子似乎建议设置 TERM=xterm 来解决这个问题,但这只是欺骗 Screen 认为终端具有 XTerm 的功能,而它并不具备。
Emacs 的 term 和 ansiterm 模式将提供 Screen 所需的终端功能,但不幸的是,您似乎在使用这些模式时遇到了麻烦。
相反,我建议查看“emacsclient -t”命令(Emacs 的一部分),它允许您打开连接到现有 Emacs 实例的本地框架,其方式与 Screen 允许您重新连接到的方式类似。先前创建的 Screen 实例。这样,您也许可以在本地计算机上配置 emacsclient,以通过 TCP 重新连接到持久的远程 Emacs 实例。
As far as I can tell, Screen requires features of your terminal that Emacs' shell mode simply does not and cannot provide, simply because it is not a traditional character terminal like VT100. So the issue is not about getting rid of or trying to interpret color codes -- there are more terminal capabilities that Screen requires to function correctly.
By default Screen does not even start in Emacs' shell mode, as far as I can tell (it errors out saying it needs clear screen capability). Some posts around the web seem to suggest setting TERM=xterm to work around this, but it is just fooling Screen into thinking the terminal has the capabilities of XTerm, which it doesn't have.
The term and ansi-term modes of Emacs would provide the terminal capabilities required by Screen, but unfortunately you seem to have had troubles with those modes.
What I would suggest instead would be to have a look at the "emacsclient -t" command (part of Emacs), which allows you to open a local frame connected to an existing Emacs instance in a similar way as Screen allows you to reconnect to a previously created Screen instance. That way you could perhaps configure a emacsclient on you local computer to reconnect over TCP to a persistent remote Emacs instance.
我不使用 screen,但也许你可以从 .bashrc 中修复这个问题。我在那里有一堆条件代码,为 xterm 窗口打开颜色,但为不支持它的其他终端保留它。 Mx shell 将 TERM 变量设置为哑,因此您可以对其进行测试并相应地设置颜色。
I don't use screen, but maybe you can fix this from your .bashrc. I've got a bunch of conditional code in there, turning color on for xterm windows, but leaving it off for other terminals that don't support it. M-x shell sets the TERM variable to dumb, so you can test for that and set the color accordingly.