[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rainbow-delimiters b656f8c9cd 064/188: Wrap rainbow-delimi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rainbow-delimiters b656f8c9cd 064/188: Wrap rainbow-delimiters-{un, }propertize-region with with-silent-modifications and with-syntax-table. |
Date: |
Sat, 1 Jan 2022 00:58:52 -0500 (EST) |
branch: elpa/rainbow-delimiters
commit b656f8c9cd1dff183bb0eda85fe21dd4a81a531f
Author: Fanael Linithien <fanael4@gmail.com>
Commit: Fanael Linithien <fanael4@gmail.com>
Wrap rainbow-delimiters-{un,}propertize-region with
with-silent-modifications and with-syntax-table.
This avoids constant variable binds in the loop and ensures all internal
function are run with the same environment.
---
rainbow-delimiters.el | 101 +++++++++++++++++++++++++-------------------------
1 file changed, 50 insertions(+), 51 deletions(-)
diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el
index 02e7c93468..a84fe7e079 100644
--- a/rainbow-delimiters.el
+++ b/rainbow-delimiters.el
@@ -402,9 +402,7 @@ The syntax table is constructed by the function
(defsubst rainbow-delimiters-depth (loc)
"Return # of nested levels of parens, brackets, braces LOC is inside of."
- (let ((depth
- (with-syntax-table rainbow-delimiters-syntax-table
- (car (rainbow-delimiters-syntax-ppss loc)))))
+ (let ((depth (car (rainbow-delimiters-syntax-ppss loc))))
(if (>= depth 0)
depth
0))) ; ignore negative depths created by unmatched closing parens.
@@ -455,22 +453,20 @@ DEPTH is the nested depth at LOC, which determines the
face to use.
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."
- (with-silent-modifications
- (let ((delim-face (if (<= depth 0)
- 'rainbow-delimiters-unmatched-face
- (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
- rear-nonsticky t)))))
+ (let ((delim-face (if (<= depth 0)
+ 'rainbow-delimiters-unmatched-face
+ (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
+ rear-nonsticky t))))
(defsubst rainbow-delimiters-unpropertize-delimiter (loc)
"Remove text properties set by rainbow-delimiters mode from char at LOC."
- (with-silent-modifications
- (remove-text-properties loc (1+ loc)
- '(font-lock-face nil
- rear-nonsticky nil))))
+ (remove-text-properties loc (1+ loc)
+ '(font-lock-face nil
+ rear-nonsticky nil)))
(defvar rainbow-delimiters-escaped-char-predicate nil)
(make-variable-buffer-local 'rainbow-delimiters-escaped-char-predicate)
@@ -539,46 +535,49 @@ Used by jit-lock for dynamic highlighting."
(setq rainbow-delimiters-escaped-char-predicate
(cdr (assoc major-mode
rainbow-delimiters-escaped-char-predicate-list)))
(save-excursion
- (goto-char start)
- ;; START can be anywhere in buffer; determine the nesting depth at START
loc
- (let ((depth (rainbow-delimiters-depth start)))
- (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)))))))
- ;; move past delimiter so re-search-forward doesn't pick it up again
- (forward-char)))))
+ (with-syntax-table rainbow-delimiters-syntax-table
+ (with-silent-modifications
+ (goto-char start)
+ ;; START can be anywhere in buffer; determine the nesting depth at
START loc
+ (let ((depth (rainbow-delimiters-depth start)))
+ (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)))))))
+ ;; move past delimiter so re-search-forward doesn't pick it up
again
+ (forward-char)))))))
(defun rainbow-delimiters-unpropertize-region (start end)
"Remove highlighting from delimiters between START and END."
(save-excursion
- (goto-char start)
- (while (and (< (point) end)
- (re-search-forward rainbow-delimiters-delim-regex end t))
- ;; re-search-forward places point 1 further than the delim matched:
- (rainbow-delimiters-unpropertize-delimiter (1- (point))))))
+ (with-silent-modifications
+ (goto-char start)
+ (while (and (< (point) end)
+ (re-search-forward rainbow-delimiters-delim-regex end t))
+ ;; re-search-forward places point 1 further than the delim matched:
+ (rainbow-delimiters-unpropertize-delimiter (1- (point)))))))
;;; Minor mode:
- [nongnu] elpa/rainbow-delimiters 30c6a4c1bc 118/188: Use the major mode's syntax table directly., (continued)
- [nongnu] elpa/rainbow-delimiters 30c6a4c1bc 118/188: Use the major mode's syntax table directly., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 406ee45e7c 126/188: Rewrite the installation and usage instructions., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 7b882c9489 138/188: Merge (let … (let* …)) => (let* …)., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f57067cda5 140/188: Make Emacs 23 tests less verbose., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 6e9e17e739 008/188: Add a 'global-rainbow-delimiters-mode' for enabling rainbow-delimiters in all buffers., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters daa1737a8f 011/188: Whitespace changes., ELPA Syncer, 2022/01/01
- [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 <=
- [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, 2022/01/01
- [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