1

Is it possible to customise emacs such that python docstrings are highlighted the same way as comments are? Here is an example of a python docstring

def python_function(argument):
    """
    doc string here

    may be multiline
    """
    return some_func(argument)
Walter
  • 44,150
  • 20
  • 113
  • 196
  • 1
    Have you read http://stackoverflow.com/q/5130088/3001761 and http://stackoverflow.com/q/27317396/3001761? – jonrsharpe Feb 24 '16 at 11:27
  • @jonrsharpe No, didn't see them. thanks for pointing me to them! Unfortunately, they don't come with the answer (the accepted answers do not answer the question satisfactorily) – Walter Feb 24 '16 at 13:29
  • Then could you edit this one to be more specific about how it differs and what from the existing answers falls short? – jonrsharpe Feb 24 '16 at 13:40
  • There are two major modes for python in common usage, `python-mode.el` from Python devs, and `python.el` which comes with Emacs. I quickly looked through `python.el` and didn't see anything to highlight docstrings differently than strings. The other answers imply that `python-mode.el` does do this. So you either need to install `python-mode.el` or add the functionality to `python.el`. FWIW, I used `python-mode.el` years ago and switched to `python.el`, and I feel like it was a good move, but there have been enormous changes in both libraries since then. – jpkotta Feb 24 '16 at 17:14
  • @jpkotta I don't have root access to the system, so how can I *install* either of these? Where does it go (if I do have root access)? – Walter Feb 25 '16 at 08:11
  • @jonrsharpe These 'answers' don't answer the question. (full stop). I want a solution, not a hint that requires in-depth knowledge of the inner workings of emacs. – Walter Feb 25 '16 at 08:12
  • @Walter perhaps you'd like someone to pop round and set up your machine for you? – jonrsharpe Feb 25 '16 at 08:26
  • @Walter You don't need root access, it can be installed in `~/.emacs.d`. You can set up the emacs package manager (use google, there are many, many guides) and use it to install `python-mode` (available in the melpa repo). If you're going to use emacs, you want to figure out the package system. It's not hard and will pay dividends many times over. – jpkotta Feb 25 '16 at 17:53

2 Answers2

1

With python-mode.el, customize font-lock-doc-face accordingly. This needs also py-use-font-lock-doc-face-p set to t.

Besides all faces are customizable. M-x customize-face RET font-lock-string-face RET and set it to the value wanted. However this would affect all modes.

Andreas Röhler
  • 4,804
  • 14
  • 18
0

As of Emacs 25.1, Emacs' bulit-in python.el displays docstrings with font-lock-doc-face.

dfan
  • 5,714
  • 1
  • 31
  • 27