-;;; hideshow.el --- minor mode cmds to selectively display blocks of code
+;;; hideshow.el --- minor mode cmds to selectively display code/comment blocks
;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 01 Free Software Foundation
;; Author: Thien-Thi Nguyen <ttn@gnu.org>
;; Dan Nicolaescu <dann@ics.uci.edu>
;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines
-;; Maintainer-Version: 5.26
+;; Maintainer-Version: 5.31
;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning
;; This file is part of GNU Emacs.
;; hs-show-all C-c @ C-M-s
;; hs-hide-level C-c @ C-l
;; hs-toggle-hiding C-c @ C-c
-;; hs-mouse-toggle-hiding [(shift button-2)]
+;; hs-mouse-toggle-hiding [(shift mouse-2)]
;; hs-hide-initial-comment-block
;;
;; Blocks are defined per mode. In c-mode, c++-mode and java-mode, they
;; The command `M-x hs-minor-mode' toggles the minor mode or sets it
;; (similar to other minor modes).
+;; * Suggested usage
+;;
+;; First make sure hideshow.el is in a directory in your `load-path'.
+;; You can optionally byte-compile it using `M-x byte-compile-file'.
+;; Then, add the following to your ~/.emacs:
+;;
+;; (load-library "hideshow")
+;; (add-hook 'X-mode-hook ; other modes similarly
+;; '(lambda () (hs-minor-mode 1)))
+;;
+;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle
+;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is
+;; activated or deactivated, `hs-minor-mode-hook' is run w/ `run-hooks'.
+;;
+;; Additionally, Joseph Eydelnant writes:
+;; I enjoy your package hideshow.el Ver. 5.24 2001/02/13
+;; a lot and I've been looking for the following functionality:
+;; toggle hide/show all with a single key.
+;; Here are a few lines of code that lets me do just that.
+;;
+;; (defvar my-hs-hide nil "Current state of hideshow for toggling all.")
+;; ;;;###autoload
+;; (defun my-toggle-hideshow-all () "Toggle hideshow all."
+;; (interactive)
+;; (setq my-hs-hide (not my-hs-hide))
+;; (if my-hs-hide
+;; (hs-hide-all)
+;; (hs-show-all)))
+;;
+;; [Your hideshow hacks here!]
+
;; * Customization
;;
;; You can use `M-x customize-variable' on the following variables:
;; submitting it for inclusion in hideshow.el. See docstring for
;; `hs-special-modes-alist' for more info on the entry format.
-;; * Suggested usage
-;;
-;; First make sure hideshow.el is in a directory in your `load-path'.
-;; You can optionally byte-compile it using `M-x byte-compile-file'.
-;; Then, add the following to your ~/.emacs:
-;;
-;; (load-library "hideshow")
-;; (add-hook 'X-mode-hook ; other modes similarly
-;; '(lambda () (hs-minor-mode 1)))
-;;
-;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle
-;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is
-;; activated or deactivated, `hs-minor-mode-hook' is run w/ `run-hooks'.
-
;; * Bugs
;;
;; (1) Hideshow does not work w/ emacs 18 because emacs 18 lacks the
;; writes this, please send me a copy.
;;
;; (2) Sometimes `hs-headline' can become out of sync. To reset, type
-;; `M-x hs-minor-mode' twice (that is, deactivate then activate
+;; `M-x hs-minor-mode' twice (that is, deactivate then re-activate
;; hideshow).
;;
-;; (3) Hideshow 5.x is developed and tested on GNU Emacs 20.4.
+;; (3) Hideshow 5.x is developed and tested on GNU Emacs 20.7.
;; XEmacs compatibility may have bitrotted since 4.29.
;;
;; (4) Some buffers can't be `byte-compile-file'd properly. This is because
;; act)
;; (let ((hs-minor-mode-hook nil))
;; ad-do-it))
+;;
+;; (5) Hideshow interacts badly with Ediff and `vc-diff'. At the moment, the
+;; suggested workaround is to turn off hideshow entirely, for example:
+;;
+;; (defun turn-off-hideshow () (hs-minor-mode -1))
+;; (add-hook 'ediff-prepare-buffer-hook 'turn-off-hideshow)
+;; (add-hook 'vc-before-checkin-hook 'turn-off-hideshow)
+;;
+;; In the case of `vc-diff', here is a less invasive workaround:
+;;
+;; (add-hook 'vc-before-checkin-hook
+;; '(lambda ()
+;; (goto-char (point-min))
+;; (hs-show-block)))
+;;
+;; Unfortunately, these workarounds do not restore hideshow state.
+;; If someone figures out a better way, please let me know.
+;; * Correspondance
+;;
;; Correspondance welcome; please indicate version number. Send bug
;; reports and inquiries to <ttn@gnu.org>.
;; Dean Andrews, Alf-Ivar Holm, Holger Bauer, Christoph Conrad, Dave
;; Love, Dirk Herrmann, Gael Marziou, Jan Djarv, Guillaume Leray,
;; Moody Ahmad, Preston F. Crow, Lars Lindberg, Reto Zimmermann,
-;; Keith Sheffield, Chew Meng Kuan, Tony Lam, Pete Ware, François Pinard
+;; Keith Sheffield, Chew Meng Kuan, Tony Lam, Pete Ware, François
+;; Pinard, Stefan Monnier, Joseph Eydelnant, Michael Ernst
;;
;; Special thanks go to Dan Nicolaescu, who reimplemented hideshow using
;; overlays (rather than selective display), added isearch magic, folded
:group 'hideshow
:version "21.1")
-(defcustom hs-isearch-open 'block
+(defcustom hs-isearch-open 'code
"*What kind of hidden blocks to open when doing `isearch'.
One of the following symbols:
- block -- open only blocks
- comment -- open only comments
- t -- open both blocks and comments
- nil -- open neither blocks nor comments
+ code -- open only code blocks
+ comment -- open only comment blocks
+ t -- open both code and comment blocks
+ nil -- open neither code nor comment blocks
This has effect iff `search-invisible' is set to `open'."
- :type '(choice (const :tag "open only blocks" block)
- (const :tag "open only comments" comment)
- (const :tag "open both blocks and comments" t)
+ :type '(choice (const :tag "open only code blocks" code)
+ (const :tag "open only comment blocks" comment)
+ (const :tag "open both code and comment blocks" t)
(const :tag "don't open any of them" nil))
:group 'hideshow)
As a special case, START may be a list of the form (COMPLEX-START
MDATA-SELECTOR), where COMPLEX-START is a regexp w/ multiple parts and
MDATA-SELECTOR an integer that specifies which sub-match is the proper
-place to adjust point, before calling `hs-forward-sexp-func'. For
-example, see the `hs-special-modes-alist' entry for `bibtex-mode'.
+place to adjust point, before calling `hs-forward-sexp-func'. Point
+is adjusted to the beginning of the specified match. For example,
+see the `hs-special-modes-alist' entry for `bibtex-mode'.
For some major modes, `forward-sexp' does not work properly. In those
cases, FORWARD-SEXP-FUNC specifies another function to use instead.
for `hs-block-start-regexp'.
For example, in c-like modes, if we wish to also hide the curly braces
-(if you think they occupy too much space on the screen), this function
+\(if you think they occupy too much space on the screen), this function
should return the starting point (at the end of line) of the hidden
region.
-It is called with a single argument ARG which is the the position in
+It is called with a single argument ARG which is the position in
buffer after the block beginning.
It should return the position from where we should start hiding.
; (setq buffer-invisibility-spec
; (cons arg buffer-invisibility-spec)))))
; (defun remove-from-invisibility-spec (arg)
-; (if buffer-invisibility-spec
-; (setq buffer-invisibility-spec
-; (delete arg buffer-invisibility-spec)))))
+; (when buffer-invisibility-spec
+; (setq buffer-invisibility-spec
+; (delete arg buffer-invisibility-spec)))))
;; hs-match-data
(defalias 'hs-match-data 'match-data)
(defun hs-flag-region (from to flag)
"Hide or show lines from FROM to TO, according to FLAG.
If FLAG is nil then text is shown, while if FLAG is non-nil the text is
-hidden. Actually flag is really either `comment' or `block' depending
-on what kind of block it is suppose to hide."
+hidden. FLAG must be one of the symbols `code' or `comment', depending
+on what kind of block is to be hidden."
(save-excursion
;; first clear it all out
(hs-discard-overlays from to)
(let ((overlay (make-overlay from to)))
(overlay-put overlay 'invisible 'hs)
(overlay-put overlay 'hs flag)
- (when (or (eq hs-isearch-open t) (eq hs-isearch-open flag))
+ (when (or (eq hs-isearch-open t)
+ (eq hs-isearch-open flag)
+ ;; deprecated backward compatibility -- `block'<=>`code'
+ (and (eq 'block hs-isearch-open)
+ (eq 'code flag)))
(overlay-put overlay 'isearch-open-invisible 'hs-isearch-show)
(overlay-put overlay
'isearch-open-invisible-temporary
and then further adjusted to be at the end of the line."
(if comment-reg
(hs-hide-comment-region (car comment-reg) (cadr comment-reg) end)
- (if (looking-at hs-block-start-regexp)
- (let* ((mdata (hs-match-data t))
- (pure-p (match-end 0))
- (p
- ;; `p' is the point at the end of the block beginning,
- ;; which may need to be adjusted
- (save-excursion
- (goto-char (funcall (or hs-adjust-block-beginning
- 'identity)
- pure-p))
- ;; whatever the adjustment, we move to eol
- (end-of-line)
- (point)))
- (q
- ;; `q' is the point at the end of the block
- (progn (hs-forward-sexp mdata 1)
- (end-of-line)
- (point))))
- (if (and (< p (point)) (> (count-lines p q) 1))
- (overlay-put (hs-flag-region p q 'block)
- 'hs-ofs
- (- pure-p p)))
- (goto-char (if end q (min p pure-p)))))))
+ (when (looking-at hs-block-start-regexp)
+ (let* ((mdata (hs-match-data t))
+ (pure-p (match-end 0))
+ (p
+ ;; `p' is the point at the end of the block beginning,
+ ;; which may need to be adjusted
+ (save-excursion
+ (goto-char (funcall (or hs-adjust-block-beginning
+ 'identity)
+ pure-p))
+ ;; whatever the adjustment, we move to eol
+ (end-of-line)
+ (point)))
+ (q
+ ;; `q' is the point at the end of the block
+ (progn (hs-forward-sexp mdata 1)
+ (end-of-line)
+ (point))))
+ (when (and (< p (point)) (> (count-lines p q) 1))
+ (overlay-put (hs-flag-region p q 'code)
+ 'hs-ofs
+ (- pure-p p)))
+ (goto-char (if end q (min p pure-p)))))))
(defun hs-safety-is-job-n ()
"Warn if `buffer-invisibility-spec' does not contain symbol `hs'."
(setq p (point));; use this to avoid an infinite cycle
(forward-comment 1)
(skip-chars-forward " \t\n\f"))
- (if (or (not (looking-at hs-c-start-regexp))
- (> (point) q))
- ;; we cannot hide this comment block
- (setq not-hidable t)))
+ (when (or (not (looking-at hs-c-start-regexp))
+ (> (point) q))
+ ;; we cannot hide this comment block
+ (setq not-hidable t)))
;; goto the end of the comment
(forward-comment (buffer-size))
(skip-chars-backward " \t\n\f")
(end-of-line)
- (if (>= (point) q)
- (list (if not-hidable nil p) (point))))))))
+ (when (>= (point) q)
+ (list (if not-hidable nil p) (point))))))))
(defun hs-grok-mode-type ()
"Set up hideshow variables for new buffers.
c-start-regexp)))
hs-forward-sexp-func (or (nth 4 lookup) 'forward-sexp)
hs-adjust-block-beginning (nth 5 lookup)))
- (progn
- (setq hs-minor-mode nil)
- (error "%s Mode doesn't support Hideshow Minor Mode" mode-name))))
+ (setq hs-minor-mode nil)
+ (error "%s Mode doesn't support Hideshow Minor Mode" mode-name)))
(defun hs-find-block-beginning ()
"Reposition point at block-start.
(if (and c-reg (nth 0 c-reg))
;; point is inside a comment, and that comment is hidable
(goto-char (nth 0 c-reg))
- (if (and (not c-reg)
- (hs-find-block-beginning)
- (looking-at hs-block-start-regexp))
- ;; point is inside a block
- (goto-char (match-end 0)))))
+ (when (and (not c-reg)
+ (hs-find-block-beginning)
+ (looking-at hs-block-start-regexp))
+ ;; point is inside a block
+ (goto-char (match-end 0)))))
(end-of-line)
(let ((overlays (overlays-at (point)))
(found nil))
(progn
(hs-grok-mode-type)
(easy-menu-add hs-minor-mode-menu)
- (make-variable-buffer-local 'line-move-ignore-invisible)
- (setq line-move-ignore-invisible t)
+ (set (make-local-variable 'line-move-ignore-invisible) t)
(add-to-invisibility-spec '(hs . t)))
(easy-menu-remove hs-minor-mode-menu)
(remove-from-invisibility-spec '(hs . t)))
;; load-time actions
;; keymaps and menus
-(if hs-minor-mode-map
- nil
+(unless hs-minor-mode-map
(setq hs-minor-mode-map (make-sparse-keymap))
(easy-menu-define hs-minor-mode-menu
hs-minor-mode-map
["Show All" hs-show-all "\C-c@\C-\M-s"]
["Hide Level" hs-hide-level "\C-c@\C-l"]
["Toggle Hiding" hs-toggle-hiding "\C-c@\C-c"]
- [nil hs-mouse-toggle-hiding [(shift button2)]]
+ [nil hs-mouse-toggle-hiding [(shift mouse-2)]]
)))))
;; some housekeeping
(provide 'hideshow)
+;;; arch-tag: 378b6852-e82a-466a-aee8-d9c73859a65e
;;; hideshow.el ends here