1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-15 17:00:26 +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) (min (point-max)
(+ (point) blink-matching-paren-distance)))) (+ (point) blink-matching-paren-distance))))
;; Scan across one sexp within that range. ;; Scan across one sexp within that range.
;; Errors or nil mean there is a mismatch.
(condition-case () (condition-case ()
(setq pos (scan-sexps (point) dir)) (setq pos (scan-sexps (point) dir))
(error nil)) (error (setq pos t
;; See if the "matching" paren is the right kind of paren mismatch t)))
;; to match the one we started at. ;; If found a "matching" paren, see if it is the right
(if pos ;; kind of paren to match the one we started at.
(if (integerp pos)
(let ((beg (min pos oldpos)) (end (max pos oldpos))) (let ((beg (min pos oldpos)) (end (max pos oldpos)))
(and (/= (char-syntax (char-after beg)) ?\$) (and (/= (char-syntax (char-after beg)) ?\$)
(setq mismatch (setq mismatch
@ -127,28 +129,39 @@ after `show-paren-delay' seconds of Emacs idle time."
(message "Paren mismatch")))) (message "Paren mismatch"))))
))) )))
(cond (pos (cond (pos
(if (= dir -1) (if (or (= dir -1)
(not (integerp pos)))
;; If matching backwards, highlight the closeparen ;; If matching backwards, highlight the closeparen
;; before point as well as its matching open. ;; 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 (if show-paren-overlay-1
(move-overlay show-paren-overlay-1 (move-overlay show-paren-overlay-1
(+ (point) dir) (point) from to
(current-buffer)) (current-buffer))
(setq show-paren-overlay-1 (setq show-paren-overlay-1
(make-overlay (+ (point) dir) (point)))) (make-overlay from to)))
;; Always set the overlay face, since it varies. ;; Always set the overlay face, since it varies.
(overlay-put show-paren-overlay-1 'face face)) (overlay-put show-paren-overlay-1 'face face))
;; Otherwise, turn off any such highlighting. ;; Otherwise, turn off any such highlighting.
(and show-paren-overlay-1 (and show-paren-overlay-1
(overlay-buffer show-paren-overlay-1) (overlay-buffer show-paren-overlay-1)
(delete-overlay show-paren-overlay-1))) (delete-overlay show-paren-overlay-1)))
;; Turn on highlighting for the matching paren. ;; 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 (if show-paren-overlay
(move-overlay show-paren-overlay (- pos dir) pos (move-overlay show-paren-overlay (- pos dir) pos
(current-buffer)) (current-buffer))
(setq show-paren-overlay (setq show-paren-overlay
(make-overlay (- pos dir) pos))) (make-overlay (- pos dir) pos))))
;; Always set the overlay face, since it varies. ;; Always set the overlay face, since it varies.
(overlay-put show-paren-overlay 'face face)) (overlay-put show-paren-overlay 'face face))
(t (t