graphql-mode icon indicating copy to clipboard operation
graphql-mode copied to clipboard

indent region doesn't work

Open jcubic opened this issue 2 years ago • 3 comments

when selecting text and press tab to indent region. Got this error:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  graphql-beginning-of-query()
  graphql-indent-line()
  indent-according-to-mode()
  indent-region-line-by-line(1 155)
  indent-region(1 155)
  indent-for-tab-command(nil)
  funcall-interactively(indent-for-tab-command nil)
  command-execute(indent-for-tab-command)

jcubic avatar Apr 10 '23 19:04 jcubic

The problem seem to be indenting lines that are outside of the {..}. For example

query |Name {
}

where | is the cursor, it'll throw that error. I've fixed it by assuming the toplevel query starts at the same line if that is the case.

Please try the latest version from master or when it is released.

davazp avatar Apr 11 '23 06:04 davazp

I've downloaded and loaded the file but now got this error when pressing TAB:

Debugger entered--Lisp error: (void-function pos-bol)
  (pos-bol)
  (syntax-ppss (pos-bol))
  (syntax-ppss-toplevel-pos (syntax-ppss (pos-bol)))
  (or (syntax-ppss-toplevel-pos (syntax-ppss (pos-bol))) (pos-bol))
  (goto-char (or (syntax-ppss-toplevel-pos (syntax-ppss (pos-bol))) (pos-bol)))
  graphql-beginning-of-query()
  (save-excursion (graphql-beginning-of-query) (setq column (current-column)))
  (let ((position (point)) (column) (indent-pos)) (save-excursion (graphql-beginning-of-query) (setq column (current-column))) (save-excursion (let ((level (car (syntax-ppss (point-at-bol))))) (if (looking-at "\\s-*\\s)") (progn (setq level (1- level)))) (indent-line-to (+ column (* graphql-indent-level level))) (setq indent-pos (point)))) (if (< position indent-pos) (progn (goto-char indent-pos))))
  graphql-indent-line()
  indent--funcall-widened(graphql-indent-line)
  indent-for-tab-command(nil)
  funcall-interactively(indent-for-tab-command nil)
  command-execute(indent-for-tab-command)

jcubic avatar Apr 11 '23 17:04 jcubic

Oh, it seems pos-bol is a new function that will be available >= 29.

Probably introduced at or before Emacs version 29.1.

I replaced with line-beginning-position at 0ad4ae0160cabad46109dfbb394297a185eb2525

davazp avatar Apr 11 '23 19:04 davazp