1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-27 10:54:40 +00:00

(show-paren-function): Handle unbalanced parens as

mismatched.  When the unbalanced paren is an opening paren,
highlight it as mismatched.
This commit is contained in:
Richard M. Stallman 1996-09-03 17:54:23 +00:00
parent 8eaa6efed2
commit 0d554bae8b

View File

@ -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