annotate lisp/progmodes/hideshow.el @ 110855:bec49af30c2f

Merge changes from emacs-23 branch.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 08 Oct 2010 12:14:47 +0200
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
1 ;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
2
64699
629afbe74e61 Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents: 64085
diff changeset
3 ;; Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105939
diff changeset
4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
5
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
6 ;; Author: Thien-Thi Nguyen <ttn@gnu.org>
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
7 ;; Dan Nicolaescu <dann@ics.uci.edu>
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
8 ;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
9 ;; Maintainer-Version: 5.65.2.2
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
10 ;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
11
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
12 ;; This file is part of GNU Emacs.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
13
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92312
diff changeset
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92312
diff changeset
16 ;; the Free Software Foundation, either version 3 of the License, or
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92312
diff changeset
17 ;; (at your option) any later version.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
18
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
19 ;; 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
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
22 ;; GNU General Public License for more details.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
23
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
24 ;; You should have received a copy of the GNU General Public License
94673
52b7a8c22af5 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92312
diff changeset
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
26
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
27 ;;; Commentary:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
28
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
29 ;; * Commands provided
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
30 ;;
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
31 ;; This file provides Hideshow Minor Mode. When active, nine commands
27029
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
32 ;; are available, implementing block hiding and showing. They (and their
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
33 ;; keybindings) are:
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
34 ;;
36784
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
35 ;; hs-hide-block C-c @ C-h
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
36 ;; hs-show-block C-c @ C-s
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
37 ;; hs-hide-all C-c @ C-M-h
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
38 ;; hs-show-all C-c @ C-M-s
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
39 ;; hs-hide-level C-c @ C-l
04b49d665787 Update copyright.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 31856
diff changeset
40 ;; hs-toggle-hiding C-c @ C-c
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
41 ;; hs-mouse-toggle-hiding [(shift mouse-2)]
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
42 ;; hs-hide-initial-comment-block
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
43 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
44 ;; Blocks are defined per mode. In c-mode, c++-mode and java-mode, they
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
45 ;; are simply text between curly braces, while in Lisp-ish modes parens
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
46 ;; are used. Multi-line comment blocks can also be hidden. Read-only
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
47 ;; buffers are not a problem, since hideshow doesn't modify the text.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
48 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
49 ;; The command `M-x hs-minor-mode' toggles the minor mode or sets it
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
50 ;; (similar to other minor modes).
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
51
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
52 ;; * Suggested usage
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
53 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
54 ;; First make sure hideshow.el is in a directory in your `load-path'.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
55 ;; You can optionally byte-compile it using `M-x byte-compile-file'.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
56 ;; Then, add the following to your ~/.emacs:
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
57 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
58 ;; (load-library "hideshow")
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
59 ;; (add-hook 'X-mode-hook ; other modes similarly
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
60 ;; (lambda () (hs-minor-mode 1)))
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
61 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
62 ;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
63 ;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
64 ;; activated or deactivated, `hs-minor-mode-hook' is run w/ `run-hooks'.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
65 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
66 ;; Additionally, Joseph Eydelnant writes:
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
67 ;; I enjoy your package hideshow.el Ver. 5.24 2001/02/13
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
68 ;; a lot and I've been looking for the following functionality:
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
69 ;; toggle hide/show all with a single key.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
70 ;; Here are a few lines of code that lets me do just that.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
71 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
72 ;; (defvar my-hs-hide nil "Current state of hideshow for toggling all.")
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
73 ;; ;;;###autoload
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
74 ;; (defun my-toggle-hideshow-all () "Toggle hideshow all."
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
75 ;; (interactive)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
76 ;; (setq my-hs-hide (not my-hs-hide))
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
77 ;; (if my-hs-hide
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
78 ;; (hs-hide-all)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
79 ;; (hs-show-all)))
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
80 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
81 ;; [Your hideshow hacks here!]
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
82
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
83 ;; * Customization
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
84 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
85 ;; You can use `M-x customize-variable' on the following variables:
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
86 ;;
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
87 ;; - hs-hide-comments-when-hiding-all -- self-explanatory!
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
88 ;; - hs-hide-all-non-comment-function -- if non-nil, when doing a
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
89 ;; `hs-hide-all', this function
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
90 ;; is called w/ no arguments
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
91 ;; - hs-isearch-open -- what kind of hidden blocks to
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
92 ;; open when doing isearch
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
93 ;;
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
94 ;; Some languages (e.g., Java) are deeply nested, so the normal behavior
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
95 ;; of `hs-hide-all' (hiding all but top-level blocks) results in very
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
96 ;; little information shown, which is not very useful. You can use the
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
97 ;; variable `hs-hide-all-non-comment-function' to implement your idea of
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
98 ;; what is more useful. For example, the following code shows the next
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
99 ;; nested level in addition to the top-level:
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
100 ;;
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
101 ;; (defun ttn-hs-hide-level-1 ()
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
102 ;; (hs-hide-level 1)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
103 ;; (forward-sexp 1))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
104 ;; (setq hs-hide-all-non-comment-function 'ttn-hs-hide-level-1)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
105 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
106 ;; Hideshow works w/ incremental search (isearch) by setting the variable
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
107 ;; `hs-headline', which is the line of text at the beginning of a hidden
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
108 ;; block that contains a match for the search. You can have this show up
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
109 ;; in the mode line by modifying the variable `mode-line-format'. For
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
110 ;; example, the following code prepends this info to the mode line:
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 14151
diff changeset
111 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
112 ;; (unless (memq 'hs-headline mode-line-format)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
113 ;; (setq mode-line-format
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
114 ;; (append '("-" hs-headline) mode-line-format)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
115 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
116 ;; See documentation for `mode-line-format' for more info.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
117 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
118 ;; 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
119 ;;
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
120 ;; hs-hide-hook in hs-hide-block, hs-hide-all, hs-hide-level
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
121 ;; hs-show-hook hs-show-block, hs-show-all
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
122 ;;
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
123 ;; One of `hs-hide-hook' or `hs-show-hook' is run for the toggling
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
124 ;; commands when the result of the toggle is to hide or show blocks,
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
125 ;; respectively. All hooks are run w/ `run-hooks'. See docs for each
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
126 ;; variable or hook for more info.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
127 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
128 ;; Normally, hideshow tries to determine appropriate values for block
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
129 ;; and comment definitions by examining the buffer's major mode. If
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
130 ;; there are problems, hideshow will not activate and in that case you
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
131 ;; may wish to override hideshow's heuristics by adding an entry to
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
132 ;; variable `hs-special-modes-alist'. Packages that use hideshow should
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
133 ;; do something like:
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
134 ;;
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
135 ;; (add-to-list 'hs-special-modes-alist '(my-mode "{{" "}}" ...))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
136 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
137 ;; If you have an entry that works particularly well, consider
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
138 ;; submitting it for inclusion in hideshow.el. See docstring for
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
139 ;; `hs-special-modes-alist' for more info on the entry format.
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
140 ;;
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
141 ;; See also variable `hs-set-up-overlay' for per-block customization of
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
142 ;; appearance or other effects associated with overlays. For example:
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
143 ;;
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
144 ;; (setq hs-set-up-overlay
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
145 ;; (defun my-display-code-line-counts (ov)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
146 ;; (when (eq 'code (overlay-get ov 'hs))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
147 ;; (overlay-put ov 'display
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
148 ;; (propertize
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
149 ;; (format " ... <%d>"
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
150 ;; (count-lines (overlay-start ov)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
151 ;; (overlay-end ov)))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
152 ;; 'face 'font-lock-type-face)))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
153
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
154 ;; * Bugs
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
155 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
156 ;; (1) Hideshow does not work w/ emacs 18 because emacs 18 lacks the
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
157 ;; function `forward-comment' (among other things). If someone
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
158 ;; writes this, please send me a copy.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
159 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
160 ;; (2) Sometimes `hs-headline' can become out of sync. To reset, type
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
161 ;; `M-x hs-minor-mode' twice (that is, deactivate then re-activate
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
162 ;; hideshow).
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
163 ;;
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
164 ;; (3) Hideshow 5.x is developed and tested on GNU Emacs 20.7.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
165 ;; XEmacs compatibility may have bitrotted since 4.29.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
166 ;;
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
167 ;; (4) Some buffers can't be `byte-compile-file'd properly. This is because
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
168 ;; `byte-compile-file' inserts the file to be compiled in a temporary
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
169 ;; buffer and switches `normal-mode' on. In the case where you have
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
170 ;; `hs-hide-initial-comment-block' in `hs-minor-mode-hook', the hiding of
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
171 ;; the initial comment sometimes hides parts of the first statement (seems
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
172 ;; to be only in `normal-mode'), so there are unbalanced "(" and ")".
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
173 ;;
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
174 ;; The workaround is to clear `hs-minor-mode-hook' when byte-compiling:
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
175 ;;
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
176 ;; (defadvice byte-compile-file (around
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
177 ;; byte-compile-file-hideshow-off
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
178 ;; act)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
179 ;; (let ((hs-minor-mode-hook nil))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
180 ;; ad-do-it))
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
181 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
182 ;; (5) Hideshow interacts badly with Ediff and `vc-diff'. At the moment, the
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
183 ;; suggested workaround is to turn off hideshow entirely, for example:
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
184 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
185 ;; (add-hook 'ediff-prepare-buffer-hook 'turn-off-hideshow)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
186 ;; (add-hook 'vc-before-checkin-hook 'turn-off-hideshow)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
187 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
188 ;; In the case of `vc-diff', here is a less invasive workaround:
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
189 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
190 ;; (add-hook 'vc-before-checkin-hook
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
191 ;; (lambda ()
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
192 ;; (goto-char (point-min))
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
193 ;; (hs-show-block)))
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
194 ;;
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
195 ;; Unfortunately, these workarounds do not restore hideshow state.
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
196 ;; If someone figures out a better way, please let me know.
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
197
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
198 ;; * Correspondance
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
199 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
200 ;; Correspondance welcome; please indicate version number. Send bug
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
201 ;; reports and inquiries to <ttn@gnu.org>.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
202
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
203 ;; * Thanks
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
204 ;;
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
205 ;; Thanks go to the following people for valuable ideas, code and
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
206 ;; bug reports.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
207 ;;
65500
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
208 ;; Dean Andrews, Alf-Ivar Holm, Holger Bauer, Christoph Conrad, Dave Love,
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
209 ;; Dirk Herrmann, Gael Marziou, Jan Djarv, Guillaume Leray, Moody Ahmad,
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
210 ;; Preston F. Crow, Lars Lindberg, Reto Zimmermann, Keith Sheffield,
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
211 ;; Chew Meng Kuan, Tony Lam, Pete Ware, François Pinard, Stefan Monnier,
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
212 ;; Joseph Eydelnant, Michael Ernst, Peter Heslin
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
213 ;;
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
214 ;; Special thanks go to Dan Nicolaescu, who reimplemented hideshow using
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
215 ;; overlays (rather than selective display), added isearch magic, folded
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
216 ;; in custom.el compatibility, generalized comment handling, incorporated
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
217 ;; mouse support, and maintained the code in general. Version 4.0 is
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
218 ;; largely due to his efforts.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
219
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
220 ;; * History
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
221 ;;
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
222 ;; Hideshow was inspired when I learned about selective display. It was
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
223 ;; reimplemented to use overlays for 4.0 (see above). WRT older history,
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
224 ;; entries in the masterfile corresponding to versions 1.x and 2.x have
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
225 ;; been lost. XEmacs support is reliable as of 4.29. State save and
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
226 ;; restore was added in 3.5 (not widely distributed), and reliable as of
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
227 ;; 4.30. Otherwise, the code seems stable. Passes checkdoc as of 4.32.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
228 ;; Version 5.x uses new algorithms for block selection and traversal,
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
229 ;; unbundles state save and restore, and includes more isearch support.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
230
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
231 ;;; Code:
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
232
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
233 ;;---------------------------------------------------------------------------
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
234 ;; user-configurable variables
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
235
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
236 (defgroup hideshow nil
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
237 "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
238 :prefix "hs-"
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
239 :group 'languages)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
240
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
241 (defcustom hs-hide-comments-when-hiding-all t
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
242 "*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
243 :type 'boolean
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
244 :group 'hideshow)
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
245
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
246 (defcustom hs-minor-mode-hook nil
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
247 "*Hook called when hideshow minor mode is activated or deactivated."
19833
fdcd167cb293 (hs-minor-mode-hook): Fix customize type.
Richard M. Stallman <rms@gnu.org>
parents: 19233
diff changeset
248 :type 'hook
36787
608c66a9bc34 (hs-minor-mode-hook): Include `:version' in defcustom form.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 36784
diff changeset
249 :group 'hideshow
608c66a9bc34 (hs-minor-mode-hook): Include `:version' in defcustom form.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 36784
diff changeset
250 :version "21.1")
18070
a99f3bd58831 (hs-hide-comments-when-hiding-all)
Richard M. Stallman <rms@gnu.org>
parents: 18016
diff changeset
251
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
252 (defcustom hs-isearch-open 'code
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
253 "*What kind of hidden blocks to open when doing `isearch'.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
254 One of the following symbols:
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
255
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
256 code -- open only code blocks
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
257 comment -- open only comment blocks
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
258 t -- open both code and comment blocks
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
259 nil -- open neither code nor comment blocks
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
260
78487
419c5c316b51 Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78234
diff changeset
261 This has effect only if `search-invisible' is set to `open'."
38980
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
262 :type '(choice (const :tag "open only code blocks" code)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
263 (const :tag "open only comment blocks" comment)
6ef918297577 Update first-line description.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 38419
diff changeset
264 (const :tag "open both code and comment blocks" t)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
265 (const :tag "don't open any of them" nil))
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
266 :group 'hideshow)
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
267
19233
520a7d40d75c Correct the autoload cookies.
Richard M. Stallman <rms@gnu.org>
parents: 18867
diff changeset
268 ;;;###autoload
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
269 (defvar hs-special-modes-alist
105939
a0f778f4a995 * term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105275
diff changeset
270 (mapcar 'purecopy
104214
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
271 '((c-mode "{" "}" "/[*/]" nil nil)
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
272 (c++-mode "{" "}" "/[*/]" nil nil)
92216
f6fa050c615a * textmodes/bibtex.el: Remove support for hideshow minor mode as
Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
parents: 91912
diff changeset
273 (bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
104272
ea67ac46d172 * progmodes/js2-mode.el: File removed.
Chong Yidong <cyd@stupidchicken.com>
parents: 104214
diff changeset
274 (java-mode "{" "}" "/[*/]" nil nil)
105939
a0f778f4a995 * term/x-win.el (x-gtk-stock-map):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 105275
diff changeset
275 (js-mode "{" "}" "/[*/]" nil)))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
276 "*Alist for initializing the hideshow variables for different modes.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
277 Each element has the form
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
278 (MODE START END COMMENT-START FORWARD-SEXP-FUNC ADJUST-BEG-FUNC).
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
279
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
280 If non-nil, hideshow will use these values as regexps to define blocks
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
281 and comments, respectively for major mode MODE.
18867
b6e4c4c2a3ef (hs-special-modes-alist): Use a regexp generated by regexp-opt.
Richard M. Stallman <rms@gnu.org>
parents: 18428
diff changeset
282
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
283 START, END and COMMENT-START are regular expressions. A block is
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
284 defined as text surrounded by START and END.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
285
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
286 As a special case, START may be a list of the form (COMPLEX-START
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
287 MDATA-SELECTOR), where COMPLEX-START is a regexp w/ multiple parts and
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
288 MDATA-SELECTOR an integer that specifies which sub-match is the proper
52021
3e312ab8ce0d (hs-special-modes-alist): Clarify MDATA-SELECTOR doc; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 45320
diff changeset
289 place to adjust point, before calling `hs-forward-sexp-func'. Point
3e312ab8ce0d (hs-special-modes-alist): Clarify MDATA-SELECTOR doc; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 45320
diff changeset
290 is adjusted to the beginning of the specified match. For example,
3e312ab8ce0d (hs-special-modes-alist): Clarify MDATA-SELECTOR doc; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 45320
diff changeset
291 see the `hs-special-modes-alist' entry for `bibtex-mode'.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
292
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
293 For some major modes, `forward-sexp' does not work properly. In those
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
294 cases, FORWARD-SEXP-FUNC specifies another function to use instead.
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
295
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
296 See the documentation for `hs-adjust-block-beginning' to see what is the
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
297 use of ADJUST-BEG-FUNC.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
298
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
299 If any of the elements is left nil or omitted, hideshow tries to guess
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
300 appropriate values. The regexps should not contain leading or trailing
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
301 whitespace. Case does not matter.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
302
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
303 (defvar hs-hide-all-non-comment-function nil
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
304 "*Function called if non-nil when doing `hs-hide-all' for non-comments.")
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
305
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
306 (defvar hs-allow-nesting nil
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
307 "*If non-nil, hiding remembers internal blocks.
105275
b78ceb253d15 * speedbar.el (speedbar-item-delete):
Juanma Barranquero <lekktu@gmail.com>
parents: 105189
diff changeset
308 This means that when the outer block is shown again,
b78ceb253d15 * speedbar.el (speedbar-item-delete):
Juanma Barranquero <lekktu@gmail.com>
parents: 105189
diff changeset
309 any previously hidden internal blocks remain hidden.")
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
310
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
311 (defvar hs-hide-hook nil
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
312 "*Hook called (with `run-hooks') at the end of commands to hide text.
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
313 These commands include the toggling commands (when the result is to hide
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
314 a block), `hs-hide-all', `hs-hide-block' and `hs-hide-level'.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
315
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
316 (defvar hs-show-hook nil
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
317 "*Hook called (with `run-hooks') at the end of commands to show text.
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
318 These commands include the toggling commands (when the result is to show
105275
b78ceb253d15 * speedbar.el (speedbar-item-delete):
Juanma Barranquero <lekktu@gmail.com>
parents: 105189
diff changeset
319 a block), `hs-show-all' and `hs-show-block'.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
320
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
321 (defvar hs-set-up-overlay nil
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
322 "*Function called with one arg, OV, a newly initialized overlay.
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
323 Hideshow puts a unique overlay on each range of text to be hidden
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
324 in the buffer. Here is a simple example of how to use this variable:
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
325
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
326 (defun display-code-line-counts (ov)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
327 (when (eq 'code (overlay-get ov 'hs))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
328 (overlay-put ov 'display
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
329 (format \"... / %d\"
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
330 (count-lines (overlay-start ov)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
331 (overlay-end ov))))))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
332
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
333 (setq hs-set-up-overlay 'display-code-line-counts)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
334
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
335 This example shows how to get information from the overlay as well
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
336 as how to set its `display' property. See `hs-make-overlay' and
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
337 info node `(elisp)Overlays'.")
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
338
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
339 ;;---------------------------------------------------------------------------
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
340 ;; internal variables
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
341
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
342 (defvar hs-minor-mode nil
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
343 "Non-nil if using hideshow mode as a minor mode of some other mode.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
344 Use the command `hs-minor-mode' to toggle or set this variable.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
345
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
346 (defvar hs-minor-mode-map
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
347 (let ((map (make-sparse-keymap)))
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
348 ;; These bindings roughly imitate those used by Outline mode.
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
349 (define-key map "\C-c@\C-h" 'hs-hide-block)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
350 (define-key map "\C-c@\C-s" 'hs-show-block)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
351 (define-key map "\C-c@\C-\M-h" 'hs-hide-all)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
352 (define-key map "\C-c@\C-\M-s" 'hs-show-all)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
353 (define-key map "\C-c@\C-l" 'hs-hide-level)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
354 (define-key map "\C-c@\C-c" 'hs-toggle-hiding)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
355 (define-key map [(shift mouse-2)] 'hs-mouse-toggle-hiding)
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
356 map)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
357 "Keymap for hideshow minor mode.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
358
91912
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
359 (easy-menu-define hs-minor-mode-menu hs-minor-mode-map
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
360 "Menu used when hideshow minor mode is active."
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
361 '("Hide/Show"
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
362 ["Hide Block" hs-hide-block
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
363 :help "Hide the code or comment block at point"]
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
364 ["Show Block" hs-show-block
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
365 :help "Show the code or comment block at point"]
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
366 ["Hide All" hs-hide-all
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
367 :help "Hide all the blocks in the buffer"]
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
368 ["Show All" hs-show-all
92289
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
369 :help "Show all the blocks in the buffer"]
91912
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
370 ["Hide Level" hs-hide-level
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
371 :help "Hide all block at levels below the current block"]
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
372 ["Toggle Hiding" hs-toggle-hiding
92289
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
373 :help "Toggle the hiding state of the current block"]
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
374 "----"
105189
7669aca277d5 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
Juanma Barranquero <lekktu@gmail.com>
parents: 104272
diff changeset
375 ["Hide comments when hiding all"
92289
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
376 (setq hs-hide-comments-when-hiding-all
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
377 (not hs-hide-comments-when-hiding-all))
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
378 :help "If t also hide comment blocks when doing `hs-hide-all'"
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
379 :style toggle :selected hs-hide-comments-when-hiding-all]
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
380 ("Reveal on isearch"
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
381 ["Code blocks" (setq hs-isearch-open 'code)
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
382 :help "Show hidden code blocks when isearch matches inside them"
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
383 :active t :style radio :selected (eq hs-isearch-open 'code)]
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
384 ["Comment blocks" (setq hs-isearch-open 'comment)
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
385 :help "Show hidden comment blocks when isearch matches inside them"
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
386 :active t :style radio :selected (eq hs-isearch-open 'comment)]
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
387 ["Code and Comment blocks" (setq hs-isearch-open t)
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
388 :help "Show both hidden code and comment blocks when isearch matches inside them"
92312
8d89f150f3d7 (hs-minor-mode-menu): Compare `hs-isearch-open' with t instead of
Juri Linkov <juri@jurta.org>
parents: 92289
diff changeset
389 :active t :style radio :selected (eq hs-isearch-open t)]
92289
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
390 ["None" (setq hs-isearch-open nil)
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
391 :help "Do not hidden code or comment blocks when isearch matches inside them"
a60153302fa5 * progmodes/hideshow.el (hs-minor-mode-menu): Add some options to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 92216
diff changeset
392 :active t :style radio :selected (eq hs-isearch-open nil)])))
91912
b6212a3c659c (hs-minor-mode-map): Move menu creation to
Dan Nicolaescu <dann@ics.uci.edu>
parents: 91869
diff changeset
393
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
394 (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
395 "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
396 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
397 surrounding whitespace is stripped.")
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
398 (make-variable-buffer-local 'hs-c-start-regexp)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
399
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
400 (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
401 "Regexp for beginning of block.")
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
402 (make-variable-buffer-local 'hs-block-start-regexp)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
403
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
404 (defvar hs-block-start-mdata-select nil
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
405 "Element in `hs-block-start-regexp' match data to consider as block start.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
406 The internal function `hs-forward-sexp' moves point to the beginning of this
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
407 element (using `match-beginning') before calling `hs-forward-sexp-func'.")
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
408 (make-variable-buffer-local 'hs-block-start-mdata-select)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
409
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
410 (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
411 "Regexp for end of block.")
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
412
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
413 (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
414 "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
415 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
416 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
417 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
418 `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
419 function is necessary.")
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
420 (make-variable-buffer-local 'hs-forward-sexp-func)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
421
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
422 (defvar hs-adjust-block-beginning nil
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
423 "Function used to tweak the block beginning.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
424 The block is hidden from the position returned by this function,
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
425 as opposed to hiding it from the position returned when searching
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
426 for `hs-block-start-regexp'.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
427
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
428 For example, in c-like modes, if we wish to also hide the curly braces
44448
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38980
diff changeset
429 \(if you think they occupy too much space on the screen), this function
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
430 should return the starting point (at the end of line) of the hidden
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
431 region.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
432
45320
886037f6f545 (hs-adjust-block-beginning): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 44448
diff changeset
433 It is called with a single argument ARG which is the position in
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
434 buffer after the block beginning.
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
435
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
436 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
437
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
438 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
439
18093
1e53ce338e0d (hs-show-hidden-short-form): Updated doc string.
Richard M. Stallman <rms@gnu.org>
parents: 18070
diff changeset
440 See `hs-c-like-adjust-block-beginning' for an example of using this.")
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
441 (make-variable-buffer-local 'hs-adjust-block-beginning)
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
442
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
443 (defvar hs-headline nil
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
444 "Text of the line where a hidden block begins, set during isearch.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
445 You can display this in the mode line by adding the symbol `hs-headline'
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
446 to the variable `mode-line-format'. For example,
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
447
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
448 (unless (memq 'hs-headline mode-line-format)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
449 (setq mode-line-format
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
450 (append '(\"-\" hs-headline) mode-line-format)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
451
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
452 Note that `mode-line-format' is buffer-local.")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
453
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
454 ;;---------------------------------------------------------------------------
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
455 ;; support functions
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
456
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
457 (defun hs-discard-overlays (from to)
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
458 "Delete hideshow overlays in region defined by FROM and TO.
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
459 Skip \"internal\" overlays if `hs-allow-nesting' is non-nil."
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
460 (when (< to from)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
461 (setq from (prog1 to (setq to from))))
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
462 (if hs-allow-nesting
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
463 (let (ov)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
464 (while (> to (setq from (next-overlay-change from)))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
465 (when (setq ov (hs-overlay-at from))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
466 (setq from (overlay-end ov))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
467 (delete-overlay ov))))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
468 (dolist (ov (overlays-in from to))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
469 (when (overlay-get ov 'hs)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
470 (delete-overlay ov)))))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
471
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
472 (defun hs-make-overlay (b e kind &optional b-offset e-offset)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
473 "Return a new overlay in region defined by B and E with type KIND.
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
474 KIND is either `code' or `comment'. Optional fourth arg B-OFFSET
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
475 when added to B specifies the actual buffer position where the block
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
476 begins. Likewise for optional fifth arg E-OFFSET. If unspecified
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
477 they are taken to be 0 (zero). The following properties are set
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
478 in the overlay: 'invisible 'hs 'hs-b-offset 'hs-e-offset. Also,
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
479 depending on variable `hs-isearch-open', the following properties may
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
480 be present: 'isearch-open-invisible 'isearch-open-invisible-temporary.
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
481 If variable `hs-set-up-overlay' is non-nil it should specify a function
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
482 to call with the newly initialized overlay."
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
483 (unless b-offset (setq b-offset 0))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
484 (unless e-offset (setq e-offset 0))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
485 (let ((ov (make-overlay b e))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
486 (io (if (eq 'block hs-isearch-open)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
487 ;; backward compatibility -- `block'<=>`code'
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
488 'code
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
489 hs-isearch-open)))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
490 (overlay-put ov 'invisible 'hs)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
491 (overlay-put ov 'hs kind)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
492 (overlay-put ov 'hs-b-offset b-offset)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
493 (overlay-put ov 'hs-e-offset e-offset)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
494 (when (or (eq io t) (eq io kind))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
495 (overlay-put ov 'isearch-open-invisible 'hs-isearch-show)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
496 (overlay-put ov 'isearch-open-invisible-temporary
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
497 'hs-isearch-show-temporary))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
498 (when hs-set-up-overlay (funcall hs-set-up-overlay ov))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
499 ov))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
500
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
501 (defun hs-isearch-show (ov)
27029
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
502 "Delete overlay OV, and set `hs-headline' to nil.
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
503
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
504 This function is meant to be used as the `isearch-open-invisible'
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
505 property of an overlay."
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
506 (setq hs-headline nil)
27029
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
507 (delete-overlay ov))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
508
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
509 (defun hs-isearch-show-temporary (ov hide-p)
27029
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
510 "Hide or show overlay OV, and set `hs-headline', all depending on HIDE-P.
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
511 If HIDE-P is non-nil, `hs-headline' is set to nil and overlay OV is hidden.
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
512 Otherwise, `hs-headline' is set to the line of text at the head of OV, and
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
513 OV is shown.
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
514
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
515 This function is meant to be used as the `isearch-open-invisible-temporary'
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
516 property of an overlay."
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
517 (setq hs-headline
59079
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
518 (if hide-p
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
519 nil
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
520 (or hs-headline
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
521 (let ((start (overlay-start ov)))
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
522 (buffer-substring
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
523 (save-excursion (goto-char start)
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
524 (beginning-of-line)
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
525 (skip-chars-forward " \t")
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
526 (point))
5070d12d24ad Untabify, reindent; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59075
diff changeset
527 start)))))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
528 (force-mode-line-update)
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
529 ;; handle `display' property specially
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
530 (let (value)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
531 (if hide-p
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
532 (when (setq value (overlay-get ov 'hs-isearch-display))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
533 (overlay-put ov 'display value)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
534 (overlay-put ov 'hs-isearch-display nil))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
535 (when (setq value (overlay-get ov 'display))
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
536 (overlay-put ov 'hs-isearch-display value)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
537 (overlay-put ov 'display nil))))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
538 (overlay-put ov 'invisible (and hide-p 'hs)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
539
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
540 (defun hs-forward-sexp (match-data arg)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
541 "Adjust point based on MATCH-DATA and call `hs-forward-sexp-func' w/ ARG.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
542 Original match data is restored upon return."
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
543 (save-match-data
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
544 (set-match-data match-data)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
545 (goto-char (match-beginning hs-block-start-mdata-select))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
546 (funcall hs-forward-sexp-func arg)))
18237
69bb3a2c95b3 (hideshow): Added a :prefix.
Richard M. Stallman <rms@gnu.org>
parents: 18093
diff changeset
547
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
548 (defun hs-hide-comment-region (beg end &optional repos-end)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
549 "Hide a region from BEG to END, marking it as a comment.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
550 Optional arg REPOS-END means reposition at end."
81555
a0461babeddf (hs-hide-comment-region): Use line-end-position.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81554
diff changeset
551 (let ((beg-eol (progn (goto-char beg) (line-end-position)))
a0461babeddf (hs-hide-comment-region): Use line-end-position.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81554
diff changeset
552 (end-eol (progn (goto-char end) (line-end-position))))
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
553 (hs-discard-overlays beg-eol end-eol)
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
554 (hs-make-overlay beg-eol end-eol 'comment beg end))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
555 (goto-char (if repos-end end beg)))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
556
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
557 (defun hs-hide-block-at-point (&optional end comment-reg)
78487
419c5c316b51 Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78234
diff changeset
558 "Hide block if on block beginning.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
559 Optional arg END means reposition at end.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
560 Optional arg COMMENT-REG is a list of the form (BEGIN END) and
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
561 specifies the limits of the comment, or nil if the block is not
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
562 a comment.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
563
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
564 The block beginning is adjusted by `hs-adjust-block-beginning'
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
565 and then further adjusted to be at the end of the line."
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
566 (if comment-reg
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
567 (hs-hide-comment-region (car comment-reg) (cadr comment-reg) end)
52873
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
568 (when (looking-at hs-block-start-regexp)
82816
b5dbe2a97229 (hs-match-data): Delete alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 82365
diff changeset
569 (let* ((mdata (match-data t))
103737
f016828ad15e * progmodes/hideshow.el (hs-hide-block-at-point): Don't move point
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
570 (header-beg (match-beginning 0))
f016828ad15e * progmodes/hideshow.el (hs-hide-block-at-point): Don't move point
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
571 (header-end (match-end 0))
104214
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
572 p q ov)
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
573 ;; `p' is the point at the end of the block beginning, which
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
574 ;; may need to be adjusted
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
575 (save-excursion
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
576 (if hs-adjust-block-beginning
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
577 (goto-char (funcall hs-adjust-block-beginning
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
578 header-end))
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
579 (goto-char header-end))
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
580 (setq p (line-end-position)))
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
581 ;; `q' is the point at the end of the block
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
582 (hs-forward-sexp mdata 1)
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
583 (setq q (if (looking-back hs-block-end-regexp)
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
584 (match-beginning 0)
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
585 (point)))
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
586 (when (and (< p q) (> (count-lines p q) 1))
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
587 (cond ((and hs-allow-nesting (setq ov (hs-overlay-at p)))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
588 (delete-overlay ov))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
589 ((not hs-allow-nesting)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
590 (hs-discard-overlays p q)))
103737
f016828ad15e * progmodes/hideshow.el (hs-hide-block-at-point): Don't move point
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
591 (hs-make-overlay p q 'code (- header-end p)))
f016828ad15e * progmodes/hideshow.el (hs-hide-block-at-point): Don't move point
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
592 (goto-char (if end q (min p header-end)))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
593
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
594 (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
595 "Return non-nil if point is inside a comment, otherwise nil.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
596 Actually, return a list containing the buffer position of the start
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
597 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
598 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
599 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
600 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
601 as cdr."
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
602 (save-excursion
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
603 ;; 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
604 ;; 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
605 ;; 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
606 (let ((q (point)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
607 (when (or (looking-at hs-c-start-regexp)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
608 (re-search-backward hs-c-start-regexp (point-min) t))
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
609 ;; first get to the beginning of this comment...
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
610 (while (and (not (bobp))
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
611 (= (point) (progn (forward-comment -1) (point))))
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
612 (forward-char -1))
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
613 ;; ...then extend backwards
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
614 (forward-comment (- (buffer-size)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
615 (skip-chars-forward " \t\n\f")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
616 (let ((p (point))
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
617 (hidable t))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
618 (beginning-of-line)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
619 (unless (looking-at (concat "[ \t]*" hs-c-start-regexp))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
620 ;; we are in this situation: (example)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
621 ;; (defun bar ()
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
622 ;; (foo)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
623 ;; ) ; comment
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
624 ;; ^
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
625 ;; the point was here before doing (beginning-of-line)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
626 ;; here we should advance till the next comment which
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
627 ;; eventually has only white spaces preceding it on the same
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
628 ;; line
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
629 (goto-char p)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
630 (forward-comment 1)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
631 (skip-chars-forward " \t\n\f")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
632 (setq p (point))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
633 (while (and (< (point) q)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
634 (> (point) p)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
635 (not (looking-at hs-c-start-regexp)))
65500
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
636 ;; avoid an infinite cycle
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
637 (setq p (point))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
638 (forward-comment 1)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
639 (skip-chars-forward " \t\n\f"))
52873
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
640 (when (or (not (looking-at hs-c-start-regexp))
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
641 (> (point) q))
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
642 ;; we cannot hide this comment block
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
643 (setq hidable nil)))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
644 ;; goto the end of the comment
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
645 (forward-comment (buffer-size))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
646 (skip-chars-backward " \t\n\f")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
647 (end-of-line)
52873
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
648 (when (>= (point) q)
59075
b449e405ed0d (hs-inside-comment-p): Fix omission bug:
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52873
diff changeset
649 (list (and hidable p) (point))))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
650
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
651 (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
652 "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
653 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
654 current buffer's major mode, use that.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
655 Otherwise, guess start, end and `comment-start' regexps; `forward-sexp'
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
656 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
657 (if (and (boundp 'comment-start)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
658 (boundp 'comment-end)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
659 comment-start comment-end)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
660 (let* ((lookup (assoc major-mode hs-special-modes-alist))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
661 (start-elem (or (nth 1 lookup) "\\s(")))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
662 (if (listp start-elem)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
663 ;; handle (START-REGEXP MDATA-SELECT)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
664 (setq hs-block-start-regexp (car start-elem)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
665 hs-block-start-mdata-select (cadr start-elem))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
666 ;; backwards compatibility: handle simple START-REGEXP
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
667 (setq hs-block-start-regexp start-elem
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
668 hs-block-start-mdata-select 0))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
669 (setq hs-block-end-regexp (or (nth 2 lookup) "\\s)")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
670 hs-c-start-regexp (or (nth 3 lookup)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
671 (let ((c-start-regexp
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
672 (regexp-quote comment-start)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
673 (if (string-match " +$" c-start-regexp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
674 (substring c-start-regexp
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
675 0 (1- (match-end 0)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
676 c-start-regexp)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
677 hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
678 hs-adjust-block-beginning (nth 5 lookup)))
52873
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
679 (setq hs-minor-mode nil)
87567
4c3c683cdff8 * erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82816
diff changeset
680 (error "%s Mode doesn't support Hideshow Minor Mode"
4c3c683cdff8 * erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82816
diff changeset
681 (format-mode-line mode-name))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
682
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
683 (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
684 "Reposition point at block-start.
27029
4ad11069f66d (hs-minor-mode-menu): Fix omission bug; was used but not declared.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 26989
diff changeset
685 Return point, or nil if original point was not in a block."
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
686 (let ((done nil)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
687 (here (point)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
688 ;; look if current line is block start
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
689 (if (looking-at hs-block-start-regexp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
690 (point)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
691 ;; look backward for the start of a block that contains the cursor
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
692 (while (and (re-search-backward hs-block-start-regexp nil t)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
693 (not (setq done
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
694 (< here (save-excursion
82816
b5dbe2a97229 (hs-match-data): Delete alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 82365
diff changeset
695 (hs-forward-sexp (match-data t) 1)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
696 (point)))))))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
697 (if done
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
698 (point)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
699 (goto-char here)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
700 nil))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
701
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
702 (defun hs-hide-level-recursive (arg minp maxp)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
703 "Recursively hide blocks ARG levels below point in region (MINP MAXP)."
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
704 (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
705 (setq minp (1+ (point)))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
706 (funcall hs-forward-sexp-func 1)
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
707 (setq maxp (1- (point))))
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
708 (unless hs-allow-nesting
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
709 (hs-discard-overlays minp maxp))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
710 (goto-char minp)
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
711 (while (progn
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
712 (forward-comment (buffer-size))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
713 (and (< (point) maxp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
714 (re-search-forward hs-block-start-regexp maxp t)))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
715 (if (> arg 1)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
716 (hs-hide-level-recursive (1- arg) minp maxp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
717 (goto-char (match-beginning hs-block-start-mdata-select))
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
718 (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
719 (goto-char maxp))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
720
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
721 (defmacro hs-life-goes-on (&rest body)
78487
419c5c316b51 Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78234
diff changeset
722 "Evaluate BODY forms if variable `hs-minor-mode' is non-nil.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
723 In the dynamic context of this macro, `inhibit-point-motion-hooks'
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
724 and `case-fold-search' are both t."
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
725 `(when hs-minor-mode
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
726 (let ((inhibit-point-motion-hooks t)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
727 (case-fold-search t))
22109
3e53877b4a08 (hs-life-goes-on): Use Emacs' native backquote support.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20820
diff changeset
728 ,@body)))
3e53877b4a08 (hs-life-goes-on): Use Emacs' native backquote support.
Dan Nicolaescu <done@ece.arizona.edu>
parents: 20820
diff changeset
729
18867
b6e4c4c2a3ef (hs-special-modes-alist): Use a regexp generated by regexp-opt.
Richard M. Stallman <rms@gnu.org>
parents: 18428
diff changeset
730 (put 'hs-life-goes-on 'edebug-form-spec '(&rest form))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
731
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
732 (defun hs-overlay-at (position)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
733 "Return hideshow overlay at POSITION, or nil if none to be found."
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
734 (let ((overlays (overlays-at position))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
735 ov found)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
736 (while (and (not found) (setq ov (car overlays)))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
737 (setq found (and (overlay-get ov 'hs) ov)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
738 overlays (cdr overlays)))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
739 found))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
740
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
741 (defun hs-already-hidden-p ()
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
742 "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
743 (save-excursion
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
744 (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
745 (if (and c-reg (nth 0 c-reg))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
746 ;; point is inside a comment, and that comment is hidable
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
747 (goto-char (nth 0 c-reg))
81554
ed157fbce08b Untabify; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76845
diff changeset
748 (end-of-line)
52873
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
749 (when (and (not c-reg)
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
750 (hs-find-block-beginning)
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
751 (looking-at hs-block-start-regexp))
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
752 ;; point is inside a block
2f6d31064afd Rewrite one-armed `if'
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52666
diff changeset
753 (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
754 (end-of-line)
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
755 (hs-overlay-at (point))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
756
104214
0cec7dac5f50 * progmodes/hideshow.el (hs-special-modes-alist): Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 103737
diff changeset
757 ;; This function is not used anymore (Bug#700).
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
758 (defun hs-c-like-adjust-block-beginning (initial)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
759 "Adjust INITIAL, the buffer position after `hs-block-start-regexp'.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
760 Actually, point is never moved; a new position is returned that is
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
761 the end of the C-function header. This adjustment function is meant
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
762 to be assigned to `hs-adjust-block-beginning' for C-like modes."
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
763 (save-excursion
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
764 (goto-char (1- initial))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
765 (forward-comment (- (buffer-size)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
766 (point)))
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
767
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
768 ;;---------------------------------------------------------------------------
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
769 ;; commands
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
770
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
771 (defun hs-hide-all ()
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
772 "Hide all top level blocks, displaying only first and last lines.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
773 Move point to the beginning of the line, and run the normal hook
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
774 `hs-hide-hook'. See documentation for `run-hooks'.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
775 If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
776 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
777 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
778 (save-excursion
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
779 (unless hs-allow-nesting
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
780 (hs-discard-overlays (point-min) (point-max)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
781 (goto-char (point-min))
81557
8ee965d8fb17 (hs-hide-all): Use progress reporter.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81555
diff changeset
782 (let ((spew (make-progress-reporter "Hiding all blocks..."
8ee965d8fb17 (hs-hide-all): Use progress reporter.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81555
diff changeset
783 (point-min) (point-max)))
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
784 (re (concat "\\("
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
785 hs-block-start-regexp
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
786 "\\)"
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
787 (if hs-hide-comments-when-hiding-all
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
788 (concat "\\|\\("
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
789 hs-c-start-regexp
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
790 "\\)")
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
791 ""))))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
792 (while (progn
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
793 (unless hs-hide-comments-when-hiding-all
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
794 (forward-comment (point-max)))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
795 (re-search-forward re (point-max) t))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
796 (if (match-beginning 1)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
797 ;; we have found a block beginning
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
798 (progn
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
799 (goto-char (match-beginning 1))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
800 (if hs-hide-all-non-comment-function
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
801 (funcall hs-hide-all-non-comment-function)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
802 (hs-hide-block-at-point t)))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
803 ;; found a comment, probably
65500
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
804 (let ((c-reg (hs-inside-comment-p)))
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
805 (when (and c-reg (car c-reg))
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
806 (if (> (count-lines (car c-reg) (nth 1 c-reg)) 1)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
807 (hs-hide-block-at-point t c-reg)
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
808 (goto-char (nth 1 c-reg))))))
81557
8ee965d8fb17 (hs-hide-all): Use progress reporter.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81555
diff changeset
809 (progress-reporter-update spew (point)))
8ee965d8fb17 (hs-hide-all): Use progress reporter.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81555
diff changeset
810 (progress-reporter-done spew)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
811 (beginning-of-line)
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
812 (run-hooks 'hs-hide-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
813
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
814 (defun hs-show-all ()
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
815 "Show everything then run `hs-show-hook'. See `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
816 (interactive)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
817 (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
818 (message "Showing all blocks ...")
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
819 (let ((hs-allow-nesting nil))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
820 (hs-discard-overlays (point-min) (point-max)))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
821 (message "Showing all blocks ... done")
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
822 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
823
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
824 (defun hs-hide-block (&optional end)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
825 "Select a block and hide it. With prefix arg, reposition at END.
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
826 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
827 `hs-hide-hook' is run. See documentation for `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
828 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
829 (hs-life-goes-on
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
830 (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
831 (cond
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
832 ((and c-reg (or (null (nth 0 c-reg))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
833 (<= (count-lines (car c-reg) (nth 1 c-reg)) 1)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
834 (message "(not enough comment lines to hide)"))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
835 ((or c-reg
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
836 (looking-at hs-block-start-regexp)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
837 (hs-find-block-beginning))
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
838 (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
839 (run-hooks 'hs-hide-hook))))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
840
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
841 (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
842 "Select a block and show it.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
843 With prefix arg, reposition at END. Upon completion, point is
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
844 repositioned and the normal hook `hs-show-hook' is run.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
845 See documentation for functions `hs-hide-block' and `run-hooks'."
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
846 (interactive "P")
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
847 (hs-life-goes-on
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
848 (or
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
849 ;; first see if we have something at the end of the line
81555
a0461babeddf (hs-hide-comment-region): Use line-end-position.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 81554
diff changeset
850 (let ((ov (hs-overlay-at (line-end-position)))
65501
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
851 (here (point)))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
852 (when ov
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
853 (goto-char
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
854 (cond (end (overlay-end ov))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
855 ((eq 'comment (overlay-get ov 'hs)) here)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
856 (t (+ (overlay-start ov) (overlay-get ov 'hs-b-offset)))))
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
857 (delete-overlay ov)
156ab91245ad (hs-hide-comments-when-hiding-all): Remove autoload cookie.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65500
diff changeset
858 t))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
859 ;; not immediately obvious, look for a suitable block
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
860 (let ((c-reg (hs-inside-comment-p))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
861 p q)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
862 (cond (c-reg
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
863 (when (car c-reg)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
864 (setq p (car c-reg)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
865 q (cadr c-reg))))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
866 ((and (hs-find-block-beginning)
65500
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
867 ;; ugh, fresh match-data
4dd9bb8826e8 Comment munging; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64699
diff changeset
868 (looking-at hs-block-start-regexp))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
869 (setq p (point)
82816
b5dbe2a97229 (hs-match-data): Delete alias.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 82365
diff changeset
870 q (progn (hs-forward-sexp (match-data t) 1) (point)))))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
871 (when (and p q)
59086
e7bb1a144715 (hs-set-up-overlay): New user var.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 59080
diff changeset
872 (hs-discard-overlays p q)
105189
7669aca277d5 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
Juanma Barranquero <lekktu@gmail.com>
parents: 104272
diff changeset
873 (goto-char (if end q (1+ p))))))
7669aca277d5 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
Juanma Barranquero <lekktu@gmail.com>
parents: 104272
diff changeset
874 (run-hooks 'hs-show-hook)))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
875
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
876 (defun hs-hide-level (arg)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
877 "Hide all blocks ARG levels below this block.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
878 The hook `hs-hide-hook' is run; see `run-hooks'."
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
879 (interactive "p")
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
880 (hs-life-goes-on
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
881 (save-excursion
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
882 (message "Hiding blocks ...")
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
883 (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
884 (message "Hiding blocks ... done"))
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
885 (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
886
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
887 (defun hs-toggle-hiding ()
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
888 "Toggle hiding/showing of a block.
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
889 See `hs-hide-block' and `hs-show-block'."
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
890 (interactive)
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
891 (hs-life-goes-on
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
892 (if (hs-already-hidden-p)
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
893 (hs-show-block)
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
894 (hs-hide-block))))
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
895
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
896 (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
897 "Toggle hiding/showing of a block.
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
898 This command should be bound to a mouse key.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
899 Argument E is a mouse event used by `mouse-set-point'.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
900 See `hs-hide-block' and `hs-show-block'."
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
901 (interactive "@e")
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
902 (hs-life-goes-on
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
903 (mouse-set-point e)
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
904 (hs-toggle-hiding)))
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
905
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
906 (defun hs-hide-initial-comment-block ()
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
907 "Hide the first block of comments in a file.
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
908 This can be useful if you have huge RCS logs in those comments."
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
909 (interactive)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
910 (hs-life-goes-on
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
911 (let ((c-reg (save-excursion
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
912 (goto-char (point-min))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
913 (skip-chars-forward " \t\n\f")
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
914 (hs-inside-comment-p))))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
915 (when c-reg
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
916 (let ((beg (car c-reg)) (end (cadr c-reg)))
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
917 ;; see if we have enough comment lines to hide
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
918 (when (> (count-lines beg end) 1)
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
919 (hs-hide-comment-region beg end)))))))
17259
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
920
24a4fe3b0ae9 (hs-show-all, hs-safety-is-job-n): Fix messages.
Richard M. Stallman <rms@gnu.org>
parents: 16774
diff changeset
921 ;;;###autoload
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
922 (define-minor-mode hs-minor-mode
105189
7669aca277d5 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
Juanma Barranquero <lekktu@gmail.com>
parents: 104272
diff changeset
923 "Minor mode to selectively hide/show code and comment blocks.
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
924 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
925 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
926 The value '(hs . t) is added to `buffer-invisibility-spec'.
14151
1087acbd29d7 Many doc fixes.
Richard M. Stallman <rms@gnu.org>
parents: 13957
diff changeset
927
22444
977318751daa Require `easymenu'. Rework to use easymenu. Remove eol ws.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 22109
diff changeset
928 The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block',
31856
0a0adbc72d2f Update author email address.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 30429
diff changeset
929 `hs-show-block', `hs-hide-level' and `hs-toggle-hiding'. There is also
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
930 `hs-hide-initial-comment-block' and `hs-mouse-toggle-hiding'.
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
931
10841
88926963f1ae Clean up doc strings.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 10276
diff changeset
932 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
933 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
934
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
935 Lastly, the normal hook `hs-minor-mode-hook' is run using `run-hooks'.
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
936
18016
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
937 Key bindings:
22cbed2e6098 (hs-special-modes-alist): Include also the
Richard M. Stallman <rms@gnu.org>
parents: 17270
diff changeset
938 \\{hs-minor-mode-map}"
105189
7669aca277d5 * progmodes/hideshow.el (hs-show-block): Run `hs-show-hook'. (Bug#4548)
Juanma Barranquero <lekktu@gmail.com>
parents: 104272
diff changeset
939 :group 'hideshow
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
940 :lighter " hs"
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
941 :keymap hs-minor-mode-map
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
942 (setq hs-headline nil)
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
943 (if hs-minor-mode
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
944 (progn
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
945 (hs-grok-mode-type)
76314
a91ba205af7e (hs-minor-mode): Turn mode off and show all when switching major mode.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
946 ;; Turn off this mode if we change major modes.
81554
ed157fbce08b Untabify; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76845
diff changeset
947 (add-hook 'change-major-mode-hook
ed157fbce08b Untabify; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76845
diff changeset
948 'turn-off-hideshow
ed157fbce08b Untabify; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 76845
diff changeset
949 nil t)
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
950 (easy-menu-add hs-minor-mode-menu)
38419
6dd037b0146e (hs-minor-mode): Use make-local-variable.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38193
diff changeset
951 (set (make-local-variable 'line-move-ignore-invisible) t)
27771
9d04cc14a320 (hs-flag-region): No longer use `intangible' overlay property.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 27183
diff changeset
952 (add-to-invisibility-spec '(hs . t)))
76314
a91ba205af7e (hs-minor-mode): Turn mode off and show all when switching major mode.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
953 (remove-from-invisibility-spec '(hs . t))
a91ba205af7e (hs-minor-mode): Turn mode off and show all when switching major mode.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
954 ;; hs-show-all does nothing unless h-m-m is non-nil.
a91ba205af7e (hs-minor-mode): Turn mode off and show all when switching major mode.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
955 (let ((hs-minor-mode t))
91869
3952f2dc0abc Remove the minor-mode bookkeeping. Move
Dan Nicolaescu <dann@ics.uci.edu>
parents: 87567
diff changeset
956 (hs-show-all))))
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
957
76844
ab61d371ed56 (turn-off-hideshow): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 76314
diff changeset
958 ;;;###autoload
ab61d371ed56 (turn-off-hideshow): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 76314
diff changeset
959 (defun turn-off-hideshow ()
76845
638ed5cc0e55 (turn-off-hideshow): Tweak docstring.
Chong Yidong <cyd@stupidchicken.com>
parents: 76844
diff changeset
960 "Unconditionally turn off `hs-minor-mode'."
76844
ab61d371ed56 (turn-off-hideshow): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 76314
diff changeset
961 (hs-minor-mode -1))
ab61d371ed56 (turn-off-hideshow): New function.
Chong Yidong <cyd@stupidchicken.com>
parents: 76314
diff changeset
962
26989
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
963 ;;---------------------------------------------------------------------------
340ed24f202a Generally, synch w/ maintainer version 5.9.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 23368
diff changeset
964 ;; that's it
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
965
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
966 (provide 'hideshow)
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
967
87567
4c3c683cdff8 * erc-ibuffer.el (erc-channel-modes):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 82816
diff changeset
968 ;; arch-tag: 378b6852-e82a-466a-aee8-d9c73859a65e
10276
86c61b6bd265 Initial revision
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
diff changeset
969 ;;; hideshow.el ends here