@@ -649,6 +649,8 @@ any number of matches of `clojure--sym-forbidden-rest-chars'."))
649
649
(,(rx " `" (group-n 1 (optional " #'" )
650
650
(+ (or (syntax symbol) (syntax word)))) " `" )
651
651
(1 'font-lock-constant-face prepend))
652
+ ; ; Highlight escaped characters in strings.
653
+ (clojure-font-lock-escaped-chars 0 'bold prepend)
652
654
; ; Highlight grouping constructs in regular expressions
653
655
(clojure-font-lock-regexp-groups
654
656
(1 'font-lock-regexp-grouping-construct prepend))))
@@ -753,40 +755,60 @@ locking in def* forms that are not at top level."
753
755
changed t )))))
754
756
changed))
755
757
758
+ (defun clojure--font-locked-as-string-p (&optional regexp )
759
+ " Non-nil if the char before point is font-locked as a string.
760
+ If REGEXP is non-nil, also check whether current string is
761
+ preceeded by a #."
762
+ (let ((face (get-text-property (1- (point )) 'face )))
763
+ (and (or (and (listp face)
764
+ (memq 'font-lock-string-face face))
765
+ (eq 'font-lock-string-face face))
766
+ (or (clojure-string-start t )
767
+ (unless regexp
768
+ (clojure-string-start nil ))))))
769
+
770
+ (defun clojure-font-lock-escaped-chars (bound )
771
+ " Highlight \e scaped chars in strings.
772
+ BOUND denotes a buffer position to limit the search."
773
+ (let ((found nil ))
774
+ (while (and (not found)
775
+ (re-search-forward " \\\\ ." bound t ))
776
+
777
+ (setq found (clojure--font-locked-as-string-p)))
778
+ found))
779
+
756
780
(defun clojure-font-lock-regexp-groups (bound )
757
781
" Highlight grouping constructs in regular expression.
758
782
759
783
BOUND denotes the maximum number of characters (relative to the
760
784
point) to check."
761
- (catch 'found
762
- (while (re-search-forward (concat
763
- ; ; A group may start using several alternatives:
764
- " \\ (\\ (?:"
765
- ; ; 1. (? special groups
766
- " (\\ ?\\ (?:"
767
- ; ; a) non-capturing group (?:X)
768
- ; ; b) independent non-capturing group (?>X)
769
- ; ; c) zero-width positive lookahead (?=X)
770
- ; ; d) zero-width negative lookahead (?!X)
771
- " [:=!>]\\ |"
772
- ; ; e) zero-width positive lookbehind (?<=X)
773
- ; ; f) zero-width negative lookbehind (?<!X)
774
- " <[=!]\\ |"
775
- ; ; g) named capturing group (?<name>X)
776
- " <[[:alnum:]]+>"
777
- " \\ )\\ |" ; ; end of special groups
778
- ; ; 2. normal capturing groups (
779
- ; ; 3. we also highlight alternative
780
- ; ; separarators |, and closing parens )
781
- " [|()]"
782
- " \\ )\\ )" )
783
- bound t )
784
- (let ((face (get-text-property (1- (point )) 'face )))
785
- (when (and (or (and (listp face)
786
- (memq 'font-lock-string-face face))
787
- (eq 'font-lock-string-face face))
788
- (clojure-string-start t ))
789
- (throw 'found t ))))))
785
+ (let ((found nil ))
786
+ (while (and (not found)
787
+ (re-search-forward (eval-when-compile
788
+ (concat
789
+ ; ; A group may start using several alternatives:
790
+ " \\ (\\ (?:"
791
+ ; ; 1. (? special groups
792
+ " (\\ ?\\ (?:"
793
+ ; ; a) non-capturing group (?:X)
794
+ ; ; b) independent non-capturing group (?>X)
795
+ ; ; c) zero-width positive lookahead (?=X)
796
+ ; ; d) zero-width negative lookahead (?!X)
797
+ " [:=!>]\\ |"
798
+ ; ; e) zero-width positive lookbehind (?<=X)
799
+ ; ; f) zero-width negative lookbehind (?<!X)
800
+ " <[=!]\\ |"
801
+ ; ; g) named capturing group (?<name>X)
802
+ " <[[:alnum:]]+>"
803
+ " \\ )\\ |" ; ; end of special groups
804
+ ; ; 2. normal capturing groups (
805
+ ; ; 3. we also highlight alternative
806
+ ; ; separarators |, and closing parens )
807
+ " [|()]"
808
+ " \\ )\\ )" ))
809
+ bound t ))
810
+ (setq found (clojure--font-locked-as-string-p 'regexp )))
811
+ found))
790
812
791
813
; ; Docstring positions
792
814
(put 'ns 'clojure-doc-string-elt 2 )
0 commit comments