3

I am trying to add a custom heading to program mode, and I want it to be on the highest level and move all other levels down, so I can add more structure to my long script. For example, for python mode, the heading format is "# *", the number of star determines its level. My approach is to modify the outline-regexp variable by add a hook like this.

(defun my_heading()
"custom heading for all prog mode"
(setq outline-regexp (concat "\\(?:" comment-start " [*]\\{1,8\\}\\)?" outline-regexp)))
(add-hook 'outline-minor-mode-hook 'my_heading)

Ideally, the smaller the match, the higher the level of the heading. But the above doesn't work. If I replace it with the following one, it doesn't work either.

(setq outline-regexp (concat comment-start " [*]\\{1,8\\}\\|" outline-regexp)))

The value of the original outline-regexp for python mode is

"[[:space:]]*\\_<\\(?:\\(?:class\\|def\\|e\\(?:l\\(?:if\\|se\\)\\|xcept\\)\\|f\\(?:inally\\|or\\)\\|if\\|try\\|w\\(?:hile\\|ith\\)\\)\\)\\_>"

Can anyone please tell me how can I achieve my goal? Thank you in advance.

0 Answers0