2

I'm facing the same problem as OP in this question: How can I make python-mode correctly indent python's match statement?.

A quote from the OP: "Python 3.10 added a match statement. When I try and type one in emacs 27.2, it does not indent it correctly, presumably because it does not yet have support for it. How do I get python-mode to indent the match statement correctly?"

One contributor suggested M-x find-library RET python RET and just append the two keywords (match and case) to appropriate places. I did just that. For a while Emacs was working wonderfully with indenting the match and case statements. However as of now the indentation and block syntax highlighting etc. is not working at all. I have tried loading python.el by load-file RET RET but of no avail. Here is an example of my additions:

`(rx-let ((block-start       (seq symbol-start
                                    (or "def" "class" "if" "elif" "else" "try"
                                        "except" "finally" "for" "while" "with"
                                        ;; Added by @Keyboard_Crasher.
                                        "match" "case"
                                        ;; Python 3.5+ PEP492
                                        (and "async" (+ space)
                                             (or "def" "for" "with")))
                                    symbol-end))

The question is: how to fix this annoying lack of indentation and syntax highlighting?

6
  • Adding this makes indenting works for me. Commented Mar 19, 2022 at 10:27
  • If you want to make syntax highlighting work either, try to add match and case to python-font-lock-keywords-level-2 Commented Mar 19, 2022 at 10:29
  • Great that it works for you! It also worked for me for a while but not anymore. I did add match and case to the place you mentioned but decided to post only a part of the changes in OP. Commented Mar 19, 2022 at 14:15
  • 1
    Did you byte compile the python.el file or get rid of the comes-with-emacs .elc file? The changes you show worked for me (thanks) once I deleted python.elc. I don't see how it would have worked for awhile and stopped.
    – Levin
    Commented Apr 16, 2022 at 16:34
  • 1
    What about emacs v28? When I run M-x find-library RET python RET I get Can't find library: python.
    – Endlisnis
    Commented Dec 21, 2022 at 2:20

0

Your Answer

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