我想outline-magic
已经被 取代了outshine
,不知道上面的代码能不能用。但是我能够让以下代码工作,这要归功于Ryan Davis 的博客文章:
(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)
也许有人会发现这很有用。我认为这是一种让代码编辑和导航更容易的好方法。