Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/emacs-for-python/plugins/python-outline.el
990 views
1
;; Outline mode extension
2
;; ----------------------
3
;;
4
;; Author: Ronny Wikh <rw at strakt.com>, May 2002
5
;;
6
;; A simple extension of the outline mode with functions provided
7
;; for python and texi modes.
8
;;
9
;; The mode simply adds toggles for outline/show everything and
10
;; outline/show paragraph, where the 'paragraph' concept is
11
;; modified to mean classes and function definitions in python
12
;; and chapters and subsections in texi.
13
;;
14
;; Toggle entry is bound to C-c C-e
15
;; Toggle all is bound to C-c C-a
16
;;
17
;; The default is that a buffer is started in outline mode. This
18
;; behaviour is controlled by the variable 'outline-start-hidden'
19
;; which can be set in your .emacs:
20
;;
21
;; (setq outline-start-hidden t) to start in outline (default) or
22
;; (setq outline-start-hidden nil) to start showing everything
23
;;
24
;; Activation of the mode can be done manually by calling the function
25
;;
26
;; 'python-outline' for python mode,
27
;; 'texi-outline' for texi mode
28
;;
29
;; or automatically by inserting the following lines into your .emacs file:
30
;;
31
;; (setq auto-mode-alist (append '(
32
;; ("\\.texi" . texi-outline)
33
;; ("\\.py" . python-outline))
34
;; auto-mode-alist))
35
;;
36
;; Modes for other languages can easily be added by providing suitable
37
;; regexp expressions for that specific language in new functions.
38
;;
39
40
(defvar outline-start-hidden t "Start outline hidden")
41
42
(defun outline-setup (regexp)
43
"Setup outline mode"
44
(defvar outline-toggle-all-flag nil "toggle all flag")
45
(make-variable-buffer-local 'outline-toggle-all-flag)
46
(defvar cpos_save nil "current cursor position")
47
(outline-minor-mode)
48
(setq outline-regexp regexp)
49
(define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry)
50
(define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all)
51
(if outline-start-hidden
52
(progn
53
(setq outline-toggle-all-flag t)
54
(hide-body)))
55
56
(defun outline-toggle-entry () (interactive)
57
"Toggle outline hiding for the entry under the cursor"
58
(if (progn
59
(setq cpos_save (point))
60
(end-of-line)
61
(get-char-property (point) 'invisible))
62
(progn
63
(show-subtree)
64
(goto-char cpos_save))
65
(progn
66
(hide-leaves)
67
(goto-char cpos_save))))
68
69
(defun outline-toggle-all () (interactive)
70
"Toggle outline hiding for the entire file"
71
(if outline-toggle-all-flag
72
(progn
73
(setq outline-toggle-all-flag nil)
74
(show-all))
75
(progn
76
(setq outline-toggle-all-flag t)
77
(hide-body))))
78
)
79
80
(defun python-outline () (interactive)
81
"Python outline mode"
82
(python-mode)
83
(outline-setup "^class \\|[ ]*def \\|^#"))
84
85
(defun texi-outline () (interactive)
86
"Texinfo outline mode"
87
(texinfo-mode)
88
(outline-setup "^@chap\\|@\\(sub\\)*section"))
89
90
(provide 'python-outline)
91