I’m finding that defining outline-regexp
does not do for me in python-mode
what it does for me in other language modes. Someone else on Stack Exchange ran into the same problem, and a suggested answer to their question makes it clear that python-mode
preconfigures some definitions for outline-minor-mode
. But what those preconfigurations are, and more importantly how to use them, is not documented anywhere I can find.
M-x find-library python
, followed byC-s outline-
shows what’s happening:python-base-mode
sets the local outline variables locally, in its mode body. Since mode hooks always run after the body of their mode definitions, you could add a bit of code to thepython-base-mode-hook
(or a parent of it, likeprog-mode-hook
) setting your desired outline config there (i.e. overwriting what python mode did).I do that using outli simply (in a use-package stanza):
BTW, here’s a handy guide (from this epic answer) to what runs in which order upon invoking a derived major mode like
python-ts-mode
: