annotate lisp/progmodes/hideshow.el @ 23253:0d6c3732f9d2

(hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
author Thien-Thi Nguyen <ttn@gnuvola.org>
date Sun, 13 Sep 1998 21:55:51 +0000
parents 49ed9656f1ed
children 99892dbdb774
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
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
3 ;; Copyright (C) 1994, 95, 96, 97, 98 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>
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
6 ;; Dan Nicolaescu <done@ece.arizona.edu>
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
7 ;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
23253
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
8 ;; Maintainer-Version: 4.21
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
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
28 ;;; Commentary:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
29
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
30 ;; - Commands provided
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
31 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
32 ;; This file provides `hs-minor-mode'. When active, seven commands:
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
33 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
34 ;; hs-{hide,show}-{all,block}, hs-show-region,
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
35 ;; hs-hide-level and hs-minor-mode
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
36 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
37 ;; are available, implementing block hiding and showing. Blocks are
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
38 ;; defined per mode. In c-mode or c++-mode, they are simply curly braces,
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
39 ;; while in Lisp-ish modes they are parens. Multi-line comments can also
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
40 ;; be hidden. The command `M-x hs-minor-mode' toggles the minor mode or
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
41 ;; sets it (similar to outline minor mode).
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
42
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
43 ;; - Customization
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
44 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
45 ;; Variables control things thusly:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
46 ;;
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
47 ;; hs-hide-comments-when-hiding-all -- self-explanatory!
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
48 ;; hs-show-hidden-short-form -- whether or not the last line in a form
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
49 ;; is omitted (saving screen space)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
50 ;; hs-isearch-open -- what kind of hidden blocks to open when
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
51 ;; doing isearch
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
52 ;; hs-special-modes-alist -- keeps at bay hideshow's heuristics with
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
53 ;; respect to block definitions
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
54 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
55 ;; Hooks are run after some commands:
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
56 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
57 ;; hs-hide-hook in hs-hide-block, hs-hide-all, hs-hide-level
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
58 ;; hs-show-hook hs-show-block, hs-show-all, hs-show-region
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
59 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
60 ;; See docs for each variable or hook for more info.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
61
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
62 ;; - Suggested usage
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
63 ;;
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
64 ;; (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
65 ;; (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
66 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
67 ;; 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
68 ;; `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
69
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
70 ;; - Bugs / caveats
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
71 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
72 ;; 1. Hideshow does not work w/ emacs 18 because emacs 18 lacks the
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
73 ;; function `forward-comment' (among other things). If someone writes
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
74 ;; this, please send me a copy.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
75 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
76 ;; 2. Users of cc-mode.el should not hook hideshow into
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
77 ;; c-mode-common-hook since at that stage of the call sequence, the
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
78 ;; variables `comment-start' and `comment-end' are not yet provided.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
79 ;; Instead, use c-mode-hook and c++-mode-hook as suggested above.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
80
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
81 ;; - Thanks and feedback
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
82 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
83 ;; Thanks go to the following people for valuable ideas, code and bug
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
84 ;; reports.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
85 ;; adahome@ix.netcom.com Dean Andrews
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
86 ;; alfh@ifi.uio.no Alf-Ivar Holm
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
87 ;; gael@gnlab030.grenoble.hp.com Gael Marziou
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
88 ;; jan.djarv@sa.erisoft.se Jan Djarv
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
89 ;; preston.f.crow@dartmouth.edu Preston F. Crow
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
90 ;; qhslali@aom.ericsson.se Lars Lindberg
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
91 ;; sheff@edcsgw2.cr.usgs.gov Keith Sheffield
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
92 ;; ware@cis.ohio-state.edu Pete Ware
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
93 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
94 ;; Special thanks go to Dan Nicolaescu <done@ece.arizona.edu>, who
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
95 ;; reimplemented hideshow using overlays (rather than selective display),
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
96 ;; added isearch magic, folded in custom.el compatibility, generalized
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
97 ;; comment handling, incorporated mouse support, and maintained the code
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
98 ;; in general. Version 4.0 is largely due to his efforts.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
99 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
100 ;; Correspondance welcome; please indicate version number.
10276
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 ;;; Code:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
103
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
104 (require 'easymenu)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
105
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 ;;; user-configurable variables
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
108
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
109 (defgroup hideshow nil
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
110 "Minor mode for hiding and showing program and comment blocks."
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
111 :prefix "hs-"
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
112 :group 'languages)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
113
19233
520a7d40d75c Correct the autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 18867
diff changeset
114 ;;;###autoload
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
115 (defcustom hs-hide-comments-when-hiding-all t
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
116 "Hide the comments too when you do an `hs-hide-all'."
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
117 :type 'boolean
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
118 :group 'hideshow)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
119
19233
520a7d40d75c Correct the autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 18867
diff changeset
120 ;;;###autoload
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
121 (defcustom hs-show-hidden-short-form t
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
122 "Leave only the first line visible in a hidden block.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
123 If non-nil only the first line is visible when a block is in the
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
124 hidden state, else both the first line and the last line are shown.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
125 A nil value disables `hs-adjust-block-beginning', which see.
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
126
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
127 An example of how this works: (in C mode)
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
128 original:
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
129
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
130 /* My function main
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
131 some more stuff about main
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
132 */
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
133 int
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
134 main(void)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
135 {
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
136 int x=0;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
137 return 0;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
138 }
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
139
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
140
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
141 hidden and `hs-show-hidden-short-form' is nil
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
142 /* My function main...
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
143 */
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
144 int
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
145 main(void)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
146 {...
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
147 }
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
148
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
149 hidden and `hs-show-hidden-short-form' is t
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
150 /* My function main...
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
151 int
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
152 main(void)...
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
153
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
154 For the last case you have to be on the line containing the
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
155 ellipsis when you do `hs-show-block'."
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
156 :type 'boolean
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
157 :group 'hideshow)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
158
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
159 (defcustom hs-minor-mode-hook 'hs-hide-initial-comment-block
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
160 "Hook called when `hs-minor-mode' is installed.
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
161 A good value for this would be `hs-hide-initial-comment-block' to
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
162 hide all the comments at the beginning of the file."
19833
fdcd167cb293 (hs-minor-mode-hook): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents: 19233
diff changeset
163 :type 'hook
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
164 :group 'hideshow)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
165
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
166 (defcustom hs-isearch-open 'block
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
167 "What kind of hidden blocks to open when doing `isearch'.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
168 One of the following values:
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
169
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
170 block -- open only blocks
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
171 comment -- open only comments
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
172 t -- open both blocks and comments
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
173 nil -- open neither blocks nor comments
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
174
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
175 This has effect iff `search-invisible' is set to `open'."
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
176 :type '(choice (const :tag "open only blocks" block)
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
177 (const :tag "open only comments" comment)
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
178 (const :tag "open both blocks and comments" t)
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
179 (const :tag "don't open any of them" nil))
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
180 :group 'hideshow)
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
181
19233
520a7d40d75c Correct the autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 18867
diff changeset
182 ;;;###autoload
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
183 (defvar hs-special-modes-alist
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
184 '((c-mode "{" "}" nil nil hs-c-like-adjust-block-beginning)
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
185 (c++-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning)
20820
0507d774e769 (hs-special-modes-alist): Improved the regexp for java.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20811
diff changeset
186 (java-mode "\\(\\(\\([ \t]*\\(\\(abstract\\|final\\|native\\|p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|s\\(tatic\\|ynchronized\\)\\)[ \t\n]+\\)*[.a-zA-Z0-9_:]+[ \t\n]*\\(\\[[ \t\n]*\\][ \t\n]*\\)?\\([a-zA-Z0-9_:]+[ \t\n]*\\)([^)]*)\\([ \n\t]+throws[ \t\n][^{]+\\)?\\)\\|\\([ \t]*static[^{]*\\)\\)[ \t\n]*{\\)" "}" "/[*/]" java-hs-forward-sexp hs-c-like-adjust-block-beginning))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
187 ; I tested the java regexp using the following:
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
188 ;(defvar hsj-public)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
189 ;(defvar hsj-type)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
190 ;(defvar hsj-fname)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
191 ;(defvar hsj-par)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
192 ;(defvar hsj-throws)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
193 ;(defvar hsj-static)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
194
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
195 ;(setq hsj-public
18867
b6e4c4c2a3ef (hs-special-modes-alist): Use a regexp generated by regexp-opt.
Richard M. Stallman <rms@gnu.org>
parents: 18428
diff changeset
196 ; (concat "[ \t]*\\("
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
197 ; (regexp-opt '("public" "private" "protected" "abstract"
20811
1e07c8543929 (hs-special-modes-alist): Improved the regexp for java.
Richard M. Stallman <rms@gnu.org>
parents: 20050
diff changeset
198 ; "synchronized" "static" "final" "native") 1)
20820
0507d774e769 (hs-special-modes-alist): Improved the regexp for java.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20811
diff changeset
199 ; "[ \t\n]+\\)*"))
18867
b6e4c4c2a3ef (hs-special-modes-alist): Use a regexp generated by regexp-opt.
Richard M. Stallman <rms@gnu.org>
parents: 18428
diff changeset
200
20811
1e07c8543929 (hs-special-modes-alist): Improved the regexp for java.
Richard M. Stallman <rms@gnu.org>
parents: 20050
diff changeset
201 ;(setq hsj-type "[.a-zA-Z0-9_:]+[ \t\n]*\\(\\[[ \t\n]*\\][ \t\n]*\\)?")
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
202 ;(setq hsj-fname "\\([a-zA-Z0-9_:]+[ \t\n]*\\)")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
203 ;(setq hsj-par "([^)]*)")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
204 ;(setq hsj-throws "\\([ \n\t]+throws[ \t\n][^{]+\\)?")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
205
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
206 ;(setq hsj-static "[ \t]*static[^{]*")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
207
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
208
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
209 ;(setq hs-block-start-regexp (concat
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
210 ; "\\("
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
211 ; "\\("
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
212 ; "\\("
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
213 ; hsj-public
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
214 ; hsj-type
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
215 ; hsj-fname
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
216 ; hsj-par
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
217 ; hsj-throws
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
218 ; "\\)"
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
219 ; "\\|"
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
220 ; "\\("
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
221 ; hsj-static
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
222 ; "\\)"
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
223 ; "\\)"
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
224 ; "[ \t\n]*{"
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
225 ; "\\)"
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
226 ; ))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
227
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
228 "*Alist for initializing the hideshow variables for different modes.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
229 It has the form
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
230 (MODE START END COMMENT-START FORWARD-SEXP-FUNC ADJUST-BEG-FUNC).
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
231 If present, hideshow will use these values as regexps for start, end
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
232 and comment-start, respectively. Since Algol-ish languages do not have
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
233 single-character block delimiters, the function `forward-sexp' used
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
234 by hideshow doesn't work. In this case, if a similar function is
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
235 available, you can register it and have hideshow use it instead of
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
236 `forward-sexp'. See the documentation for `hs-adjust-block-beginning'
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
237 to see what is the use of ADJUST-BEG-FUNC.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
238
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
239 If any of those is left nil, hideshow will try to guess some values
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
240 using function `hs-grok-mode-type'.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
241
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
242 Note that the regexps should not contain leading or trailing whitespace.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
243
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
244 (defvar hs-hide-hook nil
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
245 "*Hooks called at the end of commands to hide text.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
246 These commands include `hs-hide-all', `hs-hide-block' and `hs-hide-level'.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
247
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
248 (defvar hs-show-hook nil
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
249 "*Hooks called at the end of commands to show text.
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
250 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
251
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
252 (defvar hs-minor-mode-prefix "\C-c"
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
253 "*Prefix key to use for hideshow commands in hideshow minor mode.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
254
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
255 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
256 ;;; internal variables
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 (defvar hs-minor-mode nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
259 "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
260 Use the command `hs-minor-mode' to toggle this variable.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
261
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
262 (defvar hs-minor-mode-map nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
263 "Mode map for hideshow minor mode.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
264
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
265 ;(defvar hs-menu-bar nil
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
266 ; "Menu bar for hideshow minor mode (Xemacs only).")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
267
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
268 (defvar hs-c-start-regexp nil
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
269 "Regexp for beginning of comments.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
270 Differs from mode-specific comment regexps in that
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
271 surrounding whitespace is stripped.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
272
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
273 (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
274 "Regexp for beginning of block.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
275
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
276 (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
277 "Regexp for end of block.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
278
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
279 (defvar hs-forward-sexp-func 'forward-sexp
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
280 "Function used to do a `forward-sexp'.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
281 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
282 delimiters -- ie, the syntax table regexp for the character is
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
283 either `(' or `)' -- `hs-forward-sexp-func' would just be
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
284 `forward-sexp'. For other modes such as simula, a more specialized
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
285 function is necessary.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
286
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
287 (defvar hs-adjust-block-beginning nil
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
288 "Function used to tweak the block beginning.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
289 It has effect only if `hs-show-hidden-short-form' is non-nil.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
290 The block it is hidden from the point returned by this function,
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
291 as opposed to hiding it from the point returned when searching
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
292 `hs-block-start-regexp'. In c-like modes, if we wish to also hide the
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
293 curly braces (if you think they occupy too much space on the screen),
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
294 this function should return the starting point (at the end of line) of
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
295 the hidden region.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
296
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
297 It is called with a single argument ARG which is the the position in
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
298 buffer after the block beginning.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
299
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
300 It should return the position from where we should start hiding.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
301
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
302 It should not move the point.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
303
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
304 See `hs-c-like-adjust-block-beginning' for an example of using this.")
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
305
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
306 ;(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
307 ; "Used to support both Emacs and Xemacs.")
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
308
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
309 ;(eval-when-compile
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
310 ; (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
311 ; (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
312 ; (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
313 ; (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
314 ; (defun add-menu (arg1 arg2 arg3)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
315
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
316 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
317 ;;; support funcs
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
318
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
319 ;; snarfed from outline.el;
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
320 (defun hs-flag-region (from to flag)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
321 "Hide or show lines from FROM to TO, according to FLAG.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
322 If FLAG is nil then text is shown, while if FLAG is non-nil the text
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
323 is hidden. Actually flag is really either `comment' or `block'
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
324 depending on what kind of block it is suppose to hide."
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
325 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
326 (goto-char from)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
327 (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
328 (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
329 (if flag
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
330 (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
331 ;; 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
332 (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
333 (overlay-put overlay 'hs t)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
334 (when (or (eq hs-isearch-open t) (eq hs-isearch-open flag))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
335 (overlay-put overlay 'isearch-open-invisible
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
336 'hs-isearch-open-invisible))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
337 (overlay-put overlay 'intangible t)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
338
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
339 ;; This is set as an `isearch-open-invisible' property to hidden
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
340 ;; overlays.
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
341 (defun hs-isearch-open-invisible (ov)
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
342 (save-excursion
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
343 (goto-char (overlay-start ov))
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
344 (hs-show-block)))
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
345
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
346 ;; 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
347 ;; 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
348 ;; 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
349 (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
350 (if (< end beg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
351 (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
352 (save-excursion
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
353 (goto-char beg)
18428
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
354 (let ((overlays (overlays-in beg end))
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
355 o)
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
356 (while overlays
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
357 (setq o (car overlays))
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
358 (if (eq (overlay-get o prop) value)
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
359 (delete-overlay o))
5ec58687160a (hs-discard-overlays): Use overlays-in to
Richard M. Stallman <rms@gnu.org>
parents: 18237
diff changeset
360 (setq overlays (cdr overlays))))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
361
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
362 (defun hs-hide-block-at-point (&optional end comment-reg)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
363 "Hide block iff on block beginning.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
364 Optional arg END means reposition at end.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
365 Optional arg COMMENT-REG is a list of the form (BEGIN . END) and
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
366 specifies the limits of the comment, or nil if the block is not
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
367 a comment."
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
368 (if comment-reg
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
369 (progn
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
370 ;; goto the end of line at the end of the comment
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
371 (goto-char (nth 1 comment-reg))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
372 (unless hs-show-hidden-short-form (forward-line -1))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
373 (end-of-line)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
374 (hs-flag-region (car comment-reg) (point) 'comment)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
375 (goto-char (if end (nth 1 comment-reg) (car comment-reg))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
376 (if (looking-at hs-block-start-regexp)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
377 (let* ((p ;; p is the point at the end of the block beginning
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
378 (if (and hs-show-hidden-short-form
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
379 hs-adjust-block-beginning)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
380 ;; we need to adjust the block beginning
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
381 (funcall hs-adjust-block-beginning (match-end 0))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
382 (match-end 0)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
383 ;; q is the point at the end of the block
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
384 (q (progn (funcall hs-forward-sexp-func 1) (point))))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
385 ;; position the point so we can call `hs-flag-region'
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
386 (unless hs-show-hidden-short-form (forward-line -1))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
387 (end-of-line)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
388 (if (and (< p (point)) (> (count-lines p q)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
389 (if hs-show-hidden-short-form 1 2)))
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
390 (hs-flag-region p (point) 'block))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
391 (goto-char (if end q p))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
392
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
393 (defun hs-show-block-at-point (&optional end comment-reg)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
394 "Show block iff on block beginning.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
395 Optional arg END means reposition at end.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
396 Optional arg COMMENT-REG is a list of the forme (BEGIN . END) and
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
397 specifies the limits of the comment. It should be nil when hiding
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
398 a block."
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
399 (if comment-reg
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
400 (when (car comment-reg)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
401 (hs-flag-region (car comment-reg) (nth 1 comment-reg) nil)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
402 (goto-char (if end (nth 1 comment-reg) (car comment-reg))))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
403 (if (looking-at hs-block-start-regexp)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
404 (let* ((p (point))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
405 (q
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
406 (condition-case error ; probably unbalanced paren
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
407 (progn
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
408 (funcall hs-forward-sexp-func 1)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
409 (point))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
410 (error
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
411 ;; try to get out of rat's nest and expose the whole func
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
412 (if (/= (current-column) 0) (beginning-of-defun))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
413 (setq p (point))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
414 (re-search-forward (concat "^" hs-block-start-regexp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
415 (point-max) t 2)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
416 (point)))))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
417 (hs-flag-region p q nil)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
418 (goto-char (if end (1+ (point)) p))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
419
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
420 (defun hs-safety-is-job-n ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
421 "Warn if `buffer-invisibility-spec' does not contain hs."
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
422 (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
423 nil
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
424 (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
425 (sit-for 2)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
426
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
427 (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
428 (interactive)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
429 "Hide the first block of comments in a file.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
430 This is useful when a part of `hs-minor-mode-hook', especially with
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
431 huge header-comment RCS logs."
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
432 (let ((p (point))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
433 c-reg)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
434 (goto-char (point-min))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
435 (skip-chars-forward " \t\n^L")
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
436 (setq c-reg (hs-inside-comment-p))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
437 ;; see if we have enough comment lines to hide
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
438 (if (and c-reg (> (count-lines (car c-reg) (nth 1 c-reg))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
439 (if hs-show-hidden-short-form 1 2)))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
440 (hs-hide-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
441 (goto-char p))))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
442
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
443 (defun hs-inside-comment-p ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
444 "Return non-nil if point is inside a comment, otherwise nil.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
445 Actually, returns a list containing the buffer position of the start
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
446 and the end of the comment. A comment block can be hidden only if on
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
447 its starting line there is only whitespace preceding the actual comment
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
448 beginning. If we are inside of a comment but this condition is not met,
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
449 we return a list having a nil as its car and the end of comment position
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
450 as cdr."
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
451 (save-excursion
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
452 ;; the idea is to look backwards for a comment start regexp, do a
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
453 ;; forward comment, and see if we are inside, then extend extend
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
454 ;; forward and backward as long as we have comments
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
455 (let ((q (point)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
456 (when (or (looking-at hs-c-start-regexp)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
457 (re-search-backward hs-c-start-regexp (point-min) t))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
458 (forward-comment (- (buffer-size)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
459 (skip-chars-forward " \t\n ")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
460 (let ((p (point))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
461 (not-hidable nil))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
462 (beginning-of-line)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
463 (unless (looking-at (concat "[ \t]*" hs-c-start-regexp))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
464 ;; we are in this situation: (example)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
465 ;; (defun bar ()
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
466 ;; (foo)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
467 ;; ) ; comment
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
468 ;; ^
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
469 ;; the point was here before doing (beginning-of-line)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
470 ;; here we should advance till the next comment which
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
471 ;; eventually has only white spaces preceding it on the same
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
472 ;; line
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
473 (goto-char p)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
474 (forward-comment 1)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
475 (skip-chars-forward " \t\n ")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
476 (setq p (point))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
477 (while (and (< (point) q)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
478 (> (point) p)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
479 (not (looking-at hs-c-start-regexp)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
480 (setq p (point)) ;; use this to avoid an infinit cycle.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
481 (forward-comment 1)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
482 (skip-chars-forward " \t\n "))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
483 (if (or (not (looking-at hs-c-start-regexp))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
484 (> (point) q))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
485 ;; we cannot hide this comment block
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
486 (setq not-hidable t)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
487 ;; goto the end of the comment
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
488 (forward-comment (buffer-size))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
489 (skip-chars-backward " \t\n ")
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
490 (end-of-line)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
491 (if (>= (point) q)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
492 (list (if not-hidable nil p) (point))))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
493
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
494 (defun hs-grok-mode-type ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
495 "Set up hideshow variables for new buffers.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
496 If `hs-special-modes-alist' has information associated with the
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
497 current buffer's major mode, use that.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
498 Otherwise, guess start, end and comment-start regexps; forward-sexp
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
499 function; and adjust-block-beginning function."
23253
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
500 (if (and (boundp 'comment-start)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
501 (boundp 'comment-end)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
502 comment-start comment-end)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
503 (let ((lookup (assoc major-mode hs-special-modes-alist)))
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
504 (setq hs-block-start-regexp (or (nth 1 lookup) "\\s\(")
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
505 hs-block-end-regexp (or (nth 2 lookup) "\\s\)")
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
506 hs-c-start-regexp (or (nth 3 lookup)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
507 (let ((c-start-regexp
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
508 (regexp-quote comment-start)))
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
509 (if (string-match " +$" c-start-regexp)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
510 (substring c-start-regexp 0 (1- (match-end 0)))
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
511 c-start-regexp)))
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
512 hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
513 hs-adjust-block-beginning (nth 5 lookup)))
0d6c3732f9d2 (hs-grok-mode-type) Handle nil `comment-start' and `comment-end'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22445
diff changeset
514 (error "% Mode doesn't support Hideshow Mode" mode-name)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
515
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
516 (defun hs-find-block-beginning ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
517 "Reposition point at block-start.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
518 Return point, or nil if top-level."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
519 (let (done
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
520 (try-again t)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
521 (here (point))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
522 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
523 hs-block-end-regexp "\\)"))
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
524 (buf-size (buffer-size)))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
525 (beginning-of-line)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
526 ;; A block beginning can span on multiple lines, if the point
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
527 ;; is on one of those lines, trying a regexp search from
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
528 ;; that point would fail to find the block beginning, so we look
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
529 ;; backwards for the block beginning, or a block end.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
530 (while try-again
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
531 (setq try-again nil)
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
532 (if (and (re-search-backward both-regexps (point-min) t)
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
533 (match-beginning 1)) ; found a block beginning
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
534 (if (save-match-data (hs-inside-comment-p))
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
535 ;;but it was inside a comment, so we have to look for
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
536 ;;it again
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
537 (setq try-again t)
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
538 ;; that's what we were looking for
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
539 (setq done (match-beginning 0)))
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
540 ;; we found a block end, or we reached the beginning of the
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
541 ;; buffer look to see if we were on a block beginning when we
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
542 ;; started
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
543 (if (and
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
544 (re-search-forward hs-block-start-regexp (point-max) t)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
545 (or
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
546 (and (>= here (match-beginning 0)) (< here (match-end 0)))
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
547 (and hs-show-hidden-short-form hs-adjust-block-beginning
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
548 (save-match-data
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
549 (= 1 (count-lines
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
550 (funcall hs-adjust-block-beginning
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
551 (match-end 0)) here))))))
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
552 (setq done (match-beginning 0)))))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
553 (goto-char here)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
554 (while (and (not done)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
555 ;; This had problems because the regexp can match something
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
556 ;; inside of a comment!
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
557 ;; Since inside a comment we can have incomplete sexps
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
558 ;; this would have signaled an error.
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
559 (or (forward-comment (- buf-size)) t); `or' is a hack to
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
560 ; make it return t
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
561 (re-search-backward both-regexps (point-min) t))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
562 (if (match-beginning 1) ; start of start-regexp
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
563 (setq done (match-beginning 0))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
564 (goto-char (match-end 0)) ; end of end-regexp
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
565 (funcall hs-forward-sexp-func -1)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
566 (goto-char (or done here))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
567 done))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
568
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
569 (defun hs-hide-level-recursive (arg minp maxp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
570 "Hide blocks ARG levels below this block recursively."
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
571 (when (hs-find-block-beginning)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
572 (setq minp (1+ (point)))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
573 (forward-sexp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
574 (setq maxp (1- (point))))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
575 (hs-flag-region minp maxp ?\n) ; eliminate weirdness
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
576 (goto-char minp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
577 (while (progn
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
578 (forward-comment (buffer-size))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
579 (re-search-forward hs-block-start-regexp maxp t))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
580 (if (> arg 1)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
581 (hs-hide-level-recursive (1- arg) minp maxp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
582 (goto-char (match-beginning 0))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
583 (hs-hide-block-at-point t)))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
584 (hs-safety-is-job-n)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
585 (goto-char maxp))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
586
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
587 (defmacro hs-life-goes-on (&rest body)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
588 "Execute optional BODY iff variable `hs-minor-mode' is non-nil."
22109
3e53877b4a08 (hs-life-goes-on): Use Emacs' native backquote support.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20820
diff changeset
589 `(let ((inhibit-point-motion-hooks t))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
590 (when hs-minor-mode
22109
3e53877b4a08 (hs-life-goes-on): Use Emacs' native backquote support.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20820
diff changeset
591 ,@body)))
3e53877b4a08 (hs-life-goes-on): Use Emacs' native backquote support.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20820
diff changeset
592
18867
b6e4c4c2a3ef (hs-special-modes-alist): Use a regexp generated by regexp-opt.
Richard M. Stallman <rms@gnu.org>
parents: 18428
diff changeset
593 (put 'hs-life-goes-on 'edebug-form-spec '(&rest form))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
594
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
595 (defun hs-already-hidden-p ()
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
596 "Return non-nil if point is in an already-hidden block, otherwise nil."
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
597 (save-excursion
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
598 (let ((c-reg (hs-inside-comment-p)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
599 (if (and c-reg (nth 0 c-reg))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
600 ;; point is inside a comment, and that comment is hidable
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
601 (goto-char (nth 0 c-reg))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
602 (if (and (not c-reg) (hs-find-block-beginning)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
603 (looking-at hs-block-start-regexp))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
604 ;; point is inside a block
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
605 (goto-char (match-end 0)))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
606 (end-of-line)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
607 (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
608 (found nil))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
609 (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
610 (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
611 overlays (cdr overlays)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
612 found)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
613
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
614 (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
615 "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
616 (if (< arg 0)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
617 (backward-sexp 1)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
618 (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
619 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
620 (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
621 (forward-char -1)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
622 (forward-sexp 1))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
623 (forward-sexp 1))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
624
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
625 (defun hs-c-like-adjust-block-beginning (arg)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
626 "Function to be assigned to `hs-adjust-block-beginning' for C-like modes.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
627 Arg is a position in buffer just after {. This goes back to the end of
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
628 the function header. The purpose is to save some space on the screen
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
629 when displaying hidden blocks."
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
630 (save-excursion
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
631 (goto-char arg)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
632 (forward-char -1)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
633 (forward-comment (- (buffer-size)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
634 (point)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
635
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
636 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
637 ;;; commands
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
638
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
639 ;;;###autoload
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
640 (defun hs-hide-all ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
641 "Hide all top-level blocks, displaying only first and last lines.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
642 Move point to the beginning of the line, and it run the normal hook
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
643 `hs-hide-hook'. See documentation for `run-hooks'.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
644 If `hs-hide-comments-when-hiding-all' is t, also hide the comments."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
645 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
646 (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
647 (message "Hiding all blocks ...")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
648 (save-excursion
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
649 (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
650 (goto-char (point-min))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
651 (if hs-hide-comments-when-hiding-all
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
652 (let (c-reg
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
653 (count 0)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
654 (block-and-comment-re ;; this should match
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
655 (concat "\\(^" ;; the block beginning and comment start
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
656 hs-block-start-regexp
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
657 "\\)\\|\\(" 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
658 (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
659 (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
660 (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
661 (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
662 (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
663 (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
664 ;;found a comment
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
665 (setq c-reg (hs-inside-comment-p))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
666 (if (and c-reg (car c-reg))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
667 (if (> (count-lines (car c-reg) (nth 1 c-reg))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
668 (if hs-show-hidden-short-form 1 2))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
669 (progn
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
670 (hs-hide-block-at-point t c-reg)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
671 (message "Hiding ... %d" (setq count (1+ count))))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
672 (goto-char (nth 1 c-reg)))))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
673 (let ((count 0)
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
674 (top-level-re (concat "^" hs-block-start-regexp))
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
675 (buf-size (buffer-size)))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
676 (while
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
677 (progn
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
678 (forward-comment buf-size)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
679 (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
680 (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
681 (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
682 (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
683 (hs-safety-is-job-n))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
684 (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
685 (message "Hiding all blocks ... done")
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
686 (run-hooks 'hs-hide-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
687
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
688 (defun hs-show-all ()
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
689 "Show all top-level blocks.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
690 Point is unchanged; run the normal hook `hs-show-hook'.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
691 See documentation for `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
692 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
693 (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
694 (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
695 (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
696 (message "Showing all blocks ... done")
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
697 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
698
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
699 (defun hs-hide-block (&optional end)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
700 "Select a block and hide it.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
701 With prefix arg, reposition at end. Block is defined as a sexp for
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
702 Lispish modes, mode-specific otherwise. Comments are blocks, too.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
703 Upon completion, point is repositioned and 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
704 `hs-hide-hook' is run. See documentation for `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
705 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
706 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
707 (let ((c-reg (hs-inside-comment-p)))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
708 (cond
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
709 ((and c-reg (or (null (nth 0 c-reg))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
710 (<= (count-lines (car c-reg) (nth 1 c-reg))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
711 (if hs-show-hidden-short-form 1 2))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
712 (message "Not enough comment lines to hide!"))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
713 ((or c-reg (looking-at hs-block-start-regexp)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
714 (hs-find-block-beginning))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
715 (hs-hide-block-at-point end c-reg)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
716 (hs-safety-is-job-n)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
717 (run-hooks 'hs-hide-hook))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
718
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
719 (defun hs-show-block (&optional end)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
720 "Select a block and show it.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
721 With prefix arg, reposition at end. Upon completion, point is
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
722 repositioned and the normal hook `hs-show-hook' is run.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
723 See documentation for `hs-hide-block' and `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
724 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
725 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
726 (let ((c-reg (hs-inside-comment-p)))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
727 (if (or c-reg
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
728 (looking-at hs-block-start-regexp)
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
729 (hs-find-block-beginning))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
730 (progn
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
731 (hs-show-block-at-point end c-reg)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
732 (hs-safety-is-job-n)
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
733 (run-hooks 'hs-show-hook))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
734
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
735 (defun hs-show-region (beg end)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
736 "Show all lines from BEG to END, without doing any block analysis.
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
737 Note: `hs-show-region' is intended for use when `hs-show-block' signals
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
738 \"unbalanced parentheses\" and so is an emergency measure only. You may
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
739 become very confused if you use this command indiscriminately."
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
740 (interactive "r")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
741 (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
742 (hs-flag-region beg end nil)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
743 (hs-safety-is-job-n)
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
744 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
745
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
746 (defun hs-hide-level (arg)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
747 "Hide all blocks ARG levels below this block."
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
748 (interactive "p")
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
749 (hs-life-goes-on
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
750 (save-excursion
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
751 (message "Hiding blocks ...")
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
752 (hs-hide-level-recursive arg (point-min) (point-max))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
753 (message "Hiding blocks ... done"))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
754 (hs-safety-is-job-n)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
755 (run-hooks 'hs-hide-hook)))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
756
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
757 ;;;###autoload
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
758 (defun hs-mouse-toggle-hiding (e)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
759 "Toggle hiding/showing of a block.
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
760 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
761 (interactive "@e")
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
762 (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
763 (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
764 (hs-show-block)
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
765 (hs-hide-block)))
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
766
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
767 ;;;###autoload
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
768 (defun hs-minor-mode (&optional arg)
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
769 "Toggle hideshow minor mode.
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
770 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
771 When hideshow minor mode is on, the menu bar is augmented with hideshow
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
772 commands and the hideshow commands are enabled.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
773 The value '(hs . t) is added to `buffer-invisibility-spec'.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
774 Last, the normal hook `hs-minor-mode-hook' is run; see the doc
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
775 for `run-hooks'.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
776
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
777 The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block',
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
778 `hs-show-block', `hs-hide-level' and `hs-show-region'.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
779 Also see the documentation for the variable `hs-show-hidden-short-form'.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
780
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
781 Turning hideshow minor mode off reverts the menu bar and the
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
782 variables to default values and disables the hideshow commands.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
783
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
784 Key bindings:
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
785 \\{hs-minor-mode-map}"
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
786
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
787 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
788 (setq hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
789 (if (null arg)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
790 (not hs-minor-mode)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
791 (> (prefix-numeric-value arg) 0)))
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
792 (if hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
793 (progn
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
794 ; (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
795 ; (progn
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
796 ; (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
797 ; (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar))))
22445
49ed9656f1ed (hs-minor-mode): Use `make-local-variable' not `make-variable-buffer-local'.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22444
diff changeset
798 (make-local-variable 'line-move-ignore-invisible)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
799 (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
800 (add-to-invisibility-spec '(hs . t)) ;;hs invisible
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
801 (hs-grok-mode-type)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
802 (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
803 ; (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
804 ; (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
805 (remove-from-invisibility-spec '(hs . t))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
806
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
807
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
808 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
809 ;;; load-time setup routines
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
810
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
811 ;; 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
812 ;(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
813 ; (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
814 ; 'lucid
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
815 ; 'fsf))
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
816
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
817 ;; 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
818 (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
819 nil
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
820 (setq hs-minor-mode-map (make-sparse-keymap))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
821 (easy-menu-define hs-minor-mode-menu
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
822 hs-minor-mode-map
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
823 "Menu used when hideshow minor mode is active."
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
824 (cons "Hide/Show"
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
825 (mapcar
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
826 ;; populate keymap then massage entry for easymenu
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
827 (lambda (ent)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
828 (define-key hs-minor-mode-map (aref ent 2) (aref ent 1))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
829 (aset ent 2 (not (vectorp (aref ent 2)))) ; disable mousy stuff
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
830 ent)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
831 ;; I believe there is nothing bound on these keys
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
832 ;; menu entry command key
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
833 '(["Hide Block" hs-hide-block "\C-ch"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
834 ["Show Block" hs-show-block "\C-cs"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
835 ["Hide All" hs-hide-all "\C-cH"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
836 ["Show All" hs-show-all "\C-cS"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
837 ["Hide Level" hs-hide-level "\C-cL"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
838 ["Show Region" hs-show-region "\C-cR"]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
839 ["Toggle Hiding" hs-mouse-toggle-hiding [S-mouse-2]]
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
840 )))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
841
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
842 ;; some housekeeping
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
843 (or (assq 'hs-minor-mode minor-mode-map-alist)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
844 (setq minor-mode-map-alist
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
845 (cons (cons 'hs-minor-mode hs-minor-mode-map)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
846 minor-mode-map-alist)))
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
847 (or (assq 'hs-minor-mode minor-mode-alist)
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
848 (setq minor-mode-alist (append minor-mode-alist
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
849 (list '(hs-minor-mode " hs")))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
850
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
851 ;; make some variables permanently buffer-local
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
852 (mapcar (lambda (var)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
853 (make-variable-buffer-local var)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
854 (put var 'permanent-local t))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
855 '(hs-minor-mode
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
856 hs-c-start-regexp
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
857 hs-block-start-regexp
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
858 hs-block-end-regexp
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
859 hs-forward-sexp-func
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
860 hs-adjust-block-beginning))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
861
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
862 ;;;----------------------------------------------------------------------------
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
863 ;;; that's it
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
864
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
865 (provide 'hideshow)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
866
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
867 ;;; hideshow.el ends here