Emacs Python-mode syntax highlighting

2024/9/30 7:29:12

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.

Answer

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

https://en.xdnf.cn/q/71109.html

Related Q&A

programmatically edit tab order in pyqt4 python

I have a multiple textfield in my form. My problem is the tab order is wrong. Is there a way to edit tab order in code? Just like in QT Designer.thanks.

Getting the parent of a parent widget in Python Tkinter

I am trying to get the parent of a widget then get the parent of that widget. But Everytime I try to I get a error.Error:AttributeError: str object has no attribute _nametowidgetWhy is it giving me tha…

Python Random List Comprehension

I have a list similar to:[1 2 1 4 5 2 3 2 4 5 3 1 4 2] I want to create a list of x random elements from this list where none of the chosen elements are the same. The difficult part is that I would lik…

How to handle unseen categorical values in test data set using python?

Suppose I have location feature. In train data set its unique values are NewYork, Chicago. But in test set it has NewYork, Chicago, London. So while creating one hot encoding how to ignore London? In…

How to get Facebook access token using Python library?

Ive found this Library it seems it is the official one, then found this, but everytime i find an answer the half of it are links to Facebook API Documentation which talks about Javascript or PHP and ho…

How to convert shapefile/geojson to hexagons using uber h3 in python?

I want to create hexagons on my geographic map and want to preserve the digital boundary specified by the shapefile/geojson as well. How do I do it using ubers h3 python library? Im new to shapefiles…

Python mypy: float and int are incompatible types with numbers.Real

I am new to Pythons static typing module mypy. I am trying to append ints and floats to an array, which I typed statically to be Real. But mypy says that they are incompatible types with Real. I though…

Search/Find functionality in QTableView

I have a QWidget and inside that, there is a QTableView. I need to have a find functionality on the first column of the table, so when I click on Ctrl+F, a find dialog will pop-up.class Widget(QWidget)…

How does searching with pip work?

Yes, Im dead serious with this question. How does searching with pip work?The documentation of the keyword search refers to a "pip search reference" at https://pip.pypa.io/en/stable/user_gui…

keras LSTM feeding input with the right shape

I am getting some data from a pandas dataframe with the following shapedf.head() >>> Value USD Drop 7 Up 7 Mean Change 7 Change Predict 0.06480 2.0 4.0 -0.000429 …