9

I want to start a python-shell M-x python-shell. If I'm not happy with the syntax highlighting, is it possible to improve it (put more colors in the buffer) without changing major mode? In vim this would be simple with set filetype=python.

The python syntax itself is not highlighted in python-shell mode, I want it to be highlighted.

A simple solution will be favored because I'm just learning about emacs.

7
  • 5
    Not clear what you are asking. What "highlighter"? If you are asking whether you can change font-lock-keywords for a given mode, then yes. But depending on how the mode function is defined, re-entering the mode might re-highlight using the mode-defined font-lock-keywords and not what you have redefined. To be safer in that (but with no guarantee), you would need to redefine font-lock-keywords on the mode hook, so that it takes effect each time the mode is turned on, and after the mode code does its thing.
    – Drew
    Oct 17, 2014 at 14:52
  • 1
    Clarifying: do you want to turn off syntax highlighting, do you dislike the default color ("face") choices and want to change them, or do you want to add new highlighting on top of the existing highlighting? As @Drew suggested, it's going to involve font-lock-keywords in some way, depending on what you want to do.
    – Dan
    Oct 17, 2014 at 15:00
  • @Drew I meant the syntax highlighter. @ Dan the current python-shell mode (in emacs23) doesn't color python syntax so I want to add color.
    – Joelmob
    Oct 17, 2014 at 15:20
  • @Malabarba should be fixed now.
    – Joelmob
    Oct 17, 2014 at 16:29
  • 3
    Cant you switch to a newer python.el? IIRC, the one shipped since emacs 24.2 had font lock for the shell as well.
    – Vamsi
    Oct 18, 2014 at 1:41

1 Answer 1

4

Every major mode that supports font-lock does so via font-lock-defaults. If you check python-mode, you'll see the following:

(set (make-local-variable 'font-lock-defaults)
     '(python-font-lock-keywords nil nil nil nil))

If you're in a different major mode, you should be able to set font-lock-defaults to (python-font-lock-keywords nil nil nil nil) either interactively using M-: or via a hook.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.