From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 60001@debbugs.gnu.org
Subject: bug#60001: [PATCH] Improve completion of treesit-check-indent command
Date: Mon, 12 Dec 2022 11:53:00 +0100 [thread overview]
Message-ID: <m1wn6wj3lf.fsf@yahoo.es> (raw)
In-Reply-To: m1wn6wj3lf.fsf.ref@yahoo.es
[-- 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
next parent reply other threads:[~2022-12-12 10:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[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 [this message]
2022-12-12 14:00 ` bug#60001: [PATCH] Improve completion of treesit-check-indent command 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1wn6wj3lf.fsf@yahoo.es \
--to=bug-gnu-emacs@gnu.org \
--cc=60001@debbugs.gnu.org \
--cc=mardani29@yahoo.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.