Coder Social home page Coder Social logo

Comments (10)

dannyfreeman avatar dannyfreeman commented on June 9, 2024 2

I haven't had much chance to look at it, but the plan was to see how much I could get away with implementing using the provided simple indent functionality. I would hope that is enough to say stuff like "if the parent list first child is a ->, indent with this special rule". I have no idea if the simple indent rules mechanisms will be flexible enough to do this. Other languages much more complex than clojure have gotten away with just using them so far

from clojure-ts-mode.

dawranliou avatar dawranliou commented on June 9, 2024 1

Hey @dannyfreeman thank you for the great work! I've been using clojure-ts-mode as my daily driver since I saw the announcement blog post. It solved a pain point for me when working with humongous map literals. 🙏 Would you share how much collaboration you seek for this project? Would you like bug reports, or do you accept PRs at the current stage of the project?

Just for the people looking for a way to hack the formatting rules to comply with the Clojure Style Guide [1] before this issue #9 is resolved, here's the relevant code snippet from my config:

(with-eval-after-load 'clojure-ts-mode
  (require 'clojure-mode)
  (add-hook 'clojure-ts-mode-hook #'clojure-mode-variables)
  ;; ...
  )

This sets up many clojure-mode local variables just as the clojure-mode does, most noticeably the code and comment formats.

from clojure-ts-mode.

dannyfreeman avatar dannyfreeman commented on June 9, 2024 1

My initial plan was to allow 2 formats.

  1. Fixed indentation (currently on main branch) 'fixed
  2. Semantic indentation 'semantic

But when looking at clojure-mode and cljfmt I notice some differences.
I'm thinking of creating three preconfigured nodes now

  1. Fixed indentation 'fixed
  2. Cljfmt default settings indentation 'cljfmt
  3. Clojure-mode style indentation 'clojure-mode

I don't think it will be too bad to implement both, I'll see what that looks.
I think cljfmt would be the default.

EDIT: I have a setting (setq clojure-indent-style 'align-arguments) in my emacs configuration that is not the default. I think default clojure-indent-style is more in line with cljfmt. Maybe I turned that on to fight less some former coworkers using intellij? Either way, I will at least name the second formatting style cljfmt instead of semantic to be clear about what it should do

from clojure-ts-mode.

dannyfreeman avatar dannyfreeman commented on June 9, 2024 1

Looking good so far... will you be able to support 'clojure-align-forms-automatically t' as well?

That's been the biggest usability issue for me with clojure-ts-mode, because I can always use on-save formatter like https://github.com/radian-software/apheleia with cljfmt + clojure-ts-mode to regain the cljfmt functionality, but clojure-mode.el is the only formatter i'm aware of with 'clojure-align-forms-automatically' indenting.

I don't think that will be part of the initial pass at semantic indentation. But it is probably do-able? I think we make a new issue for this.

I was playing around with lisp-indent-function, and it seems to matter greatly what it is set to... I don't understand why that matters, but beware of it, here's the experiment

Clojure-ts-mode doesn't use lisp-indent-function (i'm 90% sure). When it's value is the function from clojure-mode we'll want to match that. Either way, it is a lot to watch out for.

from clojure-ts-mode.

dannyfreeman avatar dannyfreeman commented on June 9, 2024 1

The primary work for this is DONE now I believe. It is enabled by default on the main branch. A release has not yet been cut, but is available for testing (and should be on unstable melpa soon enough). Please open a new issue to report bugs with this.

I am currently aware that indentation within docstrings is a little too aggressive. I'm not sure how to handle it but I will open a new issue to track it.

from clojure-ts-mode.

dannyfreeman avatar dannyfreeman commented on June 9, 2024

It solved a pain point for me when working with humongous map literals.

Happy to hear this is doing some good out in the real world!

Would you share how much collaboration you seek for this project? Would you like bug reports, or do you accept PRs at the current stage of the project?

I haven't given it much thought, so far I have only received small bug reports. Happy to look at PRs though. Currently the only things I'm really thinking about are this semantic indentation issue, as well as bug fixes and improvements to the current code.

I will say that I have a pretty busy schedule between my work and my family. Usually I only have a couple weekend hours to get work done on this. If you end up opening a PR it may take some time for me to get around to reviewing it, but I will get around to it eventually.

from clojure-ts-mode.

jasonjckn avatar jasonjckn commented on June 9, 2024

What do we have for prior art, for complex indentation rules, I know https://github.com/mickeynp/combobulate has complex indentation, as I recall, it's doing a lot of calculations crawling the treesit node/graph and working directly with the AST. Is this kind of what we had in mind? Or are there simpler ways to accomplish complex indentation rules. Combobulate indentation works really well in practice for languages it supports like Python, et al, but i'm still trying to wrap my head around its source code.

from clojure-ts-mode.

dannyfreeman avatar dannyfreeman commented on June 9, 2024

Work in progress branch for implementing semantic indentation: https://github.com/clojure-emacs/clojure-ts-mode/compare/semantic-indentation

(Warning: I love to rebase branches as I work, commit history is subject to change)

from clojure-ts-mode.

jasonjckn avatar jasonjckn commented on June 9, 2024

Looking good so far... will you be able to support 'clojure-align-forms-automatically t' as well?

That's been the biggest usability issue for me with clojure-ts-mode, because I can always use on-save formatter like https://github.com/radian-software/apheleia with cljfmt + clojure-ts-mode to regain the cljfmt functionality, but clojure-mode.el is the only formatter i'm aware of with 'clojure-align-forms-automatically' indenting.

from clojure-ts-mode.

jasonjckn avatar jasonjckn commented on June 9, 2024

I was playing around with lisp-indent-function, and it seems to matter greatly what it is set to... I don't understand why that matters, but beware of it, here's the experiment

https://github.com/clojure-emacs/clojure-ts-mode/assets/550839/8613f35d-bdb6-4601-8cb5-e95117835133
higher res: https://drive.google.com/file/d/191_I0IwfxYVrv1BRCoiGgFSGtl0ln7xz/view?usp=sharing

(defun my/set-lisp-indent-lisp ()
  (interactive)

  (setq-local
  lisp-indent-function #'lisp-indent-function ; <-----------------

   indent-line-function #'treesit-indent
   indent-region-function #'treesit-indent-region
  ))

(defun my/set-lisp-indent-clojure ()
  (interactive)

  (setq-local
  lisp-indent-function #'clojure-indent-function ; <-----------------

   indent-line-function #'treesit-indent
   indent-region-function #'treesit-indent-region
  ))

(defun my/set-lisp-indent-treesit ()
  (interactive)

  (setq-local
  lisp-indent-function #'treesit-indent ; <-----------------

   indent-line-function #'treesit-indent
   indent-region-function #'treesit-indent-region
  ))

from clojure-ts-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.