1

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?

  • Adding this makes indenting works for me. – Tianshu Wang Mar 19 '22 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` – Tianshu Wang Mar 19 '22 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. – Keyboard_Crasher Mar 19 '22 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 Magruder Apr 16 '22 at 16:34
  • Ah, did recompile `python.el` (with `M-x byte-compile-file`) and now it's working again! Thank you for pointing this out! – Keyboard_Crasher Apr 24 '22 at 12:23
  • 1
    What about emacs v28? When I run `M-x find-library RET python RET` I get `Can't find library: python`. – Endlisnis Dec 21 '22 at 02:20

0 Answers0