我将org-mode与lisp-mode结合起来,在emacs中为lisp代码实现了漂亮的代码折叠:lisp-orgi-mode。基本上,我使用';‘代替'*’作为标题字符。对于注释,我只是在“;”前加了一个空格,使它成为“;”,所以它不算标题……
然而,用python-mode做同样的事情是行不通的……可能是因为python注释使用的'#‘字符干扰了组织模式设置...
有没有人能够成功地组合这些功能?我知道人们已经把python模式和大纲模式(link)结合起来了,但是outline模式不如org模式好……
编辑:让它与outline-magic很好地协同工作: python-magic.el
发布于 2010-11-04 03:11:12
我使用hideshow-org (and a small introduction here)来实现这个目的,我认为它真的非常好用。
下面是一些额外的但有用的代码片段:
(dolist (hook (list 'c-mode-common-hook
'emacs-lisp-mode-hook
'java-mode-hook
'lisp-mode-hook
'perl-mode-hook
'sh-mode-hook))
(add-hook hook 'my-hideshow-hook))
(defun my-hideshow-hook ()
"thisandthat."
(interactive)
(progn (require 'hideshow-org)
(global-set-key (kbd "C-c h") 'hs-org/minor-mode)
(hs-org/minor-mode)))
(defadvice goto-line (after expand-after-goto-line activate compile)
"hideshow-expand affected block when using goto-line in a collapsed buffer"
(save-excursion
(hs-show-block)))发布于 2015-03-15 14:12:59
我认为outshine已经取代了outline-magic,我不知道上面的代码是否适用于它。但是,由于a blog post by 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)也许有人会发现这很有用。我认为这是一种让编辑和导航代码变得更容易的神奇方式。
https://stackoverflow.com/questions/4079648
复制相似问题