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
master
Steve Purcell 12 years ago
parent 29e7bfd8e4
commit e05dd60c12
  1. 67
      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)

Loading…
Cancel
Save