-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add some way to query the current buffers indent value #299
Comments
Can you elaborate this part?
It depends on in what way. If it's to make compatible with each another, then I second it. Other than that, I need more information to give an actual opinion. cc @10sr |
For reference this is what I had so far: (seq-find
(lambda (indent-var)
(and (boundp indent-var)
(symbol-value indent-var)))
(ensure-list
(alist-get major-mode editorconfig-indentation-alist))) It returns the first variable in editorconfig-indentation-alist for the current mode that exists and is bound. This has 2 faults. One it doesn't look for the parent mode of the current major mode (easy enough, editorconfig already has something like this when setting the indent level). It doesn't work when the indent configuration specifies a function like python-mode which uses
One way I was considering was changing the contract of the indent variables so you can pass a an option to let it know what you wanted to do. If the option is a number then we retain the previous behaviour of setting the indent level. Otherwise we perform the action. For example: (defun editorconfig-set-indentation-python-mode+ (mode)
"Set `python-mode' indent size to SIZE."
(cond
((numberp mode)
(setq-local python-indent-offset mode)
;; For https://launchpad.net/python-mode
(when (boundp 'py-indent-offset)
(setq-local py-indent-offset mode)))
((eq mode :query)
(bound-and-true-p python-indent-offset))))
(editorconfig-set-indentation-python-mode+ 2)
(editorconfig-set-indentation-python-mode+ :query) Obvious downside is anyone with existing indent functions setup would set the indent to :query if they don't update it. I'd rather not create separte get-set functions but that's also an option. Alternatively it looks like all the functional ones just add a boundp check before setting the variable. It might be better to just remove this and set the variable regardless (I don't see much harm with that and the consistency benefit is nice). |
I think one reason that there are several "setter" functions is that there may be some cases where we want to compute offset value from |
This is probably somewhat out of scope but because this package is the best option for setting the indentation of a buffer and is already aware of all the indent variables associated with the various major-modes, I'm hoping you'd be receptive to supporting querying this value as well.
To give some context I'm one of the maintainers of apheleia. This is a package that lets you call formatter programs like black, clang-format, prettifier, etc. and update the text in the current Emacs buffer. A common need for a package like this is knowing what value to set the tab-width. Currently we maintain a partial list of common mode->variable associations but I think this is something better owned by editorconfig. I had thought we could just enumerate editorconfig-indentation-alist for this but the support for functional setters kind of breaks this :/.
If you're okay with it I'd like to add support for this to editorconfig and am open to suggestions on how to do this.
The text was updated successfully, but these errors were encountered: