diff options
| author | Thien-Thi Nguyen | 2000-09-23 02:37:50 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 2000-09-23 02:37:50 +0000 |
| commit | 9b4a7800433b33bc402676e17da152f1e358bf4f (patch) | |
| tree | a601a7f4f2be6257df4de34dfe8fa7c492fd0e66 /lisp/progmodes | |
| parent | 0c356565b96bc0ecd249a5beee403dff3d00b917 (diff) | |
| download | emacs-9b4a7800433b33bc402676e17da152f1e358bf4f.tar.gz emacs-9b4a7800433b33bc402676e17da152f1e358bf4f.zip | |
Update author email address.
Generally, sync w/ maintainer version 5.22.
(hs-hide-all-non-comment-function): New var.
(hs-hide-hook, hs-show-hook, hs-minor-mode): Update docstrings.
(hs-hide-all): Use `hs-hide-all-non-comment-function'.
(hs-show-region): Delete this command.
(hs-minor-mode-map): Change bindings to leave "C-c LETTER" alone.
Diffstat (limited to 'lisp/progmodes')
| -rw-r--r-- | lisp/progmodes/hideshow.el | 191 |
1 files changed, 99 insertions, 92 deletions
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index 6fccb860d4b..f47e5cd7a74 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el | |||
| @@ -2,10 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation | 3 | ;; Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation |
| 4 | 4 | ||
| 5 | ;; Author: Thien-Thi Nguyen <ttn@netcom.com> | 5 | ;; Author: Thien-Thi Nguyen <ttn@gnu.org> |
| 6 | ;; Dan Nicolaescu <dann@ics.uci.edu> | 6 | ;; Dan Nicolaescu <dann@ics.uci.edu> |
| 7 | ;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines | 7 | ;; Keywords: C C++ java lisp tools editing comments blocks hiding outlines |
| 8 | ;; Maintainer-Version: 5.11 | 8 | ;; Maintainer-Version: 5.22 |
| 9 | ;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning | 9 | ;; Time-of-Day-Author-Most-Likely-to-be-Recalcitrant: early morning |
| 10 | 10 | ||
| 11 | ;; This file is part of GNU Emacs. | 11 | ;; This file is part of GNU Emacs. |
| @@ -33,13 +33,12 @@ | |||
| 33 | ;; are available, implementing block hiding and showing. They (and their | 33 | ;; are available, implementing block hiding and showing. They (and their |
| 34 | ;; keybindings) are: | 34 | ;; keybindings) are: |
| 35 | ;; | 35 | ;; |
| 36 | ;; hs-hide-block C-c h | 36 | ;; hs-hide-block C-c C-h |
| 37 | ;; hs-show-block C-c s | 37 | ;; hs-show-block C-c C-s |
| 38 | ;; hs-hide-all C-c H | 38 | ;; hs-hide-all C-c C-M-h |
| 39 | ;; hs-show-all C-c S | 39 | ;; hs-show-all C-c C-M-s |
| 40 | ;; hs-show-region C-c R | 40 | ;; hs-hide-level C-c C-l |
| 41 | ;; hs-hide-level C-c L | 41 | ;; hs-toggle-hiding C-c C-c |
| 42 | ;; hs-toggle-hiding | ||
| 43 | ;; hs-mouse-toggle-hiding [(shift button-2)] | 42 | ;; hs-mouse-toggle-hiding [(shift button-2)] |
| 44 | ;; hs-hide-initial-comment-block | 43 | ;; hs-hide-initial-comment-block |
| 45 | ;; | 44 | ;; |
| @@ -55,10 +54,25 @@ | |||
| 55 | ;; | 54 | ;; |
| 56 | ;; You can use `M-x customize-variable' on the following variables: | 55 | ;; You can use `M-x customize-variable' on the following variables: |
| 57 | ;; | 56 | ;; |
| 58 | ;; hs-hide-comments-when-hiding-all -- self-explanatory! | 57 | ;; - hs-hide-comments-when-hiding-all -- self-explanatory! |
| 59 | ;; hs-isearch-open -- what kind of hidden blocks to | 58 | ;; - hs-hide-all-non-comment-function -- if non-nil, when doing a |
| 59 | ;; `hs-hide-all', this function | ||
| 60 | ;; is called w/ no arguments | ||
| 61 | ;; - hs-isearch-open -- what kind of hidden blocks to | ||
| 60 | ;; open when doing isearch | 62 | ;; open when doing isearch |
| 61 | ;; | 63 | ;; |
| 64 | ;; Some languages (e.g., Java) are deeply nested, so the normal behavior | ||
| 65 | ;; of `hs-hide-all' (hiding all but top-level blocks) results in very | ||
| 66 | ;; little information shown, which is not very useful. You can use the | ||
| 67 | ;; variable `hs-hide-all-non-comment-function' to implement your idea of | ||
| 68 | ;; what is more useful. For example, the following code shows the next | ||
| 69 | ;; nested level in addition to the top-level: | ||
| 70 | ;; | ||
| 71 | ;; (defun ttn-hs-hide-level-1 () | ||
| 72 | ;; (hs-hide-level 1) | ||
| 73 | ;; (forward-sexp 1)) | ||
| 74 | ;; (setq hs-hide-all-non-comment-function 'ttn-hs-hide-level-1) | ||
| 75 | ;; | ||
| 62 | ;; Hideshow works w/ incremental search (isearch) by setting the variable | 76 | ;; Hideshow works w/ incremental search (isearch) by setting the variable |
| 63 | ;; `hs-headline', which is the line of text at the beginning of a hidden | 77 | ;; `hs-headline', which is the line of text at the beginning of a hidden |
| 64 | ;; block that contains a match for the search. You can have this show up | 78 | ;; block that contains a match for the search. You can have this show up |
| @@ -74,10 +88,12 @@ | |||
| 74 | ;; Hooks are run after some commands: | 88 | ;; Hooks are run after some commands: |
| 75 | ;; | 89 | ;; |
| 76 | ;; hs-hide-hook in hs-hide-block, hs-hide-all, hs-hide-level | 90 | ;; hs-hide-hook in hs-hide-block, hs-hide-all, hs-hide-level |
| 77 | ;; hs-show-hook hs-show-block, hs-show-all, hs-show-region | 91 | ;; hs-show-hook hs-show-block, hs-show-all |
| 78 | ;; | 92 | ;; |
| 79 | ;; All hooks are run w/ `run-hooks'. See docs for each variable or hook | 93 | ;; One of `hs-hide-hook' or `hs-show-hook' is run for the toggling |
| 80 | ;; for more info. | 94 | ;; commands when the result of the toggle is to hide or show blocks, |
| 95 | ;; respectively. All hooks are run w/ `run-hooks'. See docs for each | ||
| 96 | ;; variable or hook for more info. | ||
| 81 | ;; | 97 | ;; |
| 82 | ;; Normally, hideshow tries to determine appropriate values for block | 98 | ;; Normally, hideshow tries to determine appropriate values for block |
| 83 | ;; and comment definitions by examining the buffer's major mode. If | 99 | ;; and comment definitions by examining the buffer's major mode. If |
| @@ -102,7 +118,8 @@ | |||
| 102 | ;; Then, add the following to your ~/.emacs: | 118 | ;; Then, add the following to your ~/.emacs: |
| 103 | ;; | 119 | ;; |
| 104 | ;; (load-library "hideshow") | 120 | ;; (load-library "hideshow") |
| 105 | ;; (add-hook 'X-mode-hook 'hs-minor-mode) ; other modes similarly | 121 | ;; (add-hook 'X-mode-hook ; other modes similarly |
| 122 | ;; '(lambda () (hs-minor-mode 1))) | ||
| 106 | ;; | 123 | ;; |
| 107 | ;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle | 124 | ;; where X = {emacs-lisp,c,c++,perl,...}. You can also manually toggle |
| 108 | ;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is | 125 | ;; hideshow minor mode by typing `M-x hs-minor-mode'. After hideshow is |
| @@ -121,37 +138,39 @@ | |||
| 121 | ;; (3) Hideshow 5.x is developed and tested on GNU Emacs 20.4. | 138 | ;; (3) Hideshow 5.x is developed and tested on GNU Emacs 20.4. |
| 122 | ;; XEmacs compatibility may have bitrotted since 4.29. | 139 | ;; XEmacs compatibility may have bitrotted since 4.29. |
| 123 | ;; | 140 | ;; |
| 141 | ;; (4) Some buffers can't be `byte-compile-file'd properly. This is because | ||
| 142 | ;; `byte-compile-file' inserts the file to be compiled in a temporary | ||
| 143 | ;; buffer and switches `normal-mode' on. In the case where you have | ||
| 144 | ;; `hs-hide-initial-comment-block' in `hs-minor-mode-hook', the hiding of | ||
| 145 | ;; the initial comment sometimes hides parts of the first statement (seems | ||
| 146 | ;; to be only in `normal-mode'), so there are unbalanced "(" and ")". | ||
| 147 | ;; | ||
| 148 | ;; The workaround is to clear `hs-minor-mode-hook' when byte-compiling: | ||
| 149 | ;; | ||
| 150 | ;; (defadvice byte-compile-file (around | ||
| 151 | ;; byte-compile-file-hideshow-off | ||
| 152 | ;; act) | ||
| 153 | ;; (let ((hs-minor-mode-hook nil)) | ||
| 154 | ;; ad-do-it)) | ||
| 155 | |||
| 124 | ;; Correspondance welcome; please indicate version number. Send bug | 156 | ;; Correspondance welcome; please indicate version number. Send bug |
| 125 | ;; reports and inquiries to <ttn@netcom.com>. | 157 | ;; reports and inquiries to <ttn@gnu.org>. |
| 126 | 158 | ||
| 127 | ;; * Thanks | 159 | ;; * Thanks |
| 128 | ;; | 160 | ;; |
| 129 | ;; Thanks go to the following people for valuable ideas, code and | 161 | ;; Thanks go to the following people for valuable ideas, code and |
| 130 | ;; bug reports. | 162 | ;; bug reports. |
| 131 | ;; | 163 | ;; |
| 132 | ;; adahome@ix.netcom.com Dean Andrews | 164 | ;; Dean Andrews, Alf-Ivar Holm, Holger Bauer, Christoph Conrad, Dave |
| 133 | ;; alfh@ifi.uio.no Alf-Ivar Holm | 165 | ;; Love, Dirk Herrmann, Gael Marziou, Jan Djarv, Guillaume Leray, |
| 134 | ;; bauer@itsm.uni-stuttgart.de Holger Bauer | 166 | ;; Moody Ahmad, Preston F. Crow, Lars Lindberg, Reto Zimmermann, |
| 135 | ;; christoph.conrad@post.rwth-aachen.de Christoph Conrad | 167 | ;; Keith Sheffield, Chew Meng Kuan, Tony Lam, Pete Ware, François Pinard |
| 136 | ;; d.love@dl.ac.uk Dave Love | ||
| 137 | ;; dirk@ida.ing.tu-bs.de Dirk Herrmann | ||
| 138 | ;; gael@gnlab030.grenoble.hp.com Gael Marziou | ||
| 139 | ;; jan.djarv@sa.erisoft.se Jan Djarv | ||
| 140 | ;; leray@dev-lme.pcc.philips.com Guillaume Leray | ||
| 141 | ;; moody@mwt.net Moody Ahmad | ||
| 142 | ;; preston.f.crow@dartmouth.edu Preston F. Crow | ||
| 143 | ;; qhslali@aom.ericsson.se Lars Lindberg | ||
| 144 | ;; reto@synopsys.com Reto Zimmermann | ||
| 145 | ;; sheff@edcsgw2.cr.usgs.gov Keith Sheffield | ||
| 146 | ;; smes@post1.com Chew Meng Kuan | ||
| 147 | ;; tonyl@eng.sun.com Tony Lam | ||
| 148 | ;; ware@cis.ohio-state.edu Pete Ware | ||
| 149 | ;; | 168 | ;; |
| 150 | ;; Special thanks go to Dan Nicolaescu <dann@ics.uci.edu>, who reimplemented | 169 | ;; Special thanks go to Dan Nicolaescu, who reimplemented hideshow using |
| 151 | ;; hideshow using overlays (rather than selective display), added isearch | 170 | ;; overlays (rather than selective display), added isearch magic, folded |
| 152 | ;; magic, folded in custom.el compatibility, generalized comment handling, | 171 | ;; in custom.el compatibility, generalized comment handling, incorporated |
| 153 | ;; incorporated mouse support, and maintained the code in general. Version | 172 | ;; mouse support, and maintained the code in general. Version 4.0 is |
| 154 | ;; 4.0 is largely due to his efforts. | 173 | ;; largely due to his efforts. |
| 155 | 174 | ||
| 156 | ;; * History | 175 | ;; * History |
| 157 | ;; | 176 | ;; |
| @@ -236,13 +255,18 @@ If any of the elements is left nil or omitted, hideshow tries to guess | |||
| 236 | appropriate values. The regexps should not contain leading or trailing | 255 | appropriate values. The regexps should not contain leading or trailing |
| 237 | whitespace. Case does not matter.") | 256 | whitespace. Case does not matter.") |
| 238 | 257 | ||
| 258 | (defvar hs-hide-all-non-comment-function nil | ||
| 259 | "*Function called if non-nil when doing `hs-hide-all' for non-comments.") | ||
| 260 | |||
| 239 | (defvar hs-hide-hook nil | 261 | (defvar hs-hide-hook nil |
| 240 | "*Hook called (with `run-hooks') at the end of commands to hide text. | 262 | "*Hook called (with `run-hooks') at the end of commands to hide text. |
| 241 | These commands include `hs-hide-all', `hs-hide-block' and `hs-hide-level'.") | 263 | These commands include the toggling commands (when the result is to hide |
| 264 | a block), `hs-hide-all', `hs-hide-block' and `hs-hide-level'.") | ||
| 242 | 265 | ||
| 243 | (defvar hs-show-hook nil | 266 | (defvar hs-show-hook nil |
| 244 | "*Hook called (with `run-hooks') at the end of commands to show text. | 267 | "*Hook called (with `run-hooks') at the end of commands to show text. |
| 245 | These commands include `hs-show-all', `hs-show-block' and `hs-show-region'.") | 268 | These commands include the toggling commands (when the result is to show |
| 269 | a block), `hs-show-all' and `hs-show-block'..") | ||
| 246 | 270 | ||
| 247 | ;;--------------------------------------------------------------------------- | 271 | ;;--------------------------------------------------------------------------- |
| 248 | ;; internal variables | 272 | ;; internal variables |
| @@ -637,39 +661,34 @@ If `hs-hide-comments-when-hiding-all' is non-nil, also hide the comments." | |||
| 637 | (save-excursion | 661 | (save-excursion |
| 638 | (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness | 662 | (hs-flag-region (point-min) (point-max) nil) ; eliminate weirdness |
| 639 | (goto-char (point-min)) | 663 | (goto-char (point-min)) |
| 640 | (if hs-hide-comments-when-hiding-all | 664 | (let ((count 0) |
| 641 | (let ((c-reg nil) | 665 | (re (concat "\\(" |
| 642 | (count 0) | 666 | hs-block-start-regexp |
| 643 | (block-and-comment-re | 667 | "\\)" |
| 644 | (concat "\\(" | 668 | (if hs-hide-comments-when-hiding-all |
| 645 | hs-block-start-regexp | 669 | (concat "\\|\\(" |
| 646 | "\\)\\|\\(" | 670 | hs-c-start-regexp |
| 647 | hs-c-start-regexp | 671 | "\\)") |
| 648 | "\\)"))) | 672 | "")))) |
| 649 | (while (re-search-forward block-and-comment-re (point-max) t) | 673 | (while (progn |
| 650 | (if (match-beginning 1) ;; we have found a block beginning | 674 | (unless hs-hide-comments-when-hiding-all |
| 651 | (progn | 675 | (forward-comment (point-max))) |
| 652 | (goto-char (match-beginning 1)) | 676 | (re-search-forward re (point-max) t)) |
| 653 | (hs-hide-block-at-point t) | 677 | (if (match-beginning 1) |
| 654 | (message "Hiding ... %d" (setq count (1+ count)))) | 678 | ;; we have found a block beginning |
| 655 | ;;found a comment | ||
| 656 | (setq c-reg (hs-inside-comment-p)) | ||
| 657 | (if (and c-reg (car c-reg)) | ||
| 658 | (if (> (count-lines (car c-reg) (nth 1 c-reg)) 1) | ||
| 659 | (progn | ||
| 660 | (hs-hide-block-at-point t c-reg) | ||
| 661 | (message "Hiding ... %d" (setq count (1+ count)))) | ||
| 662 | (goto-char (nth 1 c-reg))))))) | ||
| 663 | (let ((count 0) | ||
| 664 | (buf-size (buffer-size))) | ||
| 665 | (while | ||
| 666 | (progn | 679 | (progn |
| 667 | (forward-comment buf-size) | 680 | (goto-char (match-beginning 1)) |
| 668 | (re-search-forward hs-block-start-regexp (point-max) t)) | 681 | (if hs-hide-all-non-comment-function |
| 669 | (goto-char (match-beginning 0)) | 682 | (funcall hs-hide-all-non-comment-function) |
| 670 | (hs-hide-block-at-point t) | 683 | (hs-hide-block-at-point t))) |
| 671 | (message "Hiding ... %d" (setq count (1+ count)))))) | 684 | ;; found a comment, probably |
| 672 | (hs-safety-is-job-n)) | 685 | (let ((c-reg (hs-inside-comment-p))) ; blech! |
| 686 | (when (and c-reg (car c-reg)) | ||
| 687 | (if (> (count-lines (car c-reg) (nth 1 c-reg)) 1) | ||
| 688 | (hs-hide-block-at-point t c-reg) | ||
| 689 | (goto-char (nth 1 c-reg)))))) | ||
| 690 | (message "Hiding ... %d" (setq count (1+ count))))) | ||
| 691 | (hs-safety-is-job-n)) | ||
| 673 | (beginning-of-line) | 692 | (beginning-of-line) |
| 674 | (message "Hiding all blocks ... done") | 693 | (message "Hiding all blocks ... done") |
| 675 | (run-hooks 'hs-hide-hook))) | 694 | (run-hooks 'hs-hide-hook))) |
| @@ -741,18 +760,6 @@ See documentation for functions `hs-hide-block' and `run-hooks'." | |||
| 741 | (hs-safety-is-job-n) | 760 | (hs-safety-is-job-n) |
| 742 | (run-hooks 'hs-show-hook)))) | 761 | (run-hooks 'hs-show-hook)))) |
| 743 | 762 | ||
| 744 | (defun hs-show-region (beg end) | ||
| 745 | "Show all lines from BEG to END, without doing any block analysis. | ||
| 746 | Note: `hs-show-region' is intended for use when `hs-show-block' signals | ||
| 747 | \"unbalanced parentheses\" and so is an emergency measure only. You may | ||
| 748 | become very confused if you use this command indiscriminately. | ||
| 749 | The hook `hs-show-hook' is run; see `run-hooks'." | ||
| 750 | (interactive "r") | ||
| 751 | (hs-life-goes-on | ||
| 752 | (hs-flag-region beg end nil) | ||
| 753 | (hs-safety-is-job-n) | ||
| 754 | (run-hooks 'hs-show-hook))) | ||
| 755 | |||
| 756 | (defun hs-hide-level (arg) | 763 | (defun hs-hide-level (arg) |
| 757 | "Hide all blocks ARG levels below this block. | 764 | "Hide all blocks ARG levels below this block. |
| 758 | The hook `hs-hide-hook' is run; see `run-hooks'." | 765 | The hook `hs-hide-hook' is run; see `run-hooks'." |
| @@ -808,7 +815,7 @@ commands and the hideshow commands are enabled. | |||
| 808 | The value '(hs . t) is added to `buffer-invisibility-spec'. | 815 | The value '(hs . t) is added to `buffer-invisibility-spec'. |
| 809 | 816 | ||
| 810 | The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block', | 817 | The main commands are: `hs-hide-all', `hs-show-all', `hs-hide-block', |
| 811 | `hs-show-block', `hs-hide-level' and `hs-show-region'. There is also | 818 | `hs-show-block', `hs-hide-level' and `hs-toggle-hiding'. There is also |
| 812 | `hs-hide-initial-comment-block' and `hs-mouse-toggle-hiding'. | 819 | `hs-hide-initial-comment-block' and `hs-mouse-toggle-hiding'. |
| 813 | 820 | ||
| 814 | Turning hideshow minor mode off reverts the menu bar and the | 821 | Turning hideshow minor mode off reverts the menu bar and the |
| @@ -853,14 +860,14 @@ Key bindings: | |||
| 853 | (lambda (ent) | 860 | (lambda (ent) |
| 854 | (define-key hs-minor-mode-map (aref ent 2) (aref ent 1)) | 861 | (define-key hs-minor-mode-map (aref ent 2) (aref ent 1)) |
| 855 | (if (aref ent 0) ent "-----")) | 862 | (if (aref ent 0) ent "-----")) |
| 856 | ;; I believe there is nothing bound on these keys. | 863 | ;; These bindings roughly imitate those used by Outline mode. |
| 857 | ;; menu entry command key | 864 | ;; menu entry command key |
| 858 | '(["Hide Block" hs-hide-block "\C-ch"] | 865 | '(["Hide Block" hs-hide-block "\C-c\C-h"] |
| 859 | ["Show Block" hs-show-block "\C-cs"] | 866 | ["Show Block" hs-show-block "\C-c\C-s"] |
| 860 | ["Hide All" hs-hide-all "\C-cH"] | 867 | ["Hide All" hs-hide-all "\C-c\C-\M-h"] |
| 861 | ["Show All" hs-show-all "\C-cS"] | 868 | ["Show All" hs-show-all "\C-c\C-\M-s"] |
| 862 | ["Hide Level" hs-hide-level "\C-cL"] | 869 | ["Hide Level" hs-hide-level "\C-c\C-l"] |
| 863 | ["Show Region" hs-show-region "\C-cR"] | 870 | ["Toggle Hiding" hs-toggle-hiding "\C-c\C-c"] |
| 864 | [nil hs-mouse-toggle-hiding [(shift button2)]] | 871 | [nil hs-mouse-toggle-hiding [(shift button2)]] |
| 865 | ))))) | 872 | ))))) |
| 866 | 873 | ||