Last active
September 7, 2023 00:03
-
-
Save alphapapa/54761d6d507553f5a399 to your computer and use it in GitHub Desktop.
Emacs: Python: outline-minor-mode headings for both Python keywords and standard commented-starred headings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun python-mode-outline-hook () | |
(setq outline-level 'python-outline-level) | |
(setq outline-regexp | |
(rx (or | |
;; Commented outline heading | |
(group | |
(* space) ; 0 or more spaces | |
(one-or-more (syntax comment-start)) | |
(one-or-more space) | |
;; Heading level | |
(group (repeat 1 8 "\*")) ; Outline stars | |
(one-or-more space)) | |
;; Python keyword heading | |
(group | |
;; Heading level | |
(group (* space)) ; 0 or more spaces | |
bow | |
;; Keywords | |
(or "class" "def" "else" "elif" "except" "for" "if" "try" "while") | |
eow))))) | |
(defun python-outline-level () | |
(or | |
;; Commented outline heading | |
(and (string-match (rx | |
(* space) | |
(one-or-more (syntax comment-start)) | |
(one-or-more space) | |
(group (one-or-more "\*")) | |
(one-or-more space)) | |
(match-string 0)) | |
(- (match-end 0) (match-beginning 0))) | |
;; Python keyword heading, set by number of indentions | |
;; Add 8 (the highest standard outline level) to every Python keyword heading | |
(+ 8 (- (match-end 0) (match-beginning 0))))) | |
(add-hook 'python-mode-hook 'python-mode-outline-hook) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generally, Outshine isn't designed to be terribly extensible or customizeable, but you might be able to customize the corresponding
outshine
variables to achieve a similar effect.