annotate lisp/progmodes/hideshow.el @ 10559:dcb43c6d4c42

Integer width changes.
author Richard M. Stallman <rms@gnu.org>
date Fri, 27 Jan 1995 01:43:02 +0000
parents 86c61b6bd265
children 88926963f1ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
1 ;;; hideshow.el --- minor mode cmds to selectively display blocks of code
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
3 ;;; Copyright (C) 1994,1995 Free Software Foundation
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
4
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
5 ;;; Author: Thien-Thi Nguyen <ttn@netcom.com>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
6 ;;; Version: 3.4
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
7 ;;; Keywords: C C++ lisp tools editing
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
8 ;;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
9
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10 ;;; This file is part of GNU Emacs.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
11
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify it
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
13 ;;; under the terms of the GNU General Public License as published by the
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
14 ;;; Free Software Foundation; either version 2 of the License, or (at your
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
15 ;;; option) any later version.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
16 ;;;
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17 ;;; GNU Emacs is distributed in the hope that it will be useful, but WITHOUT
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18 ;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
19 ;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
20 ;;; for more details.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
21 ;;;
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License along
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23 ;;; with this program; if not, write to the Free Software Foundation, Inc.,
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
24 ;;; 675 Mass Ave, Cambridge, MA 02139, USA.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
25
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
26 ;;; LCD Archive Entry:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
27 ;;; hideshow|Thien-Thi Nguyen|ttn@netcom.com|
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
28 ;;; minor mode commands to selectively display blocks of code|
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
29 ;;; 18-Oct-1994|3.4|~/modes/hideshow.el.Z|
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
30
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
31 ;;; Commentary:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
32
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
33 ;;; this file provides `hs-minor-mode'. when active, six commands:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
34 ;;; hs-{hide,show}-{all,block}, hs-show-region and hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
35 ;;; are available. they implement block hiding and showing. blocks are
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
36 ;;; defined in mode-specific way. in c-mode or c++-mode, they are simply
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
37 ;;; curly braces, while in lisp-ish modes they are parens. multi-line
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
38 ;;; comments (c-mode) can also be hidden. the command M-x hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
39 ;;; toggles the minor mode or sets it (similar to outline minor mode).
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
40 ;;; see documentation for each command for more info.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
41 ;;;
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
42 ;;; the variable `hs-unbalance-handler-method' controls hideshow's behavior
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
43 ;;; in the case of "unbalanced parentheses". see doc for more info.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
44
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
45 ;;; suggested usage:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
47 ;;; (load-library "hideshow")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
48 ;;; (defun my-hs-setup () "enables hideshow and binds some commands"
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
49 ;;; (hs-minor-mode 1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
50 ;;; (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
51 ;;; (define-key hs-minor-mode-map "\C-cs" 'hs-show-block)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
52 ;;; (define-key hs-minor-mode-map "\C-cr" 'hs-show-region))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
53 ;;; (add-hook 'X-mode-hook 'my-hs-setup t) ; other modes similarly
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54 ;;;
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
55 ;;; where X = {emacs-lisp,c,c++,perl,...}. see the doc for the variable
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56 ;;; `hs-special-modes-alist' if you'd like to use hideshow w/ other modes.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
57
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
58 ;;; etc:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
59
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
60 ;;; bug reports and fixes welcome (comments, too). thanks go to
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61 ;;; Dean Andrews <adahome@ix.netcom.com>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
62 ;;; Preston F. Crow <preston.f.crow@dartmouth.edu>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
63 ;;; Gael Marziou <gael@gnlab030.grenoble.hp.com>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
64 ;;; Keith Sheffield <sheff@edcsgw2.cr.usgs.gov>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
65 ;;; Jan Djarv <jan.djarv@sa.erisoft.se>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
66 ;;; Lars Lindberg <qhslali@aom.ericsson.se>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ;;; Alf-Ivar Holm <alfh@ifi.uio.no>
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68 ;;; for valuable feedback and bug reports.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;;; Code:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
73 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
74 ;;; dependencies
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
75
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
76 ; (require 'emacs-vers) ; support different emacs flavors
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
77 (require 'cl) ; common lisp package
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
78
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
79
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
80 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
81 ;;; user-configurable variables
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
82
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
83 (defvar hs-unbalance-handler-method 'top-level
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
84 "*symbol representing how \"unbalanced parentheses\" should be handled.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
85 this error is usually signalled by hs-show-block. one of four values:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86 `top-level', `next-line', `signal' or `ignore'. default is `top-level'.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
87
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
88 - `top-level' -- show top-level block containing the currently troublesome
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
89 block.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
90 - `next-line' -- use the fact that, for an already hidden block, its end
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
91 will be on the next line. attempt to show this block.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
92 - `signal' -- pass the error through, stopping execution.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
93 - `ignore' -- ignore the error, continuing execution.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
94
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 values other than these four will be interpreted as `signal'.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
96
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
97 (defvar hs-special-modes-alist '((c-mode "{" "}")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
98 (c++-mode "{" "}"))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
99 "*alist of the form (MODE START-RE END-RE FORWARD-SEXP-FUNC).
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
100 if present, hideshow will use these values for the start and end regexps,
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
101 respectively. since algol-ish languages do not have single-character
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
102 block delimiters, the function `forward-sexp' which is used by hideshow
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
103 doesn't work. in this case, if a similar function is provided, you can
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
104 register it and have hideshow use it instead of `forward-sexp'. to add
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
105 more values, use
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
106
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
107 \t(pushnew '(new-mode st-re end-re function-name)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
108 \t hs-special-modes-alist :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
109
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
110 for example:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
111
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
112 \t(pushnew '(simula-mode \"begin\" \"end\" simula-next-statement)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
113 \t hs-special-modes-alist :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
114
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
115 note that the regexps should not contain leading or trailing whitespace.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
116
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
117 (defvar hs-hide-hooks nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
118 "*hooks called at the end of hs-hide-all and hs-hide-block.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
119
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
120 (defvar hs-show-hooks nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
121 "*hooks called at the end of hs-show-all, hs-show-block and hs-show-region.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
122
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
123 (defvar hs-minor-mode-prefix "\C-c"
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
124 "*prefix key to use for hideshow commands in hideshow minor mode.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
125
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
126
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
127 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
128 ;;; internal variables
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
129
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
130 (defvar hs-minor-mode nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
131 "non-nil if using hideshow mode as a minor mode of some other mode.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
132 use the command `hs-minor-mode' to toggle this variable.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
133
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
134 (defvar hs-minor-mode-map nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
135 "mode map for hideshow minor mode.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
136
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
137 (defvar hs-menu-bar nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
138 "menu bar for hideshow minor mode (xemacs only).")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
140 (defvar hs-c-start-regexp nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
141 "regexp for beginning of comments. buffer-local.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
142 differs from mode-specific comment regexps in that surrounding
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
143 whitespace is stripped.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
144
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
145 (defvar hs-c-end-regexp nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
146 "regexp for end of comments. buffer-local.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
147 see `hs-c-start-regexp'.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
148
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
149 (defvar hs-block-start-regexp nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
150 "regexp for beginning of block. buffer-local.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
151
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
152 (defvar hs-block-end-regexp nil
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153 "regexp for end of block. buffer-local.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
154
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
155 (defvar hs-forward-sexp-func 'forward-sexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
156 "function used to do a forward-sexp. should change for algol-ish modes.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
157 for single-character block delimiters -- ie, the syntax table regexp for the
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
158 character is either ( or ) -- `hs-forward-sexp-func' would just be
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
159 `forward-sexp'. for other modes such as simula, a more specialized function
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
160 is necessary.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
161
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
162 ; (eval-when-compile ; lint free!
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
163 ; (unless (emacs-type-eq 'lucid)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
164 ; (defvar current-menubar nil "")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
165 ; (defun set-buffer-menubar (arg1))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
166 ; (defun add-menu (arg1 arg2 arg3))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
167
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
168
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
169 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
170 ;;; support funcs
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
171
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
172 ;; snarfed from outline.el, but added buffer-read-only
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
173 (defun hs-flag-region (from to flag)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
174 "hides or shows lines from FROM to TO, according to FLAG.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
175 if FLAG is \\n (newline character) then text is shown, while if FLAG
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
176 is \\^M \(control-M) the text is hidden."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
177 (let ((modp (buffer-modified-p))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
178 buffer-read-only) ; nothing is immune
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
179 (unwind-protect (progn
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
180 (subst-char-in-region
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
181 from to
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
182 (if (= flag ?\n) ?\C-m ?\n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
183 flag t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
184 (set-buffer-modified-p modp))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
185
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
186 (defun hs-hide-block-at-point (&optional end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
187 "hide block iff on block beginning, optional END means reposition at end."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
188 (when (looking-at hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
189 (let* ((p (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
190 (q (progn (funcall hs-forward-sexp-func 1) (point))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
191 (forward-line -1) (end-of-line)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
192 (when (and (< p (point)) (> (count-lines p q) 1))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
193 (hs-flag-region p (point) ?\C-m))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
194 (goto-char (if end q p)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
195
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
196 (defun hs-show-block-at-point (&optional end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
197 "show block iff on block beginning. optional END means reposition at end."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
198 (when (looking-at hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
199 (let* ((p (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
200 (q
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
201 (condition-case error ; probably unbalanced paren
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
202 (progn
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
203 (funcall hs-forward-sexp-func 1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
204 (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
205 (error
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
206 (case hs-unbalance-handler-method
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
207 ('ignore
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
208 ;; just ignore this block
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
209 (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
210 ('top-level
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
211 ;; try to get out of rat's nest and expose the whole func
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
212 (unless (= (current-column) 0) (beginning-of-defun))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
213 (setq p (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
214 (re-search-forward (concat "^" hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
215 (point-max) t 2)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
216 (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
217 ('next-line
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
218 ;; assumption is that user knows what s/he's doing
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
219 (beginning-of-line) (setq p (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
220 (end-of-line 2) (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
221 (t
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
222 ;; pass error through -- this applies to `signal', too
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
223 (signal (car error) (cdr error))))))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
224 (hs-flag-region p q ?\n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
225 (goto-char (if end (1+ (point)) p)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
226
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
227 (defun hs-safety-is-job-n ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
228 "warns if selective-display or selective-display-ellipses is nil."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
229 (let ((str ""))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
230 (unless selective-display
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
231 (setq str "selective-display nil "))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
232 (unless selective-display-ellipses
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
233 (setq str (concat str "selective-display-ellipses nil")))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
234 (when (/= (length str) 0)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
235 (message "warning: %s" str)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
236 (sit-for 2))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
237
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
238 (defun hs-inside-comment-p ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
239 "returns non-nil if point is inside a comment, otherwise nil.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
240 actually, for multi-line-able comments, returns a list containing
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
241 the buffer position of the start and the end of the comment."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
242 ;; is it single-line-only or multi-line-able?
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
243 (save-excursion
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
244 (let ((p (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
245 q)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
246 (if (string= comment-end "") ; single line
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
247 (let (found)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
248 (beginning-of-line)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
249 (setq found (re-search-forward hs-c-start-regexp p t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
250 (and found (not (search-forward "\"" p t))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
251 (re-search-forward hs-c-end-regexp (point-max) 1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
252 (setq q (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
253 (forward-comment -1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
254 (re-search-forward hs-c-start-regexp (point-max) 1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
255 (when (< (- (point) (length comment-start)) p)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
256 (list (match-beginning 0) q))))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
257
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
258 (defun hs-grok-mode-type ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
259 "setup variables for new buffers where applicable."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
260 (when (and (boundp 'comment-start)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
261 (boundp 'comment-end))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
262 (setq hs-c-start-regexp (regexp-quote comment-start))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
263 (if (string-match " +$" hs-c-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
264 (setq hs-c-start-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
265 (substring hs-c-start-regexp 0 (1- (match-end 0)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
266 (setq hs-c-end-regexp (if (string= "" comment-end) "\n"
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
267 (regexp-quote comment-end)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
268 (if (string-match "^ +" hs-c-end-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
269 (setq hs-c-end-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
270 (substring hs-c-end-regexp (match-end 0))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
271 (let ((lookup (assoc major-mode hs-special-modes-alist)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
272 (setq hs-block-start-regexp (or (cadr lookup) "\\s\(")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
273 hs-block-end-regexp (or (caddr lookup) "\\s\)")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
274 hs-forward-sexp-func (or (cadddr lookup) 'forward-sexp)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
275
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
276 (defun hs-find-block-beginning ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
277 "repositions point at block-start. return point, or nil if top-level."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
278 (let (done
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
279 (here (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
280 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
281 hs-block-end-regexp "\\)")))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
282 (while (and (not done)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
283 (re-search-backward both-regexps (point-min) t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
284 (if (match-beginning 1) ; start of start-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
285 (setq done (match-beginning 1))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
286 (goto-char (match-end 2)) ; end of end-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
287 (funcall hs-forward-sexp-func -1)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
288 (goto-char (or done here))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
289 done))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
290
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
291 (defmacro hs-life-goes-on (&rest body)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
292 "executes optional BODY iff variable hs-minor-mode is non-nil."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
293 (list 'if 'hs-minor-mode (cons 'progn body)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
294
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
295
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
296 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
297 ;;; commands
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
298
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
299 ;;;###autoload
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
300 (defun hs-hide-all ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
301 "hides all top-level blocks, displaying only first and last lines.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
302 when done, point is repositioned at the beginning of the line, and
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
303 hs-hide-hooks is called. see documentation for `run-hooks'."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
304 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
305 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
306 (message "hiding all blocks ...")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
307 (save-excursion
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
308 (hs-flag-region (point-min) (point-max) ?\n) ; eliminate weirdness
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
309 (goto-char (point-min))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
310 (let ((count 0)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
311 (top-level-re (concat "^" hs-block-start-regexp)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
312 (while (progn
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
313 (forward-comment (buffer-size))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
314 (re-search-forward top-level-re (point-max) t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
315 (goto-char (match-beginning 0))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
316 (hs-hide-block-at-point t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 (message "hiding ... %d" (incf count))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
318 (hs-safety-is-job-n))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
319 (beginning-of-line)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
320 (message "hiding all blocks ... done")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
321 (run-hooks 'hs-hide-hooks)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
322
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
323 (defun hs-show-all ()
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
324 "shows all top-level blocks.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
325 when done, point is unchanged, and hs-show-hooks is called. see
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
326 documentation for `run-hooks'."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
327 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
328 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
329 (message "showing all blocks ...")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
330 (hs-flag-region (point-min) (point-max) ?\n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
331 (message "showing all blocks ... done")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
332 (run-hooks 'hs-show-hooks)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
333
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
334 ;;;###autoload
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
335 (defun hs-hide-block (&optional end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
336 "selects a block and hides it. with prefix arg, reposition at end.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
337 block is defined as a sexp for lispish modes, mode-specific otherwise.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
338 comments are blocks, too. upon completion, point is at repositioned and
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
339 hs-hide-hooks is called. see documentation for `run-hooks'."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
340 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
341 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
342 (let ((c-reg (hs-inside-comment-p)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
343 (if c-reg
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
344 (cond ((string= comment-end "")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
345 (message "can't hide a single-line comment"))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
346 ((< (count-lines (car c-reg) (cadr c-reg)) 2)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
347 (message "not enougn comment lines to hide"))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
348 (t
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
349 (goto-char (cadr c-reg))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
350 (forward-line -1)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
351 (hs-flag-region (car c-reg) (point) ?\C-m)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
352 (goto-char (if end (cadr c-reg) (car c-reg)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
353 (hs-safety-is-job-n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
354 (run-hooks 'hs-hide-hooks)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
355 (when (or (looking-at hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
356 (hs-find-block-beginning))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
357 (hs-hide-block-at-point end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358 (hs-safety-is-job-n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
359 (run-hooks 'hs-hide-hooks))))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
360
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
361 (defun hs-show-block (&optional end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
362 "selects a block and shows it. with prefix arg, reposition at end.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
363 upon completion, point is repositioned hs-show-hooks are called. see
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
364 documetation for `hs-hide-block' and `run-hooks'."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
365 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
366 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
367 (let ((c-reg (hs-inside-comment-p)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
368 (if c-reg
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
369 (cond ((string= comment-end "")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
370 (message "already looking at the entire comment"))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
371 (t
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
372 (hs-flag-region (car c-reg) (cadr c-reg) ?\n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
373 (goto-char (if end (cadr c-reg) (car c-reg)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
374 (when (or (looking-at hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
375 (hs-find-block-beginning))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
376 (hs-show-block-at-point end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
377 (hs-safety-is-job-n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
378 (run-hooks 'hs-show-hooks))))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
379
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
380 (defun hs-show-region (beg end)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
381 "shows all lines from BEG to END, without doing any block analysis.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
382 note: hs-show-region is intended for use when when hs-show-block signals
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
383 `unbalanced parentheses' and so is an emergency measure only. you may
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
384 become very confused if you use this command indiscriminately."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
385 (interactive "r")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
386 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
387 (hs-flag-region beg end ?\n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
388 (hs-safety-is-job-n)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
389 (run-hooks 'hs-show-hooks)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
390
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
391 ;;;###autoload
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
392 (defun hs-minor-mode (&optional arg)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
393 "toggle hideshow minor mode.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
394 with ARG, turn hideshow minor mode on if ARG is positive, off otherwise.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
395 when hideshow minor mode is on, the menu bar is augmented with hideshow
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
396 commands and the hideshow commands are enabled. the variables\n
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
397 \tselective-display\n\tselective-display-ellipses\n
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
398 are set to t. lastly, the hooks set in hs-minor-mode-hook are called.
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
399 see documentation for `run-hooks'.\n
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
400 turning hideshow minor mode off reverts the menu bar and the
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
401 variables to default values and disables the hideshow commands."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
402 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403 (setq hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
404 (if (null arg)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
405 (not hs-minor-mode)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
406 (> (prefix-numeric-value arg) 0)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
407 (if hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
408 (progn
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
409 ; (when (emacs-type-eq 'lucid)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
410 ; (set-buffer-menubar (copy-sequence current-menubar))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
411 ; (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
412 (setq selective-display t
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
413 selective-display-ellipses t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
414 (hs-grok-mode-type)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
415 (run-hooks 'hs-minor-mode-hook))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
416 ; (when (emacs-type-eq 'lucid)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
417 ; (set-buffer-menubar (delete hs-menu-bar current-menubar)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
418 (kill-local-variable 'selective-display)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
419 (kill-local-variable 'selective-display-ellipses)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
420
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
421
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
422 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
423 ;;; load-time setup routines
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
424
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
425 ;; keymaps and menus
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
426 (unless hs-minor-mode-map
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
427 (setq hs-minor-mode-map (make-sparse-keymap))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
428 (cond
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
429 ; ((emacs-type-eq 'lucid)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
430 ; (setq hs-menu-bar ; build top down for lucid
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
431 ; '("hideshow"
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
432 ; ["hide block" hs-hide-block t]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
433 ; ["show block" hs-show-block t]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
434 ; ["hide all" hs-hide-all t]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
435 ; ["show all" hs-show-all t]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
436 ; ["show region" hs-show-region t])))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
437 (t ; build bottom up for others
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
438 (define-key hs-minor-mode-map [menu-bar hideshow]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
439 (cons "hideshow" (make-sparse-keymap "hideshow")))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
440 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-region]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
441 '("show region" . hs-show-region))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
442 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-all]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
443 '("show all" . hs-show-all))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
444 (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-all]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
445 '("hide all" . hs-hide-all))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
446 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-block]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
447 '("show block" . hs-show-block))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
448 (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-block]
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
449 '("hide block" . hs-hide-block)))))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
450
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
451 ;; some housekeeping
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
452 (pushnew (cons 'hs-minor-mode hs-minor-mode-map)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
453 minor-mode-map-alist
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
454 :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
455 (pushnew '(hs-minor-mode " hs") minor-mode-alist :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
456
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
457 ;; make some variables buffer-local
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
458 (make-variable-buffer-local 'hs-minor-mode)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
459 (make-variable-buffer-local 'hs-c-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
460 (make-variable-buffer-local 'hs-c-end-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
461 (make-variable-buffer-local 'hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
462 (make-variable-buffer-local 'hs-block-end-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
463 (make-variable-buffer-local 'hs-forward-sexp-func)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
464 (put 'hs-minor-mode 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
465 (put 'hs-c-start-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
466 (put 'hs-c-end-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
467 (put 'hs-block-start-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
468 (put 'hs-block-end-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
469 (put 'hs-forward-sexp-func 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
470
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
471
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
472 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
473 ;;; that's it
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
474
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
475 (provide 'hideshow)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
476
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477 ;;; hideshow.el ends here