diff options
| author | Richard M. Stallman | 1997-07-04 00:16:50 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-07-04 00:16:50 +0000 |
| commit | 12eb8433586f4c8d5ffd572283e1f495ae130d6f (patch) | |
| tree | 6dfc2cb995d692f363a1c3643ac9dac0440f7a04 | |
| parent | f9be457422ea2d87f40142731d9a98701b82bf42 (diff) | |
| download | emacs-12eb8433586f4c8d5ffd572283e1f495ae130d6f.tar.gz emacs-12eb8433586f4c8d5ffd572283e1f495ae130d6f.zip | |
(show-paren-idle-timer): New defvar.
(show-paren-mode): Add :initialize attr in the defcustom.
Test the value at end of file, and turn on the mode if true.
| -rw-r--r-- | lisp/paren.el | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/lisp/paren.el b/lisp/paren.el index 893407b96c1..859049d6183 100644 --- a/lisp/paren.el +++ b/lisp/paren.el | |||
| @@ -40,39 +40,6 @@ | |||
| 40 | ;; This is the overlay used to highlight the closeparen right before point. | 40 | ;; This is the overlay used to highlight the closeparen right before point. |
| 41 | (defvar show-paren-overlay-1 nil) | 41 | (defvar show-paren-overlay-1 nil) |
| 42 | 42 | ||
| 43 | (defvar show-paren-idle-timer nil) | ||
| 44 | |||
| 45 | (defvar show-paren-mode) ;; Real definition comes later. | ||
| 46 | |||
| 47 | ;;;###autoload | ||
| 48 | (defun show-paren-mode (&optional arg) | ||
| 49 | "Toggle Show Paren mode. | ||
| 50 | With prefix ARG, turn Show Paren mode on if and only if ARG is positive. | ||
| 51 | Returns the new status of Show Paren mode (non-nil means on). | ||
| 52 | |||
| 53 | When Show Paren mode is enabled, any matching parenthesis is highlighted | ||
| 54 | in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time." | ||
| 55 | (interactive "P") | ||
| 56 | (when window-system | ||
| 57 | (let ((on-p (if arg | ||
| 58 | (> (prefix-numeric-value arg) 0) | ||
| 59 | (not show-paren-mode)))) | ||
| 60 | (setq blink-matching-paren-on-screen (not on-p)) | ||
| 61 | (when show-paren-idle-timer | ||
| 62 | (cancel-timer show-paren-idle-timer)) | ||
| 63 | (if on-p | ||
| 64 | (setq show-paren-idle-timer (run-with-idle-timer | ||
| 65 | show-paren-delay t | ||
| 66 | 'show-paren-function)) | ||
| 67 | (and show-paren-overlay (overlay-buffer show-paren-overlay) | ||
| 68 | (delete-overlay show-paren-overlay)) | ||
| 69 | (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) | ||
| 70 | (delete-overlay show-paren-overlay-1))) | ||
| 71 | (setq show-paren-mode on-p)))) | ||
| 72 | |||
| 73 | ;; Naughty hack. This variable was originally a `defvar' to keep track of | ||
| 74 | ;; whether Show Paren mode was turned on or not. As a `defcustom' with | ||
| 75 | ;; special `:set' and `:require' forms, we can provide custom mode control. | ||
| 76 | (defcustom show-paren-mode nil | 43 | (defcustom show-paren-mode nil |
| 77 | "Toggle Show Paren mode. | 44 | "Toggle Show Paren mode. |
| 78 | When Show Paren mode is enabled, any matching parenthesis is highlighted | 45 | When Show Paren mode is enabled, any matching parenthesis is highlighted |
| @@ -80,6 +47,7 @@ after `show-paren-delay' seconds of Emacs idle time. | |||
| 80 | You must modify via \\[customize] for this variable to have an effect." | 47 | You must modify via \\[customize] for this variable to have an effect." |
| 81 | :set (lambda (symbol value) | 48 | :set (lambda (symbol value) |
| 82 | (show-paren-mode (or value 0))) | 49 | (show-paren-mode (or value 0))) |
| 50 | :initialize 'custom-initialize-default | ||
| 83 | :type 'boolean | 51 | :type 'boolean |
| 84 | :group 'paren-showing | 52 | :group 'paren-showing |
| 85 | :require 'paren) | 53 | :require 'paren) |
| @@ -114,6 +82,34 @@ otherwise)." | |||
| 114 | :group 'faces | 82 | :group 'faces |
| 115 | :group 'paren-showing) | 83 | :group 'paren-showing) |
| 116 | 84 | ||
| 85 | (defvar show-paren-idle-timer nil) | ||
| 86 | |||
| 87 | ;;;###autoload | ||
| 88 | (defun show-paren-mode (&optional arg) | ||
| 89 | "Toggle Show Paren mode. | ||
| 90 | With prefix ARG, turn Show Paren mode on if and only if ARG is positive. | ||
| 91 | Returns the new status of Show Paren mode (non-nil means on). | ||
| 92 | |||
| 93 | When Show Paren mode is enabled, any matching parenthesis is highlighted | ||
| 94 | in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time." | ||
| 95 | (interactive "P") | ||
| 96 | (when window-system | ||
| 97 | (let ((on-p (if arg | ||
| 98 | (> (prefix-numeric-value arg) 0) | ||
| 99 | (not show-paren-mode)))) | ||
| 100 | (setq blink-matching-paren-on-screen (not on-p)) | ||
| 101 | (when show-paren-idle-timer | ||
| 102 | (cancel-timer show-paren-idle-timer)) | ||
| 103 | (if on-p | ||
| 104 | (setq show-paren-idle-timer (run-with-idle-timer | ||
| 105 | show-paren-delay t | ||
| 106 | 'show-paren-function)) | ||
| 107 | (and show-paren-overlay (overlay-buffer show-paren-overlay) | ||
| 108 | (delete-overlay show-paren-overlay)) | ||
| 109 | (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) | ||
| 110 | (delete-overlay show-paren-overlay-1))) | ||
| 111 | (setq show-paren-mode on-p)))) | ||
| 112 | |||
| 117 | ;; Find the place to show, if there is one, | 113 | ;; Find the place to show, if there is one, |
| 118 | ;; and show it until input arrives. | 114 | ;; and show it until input arrives. |
| 119 | (defun show-paren-function () | 115 | (defun show-paren-function () |
| @@ -212,4 +208,7 @@ otherwise)." | |||
| 212 | 208 | ||
| 213 | (provide 'paren) | 209 | (provide 'paren) |
| 214 | 210 | ||
| 211 | (if show-paren-mode | ||
| 212 | (show-paren-mode t)) | ||
| 213 | |||
| 215 | ;;; paren.el ends here | 214 | ;;; paren.el ends here |