diff options
| author | Dan Nicolaescu | 2008-02-16 07:40:06 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2008-02-16 07:40:06 +0000 |
| commit | 1f3447603f121adaade6c2f847c8135f7b7c7b67 (patch) | |
| tree | f7a800511acddcb8a8c15167c9233d4243041ad7 | |
| parent | 517045bc37831d78eb0b24a0ee20e7a011641d95 (diff) | |
| download | emacs-1f3447603f121adaade6c2f847c8135f7b7c7b67.tar.gz emacs-1f3447603f121adaade6c2f847c8135f7b7c7b67.zip | |
Remove the minor-mode bookkeeping. Move
make-variable-buffer-local code after the corresponding defvar.
(hs-minor-mode-map): Define and initialize in one step.
(hs-minor-mode): Change from defun to define-minor-mode.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/hideshow.el | 96 |
2 files changed, 45 insertions, 58 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1e74cf5a927..073fdee2815 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2008-02-16 Dan Nicolaescu <dann@ics.uci.edu> | ||
| 2 | |||
| 3 | * progmodes/hideshow.el: Remove the minor-mode bookkeeping. Move | ||
| 4 | make-variable-buffer-local code after the corresponding defvar. | ||
| 5 | (hs-minor-mode-map): Define and initialize in one step. | ||
| 6 | (hs-minor-mode): Change from defun to define-minor-mode. | ||
| 7 | |||
| 1 | 2008-02-16 Nick Roberts <nickrob@snap.net.nz> | 8 | 2008-02-16 Nick Roberts <nickrob@snap.net.nz> |
| 2 | 9 | ||
| 3 | * progmodes/gud.el (gud-gdb): Don't reset gdb-ready. | 10 | * progmodes/gud.el (gud-gdb): Don't reset gdb-ready. |
diff --git a/lisp/progmodes/hideshow.el b/lisp/progmodes/hideshow.el index 5a784b159d3..f0065cbedaf 100644 --- a/lisp/progmodes/hideshow.el +++ b/lisp/progmodes/hideshow.el | |||
| @@ -345,24 +345,49 @@ info node `(elisp)Overlays'.") | |||
| 345 | "Non-nil if using hideshow mode as a minor mode of some other mode. | 345 | "Non-nil if using hideshow mode as a minor mode of some other mode. |
| 346 | Use the command `hs-minor-mode' to toggle or set this variable.") | 346 | Use the command `hs-minor-mode' to toggle or set this variable.") |
| 347 | 347 | ||
| 348 | (defvar hs-minor-mode-map nil | 348 | (defvar hs-minor-mode-map |
| 349 | (let ((map (make-sparse-keymap))) | ||
| 350 | ;; These bindings roughly imitate those used by Outline mode. | ||
| 351 | (define-key map "\C-c@\C-h" 'hs-hide-block) | ||
| 352 | (define-key map "\C-c@\C-s" 'hs-show-block) | ||
| 353 | (define-key map "\C-c@\C-\M-h" 'hs-hide-all) | ||
| 354 | (define-key map "\C-c@\C-\M-s" 'hs-show-all) | ||
| 355 | (define-key map "\C-c@\C-l" 'hs-hide-level) | ||
| 356 | (define-key map "\C-c@\C-c" 'hs-toggle-hiding) | ||
| 357 | (define-key map [(shift mouse-2)] 'hs-mouse-toggle-hiding) | ||
| 358 | (easy-menu-define hs-minor-mode-menu map | ||
| 359 | "Menu used when hideshow minor mode is active." | ||
| 360 | '("Hide/Show" | ||
| 361 | ["Hide Block" hs-hide-block | ||
| 362 | :help "Hide the code or comment block at point"] | ||
| 363 | ["Show Block" hs-show-block | ||
| 364 | :help "Show the code or comment block at point"] | ||
| 365 | ["Hide All" hs-hide-all | ||
| 366 | :help "Hide all the blocks in the buffer"] | ||
| 367 | ["Show All" hs-show-all | ||
| 368 | :help "Show all the clocks in the buffer"] | ||
| 369 | ["Hide Level" hs-hide-level | ||
| 370 | :help "Hide all block at levels below the current block"] | ||
| 371 | ["Toggle Hiding" hs-toggle-hiding | ||
| 372 | :help "Toggle the hiding state of the current block"])) | ||
| 373 | map) | ||
| 349 | "Keymap for hideshow minor mode.") | 374 | "Keymap for hideshow minor mode.") |
| 350 | 375 | ||
| 351 | (defvar hs-minor-mode-menu nil | ||
| 352 | "Menu for hideshow minor mode.") | ||
| 353 | |||
| 354 | (defvar hs-c-start-regexp nil | 376 | (defvar hs-c-start-regexp nil |
| 355 | "Regexp for beginning of comments. | 377 | "Regexp for beginning of comments. |
| 356 | Differs from mode-specific comment regexps in that | 378 | Differs from mode-specific comment regexps in that |
| 357 | surrounding whitespace is stripped.") | 379 | surrounding whitespace is stripped.") |
| 380 | (make-variable-buffer-local 'hs-c-start-regexp) | ||
| 358 | 381 | ||
| 359 | (defvar hs-block-start-regexp nil | 382 | (defvar hs-block-start-regexp nil |
| 360 | "Regexp for beginning of block.") | 383 | "Regexp for beginning of block.") |
| 384 | (make-variable-buffer-local 'hs-block-start-regexp) | ||
| 361 | 385 | ||
| 362 | (defvar hs-block-start-mdata-select nil | 386 | (defvar hs-block-start-mdata-select nil |
| 363 | "Element in `hs-block-start-regexp' match data to consider as block start. | 387 | "Element in `hs-block-start-regexp' match data to consider as block start. |
| 364 | The internal function `hs-forward-sexp' moves point to the beginning of this | 388 | The internal function `hs-forward-sexp' moves point to the beginning of this |
| 365 | element (using `match-beginning') before calling `hs-forward-sexp-func'.") | 389 | element (using `match-beginning') before calling `hs-forward-sexp-func'.") |
| 390 | (make-variable-buffer-local 'hs-block-start-mdata-select) | ||
| 366 | 391 | ||
| 367 | (defvar hs-block-end-regexp nil | 392 | (defvar hs-block-end-regexp nil |
| 368 | "Regexp for end of block.") | 393 | "Regexp for end of block.") |
| @@ -374,6 +399,7 @@ delimiters -- ie, the syntax table regexp for the character is | |||
| 374 | either `(' or `)' -- `hs-forward-sexp-func' would just be | 399 | either `(' or `)' -- `hs-forward-sexp-func' would just be |
| 375 | `forward-sexp'. For other modes such as simula, a more specialized | 400 | `forward-sexp'. For other modes such as simula, a more specialized |
| 376 | function is necessary.") | 401 | function is necessary.") |
| 402 | (make-variable-buffer-local 'hs-forward-sexp-func) | ||
| 377 | 403 | ||
| 378 | (defvar hs-adjust-block-beginning nil | 404 | (defvar hs-adjust-block-beginning nil |
| 379 | "Function used to tweak the block beginning. | 405 | "Function used to tweak the block beginning. |
| @@ -394,6 +420,7 @@ It should return the position from where we should start hiding. | |||
| 394 | It should not move the point. | 420 | It should not move the point. |
| 395 | 421 | ||
| 396 | See `hs-c-like-adjust-block-beginning' for an example of using this.") | 422 | See `hs-c-like-adjust-block-beginning' for an example of using this.") |
| 423 | (make-variable-buffer-local 'hs-adjust-block-beginning) | ||
| 397 | 424 | ||
| 398 | (defvar hs-headline nil | 425 | (defvar hs-headline nil |
| 399 | "Text of the line where a hidden block begins, set during isearch. | 426 | "Text of the line where a hidden block begins, set during isearch. |
| @@ -873,9 +900,8 @@ This can be useful if you have huge RCS logs in those comments." | |||
| 873 | (hs-hide-comment-region beg end))))))) | 900 | (hs-hide-comment-region beg end))))))) |
| 874 | 901 | ||
| 875 | ;;;###autoload | 902 | ;;;###autoload |
| 876 | (defun hs-minor-mode (&optional arg) | 903 | (define-minor-mode hs-minor-mode |
| 877 | "Toggle hideshow minor mode. | 904 | "Minor mode to selectively hide/show code and comment blocks. |
| 878 | With ARG, turn hideshow minor mode on if ARG is positive, off otherwise. | ||
| 879 | When hideshow minor mode is on, the menu bar is augmented with hideshow | 905 | When hideshow minor mode is on, the menu bar is augmented with hideshow |
| 880 | commands and the hideshow commands are enabled. | 906 | commands and the hideshow commands are enabled. |
| 881 | The value '(hs . t) is added to `buffer-invisibility-spec'. | 907 | The value '(hs . t) is added to `buffer-invisibility-spec'. |
| @@ -891,12 +917,10 @@ Lastly, the normal hook `hs-minor-mode-hook' is run using `run-hooks'. | |||
| 891 | 917 | ||
| 892 | Key bindings: | 918 | Key bindings: |
| 893 | \\{hs-minor-mode-map}" | 919 | \\{hs-minor-mode-map}" |
| 894 | 920 | :group 'hideshow | |
| 895 | (interactive "P") | 921 | :lighter " hs" |
| 896 | (setq hs-headline nil | 922 | :keymap hs-minor-mode-map |
| 897 | hs-minor-mode (if (null arg) | 923 | (setq hs-headline nil) |
| 898 | (not hs-minor-mode) | ||
| 899 | (> (prefix-numeric-value arg) 0))) | ||
| 900 | (if hs-minor-mode | 924 | (if hs-minor-mode |
| 901 | (progn | 925 | (progn |
| 902 | (hs-grok-mode-type) | 926 | (hs-grok-mode-type) |
| @@ -907,12 +931,10 @@ Key bindings: | |||
| 907 | (easy-menu-add hs-minor-mode-menu) | 931 | (easy-menu-add hs-minor-mode-menu) |
| 908 | (set (make-local-variable 'line-move-ignore-invisible) t) | 932 | (set (make-local-variable 'line-move-ignore-invisible) t) |
| 909 | (add-to-invisibility-spec '(hs . t))) | 933 | (add-to-invisibility-spec '(hs . t))) |
| 910 | (easy-menu-remove hs-minor-mode-menu) | ||
| 911 | (remove-from-invisibility-spec '(hs . t)) | 934 | (remove-from-invisibility-spec '(hs . t)) |
| 912 | ;; hs-show-all does nothing unless h-m-m is non-nil. | 935 | ;; hs-show-all does nothing unless h-m-m is non-nil. |
| 913 | (let ((hs-minor-mode t)) | 936 | (let ((hs-minor-mode t)) |
| 914 | (hs-show-all))) | 937 | (hs-show-all)))) |
| 915 | (run-hooks 'hs-minor-mode-hook)) | ||
| 916 | 938 | ||
| 917 | ;;;###autoload | 939 | ;;;###autoload |
| 918 | (defun turn-off-hideshow () | 940 | (defun turn-off-hideshow () |
| @@ -920,48 +942,6 @@ Key bindings: | |||
| 920 | (hs-minor-mode -1)) | 942 | (hs-minor-mode -1)) |
| 921 | 943 | ||
| 922 | ;;--------------------------------------------------------------------------- | 944 | ;;--------------------------------------------------------------------------- |
| 923 | ;; load-time actions | ||
| 924 | |||
| 925 | ;; keymaps and menus | ||
| 926 | (unless hs-minor-mode-map | ||
| 927 | (setq hs-minor-mode-map (make-sparse-keymap)) | ||
| 928 | (easy-menu-define hs-minor-mode-menu | ||
| 929 | hs-minor-mode-map | ||
| 930 | "Menu used when hideshow minor mode is active." | ||
| 931 | (cons "Hide/Show" | ||
| 932 | (mapcar | ||
| 933 | ;; Interpret each table entry as follows: first, populate keymap | ||
| 934 | ;; with elements 2 and 1; then, for easymenu, use entry directly | ||
| 935 | ;; unless element 0 is nil, in which case the entry is "omitted". | ||
| 936 | (lambda (ent) | ||
| 937 | (define-key hs-minor-mode-map (aref ent 2) (aref ent 1)) | ||
| 938 | (if (aref ent 0) ent "-----")) | ||
| 939 | ;; These bindings roughly imitate those used by Outline mode. | ||
| 940 | ;; menu entry command key | ||
| 941 | '(["Hide Block" hs-hide-block "\C-c@\C-h"] | ||
| 942 | ["Show Block" hs-show-block "\C-c@\C-s"] | ||
| 943 | ["Hide All" hs-hide-all "\C-c@\C-\M-h"] | ||
| 944 | ["Show All" hs-show-all "\C-c@\C-\M-s"] | ||
| 945 | ["Hide Level" hs-hide-level "\C-c@\C-l"] | ||
| 946 | ["Toggle Hiding" hs-toggle-hiding "\C-c@\C-c"] | ||
| 947 | [nil hs-mouse-toggle-hiding [(shift mouse-2)]] | ||
| 948 | ))))) | ||
| 949 | |||
| 950 | ;; some housekeeping | ||
| 951 | (add-to-list 'minor-mode-map-alist (cons 'hs-minor-mode hs-minor-mode-map)) | ||
| 952 | (add-to-list 'minor-mode-alist '(hs-minor-mode " hs") t) | ||
| 953 | |||
| 954 | ;; make some variables buffer-local | ||
| 955 | (dolist (var '(hs-minor-mode | ||
| 956 | hs-c-start-regexp | ||
| 957 | hs-block-start-regexp | ||
| 958 | hs-block-start-mdata-select | ||
| 959 | hs-block-end-regexp | ||
| 960 | hs-forward-sexp-func | ||
| 961 | hs-adjust-block-beginning)) | ||
| 962 | (make-variable-buffer-local var)) | ||
| 963 | |||
| 964 | ;;--------------------------------------------------------------------------- | ||
| 965 | ;; that's it | 945 | ;; that's it |
| 966 | 946 | ||
| 967 | (provide 'hideshow) | 947 | (provide 'hideshow) |