(rmail-reply): Don't forget to narrow header in
[bpt/emacs.git] / lisp / paren.el
index 53fc343..40e99be 100644 (file)
 ;; This is the overlay used to highlight the closeparen right before point.
 (defvar show-paren-overlay-1 nil)
 
-;;;###autoload
-(defcustom show-paren-mode nil
-  "*Toggle Show Paren mode.
-When Show Paren mode is enabled, any matching parenthesis is highlighted
-after `show-paren-delay' seconds of Emacs idle time.
-Setting this variable directly does not take effect;
-use either \\[customize] or the function `show-paren-mode'."
-  :set (lambda (symbol value)
-        (show-paren-mode (or value 0)))
-  :initialize 'custom-initialize-default
-  :type 'boolean
-  :group 'paren-showing
-  :require 'paren)
-
 (defcustom show-paren-style 'parenthesis
   "*Style used when showing a matching paren.
 Valid styles are `parenthesis' (meaning show the matching paren),
@@ -69,6 +55,12 @@ otherwise)."
   :type '(number :tag "seconds")
   :group 'paren-showing)
 
+(defcustom show-paren-priority 1000
+  "*Priority of paren highlighting overlays."
+  :type 'integer
+  :group 'paren-showing
+  :version "21.1")
+  
 (defcustom show-paren-ring-bell-on-mismatch nil
   "*If non-nil, beep if mismatched paren is detected."
   :type 'boolean
@@ -92,24 +84,20 @@ otherwise)."
 (defvar show-paren-idle-timer nil)
 
 ;;;###autoload
-(defun show-paren-mode (&optional arg)
+(define-minor-mode show-paren-mode
   "Toggle Show Paren mode.
 With prefix ARG, turn Show Paren mode on if and only if ARG is positive.
 Returns the new status of Show Paren mode (non-nil means on).
 
 When Show Paren mode is enabled, any matching parenthesis is highlighted
 in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
-  (interactive "P")
-  (let ((on-p (if arg
-                 (> (prefix-numeric-value arg) 0)
-               (not show-paren-mode))))
-    (setq show-paren-mode on-p)
+  :global t :group 'paren-showing
     ;; Turn off the usual paren-matching method
     ;; when this one is turned on.
     (if (local-variable-p 'show-paren-mode)
        (make-local-variable 'blink-matching-paren-on-screen)
       (kill-local-variable 'blink-matching-paren-on-screen))
-    (setq blink-matching-paren-on-screen (not on-p))
+    (setq blink-matching-paren-on-screen (not show-paren-mode))
 
     ;; Now enable or disable the mechanism.
     ;; First get rid of the old idle timer.
@@ -125,13 +113,13 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
       (setq show-paren-idle-timer (run-with-idle-timer
                                   show-paren-delay t
                                   'show-paren-function)))
-    (unless on-p
+    (unless show-paren-mode
       (and show-paren-overlay
           (eq (overlay-buffer show-paren-overlay) (current-buffer))
           (delete-overlay show-paren-overlay))
       (and show-paren-overlay-1
           (eq (overlay-buffer show-paren-overlay-1) (current-buffer))
-          (delete-overlay show-paren-overlay-1)))))
+          (delete-overlay show-paren-overlay-1))))
 
 ;; Find the place to show, if there is one,
 ;; and show it until input arrives.
@@ -204,6 +192,7 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
                  (move-overlay show-paren-overlay-1 from to (current-buffer))
                (setq show-paren-overlay-1 (make-overlay from to)))
              ;; Always set the overlay face, since it varies.
+             (overlay-put show-paren-overlay-1 'priority show-paren-priority)
              (overlay-put show-paren-overlay-1 'face face)))
          ;;
          ;; Turn on highlighting for the matching paren, if found.
@@ -227,6 +216,7 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
              (setq show-paren-overlay (make-overlay from to))))
          ;;
          ;; Always set the overlay face, since it varies.
+         (overlay-put show-paren-overlay 'priority show-paren-priority)
          (overlay-put show-paren-overlay 'face face)))
     ;; show-paren-mode is nil in this buffer.
     (and show-paren-overlay
@@ -236,7 +226,4 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
 
 (provide 'paren)
 
-(if show-paren-mode
-    (show-paren-mode t))
-
 ;;; paren.el ends here