annotate lisp/modes/hideshow.el @ 194:2947057885e5

Added tag r20-3b23 for changeset f53b5ca2e663
author cvs
date Mon, 13 Aug 2007 09:58:32 +0200
parents 489f57a838ef
children
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.
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
47 ;;
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
48 ;; 30 May 1997 Pete Ware (ware@cis.ohio-state.edu)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
49 ;; * Modified to use easymenu interface.
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
50 ;; * Removed tests for XEmacs vs GNU Emacs
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
51 ;; * Got it to work under XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 ;; Suggested usage:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 ;; (load-library "hideshow")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 ;; (defun my-hs-setup () "enables hideshow and binds some commands"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ;; (hs-minor-mode 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 ;; (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 ;; (define-key hs-minor-mode-map "\C-cs" 'hs-show-block)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 ;; (define-key hs-minro-mode-map "\C-cH" 'hs-hide-all)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 ;; (define-key hs-minro-mode-map "\C-cS" 'hs-show-all)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 ;; (define-key hs-minor-mode-map "\C-cR" 'hs-show-region))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 ;; (add-hook 'X-mode-hook 'my-hs-setup t) ; other modes similarly
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 ;; 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
66 ;; `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
67
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 ;; Etc:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
70 ;; Bug reports and fixes welcome (comments, too). Thanks go to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
71 ;; Dean Andrews <adahome@ix.netcom.com>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
72 ;; Preston F. Crow <preston.f.crow@dartmouth.edu>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
73 ;; Gael Marziou <gael@gnlab030.grenoble.hp.com>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
74 ;; Keith Sheffield <sheff@edcsgw2.cr.usgs.gov>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75 ;; Jan Djarv <jan.djarv@sa.erisoft.se>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 ;; Lars Lindberg <qhslali@aom.ericsson.se>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 ;; Alf-Ivar Holm <alfh@ifi.uio.no>
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 ;; for valuable feedback, code and bug reports.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
82 (require 'easymenu)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; user-configurable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
87 (defgroup hideshow nil
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
88 "Selectively display blocks of code."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
89 :prefix "hs-"
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
90 :group 'outlines
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
91 :group 'tools)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
92
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
93
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
94 ;;;###autoload
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
95 (defcustom hs-minor-mode nil
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
96 "Non-nil if using hideshow mode as a minor mode of some other mode.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
97 Use the command `hs-minor-mode' to toggle this variable."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
98 :type 'boolean
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
99 :set (lambda (symbol value)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
100 (hs-minor-mode (or value 0)))
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
101 :initialize 'custom-initialize-default
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
102 :require 'hideshow
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
103 :group 'hideshow)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
104
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
105 (defcustom hs-unbalance-handler-method 'top-level
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 "*Symbol representing how \"unbalanced parentheses\" should be handled.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
107 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
108 `top-level', `next-line', `signal' or `ignore'. Default is `top-level'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 - `top-level' -- Show top-level block containing the currently troublesome
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
111 block.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 - `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
113 will be on the next line. Attempt to show this block.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 - `signal' -- Pass the error through, stopping execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 - `ignore' -- Ignore the error, continuing execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
117 Values other than these four will be interpreted as `signal'."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
118 :type '(radio (const :tag "Show top-level block" top-level)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
119 (const :tag "Show block to next line" next-line)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
120 (sexp :format "%t\n" :tag "Signal the error" signal)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
121 (const :tag "Ignore the error" ignore))
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
122 :group 'hideshow)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
124 (defcustom hs-special-modes-alist '((c-mode "{" "}")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (c++-mode "{" "}"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "*Alist of the form (MODE START-RE END-RE FORWARD-SEXP-FUNC).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If present, hideshow will use these values for the start and end regexps,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 respectively. Since Algol-ish languages do not have single-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 block delimiters, the function `forward-sexp' which is used by hideshow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 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
131 register it and have hideshow use it instead of `forward-sexp'. To add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 more values, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 \t(pushnew '(new-mode st-re end-re function-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 \t hs-special-modes-alist :test 'equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 For example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 \t(pushnew '(simula-mode \"begin\" \"end\" simula-next-statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 \t hs-special-modes-alist :test 'equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
142 Note that the regexps should not contain leading or trailing whitespace."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
143 :type 'sexp ; too hard to do right
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
144 :group 'hideshow)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
146 (defcustom hs-hide-hook nil
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
147 "*Hooks called at the end of `hs-hide-all' and `hs-hide-block'."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
148 :type 'hook
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
149 :group 'hideshow)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
151 (defcustom hs-show-hook nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
152 "*Hooks called at the end of commands to show text.
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
153 These commands include `hs-show-all', `hs-show-block' and `hs-show-region'."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
154 :type 'hook
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
155 :group 'hideshow)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
157 (defcustom hs-minor-mode-prefix "\C-c"
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
158 "*Prefix key to use for hideshow commands in hideshow minor mode."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
159 :type 'hook
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 155
diff changeset
160 :group 'hideshow)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;; internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
167 (defvar hs-minor-mode-map (make-sparse-keymap)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Mode map for hideshow minor mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
170 (easy-menu-define
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
171 hs-minor-mode-menu hs-minor-mode-map "Menu for hideshow minor mode"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
172 '("Hideshow"
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
173 ["Hide Block" hs-hide-block t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
174 ["Show Block" hs-show-block t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
175 ["Hide All" hs-hide-all t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
176 ["Show All" hs-show-all t]
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
177 ["Show Region" hs-show-region t]))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (defvar hs-c-start-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 "Regexp for beginning of comments. Buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 Differs from mode-specific comment regexps in that surrounding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 whitespace is stripped.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defvar hs-c-end-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "Regexp for end of comments. Buffer-local.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 See `hs-c-start-regexp'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defvar hs-block-start-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "Regexp for beginning of block. Buffer-local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defvar hs-block-end-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Regexp for end of block. Buffer-local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defvar hs-forward-sexp-func 'forward-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "Function used to do a forward-sexp. Should change for Algol-ish modes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 For single-character block delimiters -- ie, the syntax table regexp for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 character is either `(' or `)' -- `hs-forward-sexp-func' would just be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 `forward-sexp'. For other modes such as simula, a more specialized function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 is necessary.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;;; support funcs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; snarfed from outline.el, but added buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun hs-flag-region (from to flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "Hides or shows lines from FROM to TO, according to FLAG.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
207 If FLAG is `?\\n' (the newline character) then show the text;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
208 if FLAG is `?\\^M' \(control-M) then hide the text."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (let ((modp (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 buffer-read-only) ; nothing is immune
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (unwind-protect (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (subst-char-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 from to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if (= flag ?\n) ?\C-m ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 flag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (set-buffer-modified-p modp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun hs-hide-block-at-point (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Hide block iff on block beginning, optional END means reposition at end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let* ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (q (progn (funcall hs-forward-sexp-func 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (forward-line -1) (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (if (and (< p (point)) (> (count-lines p q) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (hs-flag-region p (point) ?\C-m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (goto-char (if end q p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (defun hs-show-block-at-point (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 "Show block iff on block beginning. Optional END means reposition at end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (let* ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (q
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (condition-case error ; probably unbalanced paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (funcall hs-forward-sexp-func 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ((eq hs-unbalance-handler-method 'ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;; just ignore this block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ((eq hs-unbalance-handler-method 'top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; try to get out of rat's nest and expose the whole func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (/= (current-column) 0) (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (re-search-forward (concat "^" hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (point-max) t 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ((eq hs-unbalance-handler-method 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;; assumption is that user knows what s/he's doing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (beginning-of-line) (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (end-of-line 2) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; pass error through -- this applies to `signal', too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (signal (car error) (cdr error))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (hs-flag-region p q ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (goto-char (if end (1+ (point)) p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defun hs-safety-is-job-n ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
260 "Warn if `selective-display' or `selective-display-ellipses' is nil."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (let ((str ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (or selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (setq str "selective-display nil "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (or selective-display-ellipses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (setq str (concat str "selective-display-ellipses nil")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (= (length str) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (message "warning: %s" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (sit-for 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (defun hs-inside-comment-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 "Returns non-nil if point is inside a comment, otherwise nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 Actually, for multi-line-able comments, returns a list containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 the buffer position of the start and the end of the comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;; is it single-line-only or multi-line-able?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (let ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (string= comment-end "") ; single line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (let (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (setq found (re-search-forward hs-c-start-regexp p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (and found (not (search-forward "\"" p t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (re-search-forward hs-c-end-regexp (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (setq q (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (forward-comment -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (re-search-forward hs-c-start-regexp (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (< (- (point) (length comment-start)) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (list (match-beginning 0) q))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (defun hs-grok-mode-type ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 "Setup variables for new buffers where applicable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (and (boundp 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (boundp 'comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (setq hs-c-start-regexp (regexp-quote comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (if (string-match " +$" hs-c-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq hs-c-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (substring hs-c-start-regexp 0 (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq hs-c-end-regexp (if (string= "" comment-end) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (regexp-quote comment-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (if (string-match "^ +" hs-c-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq hs-c-end-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (substring hs-c-end-regexp (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (let ((lookup (assoc major-mode hs-special-modes-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (setq hs-block-start-regexp (or (nth 1 lookup) "\\s\(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 hs-block-end-regexp (or (nth 2 lookup) "\\s\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 hs-forward-sexp-func (or (nth 3 lookup) 'forward-sexp))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defun hs-find-block-beginning ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 "Repositions point at block-start. Return point, or nil if top-level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let (done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 hs-block-end-regexp "\\)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (while (and (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (re-search-backward both-regexps (point-min) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (if (match-beginning 1) ; start of start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq done (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (goto-char (match-end 2)) ; end of end-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (funcall hs-forward-sexp-func -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (goto-char (or done here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defmacro hs-life-goes-on (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "Executes optional BODY iff variable `hs-minor-mode' is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (list 'if 'hs-minor-mode (cons 'progn body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;;; commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defun hs-hide-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 "Hides all top-level blocks, displaying only first and last lines.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
336 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
337 `hs-hide-hook'. See documentation for `run-hooks'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (message "hiding all blocks ...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (hs-flag-region (point-min) (point-max) ?\n) ; eliminate weirdness
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (top-level-re (concat "^" hs-block-start-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (forward-comment (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (re-search-forward top-level-re (point-max) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (hs-hide-block-at-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (message "hiding ... %d" (setq count (1+ count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (hs-safety-is-job-n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (message "hiding all blocks ... done")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
355 (run-hooks 'hs-hide-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (defun hs-show-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 "Shows all top-level blocks.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
359 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
360 See documentation for `run-hooks'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (message "showing all blocks ...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (hs-flag-region (point-min) (point-max) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (message "showing all blocks ... done")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
366 (run-hooks 'hs-show-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 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defun hs-hide-block (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 "Selects a block and hides it. With prefix arg, reposition at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 Block is defined as a sexp for lispish modes, mode-specific otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 Comments are blocks, too. Upon completion, point is at repositioned and
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
373 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
374 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (let ((c-reg (hs-inside-comment-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (if c-reg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (cond ((string= comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (message "can't hide a single-line comment"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ((< (count-lines (car c-reg) (nth 1 c-reg)) 2)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
381 (message "not enough comment lines to hide"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (goto-char (nth 1 c-reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (hs-flag-region (car c-reg) (point) ?\C-m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (goto-char (if end (nth 1 c-reg) (car c-reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
388 (run-hooks 'hs-hide-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (if (or (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (hs-find-block-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (hs-hide-block-at-point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
394 (run-hooks 'hs-hide-hook)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (defun hs-show-block (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 "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
398 Upon completion, point is repositioned and the normal hook
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
399 `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
400 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (let ((c-reg (hs-inside-comment-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if c-reg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (cond ((string= comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (message "already looking at the entire comment"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (hs-flag-region (car c-reg) (nth 1 c-reg) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (goto-char (if end (nth 1 c-reg) (car c-reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (if (or (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (hs-find-block-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (hs-show-block-at-point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
414 (run-hooks 'hs-show-hook)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun hs-show-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "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
418 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
419 `unbalanced parentheses' and so is an emergency measure only. You may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 become very confused if you use this command indiscriminately."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (hs-flag-region beg end ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
425 (run-hooks 'hs-show-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (defun hs-minor-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 "Toggle hideshow minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 With ARG, turn hideshow minor mode on if ARG is positive, off otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 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
432 commands and the hideshow commands are enabled. The variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
433 `selective-display' and `selective-display-ellipses' are set to t.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
434 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
435
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 Turning hideshow minor mode off reverts the menu bar and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 variables to default values and disables the hideshow commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq hs-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (not hs-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (if hs-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (progn
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
445 (easy-menu-add hs-minor-mode-menu hs-minor-mode-map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq selective-display t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 selective-display-ellipses t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (hs-grok-mode-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (run-hooks 'hs-minor-mode-hook))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
450 (easy-menu-remove hs-minor-mode-menu)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (kill-local-variable 'selective-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (kill-local-variable 'selective-display-ellipses)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;;; load-time setup routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
458 (if (fboundp 'add-minor-mode)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
459 (progn
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
460 ;; XEmacs: need this for the change in add-minor-mode
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
461 ;; ### Why? -- pete@cis.ohio-state.edu
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
462 (fset 'hs-minor-mode-map hs-minor-mode-map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
463 (add-minor-mode 'hs-minor-mode " hs" 'hs-minor-mode-map))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
464 ;;else
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
465 (or (assq 'hs-minor-mode minor-mode-map-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
466 (setq minor-mode-map-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
467 (cons (cons 'hs-minor-mode hs-minor-mode-map)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
468 minor-mode-map-alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
469 (or (assq 'hs-minor-mode minor-mode-alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
470 (setq minor-mode-alist (append minor-mode-alist
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 74
diff changeset
471 (list '(hs-minor-mode " hs"))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; make some variables buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (make-variable-buffer-local 'hs-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (make-variable-buffer-local 'hs-c-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (make-variable-buffer-local 'hs-c-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (make-variable-buffer-local 'hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (make-variable-buffer-local 'hs-block-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (make-variable-buffer-local 'hs-forward-sexp-func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (put 'hs-minor-mode 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (put 'hs-c-start-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (put 'hs-c-end-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (put 'hs-block-start-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (put 'hs-block-end-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (put 'hs-forward-sexp-func 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;;; that's it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (provide 'hideshow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;;; hideshow.el ends here