Emacs Python-mode syntax highlighting
Asked Answered
S

3

7

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.

Sharie answered 8/3, 2011 at 18:57 Comment(3)
@Michael: Thanks (didn't know about that). But I've "unsolved" it after further testing, so may someone will still have an answer.Sharie
Generally if I'm editing files on a remote system, I use emacs TRAMP mode. That way I have all my local edit settings in use. Would that be an option for you?Peele
@Jeff: Typically I ssh into the server to work on other tasks, as well as edit files, so editing files from the "client" to use the client settings isn't really what I'm looking for. Thanks for the suggestion though; it is something I'll look into more thoroughly.Sharie
A
2

For me running emacs -nw from inside byobu with TERM=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 set TERM 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

Adonai answered 11/4, 2012 at 9:46 Comment(1)
Thanks, I've just checked again and I can confirm this: Python syntax highlighting for colours is appearing correctly in byobu (TERM=xterm). Function keys in byobu also work fine.Sharie
R
2

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:

infocmp -d screen-bce xterm-color

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.

infocmp xterm-color > xterm-color.src

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.

infocmp screen-bce

Finally compile using the tic program.

tic xterm-color.src

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!

Roots answered 13/3, 2011 at 2:26 Comment(0)
A
2

For me running emacs -nw from inside byobu with TERM=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 set TERM 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

Adonai answered 11/4, 2012 at 9:46 Comment(1)
Thanks, I've just checked again and I can confirm this: Python syntax highlighting for colours is appearing correctly in byobu (TERM=xterm). Function keys in byobu also work fine.Sharie
A
1

I just added

(set-face-foreground 'font-lock-comment-face "red")

to my .emacs

Abigailabigale answered 14/6, 2014 at 19:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.