annotate lisp/progmodes/hideshow.el @ 17973:52395fdffffe

(webjump-adult-p): Function deleted.
author Richard M. Stallman <rms@gnu.org>
date Tue, 27 May 1997 16:20:16 +0000
parents 8899e9305c25
children 22cbed2e6098
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
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
3 ;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
4
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
5 ;; Author: Thien-Thi Nguyen <ttn@netcom.com>
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
6 ;; Maintainer: Dan Nicolaescu <done@ece.arizona.edu>
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
7 ;; Version: 4.0
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
8 ;; Keywords: C C++ java lisp tools editing comments blocks hiding
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
9 ;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
10
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
11 ;; This file is part of GNU Emacs.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
12
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
16 ;; any later version.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
17
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
21 ;; GNU General Public License for more details.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
22
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
23 ;; You should have received a copy of the GNU General Public License
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
26 ;; Boston, MA 02111-1307, USA.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
27
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
28 ;; LCD Archive Entry:
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
29 ;; hideshow|Thien-Thi Nguyen|ttn@netcom.com|
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
30 ;; minor mode commands to selectively display blocks of code|
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
31 ;; 18-Oct-1994|3.4|~/modes/hideshow.el.Z|
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
32
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
33 ;;; Commentary:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
34
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
35 ;; This file provides `hs-minor-mode'. When active, six commands:
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
36 ;; hs-{hide,show}-{all,block}, hs-show-region and hs-minor-mode
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
37 ;; are available. They implement block hiding and showing. Blocks are
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
38 ;; defined in mode-specific way. In c-mode or c++-mode, they are simply
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
39 ;; curly braces, while in lisp-ish modes they are parens. Multi-line
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
40 ;; comments (c-mode) can also be hidden. The command M-x hs-minor-mode
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
41 ;; toggles the minor mode or sets it (similar to outline minor mode).
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
42 ;; See documentation for each command for more info.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
43 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
44 ;; The variable `hs-unbalance-handler-method' controls hideshow's behavior
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
45 ;; in the case of "unbalanced parentheses". See doc for more info.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
46
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
47 ;; Suggested usage:
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
48
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
49 ;; (load-library "hideshow")
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
50 ;; (add-hook 'X-mode-hook 'hs-minor-mode) ; other modes similarly
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
51 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
52 ;; where X = {emacs-lisp,c,c++,perl,...}. See the doc for the variable
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
53 ;; `hs-special-modes-alist' if you'd like to use hideshow w/ other modes.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
54
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
55 ;; Etc:
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
56
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
57 ;; Bug reports and fixes welcome (comments, too). Thanks go to
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
58 ;; Dean Andrews <adahome@ix.netcom.com>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
59 ;; Preston F. Crow <preston.f.crow@dartmouth.edu>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
60 ;; Gael Marziou <gael@gnlab030.grenoble.hp.com>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
61 ;; Keith Sheffield <sheff@edcsgw2.cr.usgs.gov>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
62 ;; Jan Djarv <jan.djarv@sa.erisoft.se>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
63 ;; Lars Lindberg <qhslali@aom.ericsson.se>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
64 ;; Alf-Ivar Holm <alfh@ifi.uio.no>
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
65 ;; for valuable feedback, code and bug reports.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
66
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
67 ;;; Code:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
68
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
69
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
70 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
71 ;;; user-configurable variables
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
72
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
73 (defvar hs-unbalance-handler-method 'top-level
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
74 "*Symbol representing how \"unbalanced parentheses\" should be handled.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
75 This error is usually signaled by `hs-show-block'. One of four values:
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
76 `top-level', `next-line', `signal' or `ignore'. Default is `top-level'.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
77
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
78 - `top-level' -- Show top-level block containing the currently troublesome
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
79 block.
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
80 - `next-line' -- Use the fact that, for an already hidden block, its end
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
81 will be on the next line. Attempt to show this block.
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
82 - `signal' -- Pass the error through, stopping execution.
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
83 - `ignore' -- Ignore the error, continuing execution.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
84
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
85 Values other than these four will be interpreted as `signal'.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
86
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
87 ;;;#autoload
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
88 (defvar hs-special-modes-alist
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
89 '((c-mode "{" "}")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
90 (c++-mode "{" "}")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
91 (java-mode "\\(\\(public\\|private\\|protected\\|static\\|\\s-\\)+\\([a-zA-Z0-9_:]+[ \t]+\\)\\([a-zA-Z0-9_:]+\\)[ \t]*([^)]*)[ \t\n]*\\([ \t\n]throws[ \t]+[^{]+\\)*[ \t]*\\){" "}" java-hs-forward-sexp))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
92 "*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
93 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
94 respectively. Since Algol-ish languages do not have single-character
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
95 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
96 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
97 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
98 more values, use
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
99
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
100 \t(pushnew '(new-mode st-re end-re function-name)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
101 \t hs-special-modes-alist :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
102
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
103 For example:
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
104
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
105 \t(pushnew '(simula-mode \"begin\" \"end\" simula-next-statement)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
106 \t hs-special-modes-alist :test 'equal)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
107
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
108 Note that the regexps should not contain leading or trailing whitespace.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
109
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
110 (defvar hs-minor-mode-hook 'hs-hide-initial-comment-block
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
111 "Hook called when `hs-minor-mode' is installed.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
112 A good value for this would be `hs-hide-initial-comment-block' to
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
113 hide all the comments at the beginning of the file.")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
114
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
115 (defvar hs-hide-hook nil
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
116 "*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
117
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
118 (defvar hs-show-hook nil
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
119 "*Hooks called at the end of commands to show text.
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
120 These commands include `hs-show-all', `hs-show-block' and `hs-show-region'.")
10276
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 (defvar hs-minor-mode-prefix "\C-c"
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
123 "*Prefix key to use for hideshow commands in hideshow minor mode.")
10276
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
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
126 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
127 ;;; internal variables
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 nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
130 "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
131 Use the command `hs-minor-mode' to toggle this variable.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
132
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
133 (defvar hs-minor-mode-map nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
134 "Mode map for hideshow minor mode.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
135
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
136 (defvar hs-menu-bar nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
137 "Menu bar for hideshow minor mode (Xemacs only).")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
138
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
139 (defvar hs-c-start-regexp nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
140 "Regexp for beginning of comments.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
141 Differs from mode-specific comment regexps in that
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
142 surrounding whitespace is stripped.")
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-c-end-regexp nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
145 "Regexp for end of comments.
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
146 See `hs-c-start-regexp'.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
147
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
148 (defvar hs-block-start-regexp nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
149 "Regexp for beginning of block.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
150
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
151 (defvar hs-block-end-regexp nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
152 "Regexp for end of block.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
154 (defvar hs-forward-sexp-func 'forward-sexp
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
155 "Function used to do a forward-sexp.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
156 Should change for Algol-ish modes. For single-character block
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
157 delimiters -- ie, the syntax table regexp for the character is
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
158 either `(' or `)' -- `hs-forward-sexp-func' would just be `forward-sexp'.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
159 For other modes such as simula, a more specialized function
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
160 is necessary.")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
161
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
162 (defvar hs-hide-comments-when-hiding-all t
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
163 "Hide the comments too when you do an `hs-hide-all'." )
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
164
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
165 ;(defvar hs-emacs-type 'fsf
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
166 ; "Used to support both Emacs and Xemacs.")
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
167
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
168 ;(eval-when-compile
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
169 ; (if (string-match "xemacs\\|lucid" emacs-version)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
170 ; (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
171 ; (defvar current-menubar nil "")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
172 ; (defun set-buffer-menubar (arg1))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
173 ; (defun add-menu (arg1 arg2 arg3)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
174
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
175 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
176 ;;; support funcs
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
177
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
178 ;; snarfed from noutline.el;
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
179 (defun hs-flag-region (from to flag)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
180 "Hides or shows lines from FROM to TO, according to FLAG.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
181 If FLAG is nil then text is shown, while if FLAG is t the text is hidden."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
182 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
183 (goto-char from)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
184 (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
185 (hs-discard-overlays (point) to 'invisible 'hs)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
186 (if flag
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
187 (let ((overlay (make-overlay (point) to)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
188 ;; Make overlay hidden and intangible.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
189 (overlay-put overlay 'invisible 'hs)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
190 (overlay-put overlay 'hs t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
191 (overlay-put overlay 'intangible t)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
192
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
193 ;; Remove from the region BEG ... END all overlays
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
194 ;; with a PROP property equal to VALUE.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
195 ;; Overlays with a PROP property different from VALUE are not touched.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
196 (defun hs-discard-overlays (beg end prop value)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
197 (if (< end beg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
198 (setq beg (prog1 end (setq end beg))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
199 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
200 (goto-char beg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
201 (while (< (point) end)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
202 (let ((overlays (overlays-at (point))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
203 (while overlays
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
204 (let ((o (car overlays)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
205 (if (eq (overlay-get o prop) value)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
206 (if (or
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
207 (and (> (overlay-end o) beg) (< (overlay-end o) end))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
208 (and (< (overlay-start o) beg) (< (overlay-start o) end)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
209 (delete-overlay o))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
210 (setq overlays (cdr overlays))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
211 (goto-char (next-overlay-change (point))))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
212
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
213 (defun hs-hide-block-at-point (&optional end comment c-reg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
214 "Hide block iff on block beginning, optional END means reposition at end.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
215 COMMENT true means that it should hide a comment block, C-REG is a list
17270
8899e9305c25 (hs-hide-block-at-point): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 17259
diff changeset
216 of the form (BEGIN . END) and specifies the limits of the comment."
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
217 (if comment
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
218 (let ((reg (if c-reg c-reg (hs-inside-comment-p))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
219 (goto-char (nth 1 reg))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
220 (forward-line -1)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
221 (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
222 (hs-flag-region (car reg) (point) t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
223 (goto-char (if end (nth 1 reg) (car reg)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
224 )
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
225 (if (looking-at hs-block-start-regexp)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
226 (let* ((p (point))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
227 (q (progn (funcall hs-forward-sexp-func 1) (point))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
228 (forward-line -1) (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
229 (if (and (< p (point)) (> (count-lines p q) 1))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
230 (hs-flag-region p (point) t))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
231 (goto-char (if end q p))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
232
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
233 (defun hs-show-block-at-point (&optional end)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
234 "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
235 (if (looking-at hs-block-start-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
236 (let* ((p (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
237 (q
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
238 (condition-case error ; probably unbalanced paren
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
239 (progn
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
240 (funcall hs-forward-sexp-func 1)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
241 (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
242 (error
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
243 (cond
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
244 ((eq hs-unbalance-handler-method 'ignore)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
245 ;; just ignore this block
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
246 (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
247 ((eq hs-unbalance-handler-method 'top-level)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
248 ;; 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
249 (if (/= (current-column) 0) (beginning-of-defun))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
250 (setq p (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
251 (re-search-forward (concat "^" hs-block-start-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
252 (point-max) t 2)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
253 (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
254 ((eq hs-unbalance-handler-method 'next-line)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
255 ;; 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
256 (beginning-of-line) (setq p (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
257 (end-of-line 2) (point))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
258 (t
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
259 ;; pass error through -- this applies to `signal', too
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
260 (signal (car error) (cdr error))))))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
261 (hs-flag-region p q nil)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
262 (goto-char (if end (1+ (point)) p)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
263
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
264 (defun hs-safety-is-job-n ()
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
265 "Warn `buffer-invisibility-spec' does not contain hs."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
266 (if (or buffer-invisibility-spec (assq hs buffer-invisibility-spec) )
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
267 nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
268 (message "Warning: `buffer-invisibility-spec' does not contain hs!!")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
269 (sit-for 2)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
270
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
271 (defun hs-hide-initial-comment-block ()
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
272 (interactive)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
273 "Hides the first block of comments in a file.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
274 The best usage is in `hs-minor-mode-hook', it hides all the comments at the
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
275 file beginning, so if you have huge RCS logs you won't see them!"
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
276 (let ((p (point))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
277 c-reg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
278 (goto-char (point-min))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
279 (skip-chars-forward " \t\n")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
280 (setq c-reg (hs-inside-comment-p))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
281 (if (and c-reg (> (count-lines (car c-reg) (nth 1 c-reg)) 2))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
282 (hs-hide-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
283 (goto-char p))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
284
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
285 (defun hs-inside-single-line-comment-p ()
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
286 "Look to see if we are on a single line comment."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
287 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
288 (beginning-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
289 (looking-at (concat "^[ \t]*" hs-c-start-regexp))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
290
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
291 (defun hs-inside-comment-p ()
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
292 "Returns non-nil if point is inside a comment, otherwise nil.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
293 Actually, returns a list containing the buffer position of the start
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
294 and the end of the comment."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
295 (save-excursion
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
296 (let ((p (point))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
297 q
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
298 p-aux)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
299 (if (string= comment-end "") ; single line
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
300 (if (not (hs-inside-single-line-comment-p))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
301 nil
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
302 ;;find-beginning-of-the-chained-single-line-comments
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
303 (beginning-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
304 (forward-comment (- (buffer-size)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
305 (skip-chars-forward " \t\n")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
306 (beginning-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
307 (setq q (point))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
308 (goto-char p)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
309 ;;find-end-of-the-chained-single-line-comments
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
310 (forward-comment (buffer-size))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
311 (skip-chars-backward " \t\n")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
312 (list q (point)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
313 (re-search-forward hs-c-end-regexp (point-max) 1)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
314 (forward-comment (buffer-size))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
315 (skip-chars-backward " \t\n")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
316 (end-of-line)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 (setq q (point))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
318 (forward-comment (- 0 (buffer-size)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
319 (re-search-forward hs-c-start-regexp (point-max) 1)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
320 (setq p-aux (- (point) (length comment-start)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
321 (if (and (>= p-aux 0) (< p-aux p))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
322 (list (match-beginning 0) q))))))
10276
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-grok-mode-type ()
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
325 "Setup variables for new buffers where applicable."
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
326 (if (and (boundp 'comment-start)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
327 (boundp 'comment-end))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
328 (progn
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
329 (setq hs-c-start-regexp (regexp-quote comment-start))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
330 (if (string-match " +$" hs-c-start-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
331 (setq hs-c-start-regexp
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
332 (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
333 (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
334 (regexp-quote comment-end)))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
335 (if (string-match "^ +" hs-c-end-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
336 (setq hs-c-end-regexp
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
337 (substring hs-c-end-regexp (match-end 0))))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
338 (let ((lookup (assoc major-mode hs-special-modes-alist)))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
339 (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
340 hs-block-end-regexp (or (nth 2 lookup) "\\s\)")
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
341 hs-forward-sexp-func (or (nth 3 lookup) 'forward-sexp))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
342
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
343 (defun hs-find-block-beginning ()
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
344 "Repositions point at block-start.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
345 Return point, or nil if top-level."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
346 (let (done
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
347 (here (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
348 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
349 hs-block-end-regexp "\\)")))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
350 (while (and (not done)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
351 (re-search-backward both-regexps (point-min) t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
352 (if (match-beginning 1) ; start of start-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
353 (setq done (match-beginning 1))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
354 (goto-char (match-end 2)) ; end of end-regexp
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
355 (funcall hs-forward-sexp-func -1)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
356 (goto-char (or done here))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
357 done))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
359 (defmacro hs-life-goes-on (&rest body)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
360 "Executes optional BODY iff variable `hs-minor-mode' is non-nil."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
361 (list 'if 'hs-minor-mode (cons 'progn body)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
362
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
363 (defun hs-already-hidden-p ()
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
364 "Return non-nil if point is in an already-hidden block otherwise nil."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
365 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
366 (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
367 (let ((overlays (overlays-at (point)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
368 (found nil))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
369 (while (and (not found) (overlayp (car overlays)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
370 (setq found (overlay-get (car overlays) 'hs)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
371 overlays (cdr overlays)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
372 found)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
373
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
374 (defun java-hs-forward-sexp (arg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
375 "Function used by `hs-minor-mode' for `forward-sexp' in Java mode."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
376 (if (< arg 0)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
377 (backward-sexp 1)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
378 (if (looking-at hs-block-start-regexp)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
379 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
380 (goto-char (match-end 0))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
381 (forward-char -1)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
382 (forward-sexp 1))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
383 (forward-sexp 1))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
384
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
385 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
386 ;;; commands
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
387
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
388 ;;;###autoload
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
389 (defun hs-hide-all ()
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
390 "Hides all top-level blocks, displaying only first and last lines.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
391 It moves point to the beginning of the line, and it runs the normal hook
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
392 `hs-hide-hook'. See documentation for `run-hooks'.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
393 If `hs-hide-comments-when-hiding-all' is t also hides the comments."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
394 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
395 (hs-life-goes-on
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
396 (message "Hiding all blocks ...")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
397 (save-excursion
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
398 (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
399 (goto-char (point-min))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
400 (if hs-hide-comments-when-hiding-all
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
401 (let ((count 0)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
402 (block-and-comment-re ;; this should match
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
403 (concat "\\(^" ;; the block beginning and comment start
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
404 hs-block-start-regexp
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
405 "\\)\\|\\(" hs-c-start-regexp "\\)")))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
406 (while (re-search-forward block-and-comment-re (point-max) t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
407 (if (match-beginning 1) ;; we have found a block beginning
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
408 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
409 (goto-char (match-beginning 1))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
410 (hs-hide-block-at-point t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
411 (message "Hiding ... %d" (setq count (1+ count))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
412 ;;found a comment
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
413 (setq c-reg (hs-inside-comment-p))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
414 (if c-reg
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
415 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
416 (goto-char (nth 1 c-reg))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
417 (if (> (count-lines (car c-reg) (nth 1 c-reg)) 2)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
418 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
419 (hs-hide-block-at-point t t c-reg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
420 (message "Hiding ... %d"
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
421 (setq count (1+ count))))))))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
422 (let ((count 0)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
423 (top-level-re (concat "^" hs-block-start-regexp)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
424 (while
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
425 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
426 (forward-comment (buffer-size))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
427 (re-search-forward top-level-re (point-max) t))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
428 (goto-char (match-beginning 0))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
429 (hs-hide-block-at-point t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
430 (message "Hiding ... %d" (setq count (1+ count))))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
431 (hs-safety-is-job-n))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
432 (beginning-of-line)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
433 (message "Hiding all blocks ... done")
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
434 (run-hooks 'hs-hide-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
435
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
436 (defun hs-show-all ()
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
437 "Shows all top-level blocks.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
438 This does not change point; it runs the normal hook `hs-show-hook'.
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
439 See documentation for `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
440 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
441 (hs-life-goes-on
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
442 (message "Showing all blocks ...")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
443 (hs-flag-region (point-min) (point-max) nil)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
444 (message "Showing all blocks ... done")
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
445 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
446
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
447 (defun hs-hide-block (&optional end)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
448 "Selects a block and hides it.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
449 With prefix arg, reposition at end. Block is defined as a sexp for
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
450 lispish modes, mode-specific otherwise. Comments are blocks, too.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
451 Upon completion, point is at repositioned and the normal hook
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
452 `hs-hide-hook' is run. See documentation for `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
453 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
454 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
455 (let ((c-reg (hs-inside-comment-p)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
456 (if c-reg
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
457 (cond
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
458 ((<= (count-lines (car c-reg) (nth 1 c-reg)) 2)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
459 (message "Not enough comment lines to hide!"))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
460 (t
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
461 (goto-char (nth 1 c-reg))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
462 (hs-hide-block-at-point end t c-reg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
463 (hs-safety-is-job-n)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
464 (run-hooks 'hs-hide-hook)))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
465 (if (or (looking-at hs-block-start-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
466 (hs-find-block-beginning))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
467 (progn
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
468 (hs-hide-block-at-point end)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
469 (hs-safety-is-job-n)
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
470 (run-hooks 'hs-hide-hook)))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
471
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
472 (defun hs-show-block (&optional end)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
473 "Selects a block and shows it.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
474 With prefix arg, reposition at end. Upon completion, point is
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
475 repositioned and the normal hook `hs-show-hook' is run.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
476 See documentation for `hs-hide-block' and `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
477 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
478 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
479 (let ((c-reg (hs-inside-comment-p)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
480 (if c-reg
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
481 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
482 (hs-flag-region (car c-reg) (nth 1 c-reg) nil)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
483 (hs-safety-is-job-n)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
484 (goto-char (if end (nth 1 c-reg) (car c-reg))))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
485 (if (or (looking-at hs-block-start-regexp)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
486 (hs-find-block-beginning))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
487 (progn
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
488 (hs-show-block-at-point end)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
489 (hs-safety-is-job-n)
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
490 (run-hooks 'hs-show-hook)))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
491
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
492 (defun hs-show-region (beg end)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
493 "Shows all lines from BEG to END, without doing any block analysis.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
494 Note:`hs-show-region' is intended for use when `hs-show-block' signals
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
495 `unbalanced parentheses' and so is an emergency measure only. You may
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
496 become very confused if you use this command indiscriminately."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
497 (interactive "r")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
498 (hs-life-goes-on
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
499 (hs-flag-region beg end nil)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
500 (hs-safety-is-job-n)
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
501 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
502
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
503 ;;;###autoload
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
504 (defun hs-mouse-toggle-hiding (e)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
505 "Toggles hiding/showing of a block.
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
506 Should be bound to a mouse key."
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
507 (interactive "@e")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
508 (mouse-set-point e)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
509 (if (hs-already-hidden-p)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
510 (hs-show-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
511 (hs-hide-block)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
512
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
513 ;;;###autoload
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
514 (defun hs-minor-mode (&optional arg)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
515 "Toggle hideshow minor mode.
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
516 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
517 When hideshow minor mode is on, the menu bar is augmented with hideshow
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
518 commands and the hideshow commands are enabled. The variables
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
519 `selective-display' and `selective-display-ellipses' are set to t.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
520 Last, the normal hook `hs-minor-mode-hook' is run; see the doc
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
521 for `run-hooks'.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
522
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
523 Turning hideshow minor mode off reverts the menu bar and the
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
524 variables to default values and disables the hideshow commands."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
525 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
526 (setq hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
527 (if (null arg)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
528 (not hs-minor-mode)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
529 (> (prefix-numeric-value arg) 0)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
530 (if hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
531 (progn
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
532 ; (if (eq hs-emacs-type 'lucid)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
533 ; (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
534 ; (set-buffer-menubar (copy-sequence current-menubar))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
535 ; (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
536 (make-variable-buffer-local 'line-move-ignore-invisible)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
537 (setq line-move-ignore-invisible t)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
538 (add-to-invisibility-spec '(hs . t)) ;;hs invisible
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
539 (hs-grok-mode-type)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
540 (run-hooks 'hs-minor-mode-hook))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
541 ; (if (eq hs-emacs-type 'lucid)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
542 ; (set-buffer-menubar (delete hs-menu-bar current-menubar)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
543 (remove-from-invisibility-spec '(hs . t))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
544
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
545
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
546 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
547 ;;; load-time setup routines
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
548
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
549 ;; which emacs being used?
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
550 ;(setq hs-emacs-type
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
551 ; (if (string-match "xemacs\\|lucid" emacs-version)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
552 ; 'lucid
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
553 ; 'fsf))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
554
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
555 ;; keymaps and menus
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
556 (if hs-minor-mode-map
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
557 nil
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
558 (setq hs-minor-mode-map (make-sparse-keymap))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
559 ;; I beleive there is nothing bound on this keys
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
560 (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
561 (define-key hs-minor-mode-map "\C-cs" 'hs-show-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
562 (define-key hs-minor-mode-map "\C-cH" 'hs-hide-all)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
563 (define-key hs-minor-mode-map "\C-cS" 'hs-show-all)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
564 (define-key hs-minor-mode-map "\C-cR" 'hs-show-region)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
565
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
566 (define-key hs-minor-mode-map [S-mouse-2] 'hs-mouse-toggle-hiding)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
567
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
568 ;; should we use easymenu here?
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
569 (define-key hs-minor-mode-map [menu-bar Hide/Show]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
570 (cons "Hide/Show" (make-sparse-keymap "Hide/Show")))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
571 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-region]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
572 '("Show Region" . hs-show-region))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
573 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-all]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
574 '("Show All" . hs-show-all))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
575 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-hide-all]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
576 '("Hide All" . hs-hide-all))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
577 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-block]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
578 '("Show Block" . hs-show-block))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
579 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-hide-block]
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
580 '("Hide Block" . hs-hide-block))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
581 )
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
582
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
583 ;; some housekeeping
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
584 (or (assq 'hs-minor-mode minor-mode-map-alist)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
585 (setq minor-mode-map-alist
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
586 (cons (cons 'hs-minor-mode hs-minor-mode-map)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
587 minor-mode-map-alist)))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
588 (or (assq 'hs-minor-mode minor-mode-alist)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
589 (setq minor-mode-alist (append minor-mode-alist
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
590 (list '(hs-minor-mode " hs")))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
591
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
592 ;; make some variables buffer-local
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
593 (make-variable-buffer-local 'hs-minor-mode)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
594 (make-variable-buffer-local 'hs-c-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
595 (make-variable-buffer-local 'hs-c-end-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
596 (make-variable-buffer-local 'hs-block-start-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
597 (make-variable-buffer-local 'hs-block-end-regexp)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
598 (make-variable-buffer-local 'hs-forward-sexp-func)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
599 (put 'hs-minor-mode 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
600 (put 'hs-c-start-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
601 (put 'hs-c-end-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
602 (put 'hs-block-start-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
603 (put 'hs-block-end-regexp 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
604 (put 'hs-forward-sexp-func 'permanent-local t)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
605
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
606
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
607 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
608 ;;; that's it
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
609
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
610 (provide 'hideshow)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
611
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
612 ;;; hideshow.el ends here