Skip to content

Commit

Permalink
Merge pull request davazp#48 from michaelherold/block-string-syntax
Browse files Browse the repository at this point in the history
Fix syntax table for triple quotes
  • Loading branch information
davazp authored Jul 14, 2022
2 parents 9740e40 + 0fb22dd commit daeb555
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions graphql-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit daeb555

Please sign in to comment.