1 ;;; hideshow.el --- minor mode cmds to selectively display blocks of code
3 ;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation
5 ;; Author: Thien-Thi Nguyen <ttn@netcom.com>
6 ;; Maintainer: Dan Nicolaescu <done@ece.arizona.edu>
8 ;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
9 ;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
29 ;; hideshow|Thien-Thi Nguyen|ttn@netcom.com|
30 ;; minor mode commands to selectively display blocks of code|
31 ;; 18-Oct-1994|3.4|~/modes/hideshow.el.Z|
35 ;; This file provides `hs-minor-mode'. When active, six commands:
36 ;; hs-{hide,show}-{all,block}, hs-show-region and hs-minor-mode
37 ;; are available. They implement block hiding and showing. Blocks are
38 ;; defined in mode-specific way. In c-mode or c++-mode, they are simply
39 ;; curly braces, while in lisp-ish modes they are parens. Multi-line
40 ;; comments (c-mode) can also be hidden. The command M-x hs-minor-mode
41 ;; toggles the minor mode or sets it (similar to outline minor mode).
42 ;; See documentation for each command for more info.
44 ;; The variable `hs-unbalance-handler-method' controls hideshow's behavior
45 ;; in the case of "unbalanced parentheses". See doc for more info.
49 ;; (load-library "hideshow")
50 ;; (add-hook 'X-mode-hook 'hs-minor-mode) ; other modes similarly
52 ;; where X = {emacs-lisp,c,c++,perl,...}. See the doc for the variable
53 ;; `hs-special-modes-alist' if you'd like to use hideshow w/ other modes.
57 ;; Bug reports and fixes welcome (comments, too). Thanks go to
58 ;; Dean Andrews <adahome@ix.netcom.com>
59 ;; Preston F. Crow <preston.f.crow@dartmouth.edu>
60 ;; Gael Marziou <gael@gnlab030.grenoble.hp.com>
61 ;; Keith Sheffield <sheff@edcsgw2.cr.usgs.gov>
62 ;; Jan Djarv <jan.djarv@sa.erisoft.se>
63 ;; Lars Lindberg <qhslali@aom.ericsson.se>
64 ;; Alf-Ivar Holm <alfh@ifi.uio.no>
65 ;; for valuable feedback, code and bug reports.
70 ;;;----------------------------------------------------------------------------
71 ;;; user-configurable variables
73 (defgroup hideshow nil
74 "Minor mode for hiding and showing program and comment blocks."
79 (defcustom hs-hide-comments-when-hiding-all t
80 "Hide the comments too when you do an `hs-hide-all'."
85 (defcustom hs-show-hidden-short-form t
86 "Leave only the first line visible in a hidden block.
87 If t only the first line is visible when a block is in the hidden state,
88 else both the first line and the last line are showed. Also if t and
89 `hs-adjust-block-beginning' is set, it is used also.
91 An example of how this works: (in c-mode)
95 some more stuff about main
105 hidden and hs-show-hidden-short-form is nil
106 /* My function main...
113 hidden and hs-show-hidden-short-form is t
114 /* My function main...
118 For latest you have to be on the line containing the ellipsis when
119 you do `hs-show-block'."
123 (defcustom hs-minor-mode-hook 'hs-hide-initial-comment-block
124 "Hook called when `hs-minor-mode' is installed.
125 A good value for this would be `hs-hide-initial-comment-block' to
126 hide all the comments at the beginning of the file."
130 (defcustom hs-isearch-open 'block
131 "What kind of hidden blocks to open when doing `isearch'.
132 It can have the following values:
133 `block' open only blocks
134 `comment' open only comments
137 This only has effect iff `search-invisible' is set to `open'."
138 :type '(choice (const :tag "open only blocks" block)
139 (const :tag "open only comments" comment)
140 (const :tag "open both blocks and comments" t)
141 (const :tag "don't open any of them" nil))
144 (defvar hs-unbalance-handler-method 'top-level
145 "*Symbol representing how \"unbalanced parentheses\" should be handled.
146 This error is usually signaled by `hs-show-block'. One of four values:
147 `top-level', `next-line', `signal' or `ignore'. Default is `top-level'.
149 - `top-level' -- Show top-level block containing the currently troublesome
151 - `next-line' -- Use the fact that, for an already hidden block, its end
152 will be on the next line. Attempt to show this block.
153 - `signal' -- Pass the error through, stopping execution.
154 - `ignore' -- Ignore the error, continuing execution.
156 Values other than these four will be interpreted as `signal'.")
159 (defvar hs-special-modes-alist
160 '((c-mode "{" "}" nil nil hs-c-like-adjust-block-beginning)
161 (c++-mode "{" "}" "/[*/]" nil hs-c-like-adjust-block-beginning)
162 (java-mode "\\(\\(\\([ \t]*\\(\\(public\\|private\\|protected\\|abstract\\|static\\|\\final\\)[ \t\n]+\\)+\\(synchronized[ \t\n]*\\)?[a-zA-Z0-9_:]+[ \t\n]*\\(\\[[ \t\n]*\\][ \t\n]*\\)?\\([a-zA-Z0-9_:]+[ \t\n]*\\)([^)]*)\\([ \n\t]+throws[ \t\n][^{]+\\)?\\)\\|\\([ \t]*static[^{]*\\)\\)[ \t\n]*{\\)" "}" "/[*/]" java-hs-forward-sexp hs-c-like-adjust-block-beginning))
163 ; I tested the java regexp using the following:
165 ;(defvar hsj-syncronised)
172 ;(setq hsj-public "[ \t]*\\(\\(public\\|private\\|protected\\|abstract\\|static\\|\\final\\)[ \t\n]+\\)+")
173 ;(setq hsj-syncronised "\\(synchronized[ \t\n]*\\)?")
174 ;(setq hsj-type "[a-zA-Z0-9_:]+[ \t\n]*\\(\\[[ \t\n]*\\][ \t\n]*\\)?")
175 ;(setq hsj-fname "\\([a-zA-Z0-9_:]+[ \t\n]*\\)")
176 ;(setq hsj-par "([^)]*)")
177 ;(setq hsj-throws "\\([ \n\t]+throws[ \t\n][^{]+\\)?")
179 ;(setq hsj-static "[ \t]*static[^{]*")
182 ;(setq hs-block-start-regexp (concat
202 "*Alist for initializing the hideshow variables for different modes.
204 (MODE START-RE END-RE COMMENT-START-RE FORWARD-SEXP-FUNC ADJUST-BEG-FUNC).
205 If present, hideshow will use these values for the start and end regexps,
206 respectively. Since Algol-ish languages do not have single-character
207 block delimiters, the function `forward-sexp' which is used by hideshow
208 doesn't work. In this case, if a similar function is provided, you can
209 register it and have hideshow use it instead of `forward-sexp'. To add
212 \t(pushnew '(new-mode st-re end-re function-name)
213 \t hs-special-modes-alist :test 'equal)
217 \t(pushnew '(simula-mode \"begin\" \"end\" \"!\" simula-next-statement)
218 \t hs-special-modes-alist :test 'equal)
220 See the documentation for `hs-adjust-block-beginning' to see what
221 is the use of ADJUST-BEG-FUNC.
223 If any of those is left nil, hideshow will try to guess some values, see
224 `hs-grok-mode-type' for this.
226 Note that the regexps should not contain leading or trailing whitespace.")
228 (defvar hs-hide-hook nil
229 "*Hooks called at the end of `hs-hide-all' and `hs-hide-block'.")
231 (defvar hs-show-hook nil
232 "*Hooks called at the end of commands to show text.
233 These commands include `hs-show-all', `hs-show-block' and `hs-show-region'.")
235 (defvar hs-minor-mode-prefix "\C-c"
236 "*Prefix key to use for hideshow commands in hideshow minor mode.")
238 ;;;----------------------------------------------------------------------------
239 ;;; internal variables
241 (defvar hs-minor-mode nil
242 "Non-nil if using hideshow mode as a minor mode of some other mode.
243 Use the command `hs-minor-mode' to toggle this variable.")
245 (defvar hs-minor-mode-map nil
246 "Mode map for hideshow minor mode.")
248 ;(defvar hs-menu-bar nil
249 ; "Menu bar for hideshow minor mode (Xemacs only).")
251 (defvar hs-c-start-regexp nil
252 "Regexp for beginning of comments.
253 Differs from mode-specific comment regexps in that
254 surrounding whitespace is stripped.")
256 (defvar hs-block-start-regexp nil
257 "Regexp for beginning of block.")
259 (defvar hs-block-end-regexp nil
260 "Regexp for end of block.")
262 (defvar hs-forward-sexp-func 'forward-sexp
263 "Function used to do a forward-sexp.
264 Should change for Algol-ish modes. For single-character block
265 delimiters -- ie, the syntax table regexp for the character is
266 either `(' or `)' -- `hs-forward-sexp-func' would just be `forward-sexp'.
267 For other modes such as simula, a more specialized function
270 (defvar hs-adjust-block-beginning nil
271 "Function used to tweak the block beginning.
272 It has effect only if `hs-show-hidden-short-form' is t. The block it
273 is hidden from the point returned by this function, as opposed to
274 hiding it from the point returned when searching
275 `hs-block-start-regexp'. In c-like modes, if we wish to also hide the
276 curly braces (if you think they occupy too much space on the screen),
277 this function should return the starting point (at the end of line) of
280 It is called with a single argument ARG which is the the position in
281 buffer after the block beginning.
283 It should return the position from where we should start hiding.
285 It should not move the point.
287 See `hs-c-like-adjust-block-beginning' for an example of using this.")
289 ;(defvar hs-emacs-type 'fsf
290 ; "Used to support both Emacs and Xemacs.")
293 ; (if (string-match "xemacs\\|lucid" emacs-version)
295 ; (defvar current-menubar nil "")
296 ; (defun set-buffer-menubar (arg1))
297 ; (defun add-menu (arg1 arg2 arg3)))))
299 ;;;----------------------------------------------------------------------------
302 ;; snarfed from outline.el;
303 (defun hs-flag-region (from to flag)
304 "Hides or shows lines from FROM to TO, according to FLAG. If FLAG
305 is nil then text is shown, while if FLAG is non-nil the text is
306 hidden. Actualy flag is realy either `comment' or `block' depending on
307 what kind of block it is suppose to hide."
311 (hs-discard-overlays (point) to 'invisible 'hs)
313 (let ((overlay (make-overlay (point) to)))
314 ;; Make overlay hidden and intangible.
315 (overlay-put overlay 'invisible 'hs)
316 (overlay-put overlay 'hs t)
317 (when (or (eq hs-isearch-open t) (eq hs-isearch-open flag))
318 (overlay-put overlay 'isearch-open-invisible
319 'hs-isearch-open-invisible))
320 (overlay-put overlay 'intangible t)))))
322 ;; This is set as an `isearch-open-invisible' property to hidden
324 (defun hs-isearch-open-invisible (ov)
326 (goto-char (overlay-start ov))
329 ;; Remove from the region BEG ... END all overlays
330 ;; with a PROP property equal to VALUE.
331 ;; Overlays with a PROP property different from VALUE are not touched.
332 (defun hs-discard-overlays (beg end prop value)
334 (setq beg (prog1 end (setq end beg))))
337 (let ((overlays (overlays-in beg end))
340 (setq o (car overlays))
341 (if (eq (overlay-get o prop) value)
343 (setq overlays (cdr overlays))))))
345 (defun hs-hide-block-at-point (&optional end comment-reg)
346 "Hide block iff on block beginning, optional END means reposition at end.
347 COMMENT-REG is a list of the form (BEGIN . END) and specifies the limits
348 of the comment, or nil if the block is not a comment."
351 ;; goto the end of line at the end of the comment
352 (goto-char (nth 1 comment-reg))
353 (unless hs-show-hidden-short-form (forward-line -1))
355 (hs-flag-region (car comment-reg) (point) 'comment)
356 (goto-char (if end (nth 1 comment-reg) (car comment-reg))))
357 (if (looking-at hs-block-start-regexp)
358 (let* ((p ;; p is the point at the end of the block beginning
359 (if (and hs-show-hidden-short-form
360 hs-adjust-block-beginning)
361 ;; we need to adjust the block beginning
362 (funcall hs-adjust-block-beginning (match-end 0))
364 ;; q is the point at the end of the block
365 (q (progn (funcall hs-forward-sexp-func 1) (point))))
366 ;; position the point so we can call `hs-flag-region'
367 (unless hs-show-hidden-short-form (forward-line -1))
369 (if (and (< p (point)) (> (count-lines p q)
370 (if hs-show-hidden-short-form 1 2)))
371 (hs-flag-region p (point) 'block))
372 (goto-char (if end q p))))))
374 (defun hs-show-block-at-point (&optional end comment-reg)
375 "Show block iff on block beginning. Optional END means reposition at end.
376 COMMENT-REG is a list of the forme (BEGIN . END) and specifies the limits
377 of the comment. It should be nil when hiding a block."
379 (when (car comment-reg)
380 (hs-flag-region (car comment-reg) (nth 1 comment-reg) nil)
381 (goto-char (if end (nth 1 comment-reg) (car comment-reg))))
382 (if (looking-at hs-block-start-regexp)
385 (condition-case error ; probably unbalanced paren
387 (funcall hs-forward-sexp-func 1)
391 ((eq hs-unbalance-handler-method 'ignore)
392 ;; just ignore this block
394 ((eq hs-unbalance-handler-method 'top-level)
395 ;; try to get out of rat's nest and expose the whole func
396 (if (/= (current-column) 0) (beginning-of-defun))
398 (re-search-forward (concat "^" hs-block-start-regexp)
401 ((eq hs-unbalance-handler-method 'next-line)
402 ;; assumption is that user knows what s/he's doing
403 (beginning-of-line) (setq p (point))
404 (end-of-line 2) (point))
406 ;; pass error through -- this applies to `signal', too
407 (signal (car error) (cdr error))))))))
408 (hs-flag-region p q nil)
409 (goto-char (if end (1+ (point)) p))))))
411 (defun hs-safety-is-job-n ()
412 "Warn `buffer-invisibility-spec' does not contain hs."
413 (if (or buffer-invisibility-spec (assq 'hs buffer-invisibility-spec) )
415 (message "Warning: `buffer-invisibility-spec' does not contain hs!!")
418 (defun hs-hide-initial-comment-block ()
420 "Hides the first block of comments in a file.
421 The best usage is in `hs-minor-mode-hook', it hides all the comments at the
422 file beginning, so if you have huge RCS logs you won't see them!"
425 (goto-char (point-min))
426 (skip-chars-forward " \t\n^L")
427 (setq c-reg (hs-inside-comment-p))
428 ;; see if we have enough comment lines to hide
429 (if (and c-reg (> (count-lines (car c-reg) (nth 1 c-reg))
430 (if hs-show-hidden-short-form 1 2)))
434 (defun hs-inside-comment-p ()
435 "Returns non-nil if point is inside a comment, otherwise nil.
436 Actually, returns a list containing the buffer position of the start
437 and the end of the comment. A comment block can be hided only if on its
438 starting line there are only white spaces preceding the actual comment
439 beginning, if we are inside of a comment but this condition is not
440 we return a list having a nil as its car and the end of comment position
443 ;; the idea is to look backwards for a comment start regexp, do a
444 ;; forward comment, and see if we are inside, then extend extend
445 ;; forward and backward as long as we have comments
447 (when (or (looking-at hs-c-start-regexp)
448 (re-search-backward hs-c-start-regexp (point-min) t))
449 (forward-comment (- (buffer-size)))
450 (skip-chars-forward " \t\n
\f")
454 (unless (looking-at (concat "[ \t]*" hs-c-start-regexp))
455 ;; we are in this situation: (example)
460 ;; the point was here before doing (beginning-of-line)
461 ;; here we should advance till the next comment which
462 ;; eventually has only white spaces preceding it on the same
466 (skip-chars-forward " \t\n
\f")
468 (while (and (< (point) q)
470 (not (looking-at hs-c-start-regexp)))
471 (setq p (point)) ;; use this to avoid an infinit cycle.
473 (skip-chars-forward " \t\n
\f"))
474 (if (or (not (looking-at hs-c-start-regexp))
476 ;; we cannot hide this comment block
477 (setq not-hidable t)))
478 ;; goto the end of the comment
479 (forward-comment (buffer-size))
480 (skip-chars-backward " \t\n
\f")
483 (list (if not-hidable nil p) (point))))))))
485 (defun hs-grok-mode-type ()
486 "Setup variables for new buffers where applicable."
487 (when (and (boundp 'comment-start)
488 (boundp 'comment-end))
489 (let ((lookup (assoc major-mode hs-special-modes-alist)))
490 (setq hs-block-start-regexp (or (nth 1 lookup) "\\s\(")
491 hs-block-end-regexp (or (nth 2 lookup) "\\s\)")
492 hs-c-start-regexp (or (nth 3 lookup)
493 (let ((c-start-regexp
494 (regexp-quote comment-start)))
495 (if (string-match " +$" c-start-regexp)
496 (substring c-start-regexp 0 (1- (match-end 0)))
498 hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
499 hs-adjust-block-beginning (nth 5 lookup)))))
501 (defun hs-find-block-beginning ()
502 "Repositions point at block-start.
503 Return point, or nil if top-level."
507 (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\("
508 hs-block-end-regexp "\\)"))
509 (buf-size (buffer-size)))
511 ;; A block beginning can span on multiple lines, if the point
512 ;; is on one of those lines, trying a regexp search from
513 ;; that point would fail to find the block beginning, so we look
514 ;; backwards for the block beginning, or a block end.
517 (if (and (re-search-backward both-regexps (point-min) t)
518 (match-beginning 1)) ; found a block beginning
519 (if (save-match-data (hs-inside-comment-p))
520 ;;but it was inside a comment, so we have to look for
523 ;; that's what we were looking for
524 (setq done (match-beginning 0)))
525 ;; we found a block end, or we reached the beginning of the
526 ;; buffer look to see if we were on a block beginning when we
529 (re-search-forward hs-block-start-regexp (point-max) t)
531 (and (>= here (match-beginning 0)) (< here (match-end 0)))
532 (and hs-show-hidden-short-form hs-adjust-block-beginning
535 (funcall hs-adjust-block-beginning
536 (match-end 0)) here))))))
537 (setq done (match-beginning 0)))))
539 (while (and (not done)
540 ;; This had problems because the regexp can match something
541 ;; inside of a comment!
542 ;; Since inside a comment we can have incomplete sexps
543 ;; this would have signaled an error.
544 (or (forward-comment (- buf-size)) t); `or' is a hack to
546 (re-search-backward both-regexps (point-min) t))
547 (if (match-beginning 1) ; start of start-regexp
548 (setq done (match-beginning 0))
549 (goto-char (match-end 0)) ; end of end-regexp
550 (funcall hs-forward-sexp-func -1)))
551 (goto-char (or done here))
554 (defmacro hs-life-goes-on (&rest body)
555 "Executes optional BODY iff variable `hs-minor-mode' is non-nil."
556 (list 'if 'hs-minor-mode (cons 'progn body)))
558 (defun hs-already-hidden-p ()
559 "Return non-nil if point is in an already-hidden block, otherwise nil."
561 (let ((c-reg (hs-inside-comment-p)))
562 (if (and c-reg (nth 0 c-reg))
563 ;; point is inside a comment, and that comment is hidable
564 (goto-char (nth 0 c-reg))
565 (if (and (not c-reg) (hs-find-block-beginning)
566 (looking-at hs-block-start-regexp))
567 ;; point is inside a block
568 (goto-char (match-end 0)))))
570 (let ((overlays (overlays-at (point)))
572 (while (and (not found) (overlayp (car overlays)))
573 (setq found (overlay-get (car overlays) 'hs)
574 overlays (cdr overlays)))
577 (defun java-hs-forward-sexp (arg)
578 "Function used by `hs-minor-mode' for `forward-sexp' in Java mode."
581 (if (looking-at hs-block-start-regexp)
583 (goto-char (match-end 0))
588 (defun hs-c-like-adjust-block-beginning (arg)
589 "Function to be assigned to `hs-adjust-block-beginning' for C like modes.
590 Arg is a position in buffer just after {. This goes back to the end of
591 the function header. The purpose is to save some space on the screen
592 when displaying hidden blocks."
596 (forward-comment (- (buffer-size)))
599 ;;;----------------------------------------------------------------------------
603 (defun hs-hide-all ()
604 "Hides all top-level blocks, displaying only first and last lines.
605 It moves point to the beginning of the line, and it runs the normal hook
606 `hs-hide-hook'. See documentation for `run-hooks'.
607 If `hs-hide-comments-when-hiding-all' is t also hides the comments."
610 (message "Hiding all blocks ...")
612 (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness
613 (goto-char (point-min))
614 (if hs-hide-comments-when-hiding-all
617 (block-and-comment-re ;; this should match
618 (concat "\\(^" ;; the block beginning and comment start
619 hs-block-start-regexp
620 "\\)\\|\\(" hs-c-start-regexp "\\)")))
621 (while (re-search-forward block-and-comment-re (point-max) t)
622 (if (match-beginning 1) ;; we have found a block beginning
624 (goto-char (match-beginning 1))
625 (hs-hide-block-at-point t)
626 (message "Hiding ... %d" (setq count (1+ count))))
628 (setq c-reg (hs-inside-comment-p))
629 (if (and c-reg (car c-reg))
630 (if (> (count-lines (car c-reg) (nth 1 c-reg))
631 (if hs-show-hidden-short-form 1 2))
633 (hs-hide-block-at-point t c-reg)
634 (message "Hiding ... %d" (setq count (1+ count))))
635 (goto-char (nth 1 c-reg)))))))
637 (top-level-re (concat "^" hs-block-start-regexp))
638 (buf-size (buffer-size)))
641 (forward-comment buf-size)
642 (re-search-forward top-level-re (point-max) t))
643 (goto-char (match-beginning 0))
644 (hs-hide-block-at-point t)
645 (message "Hiding ... %d" (setq count (1+ count))))))
646 (hs-safety-is-job-n))
648 (message "Hiding all blocks ... done")
649 (run-hooks 'hs-hide-hook)))
651 (defun hs-show-all ()
652 "Shows all top-level blocks.
653 This does not change point; it runs the normal hook `hs-show-hook'.
654 See documentation for `run-hooks'."
657 (message "Showing all blocks ...")
658 (hs-flag-region (point-min) (point-max) nil)
659 (message "Showing all blocks ... done")
660 (run-hooks 'hs-show-hook)))
662 (defun hs-hide-block (&optional end)
663 "Selects a block and hides it.
664 With prefix arg, reposition at end. Block is defined as a sexp for
665 lispish modes, mode-specific otherwise. Comments are blocks, too.
666 Upon completion, point is at repositioned and the normal hook
667 `hs-hide-hook' is run. See documentation for `run-hooks'."
670 (let ((c-reg (hs-inside-comment-p)))
672 ((and c-reg (or (null (nth 0 c-reg))
673 (<= (count-lines (car c-reg) (nth 1 c-reg))
674 (if hs-show-hidden-short-form 1 2))))
675 (message "Not enough comment lines to hide!"))
676 ((or c-reg (looking-at hs-block-start-regexp)
677 (hs-find-block-beginning))
678 (hs-hide-block-at-point end c-reg)
680 (run-hooks 'hs-hide-hook))))))
682 (defun hs-show-block (&optional end)
683 "Selects a block and shows it.
684 With prefix arg, reposition at end. Upon completion, point is
685 repositioned and the normal hook `hs-show-hook' is run.
686 See documentation for `hs-hide-block' and `run-hooks'."
689 (let ((c-reg (hs-inside-comment-p)))
691 (looking-at hs-block-start-regexp)
692 (hs-find-block-beginning))
694 (hs-show-block-at-point end c-reg)
696 (run-hooks 'hs-show-hook))))))
698 (defun hs-show-region (beg end)
699 "Shows all lines from BEG to END, without doing any block analysis.
700 Note:`hs-show-region' is intended for use when `hs-show-block' signals
701 `unbalanced parentheses' and so is an emergency measure only. You may
702 become very confused if you use this command indiscriminately."
705 (hs-flag-region beg end nil)
707 (run-hooks 'hs-show-hook)))
710 (defun hs-mouse-toggle-hiding (e)
711 "Toggles hiding/showing of a block.
712 Should be bound to a mouse key."
715 (if (hs-already-hidden-p)
720 (defun hs-minor-mode (&optional arg)
721 "Toggle hideshow minor mode.
722 With ARG, turn hideshow minor mode on if ARG is positive, off otherwise.
723 When hideshow minor mode is on, the menu bar is augmented with hideshow
724 commands and the hideshow commands are enabled.
725 The value '(hs . t) is added to `buffer-invisibility-spec'.
726 Last, the normal hook `hs-minor-mode-hook' is run; see the doc
729 The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block'
731 Also see the documentation for the variable `hs-show-hidden-short-form'.
733 Turning hideshow minor mode off reverts the menu bar and the
734 variables to default values and disables the hideshow commands.
737 \\{hs-minor-mode-map}"
743 (> (prefix-numeric-value arg) 0)))
746 ; (if (eq hs-emacs-type 'lucid)
748 ; (set-buffer-menubar (copy-sequence current-menubar))
749 ; (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar))))
750 (make-variable-buffer-local 'line-move-ignore-invisible)
751 (setq line-move-ignore-invisible t)
752 (add-to-invisibility-spec '(hs . t)) ;;hs invisible
754 (run-hooks 'hs-minor-mode-hook))
755 ; (if (eq hs-emacs-type 'lucid)
756 ; (set-buffer-menubar (delete hs-menu-bar current-menubar)))
757 (remove-from-invisibility-spec '(hs . t))))
760 ;;;----------------------------------------------------------------------------
761 ;;; load-time setup routines
763 ;; which emacs being used?
765 ; (if (string-match "xemacs\\|lucid" emacs-version)
770 (if hs-minor-mode-map
772 (setq hs-minor-mode-map (make-sparse-keymap))
773 ;; I beleive there is nothing bound on this keys
774 (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block)
775 (define-key hs-minor-mode-map "\C-cs" 'hs-show-block)
776 (define-key hs-minor-mode-map "\C-cH" 'hs-hide-all)
777 (define-key hs-minor-mode-map "\C-cS" 'hs-show-all)
778 (define-key hs-minor-mode-map "\C-cR" 'hs-show-region)
780 (define-key hs-minor-mode-map [S-mouse-2] 'hs-mouse-toggle-hiding)
782 ;; should we use easymenu here?
783 (define-key hs-minor-mode-map [menu-bar Hide/Show]
784 (cons "Hide/Show" (make-sparse-keymap "Hide/Show")))
785 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-region]
786 '("Show Region" . hs-show-region))
787 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-all]
788 '("Show All" . hs-show-all))
789 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-hide-all]
790 '("Hide All" . hs-hide-all))
791 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-show-block]
792 '("Show Block" . hs-show-block))
793 (define-key hs-minor-mode-map [menu-bar Hide/Show hs-hide-block]
794 '("Hide Block" . hs-hide-block)))
797 (or (assq 'hs-minor-mode minor-mode-map-alist)
798 (setq minor-mode-map-alist
799 (cons (cons 'hs-minor-mode hs-minor-mode-map)
800 minor-mode-map-alist)))
801 (or (assq 'hs-minor-mode minor-mode-alist)
802 (setq minor-mode-alist (append minor-mode-alist
803 (list '(hs-minor-mode " hs")))))
805 ;; make some variables buffer-local
806 (make-variable-buffer-local 'hs-minor-mode)
807 (make-variable-buffer-local 'hs-c-start-regexp)
808 (make-variable-buffer-local 'hs-block-start-regexp)
809 (make-variable-buffer-local 'hs-block-end-regexp)
810 (make-variable-buffer-local 'hs-forward-sexp-func)
811 (make-variable-buffer-local 'hs-adjust-block-beginning)
812 (put 'hs-minor-mode 'permanent-local t)
813 (put 'hs-c-start-regexp 'permanent-local t)
814 (put 'hs-block-start-regexp 'permanent-local t)
815 (put 'hs-block-end-regexp 'permanent-local t)
816 (put 'hs-forward-sexp-func 'permanent-local t)
817 (put 'hs-adjust-block-beginning 'permanent-local t)
820 ;;;----------------------------------------------------------------------------
825 ;;; hideshow.el ends here