Comments (10)
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.
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.
My initial plan was to allow 2 formats.
- Fixed indentation (currently on main branch)
'fixed
- Semantic indentation
'semantic
But when looking at clojure-mode and cljfmt I notice some differences.
I'm thinking of creating three preconfigured nodes now
- Fixed indentation
'fixed
- Cljfmt default settings indentation
'cljfmt
- 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.
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.
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.
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.
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.
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.
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.
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)
- Organize repo directory structure with queries folder (?) HOT 2
- Highlight (some) regular expressions using another grammar HOT 7
- Users need a way to distinguish what dialect of clojure is represented in a buffer HOT 1
- Impossible to install the package from MELPA on emacs 29 pre-test HOT 2
- No way to recognize additional function definition macros HOT 2
- Add suport for clojure-align-forms-automatically HOT 7
- Cannot transpose keywords HOT 34
- Docstring indentation is too aggressive when semantic indentation is enabled. HOT 14
- Interactive function for diagnosing grammar version issues HOT 2
- Better font-locking in method definitions
- indent-region does not follow clojure-align-forms-automatically HOT 1
- Jank Support
- Syntax highlighting problem (?), can someone reproduce this. HOT 4
- Run clojure-mode's test suite HOT 1
- `comment-add` value is different from `clojure-mode` HOT 1
- should we support plumatic style defn syntax (?)
- Some paths in "Compile From Source" are off a bit HOT 1
- Support equivalent of clojure-toplevel-inside-comment-form
- List on Non-GNU ELPA HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clojure-ts-mode.