Emacs Python 模式语法高亮
我在 Ubuntu 10.04 桌面计算机上安装了 GNU Emacs 23(软件包 emacs23
),并在 Ubuntu 10.04 无头服务器(未安装 X)上安装了软件包 emacs23-nox
。两个安装都有相同的 ~/.emacs
文件。我在两台计算机上都使用 -nw
运行 Emacs。我没有在任何一台机器上安装 python-mode
,因为我的理解是它包含在 Emacs 23 中。
在桌面机器上,Python 中的注释(以 #
开头) )以红色突出显示。在服务器上,注释以纯白色文本显示,就像所有其他非突出显示的文本一样。关于为什么注释在服务器(nox
)安装上没有正确突出显示的任何建议?
更新:这似乎是与终端相关的问题。我通过屏幕替换byobu
从terminator
通过ssh
进入服务器计算机。如果我使用 TERM="xterm-256color" emacs
在服务器上运行 emacs,则注释会突出显示,但所有其他颜色看起来都很奇怪。
更新: 添加 `export TERM="xterm-256color" “解决”了这个问题。语法高亮现在具有非常奇怪的颜色:紫色、紫丁香和浅棕色。我的绿色当前行突出显示栏现在是浅浅黄色/绿色。不过,注释以红色突出显示:)
更新:已解决。 设置 TERM="xterm-color"
会生成“正确”的颜色,包括注释的突出显示。服务器默认为 TERM
的值“screen-bce”,该值不突出显示注释。
更新:未解决。 byobu
为各种功能键提供按键绑定,以轻松创建新的屏幕会话并在它们之间切换。当TERM
设置为xterm-color
时,这些功能键不再起作用。所以我想我只能对 Emacs 中 Python 代码中未突出显示的注释感到满意。
I have GNU Emacs 23 (package emacs23
) installed on an Ubuntu 10.04 desktop machine and package emacs23-nox
installed on an Ubuntu 10.04 headless server (no X installed). Both installations have the same ~/.emacs
file. I run Emacs with -nw
on both computers. I don't have python-mode
installed on either machine as my understanding is that this is included in Emacs 23.
On the desktop machine, comments in Python (starting with #
) are highlighted in red. On the server, comments appear in plain white text like all other non-highlighted text. Any suggestions as to why comments are not being highlighted correctly on the server (nox
) installation?
Update: This appears to be a terminal-related issue. I ssh
into the server machine from terminator
via the screen replacement byobu
. If I run emacs on the server with TERM="xterm-256color" emacs
, then comments are highlighted, but all the other colours look very strange.
Update: Adding `export TERM="xterm-256color" "solved" this. The syntax highlighting now has very strange colours though: purples lilacs and light browns. My green current line highlight bar is now a light pale yellow/green. Comments are highlighted in red though :)
Update: Solved. Setting TERM="xterm-color"
produces "proper" colors, including highlighting of comments. The server was defaulting to a value of "screen-bce" for TERM
which was not highlighting comments.
Update: Unsolved. byobu
provides keybindings for various function keys to easily create new screen sessions and switch between them. When TERM
is set to xterm-color
, these function keys no longer work. So I guess I'll just have to be happy with unhighlighted comments in Python code in Emacs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对我来说,从
byobu
内部运行emacs -nw
和TERM=xterm
生成了语法突出显示的正确颜色(python 和 bash 中的注释都是红色的不仅仅是#),而且功能键也可以工作。请注意,我将TERM
设置为运行 emacs 的别名的一部分,而不是在.bashrc
中一般设置它:alias emacs='TERM=xterm; emacs -nw'
另请参阅这篇文章:终端 emacs 颜色仅适用于 TERM=xterm-256color
For me running
emacs -nw
from insidebyobu
withTERM=xterm
produced the correct colours for syntax highlighting (the comments in python and bash are all red not just the #) and the function keys work. Note I setTERM
as part of an alias for running emacs rather than setting it generally in.bashrc
:alias emacs='TERM=xterm; emacs -nw'
See also this post: Terminal emacs colors only work with TERM=xterm-256color
我没有安装您正在使用的程序来测试这一点,但我确实注意到 screen-bce 和 xterm-color 之间功能键的定义方式存在一些差异。您可以尝试使用以下步骤将设置从 screen-bce 复制到 xterm-color。
使用 infocmp 程序,您可以查看两个 TERM 设置的 terminfo 设置之间的差异:
您可以使用 infocmp 将 terminfo 文件反编译到其源代码,并对其进行更改以尝试模仿另一个终端的行为。首先解码 xterm-color terminfo 文件。
编辑 xterm-color.src 并修改 kf1 到 kf19 字段的定义以匹配 screen-bce 的值。使用 infocmp 查看 screen-bce 的定义。
最后使用tic程序进行编译。
如果以非 root 用户身份运行它,它会将编译后的 terminfo 文件放入 $HOME/.terminfo 目录中。在我的系统上,Ubuntu 似乎会自动选择它。如果您满意,也可以将其安装到标准 /usr/share/terminfo 中。以 root 身份运行 tic 应该可以为您完成此操作。
祝你好运!
I don't have the programs you are using installed to test this, but I did notice some differences in the way the function keys are defined between screen-bce and xterm-color. You can try using the below steps to copy the settings from screen-bce to xterm-color.
Using the infocmp program, you can view the differences between the terminfo settings for two TERM settings:
You can use infocmp to decompile the terminfo file to its source and make changes to it to try to mimic the behavior of the other terminal. Start by decoding the xterm-color terminfo file.
Edit xterm-color.src and modify the definitions of the kf1 through kf19 fields to match the values for screen-bce. Use infocmp to see screen-bce's definitions.
Finally compile using the tic program.
If you run it as a non-root user, it will put the compiled terminfo file into $HOME/.terminfo directory. On my system, it seems like Ubuntu picks this up automatically. You can also install it into the standard /usr/share/terminfo when you're satisfied. Running tic as root should do this for you.
Good luck!
我刚刚添加
到我的 .emacs
I just added
to my .emacs