Function: show-paren--default

show-paren--default is a byte-compiled function defined in paren.el.gz.

Signature

(show-paren--default)

Documentation

Find the opener/closer near point and its match.

It is the default value of show-paren-data-function.

Source Code

;; Defined in /usr/src/emacs/lisp/paren.el.gz
(defun show-paren--default ()
  "Find the opener/closer near point and its match.

It is the default value of `show-paren-data-function'."
  (let* ((temp (show-paren--locate-near-paren))
	 (dir (car temp))
	 (outside (cdr temp))
         ;; If we're inside a comment, then we probably want to blink
         ;; a matching parentheses in the comment.  So don't ignore
         ;; comments in that case.
         (parse-sexp-ignore-comments
          (if (ppss-comment-depth (syntax-ppss))
              nil
            parse-sexp-ignore-comments))
	 pos mismatch here-beg here-end)
    ;;
    ;; Find the other end of the sexp.
    (when dir
      (setq here-beg (if (eq dir 1) outside (1- outside))
	    here-end (if (eq dir 1) (1+ outside) outside))
      (save-restriction
	;; Determine the range within which to look for a match.
	(when blink-matching-paren-distance
	  (narrow-to-region
	   (max (point-min) (- (point) blink-matching-paren-distance))
	   (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 outside 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,
	;; or one is inside a comment.
	(when (integerp pos)
	  (unless (condition-case ()
		      (eq outside (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.
	(if (not (integerp pos))
	    (if mismatch (list here-beg here-end nil nil t))
	  (let ((beg (min pos outside)) (end (max pos outside)))
	    (unless (eq (syntax-class (syntax-after beg)) 8)
	      (setq mismatch
		    (not (or (eq (char-before end)
				 ;; This can give nil.
				 (cdr (syntax-after beg)))
			     (eq (char-after beg)
				 ;; This can give nil.
				 (cdr (syntax-after (1- end))))
			     ;; The cdr might hold a new paren-class
			     ;; info rather than a matching-char info,
			     ;; in which case the two CDRs should match.
			     (eq (cdr (syntax-after (1- end)))
				 (cdr (syntax-after beg)))))))
	    (list here-beg here-end
		  (if (= dir 1) (1- pos) pos)
		  (if (= dir 1) pos (1+ pos))
		  mismatch)))))))