(c-require-final-newline): Added a variable to make the initialization of
[bpt/emacs.git] / lisp / paren.el
index b2d4775..a88c1f3 100644 (file)
@@ -1,6 +1,6 @@
 ;;; paren.el --- highlight matching paren
 
-;; Copyright (C) 1993, 1996 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1996, 2001 Free Software Foundation, Inc.
 
 ;; Author: rms@gnu.org
 ;; Maintainer: FSF
 
 ;;; Commentary:
 
-;; Load this and it will display highlighting on whatever
-;; paren matches the one before or after point.
+;; Put this into your ~/.emacs:
+
+;;  (show-paren-mode t)
+
+;; It will display highlighting on whatever paren matches the one
+;; before or after point.
 
 ;;; Code:
 
@@ -68,15 +72,21 @@ otherwise)."
   :version "20.3")
   
 (defface show-paren-match-face
-  '((((class color)) (:background "turquoise"))
-    (t (:background "gray")))
+  '((((class color) (background light))
+     :background "turquoise")          ; looks OK on tty (becomes cyan)
+    (((class color) (background dark))
+     :background "steelblue3")         ; looks OK on tty (becomes blue)
+    (((background dark))
+     :background "grey50")
+    (t
+     :background "gray"))
   "Show Paren mode face used for a matching paren."
   :group 'faces
   :group 'paren-showing)
 
 (defface show-paren-mismatch-face
   '((((class color)) (:foreground "white" :background "purple"))
-    (t (:reverse-video t)))
+    (t (:inverse-video t)))
   "Show Paren mode face used for a mismatching paren."
   :group 'faces
   :group 'paren-showing)
@@ -125,11 +135,10 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
 ;; and show it until input arrives.
 (defun show-paren-function ()
   (if show-paren-mode
-      (let (pos dir mismatch face (oldpos (point)))
-       (cond ((eq (char-syntax (preceding-char)) ?\))
-              (setq dir -1))
-             ((eq (char-syntax (following-char)) ?\()
-              (setq dir 1)))
+      (let ((oldpos (point))
+           (dir (cond ((eq (car (syntax-after (1- (point)))) 5) -1)
+                      ((eq (car (syntax-after (point))) 4) 1)))
+           pos mismatch face)
        ;;
        ;; Find the other end of the sexp.
        (when dir
@@ -145,6 +154,14 @@ in `show-paren-style' after `show-paren-delay' seconds of Emacs idle time."
              (condition-case ()
                  (setq pos (scan-sexps (point) dir))
                (error (setq pos t mismatch t)))
+             ;; Move back the other way and verify we get back to the
+             ;; starting point.  If not, these two parens don't really match.
+             ;; Maybe the one at point is escaped and doesn't really count.
+             (when (integerp pos)
+               (unless (condition-case ()
+                           (eq (point) (scan-sexps pos (- dir)))
+                         (error nil))
+                 (setq pos nil)))
              ;; If found a "matching" paren, see if it is the right
              ;; kind of paren to match the one we started at.
              (when (integerp pos)