Path: blob/master/elisp/emacs-for-python/plugins/python-outline.el
990 views
;; Outline mode extension1;; ----------------------2;;3;; Author: Ronny Wikh <rw at strakt.com>, May 20024;;5;; A simple extension of the outline mode with functions provided6;; for python and texi modes.7;;8;; The mode simply adds toggles for outline/show everything and9;; outline/show paragraph, where the 'paragraph' concept is10;; modified to mean classes and function definitions in python11;; and chapters and subsections in texi.12;;13;; Toggle entry is bound to C-c C-e14;; Toggle all is bound to C-c C-a15;;16;; The default is that a buffer is started in outline mode. This17;; behaviour is controlled by the variable 'outline-start-hidden'18;; which can be set in your .emacs:19;;20;; (setq outline-start-hidden t) to start in outline (default) or21;; (setq outline-start-hidden nil) to start showing everything22;;23;; Activation of the mode can be done manually by calling the function24;;25;; 'python-outline' for python mode,26;; 'texi-outline' for texi mode27;;28;; or automatically by inserting the following lines into your .emacs file:29;;30;; (setq auto-mode-alist (append '(31;; ("\\.texi" . texi-outline)32;; ("\\.py" . python-outline))33;; auto-mode-alist))34;;35;; Modes for other languages can easily be added by providing suitable36;; regexp expressions for that specific language in new functions.37;;3839(defvar outline-start-hidden t "Start outline hidden")4041(defun outline-setup (regexp)42"Setup outline mode"43(defvar outline-toggle-all-flag nil "toggle all flag")44(make-variable-buffer-local 'outline-toggle-all-flag)45(defvar cpos_save nil "current cursor position")46(outline-minor-mode)47(setq outline-regexp regexp)48(define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry)49(define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all)50(if outline-start-hidden51(progn52(setq outline-toggle-all-flag t)53(hide-body)))5455(defun outline-toggle-entry () (interactive)56"Toggle outline hiding for the entry under the cursor"57(if (progn58(setq cpos_save (point))59(end-of-line)60(get-char-property (point) 'invisible))61(progn62(show-subtree)63(goto-char cpos_save))64(progn65(hide-leaves)66(goto-char cpos_save))))6768(defun outline-toggle-all () (interactive)69"Toggle outline hiding for the entire file"70(if outline-toggle-all-flag71(progn72(setq outline-toggle-all-flag nil)73(show-all))74(progn75(setq outline-toggle-all-flag t)76(hide-body))))77)7879(defun python-outline () (interactive)80"Python outline mode"81(python-mode)82(outline-setup "^class \\|[ ]*def \\|^#"))8384(defun texi-outline () (interactive)85"Texinfo outline mode"86(texinfo-mode)87(outline-setup "^@chap\\|@\\(sub\\)*section"))8889(provide 'python-outline)9091