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

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

[nongnu] elpa/graphql-mode daeb5557a9 2/2: Merge pull request #48 from m


From: ELPA Syncer
Subject: [nongnu] elpa/graphql-mode daeb5557a9 2/2: Merge pull request #48 from michaelherold/block-string-syntax
Date: Thu, 14 Jul 2022 04:58:40 -0400 (EDT)

branch: elpa/graphql-mode
commit daeb5557a918093272755bdfbd1a56b936fca932
Merge: 9740e4027b 0fb22dd4b1
Author: David Vázquez Púa <davazp@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #48 from michaelherold/block-string-syntax
    
    Fix syntax table for triple quotes
---
 graphql-mode.el | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/graphql-mode.el b/graphql-mode.el
index 5f3ed0e161..c5e0d4bf58 100644
--- a/graphql-mode.el
+++ b/graphql-mode.el
@@ -274,6 +274,37 @@ Please install it and try again."))
     st)
   "Syntax table for GraphQL mode.")
 
+(defun graphql-syntax-stringify ()
+  "Put `syntax-table' property correctly on single/triple quotes."
+  (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss)))
+         (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
+         (quote-starting-pos (- (point) 3))
+         (quote-ending-pos (point)))
+    (cond ((or (nth 4 ppss)
+               (and string-start
+                    (not (eql (char-after string-start)
+                              (char-after quote-starting-pos)))))
+           ;; Inside of a comment or a string quoted with different triple
+           ;; quotes so do nothing
+           nil)
+          ((nth 5 ppss)
+           ;; The escaped quote - not part of a triple quote
+           (goto-char (1+ quote-starting-pos)))
+          ((null string-start)
+           ;; The start of the string, where we want the string fence syntax on
+           ;; the last quote
+           (put-text-property (1- quote-ending-pos) quote-ending-pos
+                               'syntax-table (string-to-syntax "|")))
+          (t
+           ;; The end of the string, where we want the string fence syntax on
+           ;; the first quote
+           (put-text-property quote-starting-pos (1+ quote-starting-pos)
+                              'syntax-table (string-to-syntax "|"))))))
+
+(defconst graphql-syntax-propertize-function
+  (syntax-propertize-rules
+   ("\"\"\"" (0 (ignore (graphql-syntax-stringify))))))
+
 (defvar-local graphql-edit-headers--parent-buffer nil)
 (put 'graphql-edit-headers--parent-buffer 'permanent-local t)
 
@@ -462,6 +493,8 @@ interactively with `\\[graphql-edit-headers]'."
           nil
           nil
           nil))
+  (setq-local syntax-propertize-function
+              graphql-syntax-propertize-function)
   (setq imenu-generic-expression `((nil ,graphql-definition-regex 2)))
   (add-hook 'completion-at-point-functions 'graphql-completion-at-point nil t))
 



reply via email to

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