diff options
author | Richard M. Stallman <rms@gnu.org> | 1996-09-03 17:54:23 +0000 |
---|---|---|
committer | Richard M. Stallman <rms@gnu.org> | 1996-09-03 17:54:23 +0000 |
commit | 0d554bae8bc14814de65f6164c278d6036223b52 (patch) | |
tree | 4e7b03c0e9c2df93d259ab44171cf4d622d1bf21 /lisp/paren.el | |
parent | 8eaa6efed2961c2d15e739e413a655e414fa24d5 (diff) | |
download | emacs-0d554bae8bc14814de65f6164c278d6036223b52.tar.gz |
(show-paren-function): Handle unbalanced parens as
mismatched. When the unbalanced paren is an opening paren,
highlight it as mismatched.
Diffstat (limited to 'lisp/paren.el')
-rw-r--r-- | lisp/paren.el | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/lisp/paren.el b/lisp/paren.el index 810fa691980..66d27fbb6af 100644 --- a/lisp/paren.el +++ b/lisp/paren.el @@ -93,12 +93,14 @@ after `show-paren-delay' seconds of Emacs idle time." (min (point-max) (+ (point) blink-matching-paren-distance)))) ;; Scan across one sexp within that range. + ;; Errors or nil mean there is a mismatch. (condition-case () (setq pos (scan-sexps (point) dir)) - (error nil)) - ;; See if the "matching" paren is the right kind of paren - ;; to match the one we started at. - (if pos + (error (setq pos t + mismatch t))) + ;; If found a "matching" paren, see if it is the right + ;; kind of paren to match the one we started at. + (if (integerp pos) (let ((beg (min pos oldpos)) (end (max pos oldpos))) (and (/= (char-syntax (char-after beg)) ?\$) (setq mismatch @@ -127,28 +129,39 @@ after `show-paren-delay' seconds of Emacs idle time." (message "Paren mismatch")))) ))) (cond (pos - (if (= dir -1) + (if (or (= dir -1) + (not (integerp pos))) ;; If matching backwards, highlight the closeparen ;; before point as well as its matching open. - (progn + ;; If matching forward, and the openparen is unbalanced, + ;; highlight the paren at point to indicate misbalance. + (let ((from (if (= dir 1) + (point) + (1- (point)))) + (to (if (= dir 1) + (1+ (point)) + (point)))) (if show-paren-overlay-1 (move-overlay show-paren-overlay-1 - (+ (point) dir) (point) + from to (current-buffer)) (setq show-paren-overlay-1 - (make-overlay (+ (point) dir) (point)))) + (make-overlay from to))) ;; Always set the overlay face, since it varies. (overlay-put show-paren-overlay-1 'face face)) ;; Otherwise, turn off any such highlighting. (and show-paren-overlay-1 (overlay-buffer show-paren-overlay-1) (delete-overlay show-paren-overlay-1))) - ;; Turn on highlighting for the matching paren. - (if show-paren-overlay - (move-overlay show-paren-overlay (- pos dir) pos - (current-buffer)) - (setq show-paren-overlay - (make-overlay (- pos dir) pos))) + ;; Turn on highlighting for the matching paren, if found. + ;; If it's an unmatched paren, turn off any such highlighting. + (or (and (not (integerp pos)) + (delete-overlay show-paren-overlay)) + (if show-paren-overlay + (move-overlay show-paren-overlay (- pos dir) pos + (current-buffer)) + (setq show-paren-overlay + (make-overlay (- pos dir) pos)))) ;; Always set the overlay face, since it varies. (overlay-put show-paren-overlay 'face face)) (t |