branch: elpa/yaml-mode commit 9e8362dc553cde6f5ff27c4dd9b119200445819f Merge: e1aed40 97a58b3 Author: Vasilij Schneidermann <m...@vasilij.de> Commit: GitHub <nore...@github.com>
Merge pull request #76 from dgutov/spf-speedup Speed up syntax-propertize-function in files with large JSON strings --- test-files/test-quotes-in-strings.yaml | 5 +++++ yaml-mode.el | 36 +++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/test-files/test-quotes-in-strings.yaml b/test-files/test-quotes-in-strings.yaml new file mode 100644 index 0000000..5859bbd --- /dev/null +++ b/test-files/test-quotes-in-strings.yaml @@ -0,0 +1,5 @@ +some's'strings'some's'nots: +- here: syntax is not string +- this: 'is a string with "quotes"' +- and: 'to express one single quote, use '' two of them' +- finally: syntax is not string diff --git a/yaml-mode.el b/yaml-mode.el index 19f1bc0..66e41b3 100644 --- a/yaml-mode.el +++ b/yaml-mode.el @@ -258,25 +258,33 @@ that key is pressed to begin a block literal." (put-text-property (point) (1+ (point)) 'syntax-table (string-to-syntax "_")))))) - ;; If quote is detected as a syntactic string start but appeared - ;; after a non-whitespace character, then mark it as syntactic word. (save-excursion (goto-char beg) - (while (re-search-forward "['\"]" end t) + (while (and + (> end (point)) + (re-search-forward "['\"]" end t)) (when (get-text-property (point) 'yaml-block-literal) (put-text-property (1- (point)) (point) 'syntax-table (string-to-syntax "w"))) - (when (nth 8 (syntax-ppss)) - (save-excursion - (forward-char -1) - (cond ((and (char-equal ?' (char-before (point))) - (char-equal ?' (char-after (point))) - (put-text-property (1- (point)) (1+ (point)) - 'syntax-table (string-to-syntax "w")))) - ((and (not (bolp)) - (char-equal ?w (char-syntax (char-before (point))))) - (put-text-property (point) (1+ (point)) - 'syntax-table (string-to-syntax "w"))))))))) + (let* ((pt (point)) + (sps (save-excursion (syntax-ppss (1- pt))))) + (when (not (nth 8 sps)) + (cond + ((and (char-equal ?' (char-before (1- pt))) + (char-equal ?' (char-before pt))) + (put-text-property (- pt 2) pt + 'syntax-table (string-to-syntax "w"))) + ;; If quote is detected as a syntactic string start but appeared + ;; after a non-whitespace character, then mark it as syntactic word. + ((and (char-before (1- pt)) + (char-equal ?w (char-syntax (char-before (1- pt))))) + (put-text-property (1- pt) pt + 'syntax-table (string-to-syntax "w"))) + (t + ;; We're right after a quote that opens a string literal. + ;; Skip over it (big speedup for long JSON strings). + (goto-char (1- pt)) + (ignore-errors (forward-sexp))))))))) (defun yaml-font-lock-block-literals (bound) "Find lines within block literals.