Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "wrong-type-argument integerp" error in clojure-align #673

Merged

Conversation

kommen
Copy link
Contributor

@kommen kommen commented Feb 11, 2024

Background: clojure-ts-mode doesn't (yet) have an equivalent to clojure-align for vertically aligning contents of sexps. See clojure-emacs/clojure-ts-mode#16

To aid this for the time being, users of clojure-ts-mode major mode could use clojure-mode's clojure-align.

However, this currently fails with this error (tested on Emacs 29.2):

Debugger entered--Lisp error: (wrong-type-argument integerp #<marker at 16 in *scratch-clj*>)
  treesit-query-range(clojure #<treesit-compiled-query> 3 #<marker at 16 in *scratch-clj*>)
  treesit-update-ranges(3 #<marker at 16 in *scratch-clj*>)
  treesit-indent-region(3 #<marker at 16 in *scratch-clj*>)
  indent-region(3 #<marker at 16 in *scratch-clj*>)
  (let ((sexp-end (save-excursion (backward-up-list) (forward-sexp 1) (point-marker))) (clojure-align-forms-automatically nil) (count 1)) (save-excursion (while (search-forward-regexp "^ *\n" sexp-end 'noerror) (setq count (1+ count)))) (indent-region (point) sexp-end) (let ((upper-bound count) (counter 0)) (while (< counter upper-bound) (let ((_ counter)) (align-region (point) sexp-end nil (list (cons 'clojure-align (cons ... ...))) nil)) (setq counter (1+ counter)))))
  (while (clojure--find-sexp-to-align end) (let ((sexp-end (save-excursion (backward-up-list) (forward-sexp 1) (point-marker))) (clojure-align-forms-automatically nil) (count 1)) (save-excursion (while (search-forward-regexp "^ *\n" sexp-end 'noerror) (setq count (1+ count)))) (indent-region (point) sexp-end) (let ((upper-bound count) (counter 0)) (while (< counter upper-bound) (let ((_ counter)) (align-region (point) sexp-end nil (list (cons ... ...)) nil)) (setq counter (1+ counter))))))
  (save-excursion (goto-char beg) (while (clojure--find-sexp-to-align end) (let ((sexp-end (save-excursion (backward-up-list) (forward-sexp 1) (point-marker))) (clojure-align-forms-automatically nil) (count 1)) (save-excursion (while (search-forward-regexp "^ *\n" sexp-end 'noerror) (setq count (1+ count)))) (indent-region (point) sexp-end) (let ((upper-bound count) (counter 0)) (while (< counter upper-bound) (let ((_ counter)) (align-region (point) sexp-end nil (list ...) nil)) (setq counter (1+ counter)))))))
  clojure-align(2 17)
  funcall-interactively(clojure-align 2 17)
  command-execute(clojure-align record)
  counsel-M-x-action("clojure-align")
  #f(compiled-function (x) #<bytecode -0x184d662e7783db00>)("clojure-align")
 ...

It seems treesit-indent-region is picky to actually get the positions as integers, whereas other implementations also accept markers.

This change ensures that indent-region is called with the positions as integers, allowing clojure-align also being successfully called from clojure-ts-mode buffers.

Tests: As there is no test harness yet for clojure-ts-mode, I think there is only to ensure clojure-align still works as expected from clojure-mode major mode, which is covered here.

@bbatsov bbatsov merged commit 799b774 into clojure-emacs:master Feb 11, 2024
4 of 7 checks passed
@bbatsov
Copy link
Member

bbatsov commented Feb 11, 2024

Your change looks good to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants