I want to syntax highlight the code block separately while editing the restructuredText in Emacs.

Asked 2 years ago, Updated 2 years ago, 89 views

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()

emacs sphinx

2022-09-29 22:04

1 Answers

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.


2022-09-29 22:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.