diff options
| author | Thien-Thi Nguyen | 1995-02-26 21:05:42 +0000 |
|---|---|---|
| committer | Thien-Thi Nguyen | 1995-02-26 21:05:42 +0000 |
| commit | c1ff6dac5c095a9e77621c511bc2599aa21eb0a1 (patch) | |
| tree | 9ae5927c89da327502944f5c505cf24154bafe9c | |
| parent | f09bc9246449428644601982bd86f5bbe5eb110b (diff) | |
| download | emacs-c1ff6dac5c095a9e77621c511bc2599aa21eb0a1.tar.gz emacs-c1ff6dac5c095a9e77621c511bc2599aa21eb0a1.zip | |
Clean up doc strings.
Remove cl.el and emacs-vers.el dependencies.
| -rw-r--r-- | lisp/progmodes/hideshow.el | 401 |
1 files changed, 207 insertions, 194 deletions
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index 146cc7ed1e9..262543818b4 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el | |||
| @@ -30,34 +30,36 @@ | |||
| 30 | 30 | ||
| 31 | ;;; Commentary: | 31 | ;;; Commentary: |
| 32 | 32 | ||
| 33 | ;;; this file provides `hs-minor-mode'. when active, six commands: | 33 | ;;; This file provides `hs-minor-mode'. When active, six commands: |
| 34 | ;;; hs-{hide,show}-{all,block}, hs-show-region and hs-minor-mode | 34 | ;;; hs-{hide,show}-{all,block}, hs-show-region and hs-minor-mode |
| 35 | ;;; are available. they implement block hiding and showing. blocks are | 35 | ;;; are available. They implement block hiding and showing. Blocks are |
| 36 | ;;; defined in mode-specific way. in c-mode or c++-mode, they are simply | 36 | ;;; defined in mode-specific way. In c-mode or c++-mode, they are simply |
| 37 | ;;; curly braces, while in lisp-ish modes they are parens. multi-line | 37 | ;;; curly braces, while in lisp-ish modes they are parens. Multi-line |
| 38 | ;;; comments (c-mode) can also be hidden. the command M-x hs-minor-mode | 38 | ;;; comments (c-mode) can also be hidden. The command M-x hs-minor-mode |
| 39 | ;;; toggles the minor mode or sets it (similar to outline minor mode). | 39 | ;;; toggles the minor mode or sets it (similar to outline minor mode). |
| 40 | ;;; see documentation for each command for more info. | 40 | ;;; See documentation for each command for more info. |
| 41 | ;;; | 41 | ;;; |
| 42 | ;;; the variable `hs-unbalance-handler-method' controls hideshow's behavior | 42 | ;;; The variable `hs-unbalance-handler-method' controls hideshow's behavior |
| 43 | ;;; in the case of "unbalanced parentheses". see doc for more info. | 43 | ;;; in the case of "unbalanced parentheses". See doc for more info. |
| 44 | 44 | ||
| 45 | ;;; suggested usage: | 45 | ;;; Suggested usage: |
| 46 | 46 | ||
| 47 | ;;; (load-library "hideshow") | 47 | ;;; (load-library "hideshow") |
| 48 | ;;; (defun my-hs-setup () "enables hideshow and binds some commands" | 48 | ;;; (defun my-hs-setup () "enables hideshow and binds some commands" |
| 49 | ;;; (hs-minor-mode 1) | 49 | ;;; (hs-minor-mode 1) |
| 50 | ;;; (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block) | 50 | ;;; (define-key hs-minor-mode-map "\C-ch" 'hs-hide-block) |
| 51 | ;;; (define-key hs-minor-mode-map "\C-cs" 'hs-show-block) | 51 | ;;; (define-key hs-minor-mode-map "\C-cs" 'hs-show-block) |
| 52 | ;;; (define-key hs-minor-mode-map "\C-cr" 'hs-show-region)) | 52 | ;;; (define-key hs-minro-mode-map "\C-cH" 'hs-hide-all) |
| 53 | ;;; (define-key hs-minro-mode-map "\C-cS" 'hs-show-all) | ||
| 54 | ;;; (define-key hs-minor-mode-map "\C-cR" 'hs-show-region)) | ||
| 53 | ;;; (add-hook 'X-mode-hook 'my-hs-setup t) ; other modes similarly | 55 | ;;; (add-hook 'X-mode-hook 'my-hs-setup t) ; other modes similarly |
| 54 | ;;; | 56 | ;;; |
| 55 | ;;; where X = {emacs-lisp,c,c++,perl,...}. see the doc for the variable | 57 | ;;; where X = {emacs-lisp,c,c++,perl,...}. See the doc for the variable |
| 56 | ;;; `hs-special-modes-alist' if you'd like to use hideshow w/ other modes. | 58 | ;;; `hs-special-modes-alist' if you'd like to use hideshow w/ other modes. |
| 57 | 59 | ||
| 58 | ;;; etc: | 60 | ;;; Etc: |
| 59 | 61 | ||
| 60 | ;;; bug reports and fixes welcome (comments, too). thanks go to | 62 | ;;; Bug reports and fixes welcome (comments, too). Thanks go to |
| 61 | ;;; Dean Andrews <adahome@ix.netcom.com> | 63 | ;;; Dean Andrews <adahome@ix.netcom.com> |
| 62 | ;;; Preston F. Crow <preston.f.crow@dartmouth.edu> | 64 | ;;; Preston F. Crow <preston.f.crow@dartmouth.edu> |
| 63 | ;;; Gael Marziou <gael@gnlab030.grenoble.hp.com> | 65 | ;;; Gael Marziou <gael@gnlab030.grenoble.hp.com> |
| @@ -65,105 +67,102 @@ | |||
| 65 | ;;; Jan Djarv <jan.djarv@sa.erisoft.se> | 67 | ;;; Jan Djarv <jan.djarv@sa.erisoft.se> |
| 66 | ;;; Lars Lindberg <qhslali@aom.ericsson.se> | 68 | ;;; Lars Lindberg <qhslali@aom.ericsson.se> |
| 67 | ;;; Alf-Ivar Holm <alfh@ifi.uio.no> | 69 | ;;; Alf-Ivar Holm <alfh@ifi.uio.no> |
| 68 | ;;; for valuable feedback and bug reports. | 70 | ;;; for valuable feedback, code and bug reports. |
| 69 | 71 | ||
| 70 | ;;; Code: | 72 | ;;; Code: |
| 71 | 73 | ||
| 72 | 74 | ||
| 73 | ;;;---------------------------------------------------------------------------- | 75 | ;;;---------------------------------------------------------------------------- |
| 74 | ;;; dependencies | ||
| 75 | |||
| 76 | ; (require 'emacs-vers) ; support different emacs flavors | ||
| 77 | (require 'cl) ; common lisp package | ||
| 78 | |||
| 79 | |||
| 80 | ;;;---------------------------------------------------------------------------- | ||
| 81 | ;;; user-configurable variables | 76 | ;;; user-configurable variables |
| 82 | 77 | ||
| 83 | (defvar hs-unbalance-handler-method 'top-level | 78 | (defvar hs-unbalance-handler-method 'top-level |
| 84 | "*symbol representing how \"unbalanced parentheses\" should be handled. | 79 | "*Symbol representing how \"unbalanced parentheses\" should be handled. |
| 85 | this error is usually signalled by hs-show-block. one of four values: | 80 | This error is usually signalled by hs-show-block. One of four values: |
| 86 | `top-level', `next-line', `signal' or `ignore'. default is `top-level'. | 81 | `top-level', `next-line', `signal' or `ignore'. Default is `top-level'. |
| 87 | 82 | ||
| 88 | - `top-level' -- show top-level block containing the currently troublesome | 83 | - `top-level' -- Show top-level block containing the currently troublesome |
| 89 | block. | 84 | block. |
| 90 | - `next-line' -- use the fact that, for an already hidden block, its end | 85 | - `next-line' -- Use the fact that, for an already hidden block, its end |
| 91 | will be on the next line. attempt to show this block. | 86 | will be on the next line. Attempt to show this block. |
| 92 | - `signal' -- pass the error through, stopping execution. | 87 | - `signal' -- Pass the error through, stopping execution. |
| 93 | - `ignore' -- ignore the error, continuing execution. | 88 | - `ignore' -- Ignore the error, continuing execution. |
| 94 | 89 | ||
| 95 | values other than these four will be interpreted as `signal'.") | 90 | Values other than these four will be interpreted as `signal'.") |
| 96 | 91 | ||
| 97 | (defvar hs-special-modes-alist '((c-mode "{" "}") | 92 | (defvar hs-special-modes-alist '((c-mode "{" "}") |
| 98 | (c++-mode "{" "}")) | 93 | (c++-mode "{" "}")) |
| 99 | "*alist of the form (MODE START-RE END-RE FORWARD-SEXP-FUNC). | 94 | "*Alist of the form (MODE START-RE END-RE FORWARD-SEXP-FUNC). |
| 100 | if present, hideshow will use these values for the start and end regexps, | 95 | If present, hideshow will use these values for the start and end regexps, |
| 101 | respectively. since algol-ish languages do not have single-character | 96 | respectively. Since Algol-ish languages do not have single-character |
| 102 | block delimiters, the function `forward-sexp' which is used by hideshow | 97 | block delimiters, the function `forward-sexp' which is used by hideshow |
| 103 | doesn't work. in this case, if a similar function is provided, you can | 98 | doesn't work. In this case, if a similar function is provided, you can |
| 104 | register it and have hideshow use it instead of `forward-sexp'. to add | 99 | register it and have hideshow use it instead of `forward-sexp'. To add |
| 105 | more values, use | 100 | more values, use |
| 106 | 101 | ||
| 107 | \t(pushnew '(new-mode st-re end-re function-name) | 102 | \t(pushnew '(new-mode st-re end-re function-name) |
| 108 | \t hs-special-modes-alist :test 'equal) | 103 | \t hs-special-modes-alist :test 'equal) |
| 109 | 104 | ||
| 110 | for example: | 105 | For example: |
| 111 | 106 | ||
| 112 | \t(pushnew '(simula-mode \"begin\" \"end\" simula-next-statement) | 107 | \t(pushnew '(simula-mode \"begin\" \"end\" simula-next-statement) |
| 113 | \t hs-special-modes-alist :test 'equal) | 108 | \t hs-special-modes-alist :test 'equal) |
| 114 | 109 | ||
| 115 | note that the regexps should not contain leading or trailing whitespace.") | 110 | Note that the regexps should not contain leading or trailing whitespace.") |
| 116 | 111 | ||
| 117 | (defvar hs-hide-hooks nil | 112 | (defvar hs-hide-hooks nil |
| 118 | "*hooks called at the end of hs-hide-all and hs-hide-block.") | 113 | "*Hooks called at the end of hs-hide-all and hs-hide-block.") |
| 119 | 114 | ||
| 120 | (defvar hs-show-hooks nil | 115 | (defvar hs-show-hooks nil |
| 121 | "*hooks called at the end of hs-show-all, hs-show-block and hs-show-region.") | 116 | "*Hooks called at the end of hs-show-all, hs-show-block and hs-show-region.") |
| 122 | 117 | ||
| 123 | (defvar hs-minor-mode-prefix "\C-c" | 118 | (defvar hs-minor-mode-prefix "\C-c" |
| 124 | "*prefix key to use for hideshow commands in hideshow minor mode.") | 119 | "*Prefix key to use for hideshow commands in hideshow minor mode.") |
| 125 | 120 | ||
| 126 | 121 | ||
| 127 | ;;;---------------------------------------------------------------------------- | 122 | ;;;---------------------------------------------------------------------------- |
| 128 | ;;; internal variables | 123 | ;;; internal variables |
| 129 | 124 | ||
| 130 | (defvar hs-minor-mode nil | 125 | (defvar hs-minor-mode nil |
| 131 | "non-nil if using hideshow mode as a minor mode of some other mode. | 126 | "Non-nil if using hideshow mode as a minor mode of some other mode. |
| 132 | use the command `hs-minor-mode' to toggle this variable.") | 127 | Use the command `hs-minor-mode' to toggle this variable.") |
| 133 | 128 | ||
| 134 | (defvar hs-minor-mode-map nil | 129 | (defvar hs-minor-mode-map nil |
| 135 | "mode map for hideshow minor mode.") | 130 | "Mode map for hideshow minor mode.") |
| 136 | 131 | ||
| 137 | (defvar hs-menu-bar nil | 132 | (defvar hs-menu-bar nil |
| 138 | "menu bar for hideshow minor mode (xemacs only).") | 133 | "Menu bar for hideshow minor mode (Xemacs only).") |
| 139 | 134 | ||
| 140 | (defvar hs-c-start-regexp nil | 135 | (defvar hs-c-start-regexp nil |
| 141 | "regexp for beginning of comments. buffer-local. | 136 | "Regexp for beginning of comments. Buffer-local. |
| 142 | differs from mode-specific comment regexps in that surrounding | 137 | Differs from mode-specific comment regexps in that surrounding |
| 143 | whitespace is stripped.") | 138 | whitespace is stripped.") |
| 144 | 139 | ||
| 145 | (defvar hs-c-end-regexp nil | 140 | (defvar hs-c-end-regexp nil |
| 146 | "regexp for end of comments. buffer-local. | 141 | "Regexp for end of comments. Buffer-local. |
| 147 | see `hs-c-start-regexp'.") | 142 | See `hs-c-start-regexp'.") |
| 148 | 143 | ||
| 149 | (defvar hs-block-start-regexp nil | 144 | (defvar hs-block-start-regexp nil |
| 150 | "regexp for beginning of block. buffer-local.") | 145 | "Regexp for beginning of block. Buffer-local.") |
| 151 | 146 | ||
| 152 | (defvar hs-block-end-regexp nil | 147 | (defvar hs-block-end-regexp nil |
| 153 | "regexp for end of block. buffer-local.") | 148 | "Regexp for end of block. Buffer-local.") |
| 154 | 149 | ||
| 155 | (defvar hs-forward-sexp-func 'forward-sexp | 150 | (defvar hs-forward-sexp-func 'forward-sexp |
| 156 | "function used to do a forward-sexp. should change for algol-ish modes. | 151 | "Function used to do a forward-sexp. Should change for Algol-ish modes. |
| 157 | for single-character block delimiters -- ie, the syntax table regexp for the | 152 | For single-character block delimiters -- ie, the syntax table regexp for the |
| 158 | character is either ( or ) -- `hs-forward-sexp-func' would just be | 153 | character is either `(' or `)' -- `hs-forward-sexp-func' would just be |
| 159 | `forward-sexp'. for other modes such as simula, a more specialized function | 154 | `forward-sexp'. For other modes such as simula, a more specialized function |
| 160 | is necessary.") | 155 | is necessary.") |
| 161 | 156 | ||
| 162 | ; (eval-when-compile ; lint free! | 157 | (defvar hs-emacs-type 'fsf |
| 163 | ; (unless (emacs-type-eq 'lucid) | 158 | "Used to support both FSF Emacs and Xemacs.") |
| 164 | ; (defvar current-menubar nil "") | 159 | |
| 165 | ; (defun set-buffer-menubar (arg1)) | 160 | (eval-when-compile |
| 166 | ; (defun add-menu (arg1 arg2 arg3)))) | 161 | (if (string-match "^19" emacs-version) |
| 162 | nil | ||
| 163 | (defvar current-menubar nil "") | ||
| 164 | (defun set-buffer-menubar (arg1)) | ||
| 165 | (defun add-menu (arg1 arg2 arg3)))) | ||
| 167 | 166 | ||
| 168 | 167 | ||
| 169 | ;;;---------------------------------------------------------------------------- | 168 | ;;;---------------------------------------------------------------------------- |
| @@ -171,8 +170,8 @@ is necessary.") | |||
| 171 | 170 | ||
| 172 | ;; snarfed from outline.el, but added buffer-read-only | 171 | ;; snarfed from outline.el, but added buffer-read-only |
| 173 | (defun hs-flag-region (from to flag) | 172 | (defun hs-flag-region (from to flag) |
| 174 | "hides or shows lines from FROM to TO, according to FLAG. | 173 | "Hides or shows lines from FROM to TO, according to FLAG. |
| 175 | if FLAG is \\n (newline character) then text is shown, while if FLAG | 174 | If FLAG is \\n (newline character) then text is shown, while if FLAG |
| 176 | is \\^M \(control-M) the text is hidden." | 175 | is \\^M \(control-M) the text is hidden." |
| 177 | (let ((modp (buffer-modified-p)) | 176 | (let ((modp (buffer-modified-p)) |
| 178 | buffer-read-only) ; nothing is immune | 177 | buffer-read-only) ; nothing is immune |
| @@ -184,60 +183,61 @@ is \\^M \(control-M) the text is hidden." | |||
| 184 | (set-buffer-modified-p modp)))) | 183 | (set-buffer-modified-p modp)))) |
| 185 | 184 | ||
| 186 | (defun hs-hide-block-at-point (&optional end) | 185 | (defun hs-hide-block-at-point (&optional end) |
| 187 | "hide block iff on block beginning, optional END means reposition at end." | 186 | "Hide block iff on block beginning, optional END means reposition at end." |
| 188 | (when (looking-at hs-block-start-regexp) | 187 | (if (looking-at hs-block-start-regexp) |
| 189 | (let* ((p (point)) | 188 | (let* ((p (point)) |
| 190 | (q (progn (funcall hs-forward-sexp-func 1) (point)))) | 189 | (q (progn (funcall hs-forward-sexp-func 1) (point)))) |
| 191 | (forward-line -1) (end-of-line) | 190 | (forward-line -1) (end-of-line) |
| 192 | (when (and (< p (point)) (> (count-lines p q) 1)) | 191 | (if (and (< p (point)) (> (count-lines p q) 1)) |
| 193 | (hs-flag-region p (point) ?\C-m)) | 192 | (hs-flag-region p (point) ?\C-m)) |
| 194 | (goto-char (if end q p))))) | 193 | (goto-char (if end q p))))) |
| 195 | 194 | ||
| 196 | (defun hs-show-block-at-point (&optional end) | 195 | (defun hs-show-block-at-point (&optional end) |
| 197 | "show block iff on block beginning. optional END means reposition at end." | 196 | "Show block iff on block beginning. Optional END means reposition at end." |
| 198 | (when (looking-at hs-block-start-regexp) | 197 | (if (looking-at hs-block-start-regexp) |
| 199 | (let* ((p (point)) | 198 | (let* ((p (point)) |
| 200 | (q | 199 | (q |
| 201 | (condition-case error ; probably unbalanced paren | 200 | (condition-case error ; probably unbalanced paren |
| 202 | (progn | 201 | (progn |
| 203 | (funcall hs-forward-sexp-func 1) | 202 | (funcall hs-forward-sexp-func 1) |
| 204 | (point)) | 203 | (point)) |
| 205 | (error | 204 | (error |
| 206 | (case hs-unbalance-handler-method | 205 | (cond |
| 207 | ('ignore | 206 | ((eq hs-unbalance-handler-method 'ignore) |
| 208 | ;; just ignore this block | 207 | ;; just ignore this block |
| 209 | (point)) | 208 | (point)) |
| 210 | ('top-level | 209 | ((eq hs-unbalance-handler-method 'top-level) |
| 211 | ;; try to get out of rat's nest and expose the whole func | 210 | ;; try to get out of rat's nest and expose the whole func |
| 212 | (unless (= (current-column) 0) (beginning-of-defun)) | 211 | (if (/= (current-column) 0) (beginning-of-defun)) |
| 213 | (setq p (point)) | 212 | (setq p (point)) |
| 214 | (re-search-forward (concat "^" hs-block-start-regexp) | 213 | (re-search-forward (concat "^" hs-block-start-regexp) |
| 215 | (point-max) t 2) | 214 | (point-max) t 2) |
| 216 | (point)) | 215 | (point)) |
| 217 | ('next-line | 216 | ((eq hs-unbalance-handler-method 'next-line) |
| 218 | ;; assumption is that user knows what s/he's doing | 217 | ;; assumption is that user knows what s/he's doing |
| 219 | (beginning-of-line) (setq p (point)) | 218 | (beginning-of-line) (setq p (point)) |
| 220 | (end-of-line 2) (point)) | 219 | (end-of-line 2) (point)) |
| 221 | (t | 220 | (t |
| 222 | ;; pass error through -- this applies to `signal', too | 221 | ;; pass error through -- this applies to `signal', too |
| 223 | (signal (car error) (cdr error)))))))) | 222 | (signal (car error) (cdr error)))))))) |
| 224 | (hs-flag-region p q ?\n) | 223 | (hs-flag-region p q ?\n) |
| 225 | (goto-char (if end (1+ (point)) p))))) | 224 | (goto-char (if end (1+ (point)) p))))) |
| 226 | 225 | ||
| 227 | (defun hs-safety-is-job-n () | 226 | (defun hs-safety-is-job-n () |
| 228 | "warns if selective-display or selective-display-ellipses is nil." | 227 | "Warns if selective-display or selective-display-ellipses is nil." |
| 229 | (let ((str "")) | 228 | (let ((str "")) |
| 230 | (unless selective-display | 229 | (or selective-display |
| 231 | (setq str "selective-display nil ")) | 230 | (setq str "selective-display nil ")) |
| 232 | (unless selective-display-ellipses | 231 | (or selective-display-ellipses |
| 233 | (setq str (concat str "selective-display-ellipses nil"))) | 232 | (setq str (concat str "selective-display-ellipses nil"))) |
| 234 | (when (/= (length str) 0) | 233 | (if (= (length str) 0) |
| 234 | nil | ||
| 235 | (message "warning: %s" str) | 235 | (message "warning: %s" str) |
| 236 | (sit-for 2)))) | 236 | (sit-for 2)))) |
| 237 | 237 | ||
| 238 | (defun hs-inside-comment-p () | 238 | (defun hs-inside-comment-p () |
| 239 | "returns non-nil if point is inside a comment, otherwise nil. | 239 | "Returns non-nil if point is inside a comment, otherwise nil. |
| 240 | actually, for multi-line-able comments, returns a list containing | 240 | Actually, for multi-line-able comments, returns a list containing |
| 241 | the buffer position of the start and the end of the comment." | 241 | the buffer position of the start and the end of the comment." |
| 242 | ;; is it single-line-only or multi-line-able? | 242 | ;; is it single-line-only or multi-line-able? |
| 243 | (save-excursion | 243 | (save-excursion |
| @@ -252,29 +252,30 @@ the buffer position of the start and the end of the comment." | |||
| 252 | (setq q (point)) | 252 | (setq q (point)) |
| 253 | (forward-comment -1) | 253 | (forward-comment -1) |
| 254 | (re-search-forward hs-c-start-regexp (point-max) 1) | 254 | (re-search-forward hs-c-start-regexp (point-max) 1) |
| 255 | (when (< (- (point) (length comment-start)) p) | 255 | (if (< (- (point) (length comment-start)) p) |
| 256 | (list (match-beginning 0) q)))))) | 256 | (list (match-beginning 0) q)))))) |
| 257 | 257 | ||
| 258 | (defun hs-grok-mode-type () | 258 | (defun hs-grok-mode-type () |
| 259 | "setup variables for new buffers where applicable." | 259 | "Setup variables for new buffers where applicable." |
| 260 | (when (and (boundp 'comment-start) | 260 | (if (and (boundp 'comment-start) |
| 261 | (boundp 'comment-end)) | 261 | (boundp 'comment-end)) |
| 262 | (setq hs-c-start-regexp (regexp-quote comment-start)) | 262 | (progn |
| 263 | (if (string-match " +$" hs-c-start-regexp) | 263 | (setq hs-c-start-regexp (regexp-quote comment-start)) |
| 264 | (setq hs-c-start-regexp | 264 | (if (string-match " +$" hs-c-start-regexp) |
| 265 | (substring hs-c-start-regexp 0 (1- (match-end 0))))) | 265 | (setq hs-c-start-regexp |
| 266 | (setq hs-c-end-regexp (if (string= "" comment-end) "\n" | 266 | (substring hs-c-start-regexp 0 (1- (match-end 0))))) |
| 267 | (regexp-quote comment-end))) | 267 | (setq hs-c-end-regexp (if (string= "" comment-end) "\n" |
| 268 | (if (string-match "^ +" hs-c-end-regexp) | 268 | (regexp-quote comment-end))) |
| 269 | (setq hs-c-end-regexp | 269 | (if (string-match "^ +" hs-c-end-regexp) |
| 270 | (substring hs-c-end-regexp (match-end 0)))) | 270 | (setq hs-c-end-regexp |
| 271 | (let ((lookup (assoc major-mode hs-special-modes-alist))) | 271 | (substring hs-c-end-regexp (match-end 0)))) |
| 272 | (setq hs-block-start-regexp (or (cadr lookup) "\\s\(") | 272 | (let ((lookup (assoc major-mode hs-special-modes-alist))) |
| 273 | hs-block-end-regexp (or (caddr lookup) "\\s\)") | 273 | (setq hs-block-start-regexp (or (nth 1 lookup) "\\s\(") |
| 274 | hs-forward-sexp-func (or (cadddr lookup) 'forward-sexp))))) | 274 | hs-block-end-regexp (or (nth 2 lookup) "\\s\)") |
| 275 | hs-forward-sexp-func (or (nth 3 lookup) 'forward-sexp)))))) | ||
| 275 | 276 | ||
| 276 | (defun hs-find-block-beginning () | 277 | (defun hs-find-block-beginning () |
| 277 | "repositions point at block-start. return point, or nil if top-level." | 278 | "Repositions point at block-start. Return point, or nil if top-level." |
| 278 | (let (done | 279 | (let (done |
| 279 | (here (point)) | 280 | (here (point)) |
| 280 | (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\(" | 281 | (both-regexps (concat "\\(" hs-block-start-regexp "\\)\\|\\(" |
| @@ -289,7 +290,7 @@ the buffer position of the start and the end of the comment." | |||
| 289 | done)) | 290 | done)) |
| 290 | 291 | ||
| 291 | (defmacro hs-life-goes-on (&rest body) | 292 | (defmacro hs-life-goes-on (&rest body) |
| 292 | "executes optional BODY iff variable hs-minor-mode is non-nil." | 293 | "Executes optional BODY iff variable `hs-minor-mode' is non-nil." |
| 293 | (list 'if 'hs-minor-mode (cons 'progn body))) | 294 | (list 'if 'hs-minor-mode (cons 'progn body))) |
| 294 | 295 | ||
| 295 | 296 | ||
| @@ -298,9 +299,9 @@ the buffer position of the start and the end of the comment." | |||
| 298 | 299 | ||
| 299 | ;;;###autoload | 300 | ;;;###autoload |
| 300 | (defun hs-hide-all () | 301 | (defun hs-hide-all () |
| 301 | "hides all top-level blocks, displaying only first and last lines. | 302 | "Hides all top-level blocks, displaying only first and last lines. |
| 302 | when done, point is repositioned at the beginning of the line, and | 303 | When done, point is repositioned at the beginning of the line, and |
| 303 | hs-hide-hooks is called. see documentation for `run-hooks'." | 304 | hs-hide-hooks is called. See documentation for `run-hooks'." |
| 304 | (interactive) | 305 | (interactive) |
| 305 | (hs-life-goes-on | 306 | (hs-life-goes-on |
| 306 | (message "hiding all blocks ...") | 307 | (message "hiding all blocks ...") |
| @@ -314,15 +315,15 @@ hs-hide-hooks is called. see documentation for `run-hooks'." | |||
| 314 | (re-search-forward top-level-re (point-max) t)) | 315 | (re-search-forward top-level-re (point-max) t)) |
| 315 | (goto-char (match-beginning 0)) | 316 | (goto-char (match-beginning 0)) |
| 316 | (hs-hide-block-at-point t) | 317 | (hs-hide-block-at-point t) |
| 317 | (message "hiding ... %d" (incf count)))) | 318 | (message "hiding ... %d" (setq count (1+ count))))) |
| 318 | (hs-safety-is-job-n)) | 319 | (hs-safety-is-job-n)) |
| 319 | (beginning-of-line) | 320 | (beginning-of-line) |
| 320 | (message "hiding all blocks ... done") | 321 | (message "hiding all blocks ... done") |
| 321 | (run-hooks 'hs-hide-hooks))) | 322 | (run-hooks 'hs-hide-hooks))) |
| 322 | 323 | ||
| 323 | (defun hs-show-all () | 324 | (defun hs-show-all () |
| 324 | "shows all top-level blocks. | 325 | "Shows all top-level blocks. |
| 325 | when done, point is unchanged, and hs-show-hooks is called. see | 326 | When done, point is unchanged, and hs-show-hooks is called. See |
| 326 | documentation for `run-hooks'." | 327 | documentation for `run-hooks'." |
| 327 | (interactive) | 328 | (interactive) |
| 328 | (hs-life-goes-on | 329 | (hs-life-goes-on |
| @@ -333,34 +334,35 @@ documentation for `run-hooks'." | |||
| 333 | 334 | ||
| 334 | ;;;###autoload | 335 | ;;;###autoload |
| 335 | (defun hs-hide-block (&optional end) | 336 | (defun hs-hide-block (&optional end) |
| 336 | "selects a block and hides it. with prefix arg, reposition at end. | 337 | "Selects a block and hides it. With prefix arg, reposition at end. |
| 337 | block is defined as a sexp for lispish modes, mode-specific otherwise. | 338 | Block is defined as a sexp for lispish modes, mode-specific otherwise. |
| 338 | comments are blocks, too. upon completion, point is at repositioned and | 339 | Comments are blocks, too. Upon completion, point is at repositioned and |
| 339 | hs-hide-hooks is called. see documentation for `run-hooks'." | 340 | hs-hide-hooks is called. See documentation for `run-hooks'." |
| 340 | (interactive "P") | 341 | (interactive "P") |
| 341 | (hs-life-goes-on | 342 | (hs-life-goes-on |
| 342 | (let ((c-reg (hs-inside-comment-p))) | 343 | (let ((c-reg (hs-inside-comment-p))) |
| 343 | (if c-reg | 344 | (if c-reg |
| 344 | (cond ((string= comment-end "") | 345 | (cond ((string= comment-end "") |
| 345 | (message "can't hide a single-line comment")) | 346 | (message "can't hide a single-line comment")) |
| 346 | ((< (count-lines (car c-reg) (cadr c-reg)) 2) | 347 | ((< (count-lines (car c-reg) (nth 1 c-reg)) 2) |
| 347 | (message "not enougn comment lines to hide")) | 348 | (message "not enougn comment lines to hide")) |
| 348 | (t | 349 | (t |
| 349 | (goto-char (cadr c-reg)) | 350 | (goto-char (nth 1 c-reg)) |
| 350 | (forward-line -1) | 351 | (forward-line -1) |
| 351 | (hs-flag-region (car c-reg) (point) ?\C-m) | 352 | (hs-flag-region (car c-reg) (point) ?\C-m) |
| 352 | (goto-char (if end (cadr c-reg) (car c-reg))) | 353 | (goto-char (if end (nth 1 c-reg) (car c-reg))) |
| 353 | (hs-safety-is-job-n) | 354 | (hs-safety-is-job-n) |
| 354 | (run-hooks 'hs-hide-hooks))) | 355 | (run-hooks 'hs-hide-hooks))) |
| 355 | (when (or (looking-at hs-block-start-regexp) | 356 | (if (or (looking-at hs-block-start-regexp) |
| 356 | (hs-find-block-beginning)) | 357 | (hs-find-block-beginning)) |
| 357 | (hs-hide-block-at-point end) | 358 | (progn |
| 358 | (hs-safety-is-job-n) | 359 | (hs-hide-block-at-point end) |
| 359 | (run-hooks 'hs-hide-hooks)))))) | 360 | (hs-safety-is-job-n) |
| 361 | (run-hooks 'hs-hide-hooks))))))) | ||
| 360 | 362 | ||
| 361 | (defun hs-show-block (&optional end) | 363 | (defun hs-show-block (&optional end) |
| 362 | "selects a block and shows it. with prefix arg, reposition at end. | 364 | "Selects a block and shows it. With prefix arg, reposition at end. |
| 363 | upon completion, point is repositioned hs-show-hooks are called. see | 365 | Upon completion, point is repositioned hs-show-hooks are called. See |
| 364 | documetation for `hs-hide-block' and `run-hooks'." | 366 | documetation for `hs-hide-block' and `run-hooks'." |
| 365 | (interactive "P") | 367 | (interactive "P") |
| 366 | (hs-life-goes-on | 368 | (hs-life-goes-on |
| @@ -369,18 +371,19 @@ documetation for `hs-hide-block' and `run-hooks'." | |||
| 369 | (cond ((string= comment-end "") | 371 | (cond ((string= comment-end "") |
| 370 | (message "already looking at the entire comment")) | 372 | (message "already looking at the entire comment")) |
| 371 | (t | 373 | (t |
| 372 | (hs-flag-region (car c-reg) (cadr c-reg) ?\n) | 374 | (hs-flag-region (car c-reg) (nth 1 c-reg) ?\n) |
| 373 | (goto-char (if end (cadr c-reg) (car c-reg))))) | 375 | (goto-char (if end (nth 1 c-reg) (car c-reg))))) |
| 374 | (when (or (looking-at hs-block-start-regexp) | 376 | (if (or (looking-at hs-block-start-regexp) |
| 375 | (hs-find-block-beginning)) | 377 | (hs-find-block-beginning)) |
| 376 | (hs-show-block-at-point end) | 378 | (progn |
| 377 | (hs-safety-is-job-n) | 379 | (hs-show-block-at-point end) |
| 378 | (run-hooks 'hs-show-hooks)))))) | 380 | (hs-safety-is-job-n) |
| 381 | (run-hooks 'hs-show-hooks))))))) | ||
| 379 | 382 | ||
| 380 | (defun hs-show-region (beg end) | 383 | (defun hs-show-region (beg end) |
| 381 | "shows all lines from BEG to END, without doing any block analysis. | 384 | "Shows all lines from BEG to END, without doing any block analysis. |
| 382 | note: hs-show-region is intended for use when when hs-show-block signals | 385 | Note: hs-show-region is intended for use when when hs-show-block signals |
| 383 | `unbalanced parentheses' and so is an emergency measure only. you may | 386 | `unbalanced parentheses' and so is an emergency measure only. You may |
| 384 | become very confused if you use this command indiscriminately." | 387 | become very confused if you use this command indiscriminately." |
| 385 | (interactive "r") | 388 | (interactive "r") |
| 386 | (hs-life-goes-on | 389 | (hs-life-goes-on |
| @@ -390,14 +393,14 @@ become very confused if you use this command indiscriminately." | |||
| 390 | 393 | ||
| 391 | ;;;###autoload | 394 | ;;;###autoload |
| 392 | (defun hs-minor-mode (&optional arg) | 395 | (defun hs-minor-mode (&optional arg) |
| 393 | "toggle hideshow minor mode. | 396 | "Toggle hideshow minor mode. |
| 394 | with ARG, turn hideshow minor mode on if ARG is positive, off otherwise. | 397 | With ARG, turn hideshow minor mode on if ARG is positive, off otherwise. |
| 395 | when hideshow minor mode is on, the menu bar is augmented with hideshow | 398 | When hideshow minor mode is on, the menu bar is augmented with hideshow |
| 396 | commands and the hideshow commands are enabled. the variables\n | 399 | commands and the hideshow commands are enabled. The variables\n |
| 397 | \tselective-display\n\tselective-display-ellipses\n | 400 | \tselective-display\n\tselective-display-ellipses\n |
| 398 | are set to t. lastly, the hooks set in hs-minor-mode-hook are called. | 401 | are set to t. Lastly, the hooks set in hs-minor-mode-hook are called. |
| 399 | see documentation for `run-hooks'.\n | 402 | See documentation for `run-hooks'.\n |
| 400 | turning hideshow minor mode off reverts the menu bar and the | 403 | Turning hideshow minor mode off reverts the menu bar and the |
| 401 | variables to default values and disables the hideshow commands." | 404 | variables to default values and disables the hideshow commands." |
| 402 | (interactive "P") | 405 | (interactive "P") |
| 403 | (setq hs-minor-mode | 406 | (setq hs-minor-mode |
| @@ -406,15 +409,16 @@ variables to default values and disables the hideshow commands." | |||
| 406 | (> (prefix-numeric-value arg) 0))) | 409 | (> (prefix-numeric-value arg) 0))) |
| 407 | (if hs-minor-mode | 410 | (if hs-minor-mode |
| 408 | (progn | 411 | (progn |
| 409 | ; (when (emacs-type-eq 'lucid) | 412 | (if (eq hs-emacs-type 'lucid) |
| 410 | ; (set-buffer-menubar (copy-sequence current-menubar)) | 413 | (progn |
| 411 | ; (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar))) | 414 | (set-buffer-menubar (copy-sequence current-menubar)) |
| 415 | (add-menu nil (car hs-menu-bar) (cdr hs-menu-bar)))) | ||
| 412 | (setq selective-display t | 416 | (setq selective-display t |
| 413 | selective-display-ellipses t) | 417 | selective-display-ellipses t) |
| 414 | (hs-grok-mode-type) | 418 | (hs-grok-mode-type) |
| 415 | (run-hooks 'hs-minor-mode-hook)) | 419 | (run-hooks 'hs-minor-mode-hook)) |
| 416 | ; (when (emacs-type-eq 'lucid) | 420 | (if (eq hs-emacs-type 'lucid) |
| 417 | ; (set-buffer-menubar (delete hs-menu-bar current-menubar))) | 421 | (set-buffer-menubar (delete hs-menu-bar current-menubar))) |
| 418 | (kill-local-variable 'selective-display) | 422 | (kill-local-variable 'selective-display) |
| 419 | (kill-local-variable 'selective-display-ellipses))) | 423 | (kill-local-variable 'selective-display-ellipses))) |
| 420 | 424 | ||
| @@ -422,37 +426,46 @@ variables to default values and disables the hideshow commands." | |||
| 422 | ;;;---------------------------------------------------------------------------- | 426 | ;;;---------------------------------------------------------------------------- |
| 423 | ;;; load-time setup routines | 427 | ;;; load-time setup routines |
| 424 | 428 | ||
| 429 | ;; which emacs being used? | ||
| 430 | (setq hs-emacs-type | ||
| 431 | (if (string-match "^19" emacs-version) | ||
| 432 | 'fsf | ||
| 433 | 'lucid)) | ||
| 434 | |||
| 425 | ;; keymaps and menus | 435 | ;; keymaps and menus |
| 426 | (unless hs-minor-mode-map | 436 | (if (not hs-minor-mode-map) |
| 427 | (setq hs-minor-mode-map (make-sparse-keymap)) | 437 | (setq hs-minor-mode-map (make-sparse-keymap)) |
| 428 | (cond | 438 | (cond |
| 429 | ; ((emacs-type-eq 'lucid) | 439 | ((eq hs-emacs-type 'lucid) |
| 430 | ; (setq hs-menu-bar ; build top down for lucid | 440 | (setq hs-menu-bar ; build top down for lucid |
| 431 | ; '("hideshow" | 441 | '("hideshow" |
| 432 | ; ["hide block" hs-hide-block t] | 442 | ["hide block" hs-hide-block t] |
| 433 | ; ["show block" hs-show-block t] | 443 | ["show block" hs-show-block t] |
| 434 | ; ["hide all" hs-hide-all t] | 444 | ["hide all" hs-hide-all t] |
| 435 | ; ["show all" hs-show-all t] | 445 | ["show all" hs-show-all t] |
| 436 | ; ["show region" hs-show-region t]))) | 446 | ["show region" hs-show-region t]))) |
| 437 | (t ; build bottom up for others | 447 | (t ; build bottom up for others |
| 438 | (define-key hs-minor-mode-map [menu-bar hideshow] | 448 | (define-key hs-minor-mode-map [menu-bar hideshow] |
| 439 | (cons "hideshow" (make-sparse-keymap "hideshow"))) | 449 | (cons "hideshow" (make-sparse-keymap "hideshow"))) |
| 440 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-region] | 450 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-region] |
| 441 | '("show region" . hs-show-region)) | 451 | '("show region" . hs-show-region)) |
| 442 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-all] | 452 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-all] |
| 443 | '("show all" . hs-show-all)) | 453 | '("show all" . hs-show-all)) |
| 444 | (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-all] | 454 | (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-all] |
| 445 | '("hide all" . hs-hide-all)) | 455 | '("hide all" . hs-hide-all)) |
| 446 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-block] | 456 | (define-key hs-minor-mode-map [menu-bar hideshow hs-show-block] |
| 447 | '("show block" . hs-show-block)) | 457 | '("show block" . hs-show-block)) |
| 448 | (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-block] | 458 | (define-key hs-minor-mode-map [menu-bar hideshow hs-hide-block] |
| 449 | '("hide block" . hs-hide-block))))) | 459 | '("hide block" . hs-hide-block))))) |
| 450 | 460 | ||
| 451 | ;; some housekeeping | 461 | ;; some housekeeping |
| 452 | (pushnew (cons 'hs-minor-mode hs-minor-mode-map) | 462 | (or (assq 'hs-minor-mode minor-mode-map-alist) |
| 453 | minor-mode-map-alist | 463 | (setq minor-mode-map-alist |
| 454 | :test 'equal) | 464 | (cons (cons 'hs-minor-mode hs-minor-mode-map) |
| 455 | (pushnew '(hs-minor-mode " hs") minor-mode-alist :test 'equal) | 465 | minor-mode-map-alist))) |
| 466 | (or (assq 'hs-minor-mode minor-mode-alist) | ||
| 467 | (setq minor-mode-alist (append minor-mode-alist | ||
| 468 | (list '(hs-minor-mode " hs"))))) | ||
| 456 | 469 | ||
| 457 | ;; make some variables buffer-local | 470 | ;; make some variables buffer-local |
| 458 | (make-variable-buffer-local 'hs-minor-mode) | 471 | (make-variable-buffer-local 'hs-minor-mode) |