diff options
| author | Daniel MartÃn | 2022-12-12 11:33:01 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2023-09-05 22:40:38 +0200 |
| commit | cd6dcfad1074cfdc2a3b18d905cb60ce977ed6b0 (patch) | |
| tree | 8f654fb4bb6f6b5b9bc6b6172540d7e14db866d2 | |
| parent | 07454c47a62d9450f194dc0177a3a5b10846195b (diff) | |
| download | emacs-cd6dcfad1074cfdc2a3b18d905cb60ce977ed6b0.tar.gz emacs-cd6dcfad1074cfdc2a3b18d905cb60ce977ed6b0.zip | |
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. (Bug#60001)
| -rw-r--r-- | lisp/treesit.el | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index d7032b16dab..1eccede436e 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el | |||
| @@ -1703,12 +1703,28 @@ OFFSET." | |||
| 1703 | (message "No matched rule")) | 1703 | (message "No matched rule")) |
| 1704 | (cons nil nil)))))) | 1704 | (cons nil nil)))))) |
| 1705 | 1705 | ||
| 1706 | (defun treesit-check-indent (mode) | 1706 | (defun treesit--read-major-mode () |
| 1707 | "Check current buffer's indentation against a major mode MODE. | 1707 | "Read a major mode using completion. |
| 1708 | Helper function to use in the `interactive' spec of `treesit-check-indent'." | ||
| 1709 | (let* ((default (and (symbolp major-mode) (symbol-name major-mode))) | ||
| 1710 | (mode | ||
| 1711 | (completing-read | ||
| 1712 | (format-prompt "Target major mode" default) | ||
| 1713 | obarray | ||
| 1714 | (lambda (sym) | ||
| 1715 | (and (string-match-p "-mode\\'" (symbol-name sym)) | ||
| 1716 | (not (or (memq sym minor-mode-list) | ||
| 1717 | (string-match-p "-minor-mode\\'" | ||
| 1718 | (symbol-name sym)))))) | ||
| 1719 | nil nil nil default nil))) | ||
| 1720 | (cond | ||
| 1721 | ((equal mode "nil") nil) | ||
| 1722 | ((and (stringp mode) (fboundp (intern mode))) (intern mode)) | ||
| 1723 | (t mode)))) | ||
| 1708 | 1724 | ||
| 1709 | Pop up a diff buffer showing the difference. Correct | 1725 | (defun treesit-check-indent (mode) |
| 1710 | indentation (target) is in green, current indentation is in red." | 1726 | "Compare the current buffer with how major mode MODE would indent it." |
| 1711 | (interactive "CTarget major mode: ") | 1727 | (interactive (list (treesit--read-major-mode))) |
| 1712 | (let ((source-buf (current-buffer))) | 1728 | (let ((source-buf (current-buffer))) |
| 1713 | (with-temp-buffer | 1729 | (with-temp-buffer |
| 1714 | (insert-buffer-substring source-buf) | 1730 | (insert-buffer-substring source-buf) |