第二个例子显然更复杂,我不打算解决它,但是大纲模式/次要模式对于基于缩进的树会很好地工作,所以这里有一个方法,大纲标题基于任意重复的前缀字符串(本示例中为四个空格,但可根据需要进行配置)。
如果您加载/评估下面的代码,然后加载数据文件(包括局部变量),那么您可以使用and (光标键)隐藏/显示分支SHIFT+TAB并提升/降级分支。当然,所有其他功能也可用。SHIFT+LEFTSHIFT+RIGHToutline-minor-mode
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
;;; Local Variables:
;;; my-outline-prefix: " "
;;; eval: (my-outline-minor-mode 1)
;;; End:
(global-set-key (kbd "<S-tab>") 'outline-toggle-children)
(global-set-key (kbd "<S-left>") 'outline-promote)
(global-set-key (kbd "<S-right>") 'outline-demote)
(defvar my-outline-prefix " "
"Prefix string denoting a single outline level for `my-outline-minor-mode'.")
(defvar my-outline-max-level 20
"Maximum number of levels for `my-outline-minor-mode'.")
(define-minor-mode my-outline-minor-mode
"Outline levels based on repetitions of `my-outline-prefix'."
0 nil nil
(outline-minor-mode 1)
(setq-local outline-level 'my-outline-level)
(setq-local outline-regexp (format "\\(%s\\)*"
(regexp-quote my-outline-prefix)))
(setq outline-heading-alist '())
(let ((level 0)
(level-prefix ""))
(while (< level my-outline-max-level)
(setq outline-heading-alist (cons (cons level-prefix level)
outline-heading-alist)
level (1+ level)
level-prefix (concat level-prefix my-outline-prefix)))
(setq outline-heading-alist (nreverse outline-heading-alist))))
(defun my-outline-level ()
"Counts how many times `my-outline-prefix' appears at the start of the line."
(let* ((data (match-data))
(start (car data))
(end (cadr data))
(indent (- end start)))
(/ indent (length my-outline-prefix))))