annotate lisp/modes/hideshow.el @ 2:ac2d302a0011 r19-15b2

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