I am writing using Sphinx. While editing a file in the reStructuredText format in Emacs: I would like to highlight the contents of the code block in a different major mode from rst-mode, but how can I do it well?
Hello, world
==============
- baldness
.. code-block::python
# This block is not in rst-mode, but in python-mode.
# Syntax highlights and indentations.
def hello():
print("Hello, world!")
hello()
I don't know if it will work because I haven't tried it myself, but mumamo or mmm-mode allows you to switch between different modes in one buffer depending on the code type (see also MultipleModes in EmacsWiki).
In mmm-mode, what you're doing is the opposite (editing rst in Python code), but this answer or this code may help you set it up.
© 2025 OneMinuteCode. All rights reserved.