clojure-emacs / clojure-ts-mode

The next generation Clojure major mode for Emacs, powered by TreeSitter
GNU General Public License v3.0
140 stars 13 forks source link

Consider all clojure sexps as defuns #32

Closed kommen closed 9 months ago

kommen commented 9 months ago

Consider this clojure code, | indicating the point position

(ns my.app)

(defn foo []
  (+ 1 1))

foo|

"another sexp"

(defn bar []
  (+ 2 1))

Without this change, beginning-of-defun would move point before the (defn foo,,,) as the symbol literal foo is not considered as a valid defun.

With this change, all clojure sexps will be considered as defuns, so beginning-of-defun moves point before foo, which I would consider as the expected behavior.

Similar for cider-eval-defun-at-point: At the point position indicated in the example without this change the (defn bar,,,) form is evaluated. With this change, foo is evaluated, which I also would consider the expected behavior.

bbatsov commented 9 months ago

I'm fine with the proposal as it's in line with how most Emacs modes work - defuns are essentially top-level forms in them, not real defuns.

I'd suggest adding a couple of unit tests for this (you can copy something from clojure-mode) and a changelog entry, though.

kommen commented 9 months ago

@bbatsov thanks for the review! I added the note and the changelog entry. However, for the tests there is nothing set up yet here and I guess adding some bare-bone tests could conflict with @dannyfreeman's plan outlined in https://github.com/clojure-emacs/clojure-ts-mode/issues/25#issuecomment-1742142160?

bbatsov commented 9 months ago

Well, I see those tests as accretive to the tests that we plan to copy, so I don't think that would create any issues. I'm guessing you can just copy all the tests, as this would help set up the infra here and this would actually speed up the compatibility work.

But if you don't want to tackle this, I or Danny can do it down the road.

kommen commented 9 months ago

@bbatsov I'd rather not tackle setting up the tests here and now, but would be happy to help Danny and you down the road.

camdez commented 9 months ago

It might be clarifying for the issue title (and more importantly the changelog) if it said "top-level forms" (or even "top-level sexps"). I read the title and thought every (possibly-nested) sexp would be a target for beginning-of-defun, but that appears not to be the case.

(Please disregard entirely if I've misunderstood—I haven't run this.)

Cheers.

bbatsov commented 9 months ago

Yeah, that affects only top-level forms. I'll update the changelog.