emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/yaml-mode ad8685c 104/124: yaml-mode-syntax-propertize-fun


From: ELPA Syncer
Subject: [nongnu] elpa/yaml-mode ad8685c 104/124: yaml-mode-syntax-propertize-function: Speed up in large strings
Date: Sun, 29 Aug 2021 11:36:22 -0400 (EDT)

branch: elpa/yaml-mode
commit ad8685c24846ccde4f618589812d7324c0ac7210
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    yaml-mode-syntax-propertize-function: Speed up in large strings
    
    Fixes #75
---
 yaml-mode.el | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/yaml-mode.el b/yaml-mode.el
index 7adb17f..5eaa51e 100644
--- a/yaml-mode.el
+++ b/yaml-mode.el
@@ -262,21 +262,30 @@ that key is pressed to begin a block literal."
   ;; 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 ((sps (syntax-ppss)))
+        (when (nth 8 sps)
+          (or
+           (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")))))
+           ;; We're right after a quote that opens a string literal.
+           ;; Skip over it (big speedup for long JSON strings).
+           (when (nth 3 sps)
+             (goto-char (nth 8 sps))
+             (ignore-errors (forward-sexp)))))))))
 
 (defun yaml-font-lock-block-literals (bound)
   "Find lines within block literals.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]