
我正在嘗試向程式模式添加自訂標題,並且我希望它位於最高層級並將所有其他層級向下移動,以便我可以為長腳本添加更多結構。例如,對於python模式,標題格式為“# *”,星數決定其等級。我的方法是透過添加這樣的鉤子來修改outline-regexp變數。
(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)
理想情況下,匹配越小,標題的等級就越高。但上面的方法不起作用。如果我用下面的替換它,它也不起作用。
(setq outline-regexp (concat comment-start " [*]\\{1,8\\}\\|" outline-regexp)))
python模式的原始outline-regexp的值為
"[[:space:]]*\\_<\\(?:\\(?:class\\|def\\|e\\(?:l\\(?:if\\|se\\)\\|xcept\\)\\|f\\(?:inally\\|or\\)\\|if\\|try\\|w\\(?:hile\\|ith\\)\\)\\)\\_>"
誰能告訴我如何實現我的目標?先感謝您。