annotate lisp/modes/hideshow.el @ 74:54cc21c15cbb r20-0b32

Import from CVS: tag r20-0b32
author cvs
date Mon, 13 Aug 2007 09:04:33 +0200
parents ac2d302a0011
children 43dd3413c7c7
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
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
162 (defvar hs-emacs-type 'lucid
0
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
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
165 ;; This doesn't work
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
166 ;(eval-when-compile
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
167 ; (if (string-match "XEmacs\\|Lucid" emacs-version)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
168 ; (progn
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
169 ; (defvar current-menubar nil "")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
170 ; (defun set-buffer-menubar (arg1))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
171 ; (defmacro add-menu (arg1 arg2 arg3)))))
0
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 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;; support funcs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; snarfed from outline.el, but added buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun hs-flag-region (from to flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Hides or shows lines from FROM to TO, according to FLAG.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
180 If FLAG is `?\\n' (the newline character) then show the text;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
181 if FLAG is `?\\^M' \(control-M) then hide the text."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (let ((modp (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 buffer-read-only) ; nothing is immune
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (unwind-protect (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (subst-char-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 from to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (if (= flag ?\n) ?\C-m ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 flag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (set-buffer-modified-p modp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defun hs-hide-block-at-point (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Hide block iff on block beginning, optional END means reposition at end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (let* ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (q (progn (funcall hs-forward-sexp-func 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (forward-line -1) (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if (and (< p (point)) (> (count-lines p q) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (hs-flag-region p (point) ?\C-m))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (goto-char (if end q p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defun hs-show-block-at-point (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "Show block iff on block beginning. Optional END means reposition at end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (let* ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (q
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (condition-case error ; probably unbalanced paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (funcall hs-forward-sexp-func 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ((eq hs-unbalance-handler-method 'ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; just ignore this block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ((eq hs-unbalance-handler-method 'top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; try to get out of rat's nest and expose the whole func
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (if (/= (current-column) 0) (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (re-search-forward (concat "^" hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (point-max) t 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ((eq hs-unbalance-handler-method 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; assumption is that user knows what s/he's doing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (beginning-of-line) (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (end-of-line 2) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; pass error through -- this applies to `signal', too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (signal (car error) (cdr error))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (hs-flag-region p q ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (goto-char (if end (1+ (point)) p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defun hs-safety-is-job-n ()
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
233 "Warn if `selective-display' or `selective-display-ellipses' is nil."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (let ((str ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (or selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq str "selective-display nil "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (or selective-display-ellipses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq str (concat str "selective-display-ellipses nil")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (if (= (length str) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (message "warning: %s" str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (sit-for 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun hs-inside-comment-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Returns non-nil if point is inside a comment, otherwise nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Actually, for multi-line-able comments, returns a list containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 the buffer position of the start and the end of the comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; is it single-line-only or multi-line-able?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (let ((p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 q)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (if (string= comment-end "") ; single line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (let (found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq found (re-search-forward hs-c-start-regexp p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (and found (not (search-forward "\"" p t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (re-search-forward hs-c-end-regexp (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (setq q (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (forward-comment -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (re-search-forward hs-c-start-regexp (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if (< (- (point) (length comment-start)) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (list (match-beginning 0) q))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defun hs-grok-mode-type ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "Setup variables for new buffers where applicable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (and (boundp 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (boundp 'comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq hs-c-start-regexp (regexp-quote comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (if (string-match " +$" hs-c-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq hs-c-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (substring hs-c-start-regexp 0 (1- (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq hs-c-end-regexp (if (string= "" comment-end) "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (regexp-quote comment-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if (string-match "^ +" hs-c-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq hs-c-end-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (substring hs-c-end-regexp (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (let ((lookup (assoc major-mode hs-special-modes-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq hs-block-start-regexp (or (nth 1 lookup) "\\s\(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 hs-block-end-regexp (or (nth 2 lookup) "\\s\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 hs-forward-sexp-func (or (nth 3 lookup) 'forward-sexp))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (defun hs-find-block-beginning ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 "Repositions point at block-start. Return point, or nil if top-level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (let (done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 hs-block-end-regexp "\\)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (while (and (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (re-search-backward both-regexps (point-min) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (if (match-beginning 1) ; start of start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq done (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (goto-char (match-end 2)) ; end of end-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (funcall hs-forward-sexp-func -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (goto-char (or done here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defmacro hs-life-goes-on (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "Executes optional BODY iff variable `hs-minor-mode' is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (list 'if 'hs-minor-mode (cons 'progn body)))
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 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;; commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defun hs-hide-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "Hides all top-level blocks, displaying only first and last lines.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
309 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
310 `hs-hide-hook'. See documentation for `run-hooks'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (message "hiding all blocks ...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (hs-flag-region (point-min) (point-max) ?\n) ; eliminate weirdness
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (top-level-re (concat "^" hs-block-start-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (while (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (forward-comment (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (re-search-forward top-level-re (point-max) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (hs-hide-block-at-point t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (message "hiding ... %d" (setq count (1+ count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (hs-safety-is-job-n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (message "hiding all blocks ... done")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
328 (run-hooks 'hs-hide-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defun hs-show-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "Shows all top-level blocks.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
332 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
333 See documentation for `run-hooks'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (message "showing all blocks ...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (hs-flag-region (point-min) (point-max) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (message "showing all blocks ... done")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
339 (run-hooks 'hs-show-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (defun hs-hide-block (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 "Selects a block and hides it. With prefix arg, reposition at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 Block is defined as a sexp for lispish modes, mode-specific otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 Comments are blocks, too. Upon completion, point is at repositioned and
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
346 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
347 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (let ((c-reg (hs-inside-comment-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (if c-reg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (cond ((string= comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (message "can't hide a single-line comment"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ((< (count-lines (car c-reg) (nth 1 c-reg)) 2)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
354 (message "not enough comment lines to hide"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (goto-char (nth 1 c-reg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (hs-flag-region (car c-reg) (point) ?\C-m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (goto-char (if end (nth 1 c-reg) (car c-reg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
361 (run-hooks 'hs-hide-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (if (or (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (hs-find-block-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (hs-hide-block-at-point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
367 (run-hooks 'hs-hide-hook)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (defun hs-show-block (&optional end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 "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
371 Upon completion, point is repositioned and the normal hook
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
372 `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
373 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (let ((c-reg (hs-inside-comment-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (if c-reg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (cond ((string= comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (message "already looking at the entire comment"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (hs-flag-region (car c-reg) (nth 1 c-reg) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (goto-char (if end (nth 1 c-reg) (car c-reg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (if (or (looking-at hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (hs-find-block-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (hs-show-block-at-point end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
387 (run-hooks 'hs-show-hook)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defun hs-show-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 "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
391 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
392 `unbalanced parentheses' and so is an emergency measure only. You may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 become very confused if you use this command indiscriminately."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (hs-life-goes-on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (hs-flag-region beg end ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (hs-safety-is-job-n)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
398 (run-hooks 'hs-show-hook)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (defun hs-minor-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 "Toggle hideshow minor mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 With ARG, turn hideshow minor mode on if ARG is positive, off otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 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
405 commands and the hideshow commands are enabled. The variables
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
406 `selective-display' and `selective-display-ellipses' are set to t.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
407 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
408
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 Turning hideshow minor mode off reverts the menu bar and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 variables to default values and disables the hideshow commands."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (setq hs-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (not hs-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (if hs-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (if (eq hs-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (set-buffer-menubar (copy-sequence current-menubar))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 2
diff changeset
421 (add-submenu (car hs-menu-bar) hs-menu-bar)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (setq selective-display t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 selective-display-ellipses t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (hs-grok-mode-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (run-hooks 'hs-minor-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (if (eq hs-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (set-buffer-menubar (delete hs-menu-bar current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (kill-local-variable 'selective-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (kill-local-variable 'selective-display-ellipses)))
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 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;;; load-time setup routines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;; which emacs being used?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (setq hs-emacs-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (if (string-match "XEmacs\\|Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 'lucid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 'fsf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;; keymaps and menus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (if (not hs-minor-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (setq hs-minor-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; XEmacs: need this for the change in add-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (fset 'hs-minor-mode-map hs-minor-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ((eq hs-emacs-type 'lucid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (setq hs-menu-bar ; build top down for lucid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 '("hideshow"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ["Hide Block" hs-hide-block t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ["Show Block" hs-show-block t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ["Hide All" hs-hide-all t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ["Show All" hs-show-all t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ["Show Region" hs-show-region t])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (t ; build bottom up for others
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (define-key hs-minor-mode-map [menu-bar hideshow]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (cons "hideshow" (make-sparse-keymap "hideshow")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-region]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 '("Show Region" . hs-show-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-all]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 '("Show All" . hs-show-all))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-all]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 '("Hide All" . hs-hide-all))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (define-key hs-minor-mode-map [menu-bar hideshow hs-show-block]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 '("Show Block" . hs-show-block))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-block]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 '("Hide Block" . hs-hide-block)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; some housekeeping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;(or (assq 'hs-minor-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ; (setq minor-mode-map-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ; (cons (cons 'hs-minor-mode hs-minor-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ; minor-mode-map-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;(or (assq 'hs-minor-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ; (setq minor-mode-alist (append minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ; (list '(hs-minor-mode " hs")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; XEmacs: do it right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (add-minor-mode 'hs-minor-mode " hs" 'hs-minor-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; make some variables buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (make-variable-buffer-local 'hs-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (make-variable-buffer-local 'hs-c-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (make-variable-buffer-local 'hs-c-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (make-variable-buffer-local 'hs-block-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (make-variable-buffer-local 'hs-block-end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (make-variable-buffer-local 'hs-forward-sexp-func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (put 'hs-minor-mode 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (put 'hs-c-start-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (put 'hs-c-end-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (put 'hs-block-start-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (put 'hs-block-end-regexp 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (put 'hs-forward-sexp-func 'permanent-local t)
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 ;;;----------------------------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;;; that's it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (provide 'hideshow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 ;;; hideshow.el ends here