annotate lisp/progmodes/hideshow.el @ 11969:fe63b4e6021a

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