-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathoutline-mode-easy-bindings.el
93 lines (81 loc) · 3.13 KB
/
outline-mode-easy-bindings.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;; [OBSOLETE FOR OUTSHINE.EL, BECAUSE ALL FUNCTIONS AND KEYBINDINGS FROM THIS
;; LIBRARY HAVE BEEN MERGED INTO OUTSHINE.EL]
;; outline-mode-easy-bindings.el (2010-08-15)
;;
;; Outlines can be managed entirely with Meta + <arrow key>.
;;
;; Installation: Store this file as outline-mode-easy-bindings.el
;; somewhere in your load-path and create hooks for outline modes to
;; load this automatically, for example:
;; (add-hook 'outline-mode-hook 'my-outline-easy-bindings)
;; (add-hook 'outline-minor-mode-hook 'my-outline-easy-bindings)
;;
;; (defun my-outline-easy-bindings ()
;; (require 'outline-mode-easy-bindings nil t))
;; Copied from: http://emacswiki.org/emacs/OutlineMinorMode
(defun outline-body-p ()
(save-excursion
(outline-back-to-heading)
(outline-end-of-heading)
(and (not (eobp))
(progn (forward-char 1)
(not (outline-on-heading-p))))))
(defun outline-body-visible-p ()
(save-excursion
(outline-back-to-heading)
(outline-end-of-heading)
(not (outline-invisible-p))))
(defun outline-subheadings-p ()
(save-excursion
(outline-back-to-heading)
(let ((level (funcall outline-level)))
(outline-next-heading)
(and (not (eobp))
(< level (funcall outline-level))))))
(defun outline-subheadings-visible-p ()
(interactive)
(save-excursion
(outline-next-heading)
(not (outline-invisible-p))))
(defun outline-hide-more ()
(interactive)
(when (outline-on-heading-p)
(cond ((and (outline-body-p)
(outline-body-visible-p))
(hide-entry)
(hide-leaves))
(t
(hide-subtree)))))
(defun outline-show-more ()
(interactive)
(when (outline-on-heading-p)
(cond ((and (outline-subheadings-p)
(not (outline-subheadings-visible-p)))
(show-children))
((and (not (outline-subheadings-p))
(not (outline-body-visible-p)))
(show-subtree))
((and (outline-body-p)
(not (outline-body-visible-p)))
(show-entry))
(t
(show-subtree)))))
(let ((map outline-mode-map))
(define-key map (kbd "M-<left>") 'outline-hide-more)
(define-key map (kbd "M-<right>") 'outline-show-more)
(define-key map (kbd "M-<up>") 'outline-previous-visible-heading)
(define-key map (kbd "M-<down>") 'outline-next-visible-heading)
(define-key map (kbd "C-c J") 'outline-hide-more)
(define-key map (kbd "C-c L") 'outline-show-more)
(define-key map (kbd "C-c I") 'outline-previous-visible-heading)
(define-key map (kbd "C-c K") 'outline-next-visible-heading))
(let ((map outline-minor-mode-map))
(define-key map (kbd "M-<left>") 'outline-hide-more)
(define-key map (kbd "M-<right>") 'outline-show-more)
(define-key map (kbd "M-<up>") 'outline-previous-visible-heading)
(define-key map (kbd "M-<down>") 'outline-next-visible-heading)
(define-key map (kbd "C-c J") 'outline-hide-more)
(define-key map (kbd "C-c L") 'outline-show-more)
(define-key map (kbd "C-c I") 'outline-previous-visible-heading)
(define-key map (kbd "C-c K") 'outline-next-visible-heading))
(provide 'outline-mode-easy-bindings)