[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rainbow-delimiters 36df2e014c 067/188: Add code to highlig
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rainbow-delimiters 36df2e014c 067/188: Add code to highlight mismatched closing delimiters. |
Date: |
Sat, 1 Jan 2022 00:58:53 -0500 (EST) |
branch: elpa/rainbow-delimiters
commit 36df2e014ce6e8d067e371c00b134aca84430ff7
Author: Fanael Linithien <fanael4@gmail.com>
Commit: Fanael Linithien <fanael4@gmail.com>
Add code to highlight mismatched closing delimiters.
Fixes #27.
---
rainbow-delimiters.el | 97 +++++++++++++++++++++++++++++++--------------------
1 file changed, 60 insertions(+), 37 deletions(-)
diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el
index 16b8465f90..b6e784e7a8 100644
--- a/rainbow-delimiters.el
+++ b/rainbow-delimiters.el
@@ -216,6 +216,12 @@ Nil disables brace highlighting."
"Face to highlight unmatched closing delimiters in."
:group 'rainbow-delimiters-faces)
+;; Mismatched delimiter face:
+(defface rainbow-delimiters-mismatched-face
+ '((t :inherit rainbow-delimiters-unmatched-face))
+ "Face to highlight mismatched closing delimiters in."
+ :group 'rainbow-delimiters-faces)
+
;; Faces for highlighting delimiters by nested level:
(defface rainbow-delimiters-depth-1-face
'((((background light)) (:foreground "#707183"))
@@ -446,18 +452,23 @@ not really affect the buffer's content."
(unless ,modified
(restore-buffer-modified-p nil))))))))
-(defsubst rainbow-delimiters-propertize-delimiter (loc depth)
+(defsubst rainbow-delimiters-propertize-delimiter (loc depth match)
"Highlight a single delimiter at LOC according to DEPTH.
LOC is the location of the character to add text properties to.
DEPTH is the nested depth at LOC, which determines the face to use.
+MATCH is nil iff it's a mismatched closing delimiter.
Sets text properties:
`font-lock-face' to the appropriate delimiter face.
`rear-nonsticky' to prevent color from bleeding into subsequent characters
typed by the user."
- (let ((delim-face (if (<= depth 0)
- 'rainbow-delimiters-unmatched-face
- (rainbow-delimiters-depth-face depth))))
+ (let ((delim-face (cond
+ ((<= depth 0)
+ 'rainbow-delimiters-unmatched-face)
+ ((not match)
+ 'rainbow-delimiters-mismatched-face)
+ (t
+ (rainbow-delimiters-depth-face depth)))))
;; (when (eq depth -1) (message "Unmatched delimiter at char %s." loc))
(add-text-properties loc (1+ loc)
`(font-lock-face ,delim-face
@@ -494,33 +505,35 @@ Sets text properties:
"Non-nil iff the character at LOC is escaped as per some generic Lisp rules."
(eq (char-before loc) ?\\))
-(defsubst rainbow-delimiters-char-ineligible-p (loc)
+(defsubst rainbow-delimiters-char-ineligible-p (loc ppss)
"Return t if char at LOC should be skipped, e.g. if inside a comment.
+PPSS should be the `parse-partial-sexp' state at LOC.
Returns t if char at loc meets one of the following conditions:
- Inside a string.
- Inside a comment.
- Is an escaped char, e.g. ?\)"
- (let ((parse-state (rainbow-delimiters-syntax-ppss loc)))
- (or
- (nth 3 parse-state) ; inside string?
- (nth 4 parse-state) ; inside comment?
- (and rainbow-delimiters-escaped-char-predicate
- (funcall rainbow-delimiters-escaped-char-predicate loc)))))
+ (or
+ (nth 3 ppss) ; inside string?
+ (nth 4 ppss) ; inside comment?
+ (and rainbow-delimiters-escaped-char-predicate
+ (funcall rainbow-delimiters-escaped-char-predicate loc))))
-(defsubst rainbow-delimiters-apply-color (delim depth loc)
+(defsubst rainbow-delimiters-apply-color (delim depth loc match)
"Apply color for DEPTH to DELIM at LOC following user settings.
DELIM is a string specifying delimiter type.
DEPTH is the delimiter depth, or corresponding face # if colors are repeating.
-LOC is location of character (delimiter) to be colorized."
+LOC is location of character (delimiter) to be colorized.
+MATCH is nil iff it's a mismatched closing delimiter."
(and
;; Ensure user has enabled highlighting of this delimiter type.
(symbol-value (intern-soft
(concat "rainbow-delimiters-highlight-" delim "s-p")))
(rainbow-delimiters-propertize-delimiter loc
- depth)))
+ depth
+ match)))
;;; JIT-Lock functionality
@@ -545,29 +558,39 @@ Used by jit-lock for dynamic highlighting."
(while (and (< (point) end)
(re-search-forward rainbow-delimiters-delim-regex end t))
(backward-char) ; re-search-forward places point after delim; go
back.
- (unless (rainbow-delimiters-char-ineligible-p (point))
- (let ((delim (char-after (point))))
- (cond ((eq ?\( delim) ; (
- (setq depth (1+ depth))
- (rainbow-delimiters-apply-color "paren" depth (point)))
- ((eq ?\) delim) ; )
- (rainbow-delimiters-apply-color "paren" depth (point))
- (setq depth (or (and (<= depth 0) 0) ; unmatched paren
- (1- depth))))
- ((eq ?\[ delim) ; [
- (setq depth (1+ depth))
- (rainbow-delimiters-apply-color "bracket" depth
(point)))
- ((eq ?\] delim) ; ]
- (rainbow-delimiters-apply-color "bracket" depth (point))
- (setq depth (or (and (<= depth 0) 0) ; unmatched bracket
- (1- depth))))
- ((eq ?\{ delim) ; {
- (setq depth (1+ depth))
- (rainbow-delimiters-apply-color "brace" depth (point)))
- ((eq ?\} delim) ; }
- (rainbow-delimiters-apply-color "brace" depth (point))
- (setq depth (or (and (<= depth 0) 0) ; unmatched brace
- (1- depth)))))))
+ (let ((ppss (rainbow-delimiters-syntax-ppss (point))))
+ (unless (rainbow-delimiters-char-ineligible-p (point) ppss)
+ (let ((delim (char-after (point))))
+ (cond ((eq ?\( delim) ; (
+ (setq depth (1+ depth))
+ (rainbow-delimiters-apply-color "paren" depth (point)
t))
+ ((eq ?\) delim) ; )
+ (rainbow-delimiters-apply-color "paren"
+ depth
+ (point)
+ (= ?\( (char-after
(nth 1 ppss))))
+ (setq depth (or (and (<= depth 0) 0) ; unmatched paren
+ (1- depth))))
+ ((eq ?\[ delim) ; [
+ (setq depth (1+ depth))
+ (rainbow-delimiters-apply-color "bracket" depth
(point) t))
+ ((eq ?\] delim) ; ]
+ (rainbow-delimiters-apply-color "bracket"
+ depth
+ (point)
+ (= ?\[ (char-after
(nth 1 ppss))))
+ (setq depth (or (and (<= depth 0) 0) ; unmatched
bracket
+ (1- depth))))
+ ((eq ?\{ delim) ; {
+ (setq depth (1+ depth))
+ (rainbow-delimiters-apply-color "brace" depth (point)
t))
+ ((eq ?\} delim) ; }
+ (rainbow-delimiters-apply-color "brace"
+ depth
+ (point)
+ (= ?\{ (char-after
(nth 1 ppss))))
+ (setq depth (or (and (<= depth 0) 0) ; unmatched brace
+ (1- depth))))))))
;; move past delimiter so re-search-forward doesn't pick it up
again
(forward-char)))))))
- [nongnu] elpa/rainbow-delimiters f1ff54da71 051/188: Release version 1.3.5., (continued)
- [nongnu] elpa/rainbow-delimiters f1ff54da71 051/188: Release version 1.3.5., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 2561e9853c 052/188: Attempt to fix issue #25., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 4c94853583 007/188: Add an item to the TODO list., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b9252e33d2 057/188: Remove unneeded require., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b656f8c9cd 064/188: Wrap rainbow-delimiters-{un, }propertize-region with with-silent-modifications and with-syntax-table., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters a1dd352c1a 059/188: Fix docstring style errors reported by checkdoc., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 3dfd3fa9b1 054/188: Use sorted-list caching to improve large-file performance, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters fc70c7ec67 058/188: Use standard form of the footer comment., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 949078cfd7 042/188: Ignoring compiled files, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters ee4519d20a 046/188: Use face symbols instead of face strings to better cooperate with htmlize., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 36df2e014c 067/188: Add code to highlight mismatched closing delimiters.,
ELPA Syncer <=
- [nongnu] elpa/rainbow-delimiters c4c127992a 071/188: Use font-lock instead of jit-lock., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 4144a75120 070/188: Add lisp-interaction-mode to rainbow-delimiters-escaped-char-predicate-list., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 447293003b 069/188: Highlight correctly even in presence of these evil 'intangible' properties., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f73763583c 077/188: Remove unneeded save-excursion., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters edf59bad7f 165/188: Move the usage instructions from installation to commentary., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 352b4f2bfe 177/188: No need to set inhibit-point-motion-hooks, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b316b7f49d 130/188: Make the MELPA Stable link actually point at MELPA Stable., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 8012604ea9 132/188: Add maintainership information., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters fb54c05ba0 095/188: Don't enable in special RefTeX modes, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f116221d42 076/188: Simplify the logic in rainbow-delimiters-propertize a little..., ELPA Syncer, 2022/01/01