* bug#60001: [PATCH] Improve completion of treesit-check-indent command
[not found] <m1wn6wj3lf.fsf.ref@yahoo.es>
@ 2022-12-12 10:53 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 14:00 ` Eli Zaretskii
2023-01-07 23:13 ` Yuan Fu
0 siblings, 2 replies; 8+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-12 10:53 UTC (permalink / raw)
To: 60001
[-- Attachment #1: Type: text/plain, Size: 343 bytes --]
Tags: patch
The treesit-check-indent command is not really related to Tree-sitter
and could be in a more general place than treesit.el. WDYT?
In any case, I have a patch to improve this command a bit by offering
more accurate completion for major modes, not Emacs commands. I have
also tried to improve its documentation a bit.
Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-completion-of-treesit-check-indent-command.patch --]
[-- Type: text/patch, Size: 2069 bytes --]
From e6699c1671f3f13fa7d98ef958c0159e80aa2645 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Mon, 12 Dec 2022 11:33:01 +0100
Subject: [PATCH] Improve completion of treesit-check-indent command
* lisp/treesit.el (treesit--read-major-mode): Helper function to
provide completion for most major modes.
(treesit-check-indent): Use the new interactive spec and improve the
docstring.
---
lisp/treesit.el | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 85154d0d1c..de18796628 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1469,12 +1469,28 @@ treesit-simple-indent
(message "No matched rule"))
(cons nil nil))))))
-(defun treesit-check-indent (mode)
- "Check current buffer's indentation against a major mode MODE.
+(defun treesit--read-major-mode ()
+ "Read a major mode using completion.
+Helper function to use in the `interactive' spec of `treesit-check-indent'."
+ (let* ((default (and (symbolp major-mode) (symbol-name major-mode)))
+ (mode
+ (completing-read
+ (format-prompt "Target major mode" default)
+ obarray
+ (lambda (sym)
+ (and (string-match-p "-mode\\'" (symbol-name sym))
+ (not (or (memq sym minor-mode-list)
+ (string-match-p "-minor-mode\\'"
+ (symbol-name sym))))))
+ nil nil nil default nil)))
+ (cond
+ ((equal mode "nil") nil)
+ ((and (stringp mode) (fboundp (intern mode))) (intern mode))
+ (t mode))))
-Pop up a diff buffer showing the difference. Correct
-indentation (target) is in green, current indentation is in red."
- (interactive "CTarget major mode: ")
+(defun treesit-check-indent (mode)
+ "Compare the current buffer with how major mode MODE would indent it."
+ (interactive (list (treesit--read-major-mode)))
(let ((source-buf (current-buffer)))
(with-temp-buffer
(insert-buffer-substring source-buf)
--
2.34.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2022-12-12 10:53 ` bug#60001: [PATCH] Improve completion of treesit-check-indent command Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-12-12 14:00 ` Eli Zaretskii
2023-01-07 23:13 ` Yuan Fu
1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2022-12-12 14:00 UTC (permalink / raw)
To: Daniel Martín; +Cc: 60001
> Date: Mon, 12 Dec 2022 11:53:00 +0100
> From: Daniel Martín via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>
> The treesit-check-indent command is not really related to Tree-sitter
> and could be in a more general place than treesit.el. WDYT?
I agree, but then we'd need a definition for it that doesn't need
tree-sitter support. Is that easy to provide?
> In any case, I have a patch to improve this command a bit by offering
> more accurate completion for major modes, not Emacs commands. I have
> also tried to improve its documentation a bit.
How about a read-major-mode function in subr.el?
But I think all these generalizations and improvements should go to
master. On the release branch, I'd prefer to leave
treesit-check-indent alone.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2022-12-12 10:53 ` bug#60001: [PATCH] Improve completion of treesit-check-indent command Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 14:00 ` Eli Zaretskii
@ 2023-01-07 23:13 ` Yuan Fu
2023-01-08 11:53 ` Eli Zaretskii
1 sibling, 1 reply; 8+ messages in thread
From: Yuan Fu @ 2023-01-07 23:13 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 60001, Daniel Martín
Eli Zaretskii <eliz@gnu.org> writes:
>> Date: Mon, 12 Dec 2022 11:53:00 +0100
>> From: Daniel Martín via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>>
>> The treesit-check-indent command is not really related to Tree-sitter
>> and could be in a more general place than treesit.el. WDYT?
>
> I agree, but then we'd need a definition for it that doesn't need
> tree-sitter support. Is that easy to provide?
>
>> In any case, I have a patch to improve this command a bit by offering
>> more accurate completion for major modes, not Emacs commands. I have
>> also tried to improve its documentation a bit.
>
> How about a read-major-mode function in subr.el?
>
> But I think all these generalizations and improvements should go to
> master. On the release branch, I'd prefer to leave
> treesit-check-indent alone.
Has this patch been pushed to master? Should I close this report?
Yuan
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2023-01-07 23:13 ` Yuan Fu
@ 2023-01-08 11:53 ` Eli Zaretskii
2023-09-04 20:02 ` Stefan Kangas
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-01-08 11:53 UTC (permalink / raw)
To: Yuan Fu; +Cc: 60001, mardani29
> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 7 Jan 2023 15:13:54 -0800
> Cc: Daniel Martín <mardani29@yahoo.es>,
> 60001@debbugs.gnu.org
>
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> Date: Mon, 12 Dec 2022 11:53:00 +0100
> >> From: Daniel Martín via "Bug reports for GNU Emacs,
> >> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> >>
> >> The treesit-check-indent command is not really related to Tree-sitter
> >> and could be in a more general place than treesit.el. WDYT?
> >
> > I agree, but then we'd need a definition for it that doesn't need
> > tree-sitter support. Is that easy to provide?
> >
> >> In any case, I have a patch to improve this command a bit by offering
> >> more accurate completion for major modes, not Emacs commands. I have
> >> also tried to improve its documentation a bit.
> >
> > How about a read-major-mode function in subr.el?
> >
> > But I think all these generalizations and improvements should go to
> > master. On the release branch, I'd prefer to leave
> > treesit-check-indent alone.
>
> Has this patch been pushed to master?
No, I don't think so.
> Should I close this report?
If you agree with the change, please install it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2023-01-08 11:53 ` Eli Zaretskii
@ 2023-09-04 20:02 ` Stefan Kangas
2023-09-05 10:51 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2023-09-04 20:02 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 60001, Yuan Fu, mardani29
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 7 Jan 2023 15:13:54 -0800
>> Cc: Daniel Martín <mardani29@yahoo.es>,
>> 60001@debbugs.gnu.org
>>
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> Date: Mon, 12 Dec 2022 11:53:00 +0100
>> >> From: Daniel Martín via "Bug reports for GNU Emacs,
>> >> the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
>> >>
>> >> The treesit-check-indent command is not really related to Tree-sitter
>> >> and could be in a more general place than treesit.el. WDYT?
>> >
>> > I agree, but then we'd need a definition for it that doesn't need
>> > tree-sitter support. Is that easy to provide?
>> >
>> >> In any case, I have a patch to improve this command a bit by offering
>> >> more accurate completion for major modes, not Emacs commands. I have
>> >> also tried to improve its documentation a bit.
>> >
>> > How about a read-major-mode function in subr.el?
>> >
>> > But I think all these generalizations and improvements should go to
>> > master. On the release branch, I'd prefer to leave
>> > treesit-check-indent alone.
>>
>> Has this patch been pushed to master?
>
> No, I don't think so.
>
>> Should I close this report?
>
> If you agree with the change, please install it.
It seems like this patch was never installed. Should it be?
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2023-09-04 20:02 ` Stefan Kangas
@ 2023-09-05 10:51 ` Eli Zaretskii
2023-09-05 20:40 ` Stefan Kangas
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2023-09-05 10:51 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 60001, casouri, mardani29
> From: Stefan Kangas <stefankangas@gmail.com>
> Date: Mon, 4 Sep 2023 13:02:23 -0700
> Cc: Yuan Fu <casouri@gmail.com>, 60001@debbugs.gnu.org, mardani29@yahoo.es
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> >> Should I close this report?
> >
> > If you agree with the change, please install it.
>
> It seems like this patch was never installed. Should it be?
I think so, yes.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2023-09-05 10:51 ` Eli Zaretskii
@ 2023-09-05 20:40 ` Stefan Kangas
2023-09-06 6:53 ` Juri Linkov
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2023-09-05 20:40 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 60001-done, casouri, mardani29
Version: 30.1
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Stefan Kangas <stefankangas@gmail.com>
>> Date: Mon, 4 Sep 2023 13:02:23 -0700
>> Cc: Yuan Fu <casouri@gmail.com>, 60001@debbugs.gnu.org, mardani29@yahoo.es
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> >> Should I close this report?
>> >
>> > If you agree with the change, please install it.
>>
>> It seems like this patch was never installed. Should it be?
>
> I think so, yes.
Thanks, pushed to master as commit cd6dcfad107.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#60001: [PATCH] Improve completion of treesit-check-indent command
2023-09-05 20:40 ` Stefan Kangas
@ 2023-09-06 6:53 ` Juri Linkov
0 siblings, 0 replies; 8+ messages in thread
From: Juri Linkov @ 2023-09-06 6:53 UTC (permalink / raw)
To: 60001; +Cc: stefankangas, mardani29
>>> > If you agree with the change, please install it.
>>>
>>> It seems like this patch was never installed. Should it be?
>>
>> I think so, yes.
>
> Thanks, pushed to master as commit cd6dcfad107.
Would it be possible to avoid code duplication in
'treesit--read-major-mode' with the same code as in
'read-file-local-variable-mode'?
Maybe by creating a new core function to read a major mode?
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-09-06 6:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <m1wn6wj3lf.fsf.ref@yahoo.es>
2022-12-12 10:53 ` bug#60001: [PATCH] Improve completion of treesit-check-indent command Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-12 14:00 ` Eli Zaretskii
2023-01-07 23:13 ` Yuan Fu
2023-01-08 11:53 ` Eli Zaretskii
2023-09-04 20:02 ` Stefan Kangas
2023-09-05 10:51 ` Eli Zaretskii
2023-09-05 20:40 ` Stefan Kangas
2023-09-06 6:53 ` Juri Linkov
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).