Skip to content

Commit 92136cf

Browse files
authored
Merge pull request #50 from flooose/feature/better-indent-in-polymode
Basic support for better indenting in polymode
2 parents daeb555 + 5975f0d commit 92136cf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

graphql-mode.el

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,8 @@ Please install it and try again."))
157157
(defun graphql-beginning-of-query ()
158158
"Move the point to the beginning of the current query."
159159
(interactive)
160-
(while (and (> (point) (point-min))
161-
(or (> (current-indentation) 0)
162-
(> (car (syntax-ppss)) 0)))
163-
(forward-line -1)))
160+
(goto-char (syntax-ppss-toplevel-pos (syntax-ppss (point-at-bol))))
161+
(back-to-indentation))
164162

165163
(defun graphql-end-of-query ()
166164
"Move the point to the end of the current query."
@@ -312,15 +310,20 @@ Please install it and try again."))
312310
(defun graphql-indent-line ()
313311
"Indent GraphQL schema language."
314312
(let ((position (point))
313+
(column)
315314
(indent-pos))
315+
(save-excursion
316+
(graphql-beginning-of-query)
317+
(setq column (current-column)))
318+
316319
(save-excursion
317320
(let ((level (car (syntax-ppss (point-at-bol)))))
318321

319322
;; Handle closing pairs
320323
(when (looking-at "\\s-*\\s)")
321324
(setq level (1- level)))
322325

323-
(indent-line-to (* graphql-indent-level level))
326+
(indent-line-to (+ column (* graphql-indent-level level)))
324327
(setq indent-pos (point))))
325328

326329
(when (< position indent-pos)

0 commit comments

Comments
 (0)