From e05dd60c123cdc7224623fd68f18c75b486a6783 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Mon, 29 Sep 2014 14:17:16 +0100 Subject: [PATCH] Don't propertize if the syntax table is unset `rainbow-delimiters-mode' may be restored via desktop.el. When this happens inside an `mmm-mode' buffer, the subregion-specific values of the syntax table will not be restored, and so `rainbow-delimiters-syntax-table' can be nil. We handle this case by skipping propertization if the syntax table is unset. Closes https://github.com/purcell/emacs.d/issues/209 --- rainbow-delimiters.el | 67 ++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el index cf9b7fe..6d9ed3b 100644 --- a/rainbow-delimiters.el +++ b/rainbow-delimiters.el @@ -490,41 +490,42 @@ TYPE is the delimiter type string for `rainbow-delimiters-apply-color'.") Used by font-lock for dynamic highlighting." (setq rainbow-delimiters-escaped-char-predicate (cdr (assoc major-mode rainbow-delimiters-escaped-char-predicate-list))) - (with-syntax-table rainbow-delimiters-syntax-table - (let ((inhibit-point-motion-hooks t)) - ;; Point can be anywhere in buffer; determine the nesting depth at point. - (let* ((last-ppss-pos (point)) - (ppss (rainbow-delimiters-syntax-ppss last-ppss-pos)) - (depth (rainbow-delimiters-depth ppss))) - (while (and (< (point) end) - (re-search-forward rainbow-delimiters-delim-regex end t)) - (let ((delim-pos (match-beginning 0))) - (setq ppss (save-excursion - (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss))) - (setq last-ppss-pos delim-pos) - (unless (rainbow-delimiters-char-ineligible-p delim-pos ppss) - (let* ((delim (char-after delim-pos)) - (opening-delim-info - (assq delim rainbow-delimiters-opening-delim-info))) - (if opening-delim-info - (progn - (setq depth (1+ depth)) - (rainbow-delimiters-apply-color (cdr opening-delim-info) + (when rainbow-delimiters-syntax-table + (with-syntax-table rainbow-delimiters-syntax-table + (let ((inhibit-point-motion-hooks t)) + ;; Point can be anywhere in buffer; determine the nesting depth at point. + (let* ((last-ppss-pos (point)) + (ppss (rainbow-delimiters-syntax-ppss last-ppss-pos)) + (depth (rainbow-delimiters-depth ppss))) + (while (and (< (point) end) + (re-search-forward rainbow-delimiters-delim-regex end t)) + (let ((delim-pos (match-beginning 0))) + (setq ppss (save-excursion + (parse-partial-sexp last-ppss-pos delim-pos nil nil ppss))) + (setq last-ppss-pos delim-pos) + (unless (rainbow-delimiters-char-ineligible-p delim-pos ppss) + (let* ((delim (char-after delim-pos)) + (opening-delim-info + (assq delim rainbow-delimiters-opening-delim-info))) + (if opening-delim-info + (progn + (setq depth (1+ depth)) + (rainbow-delimiters-apply-color (cdr opening-delim-info) + depth + delim-pos + t)) + ;; Not an opening delimiter, so it's a closing delimiter. + (let ((closing-delim-info + (assq delim rainbow-delimiters-closing-delim-info)) + (matching-opening-delim (char-after (nth 1 ppss)))) + (rainbow-delimiters-apply-color (nthcdr 2 closing-delim-info) depth delim-pos - t)) - ;; Not an opening delimiter, so it's a closing delimiter. - (let ((closing-delim-info - (assq delim rainbow-delimiters-closing-delim-info)) - (matching-opening-delim (char-after (nth 1 ppss)))) - (rainbow-delimiters-apply-color (nthcdr 2 closing-delim-info) - depth - delim-pos - (= (nth 1 closing-delim-info) - matching-opening-delim)) - (setq depth (if (<= depth 0) - 0 ; unmatched delim - (1- depth)))))))))))) + (= (nth 1 closing-delim-info) + matching-opening-delim)) + (setq depth (if (<= depth 0) + 0 ; unmatched delim + (1- depth))))))))))))) ;; We already fontified the delimiters, tell font-lock there's nothing more ;; to do. nil)