aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShynur2023-05-02 01:32:44 +0800
committerEli Zaretskii2023-05-02 21:31:29 +0300
commit299bd316cd172f3a71705ab33efbf23590241e15 (patch)
tree2a45ab053b832fee43567e5f332fd89608984f73
parentf1a7cd71a04270e44845427daa896afe80b0acb0 (diff)
downloademacs-299bd316cd172f3a71705ab33efbf23590241e15.tar.gz
emacs-299bd316cd172f3a71705ab33efbf23590241e15.zip
Display matched offscreen open paren with a distinct face
Propertize matched offscreen openparen that is showing in the echo area in order to make it prominent; use shadow face for non-context characters (i.e., 'Matches') for the same purpose. * lisp/simple.el (blink-matching-paren-offscreen): Add this face for highlighting. * lisp/simple.el (blink-matching-paren-highlight-offscreen): Add this option to toggle face `blink-matching-paren-offscreen'. * lisp/simple.el (blink-paren-open-paren-line-string): Propertize the matched offscreen openparen with a face conditionally. (Bug#63089)
-rw-r--r--lisp/simple.el87
1 files changed, 67 insertions, 20 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index b621e1603bd..e4a0b9549e0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9215,6 +9215,21 @@ it skips the contents of comments that end before point."
9215 :type 'boolean 9215 :type 'boolean
9216 :group 'paren-blinking) 9216 :group 'paren-blinking)
9217 9217
9218(defcustom blink-matching-paren-highlight-offscreen nil
9219 "If non-nil, highlight showing in the echo area matched off-screen open paren.
9220This highlighting uses face `blink-matching-paren-offscreen'."
9221 :type 'boolean
9222 :version "30.1"
9223 :group 'paren-blinking)
9224
9225(defface blink-matching-paren-offscreen
9226 '((t :foreground "green"))
9227 "Face for showing in the echo area matched open paren that is off-screen.
9228This face will not be used when `blink-matching-paren-highlight-offscreen'
9229is nil."
9230 :version "30.1"
9231 :group 'paren-blinking)
9232
9218(defun blink-matching-check-mismatch (start end) 9233(defun blink-matching-check-mismatch (start end)
9219 "Return whether or not START...END are matching parens. 9234 "Return whether or not START...END are matching parens.
9220END is the current point and START is the blink position. 9235END is the current point and START is the blink position.
@@ -9312,47 +9327,79 @@ The function should return non-nil if the two tokens do not match.")
9312 (delete-overlay blink-matching--overlay))))) 9327 (delete-overlay blink-matching--overlay)))))
9313 ((not show-paren-context-when-offscreen) 9328 ((not show-paren-context-when-offscreen)
9314 (minibuffer-message 9329 (minibuffer-message
9315 "Matches %s" 9330 #("Matches %s"
9316 (substring-no-properties 9331 ;; Make the following text (i.e., %s) prominent.
9317 (blink-paren-open-paren-line-string blinkpos)))))))) 9332 0 7 (face shadow))
9333 (blink-paren-open-paren-line-string blinkpos)))))))
9318 9334
9319(defun blink-paren-open-paren-line-string (pos) 9335(defun blink-paren-open-paren-line-string (pos)
9320 "Return the line string that contains the openparen at POS." 9336 "Return the line string that contains the openparen at POS.
9337Remove the line string's properties but give the openparen a
9338face if `blink-matching-paren-highlight-offscreen' is non-nil."
9321 (save-excursion 9339 (save-excursion
9322 (goto-char pos) 9340 (goto-char pos)
9323 ;; Capture the regions in terms of (beg . end) conses whose 9341 ;; Capture the regions in terms of (beg . end) conses whose
9324 ;; buffer-substrings we want to show as a context string. Ensure 9342 ;; buffer-substrings we want to show as a context string. Ensure
9325 ;; they are font-locked (bug#59527). 9343 ;; they are font-locked (bug#59527).
9326 (let (regions) 9344 (let (regions
9327 ;; Show what precedes the open in its line, if anything. 9345 openparen-idx)
9328 (cond 9346 (cond
9347 ;; Show what precedes the open in its line, if anything.
9329 ((save-excursion (skip-chars-backward " \t") (not (bolp))) 9348 ((save-excursion (skip-chars-backward " \t") (not (bolp)))
9330 (setq regions (list (cons (line-beginning-position) 9349 (let ((bol (line-beginning-position)))
9331 (1+ pos))))) 9350 (setq regions (list (cons bol (1+ pos)))
9351 openparen-idx (- pos bol))))
9332 ;; Show what follows the open in its line, if anything. 9352 ;; Show what follows the open in its line, if anything.
9333 ((save-excursion 9353 ((save-excursion
9334 (forward-char 1) 9354 (forward-char 1)
9335 (skip-chars-forward " \t") 9355 (skip-chars-forward " \t")
9336 (not (eolp))) 9356 (not (eolp)))
9337 (setq regions (list (cons pos (line-end-position))))) 9357 (setq regions (list (cons pos (line-end-position)))
9358 openparen-idx 0))
9338 ;; Otherwise show the previous nonblank line, 9359 ;; Otherwise show the previous nonblank line,
9339 ;; if there is one. 9360 ;; if there is one.
9340 ((save-excursion (skip-chars-backward "\n \t") (not (bobp))) 9361 ((save-excursion (skip-chars-backward "\n \t") (not (bobp)))
9341 (setq regions (list (cons (progn 9362 (setq regions (list (cons
9342 (skip-chars-backward "\n \t") 9363 (let (bol)
9343 (line-beginning-position)) 9364 (skip-chars-backward "\n \t")
9344 (progn (end-of-line) 9365 (setq bol (line-beginning-position)
9345 (skip-chars-backward " \t") 9366 openparen-idx (- bol))
9346 (point))) 9367 bol)
9368 (let (eol)
9369 (end-of-line)
9370 (skip-chars-backward " \t")
9371 (setq eol (point)
9372 openparen-idx (+ openparen-idx
9373 eol
9374 ;; (length "...")
9375 3))
9376 eol))
9347 (cons pos (1+ pos))))) 9377 (cons pos (1+ pos)))))
9348 ;; There is nothing to show except the char itself. 9378 ;; There is nothing to show except the char itself.
9349 (t (setq regions (list (cons pos (1+ pos)))))) 9379 (t (setq regions (list (cons pos (1+ pos)))
9380 openparen-idx 0)))
9350 ;; Ensure we've font-locked the context region. 9381 ;; Ensure we've font-locked the context region.
9351 (font-lock-ensure (caar regions) (cdar (last regions))) 9382 (font-lock-ensure (caar regions) (cdar (last regions)))
9352 (mapconcat (lambda (region) 9383 (let ((line-string
9353 (buffer-substring (car region) (cdr region))) 9384 (mapconcat
9354 regions 9385 (lambda (region)
9355 "...")))) 9386 (buffer-substring (car region) (cdr region)))
9387 regions
9388 "..."))
9389 (openparen-next-char-idx (1+ openparen-idx)))
9390 (setq line-string (substring-no-properties line-string))
9391 (concat
9392 (substring line-string
9393 0 openparen-idx)
9394 (let ((matched-offscreen-openparen
9395 (substring line-string
9396 openparen-idx openparen-next-char-idx)))
9397 (if blink-matching-paren-highlight-offscreen
9398 (propertize matched-offscreen-openparen
9399 'face 'blink-matching-paren-offscreen)
9400 matched-offscreen-openparen))
9401 (substring line-string
9402 openparen-next-char-idx))))))
9356 9403
9357(defvar blink-paren-function 'blink-matching-open 9404(defvar blink-paren-function 'blink-matching-open
9358 "Function called, if non-nil, whenever a close parenthesis is inserted. 9405 "Function called, if non-nil, whenever a close parenthesis is inserted.