comparison lisp/textmodes/outline.el @ 31986:350d5ee0e430

(outline-minor-mode): Use define-minor-mode. (outline-mode): Use define-derived-mode.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 29 Sep 2000 03:34:13 +0000
parents 4758e306c41e
children b5df14d31790
comparison
equal deleted inserted replaced
31985:d3eedbb7bb46 31986:350d5ee0e430
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; This package is a major mode for editing outline-format documents. 27 ;; This package is a major mode for editing outline-format documents.
28 ;; An outline can be `abstracted' to show headers at any given level, 28 ;; An outline can be `abstracted' to show headers at any given level,
29 ;; with all stuff below hidden. See the Emacs manual for details. 29 ;; with all stuff below hidden. See the Emacs manual for details.
30
31 ;;; Todo:
32
33 ;; - subtree-terminators
30 34
31 ;;; Code: 35 ;;; Code:
32 36
33 (defgroup outlines nil 37 (defgroup outlines nil
34 "Support for hierarchical outlining" 38 "Support for hierarchical outlining"
138 nil 142 nil
139 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map)) 143 (setq outline-mode-map (nconc (make-sparse-keymap) text-mode-map))
140 (define-key outline-mode-map "\C-c" outline-mode-prefix-map) 144 (define-key outline-mode-map "\C-c" outline-mode-prefix-map)
141 (define-key outline-mode-map [menu-bar] outline-mode-menu-bar-map)) 145 (define-key outline-mode-map [menu-bar] outline-mode-menu-bar-map))
142 146
143 (defcustom outline-minor-mode nil
144 "Non-nil if using Outline mode as a minor mode of some other mode."
145 :type 'boolean
146 :group 'outlines)
147 (make-variable-buffer-local 'outline-minor-mode)
148 (or (assq 'outline-minor-mode minor-mode-alist)
149 (setq minor-mode-alist (append minor-mode-alist
150 (list '(outline-minor-mode " Outl")))))
151
152 (defvar outline-font-lock-keywords 147 (defvar outline-font-lock-keywords
153 '(;; 148 '(;;
154 ;; Highlight headings according to the level. 149 ;; Highlight headings according to the level.
155 (eval . (list (concat "^" outline-regexp ".+") 150 (eval . (list (concat "^" outline-regexp ".+")
156 0 '(or (cdr (assq (outline-font-lock-level) 151 0 '(or (cdr (assq (outline-font-lock-level)
179 174
180 (defvar outline-view-change-hook nil 175 (defvar outline-view-change-hook nil
181 "Normal hook to be run after outline visibility changes.") 176 "Normal hook to be run after outline visibility changes.")
182 177
183 ;;;###autoload 178 ;;;###autoload
184 (defun outline-mode () 179 (define-derived-mode outline-mode text-mode "Outline"
185 "Set major mode for editing outlines with selective display. 180 "Set major mode for editing outlines with selective display.
186 Headings are lines which start with asterisks: one for major headings, 181 Headings are lines which start with asterisks: one for major headings,
187 two for subheadings, etc. Lines not starting with asterisks are body lines. 182 two for subheadings, etc. Lines not starting with asterisks are body lines.
188 183
189 Body text or subheadings under a heading can be made temporarily 184 Body text or subheadings under a heading can be made temporarily
218 A line is a heading if `outline-regexp' matches something at the 213 A line is a heading if `outline-regexp' matches something at the
219 beginning of the line. The longer the match, the deeper the level. 214 beginning of the line. The longer the match, the deeper the level.
220 215
221 Turning on outline mode calls the value of `text-mode-hook' and then of 216 Turning on outline mode calls the value of `text-mode-hook' and then of
222 `outline-mode-hook', if they are non-nil." 217 `outline-mode-hook', if they are non-nil."
223 (interactive)
224 (kill-all-local-variables)
225 (use-local-map outline-mode-map)
226 (setq mode-name "Outline")
227 (setq major-mode 'outline-mode)
228 (define-abbrev-table 'text-mode-abbrev-table ())
229 (setq local-abbrev-table text-mode-abbrev-table)
230 (set-syntax-table text-mode-syntax-table)
231 (make-local-variable 'line-move-ignore-invisible) 218 (make-local-variable 'line-move-ignore-invisible)
232 (setq line-move-ignore-invisible t) 219 (setq line-move-ignore-invisible t)
233 ;; Cause use of ellipses for invisible text. 220 ;; Cause use of ellipses for invisible text.
234 (add-to-invisibility-spec '(outline . t)) 221 (add-to-invisibility-spec '(outline . t))
235 (make-local-variable 'paragraph-start) 222 (set (make-local-variable 'paragraph-start)
236 (setq paragraph-start (concat paragraph-start "\\|\\(" 223 (concat paragraph-start "\\|\\(" outline-regexp "\\)"))
237 outline-regexp "\\)"))
238 ;; Inhibit auto-filling of header lines. 224 ;; Inhibit auto-filling of header lines.
239 (make-local-variable 'auto-fill-inhibit-regexp) 225 (set (make-local-variable 'auto-fill-inhibit-regexp) outline-regexp)
240 (setq auto-fill-inhibit-regexp outline-regexp) 226 (set (make-local-variable 'paragraph-separate)
241 (make-local-variable 'paragraph-separate) 227 (concat paragraph-separate "\\|\\(" outline-regexp "\\)"))
242 (setq paragraph-separate (concat paragraph-separate "\\|\\(" 228 (set (make-local-variable 'font-lock-defaults)
243 outline-regexp "\\)")) 229 '(outline-font-lock-keywords t))
244 (make-local-variable 'font-lock-defaults)
245 (setq font-lock-defaults '(outline-font-lock-keywords t))
246 (make-local-variable 'change-major-mode-hook)
247 (setq imenu-generic-expression 230 (setq imenu-generic-expression
248 (list (list nil (concat outline-regexp ".*$") 0))) 231 (list (list nil (concat outline-regexp ".*$") 0)))
249 (add-hook 'change-major-mode-hook 'show-all) 232 (add-hook 'change-major-mode-hook 'show-all nil t))
250 (run-hooks 'text-mode-hook 'outline-mode-hook))
251 233
252 (defcustom outline-minor-mode-prefix "\C-c@" 234 (defcustom outline-minor-mode-prefix "\C-c@"
253 "*Prefix key to use for Outline commands in Outline minor mode. 235 "*Prefix key to use for Outline commands in Outline minor mode.
254 The value of this variable is checked as part of loading Outline mode. 236 The value of this variable is checked as part of loading Outline mode.
255 After that, changing the prefix key requires manipulating keymaps." 237 After that, changing the prefix key requires manipulating keymaps."
256 :type 'string 238 :type 'string
257 :group 'outlines) 239 :group 'outlines)
258 240
259 (defvar outline-minor-mode-map nil)
260 (if outline-minor-mode-map
261 nil
262 (setq outline-minor-mode-map (make-sparse-keymap))
263 (define-key outline-minor-mode-map [menu-bar]
264 outline-mode-menu-bar-map)
265 (define-key outline-minor-mode-map outline-minor-mode-prefix
266 outline-mode-prefix-map))
267
268 (or (assq 'outline-minor-mode minor-mode-map-alist)
269 (setq minor-mode-map-alist
270 (cons (cons 'outline-minor-mode outline-minor-mode-map)
271 minor-mode-map-alist)))
272
273 ;;;###autoload 241 ;;;###autoload
274 (defun outline-minor-mode (&optional arg) 242 (define-minor-mode outline-minor-mode
275 "Toggle Outline minor mode. 243 "Toggle Outline minor mode.
276 With arg, turn Outline minor mode on if arg is positive, off otherwise. 244 With arg, turn Outline minor mode on if arg is positive, off otherwise.
277 See the command `outline-mode' for more information on this mode." 245 See the command `outline-mode' for more information on this mode."
278 (interactive "P") 246 nil " Outl" (list (cons [menu-bar] outline-mode-menu-bar-map)
279 (setq outline-minor-mode 247 (cons outline-minor-mode-prefix outline-mode-prefix-map))
280 (if (null arg) (not outline-minor-mode)
281 (> (prefix-numeric-value arg) 0)))
282 (if outline-minor-mode 248 (if outline-minor-mode
283 (progn 249 (progn
284 (make-local-hook 'change-major-mode-hook)
285 ;; Turn off this mode if we change major modes. 250 ;; Turn off this mode if we change major modes.
286 (add-hook 'change-major-mode-hook 251 (add-hook 'change-major-mode-hook
287 (lambda () (outline-minor-mode -1)) 252 (lambda () (outline-minor-mode -1))
288 nil t) 253 nil t)
289 (make-local-variable 'line-move-ignore-invisible) 254 (set (make-local-variable 'line-move-ignore-invisible) t)
290 (setq line-move-ignore-invisible t)
291 ;; Cause use of ellipses for invisible text. 255 ;; Cause use of ellipses for invisible text.
292 (add-to-invisibility-spec '(outline . t)) 256 (add-to-invisibility-spec '(outline . t)))
293 (run-hooks 'outline-minor-mode-hook))
294 (setq line-move-ignore-invisible nil) 257 (setq line-move-ignore-invisible nil)
295 ;; Cause use of ellipses for invisible text. 258 ;; Cause use of ellipses for invisible text.
296 (remove-from-invisibility-spec '(outline . t))) 259 (remove-from-invisibility-spec '(outline . t)))
297 ;; When turning off outline mode, get rid of any outline hiding. 260 ;; When turning off outline mode, get rid of any outline hiding.
298 (or outline-minor-mode 261 (or outline-minor-mode
299 (show-all)) 262 (show-all)))
300 (force-mode-line-update))
301 263
302 (defcustom outline-level 'outline-level 264 (defcustom outline-level 'outline-level
303 "*Function of no args to compute a header's nesting level in an outline. 265 "*Function of no args to compute a header's nesting level in an outline.
304 It can assume point is at the beginning of a header line." 266 It can assume point is at the beginning of a header line."
305 :type 'function 267 :type 'function