diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el index 7495d31..ea16082 100644 --- a/rainbow-delimiters.el +++ b/rainbow-delimiters.el @@ -215,9 +215,6 @@ Returns t if char at loc meets one of the following conditions: (t nil)))) -(defconst rainbow-delimiters--delim-regex "\\s(\\|\\s)" - "Regex matching all opening and closing delimiters the mode highlights.") - ;; Main function called by font-lock. (defun rainbow-delimiters--propertize (end) "Highlight delimiters in region between point and END. @@ -226,12 +223,15 @@ Used by font-lock for dynamic highlighting." (let* ((inhibit-point-motion-hooks t) (last-ppss-pos (point)) (ppss (syntax-ppss))) - (while (re-search-forward rainbow-delimiters--delim-regex end t) - (let* ((delim-pos (match-beginning 0)) + (while (> end (progn (skip-syntax-forward "^()" end) + (point))) + (let* ((delim-pos (point)) (delim-syntax (syntax-after delim-pos))) - (setq ppss (save-excursion - (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss))) + (setq ppss (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss)) (setq last-ppss-pos delim-pos) + ;; `skip-syntax-forward' leaves the point at the delimiter, move past + ;; it. + (forward-char) (let ((delim-syntax-code (car delim-syntax))) (cond ((rainbow-delimiters--char-ineligible-p delim-pos ppss delim-syntax-code)