[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/reformatter dce9c3fdd3 1/2: Integrate with `read-extended-
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/reformatter dce9c3fdd3 1/2: Integrate with `read-extended-command-predicate' |
Date: |
Wed, 4 Dec 2024 07:02:13 -0500 (EST) |
branch: elpa/reformatter
commit dce9c3fdd39c04fe54c2f7691669381b7d0b1a2d
Author: Johannes Maier <johannes.maier@mailbox.org>
Commit: Johannes Maier <johannes.maier@mailbox.org>
Integrate with `read-extended-command-predicate'
Adds the option to specify a list of modes that the interactive commands
are defined for. This way, people using a
`read-extended-command-predicate' may have the "-region" and "-buffer"
commands only available via M-x in those modes.
---
reformatter-tests.el | 31 +++++++++++++++++++++++++++++++
reformatter.el | 17 +++++++++++++----
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/reformatter-tests.el b/reformatter-tests.el
index 2878734eb9..b59d5f62dd 100644
--- a/reformatter-tests.el
+++ b/reformatter-tests.el
@@ -81,6 +81,37 @@
(reformatter-tests-shfmt-in-place-buffer)
(should (equal "[ foo ] && echo yes\n" (buffer-string)))))
+;; Formatting commands tagged for specific modes: `command-modes' checks which
+;; modes they're defined to be interactively usable in, but it's only available
+;; in Emacs 28 and newer.
+(when (fboundp 'command-modes)
+ (reformatter-define reformatter-tests-shfmt-no-interactive-modes
+ :program "shfmt")
+
+ (ert-deftest reformatter-tests-no-interactive-modes ()
+ (should (not (command-modes
'reformatter-tests-shfmt-no-interactive-modes-buffer)))
+ (should (not (command-modes
'reformatter-tests-shfmt-no-interactive-modes-region))))
+
+ (reformatter-define reformatter-tests-shfmt-single-interactive-mode
+ :program "shfmt"
+ :interactive-modes (sh-mode))
+
+ (ert-deftest reformatter-tests-single-interactive-mode ()
+ (should (equal (command-modes
'reformatter-tests-shfmt-single-interactive-mode-buffer)
+ '(sh-mode)))
+ (should (equal (command-modes
'reformatter-tests-shfmt-single-interactive-mode-region)
+ '(sh-mode))))
+
+ (reformatter-define reformatter-tests-shfmt-multiple-interactive-modes
+ :program "shfmt"
+ :interactive-modes (sh-mode haskell-mode))
+
+ (ert-deftest reformatter-tests-multiple-interactive-modes ()
+ (should (equal (command-modes
'reformatter-tests-shfmt-multiple-interactive-modes-buffer)
+ '(sh-mode haskell-mode)))
+ (should (equal (command-modes
'reformatter-tests-shfmt-multiple-interactive-modes-region)
+ '(sh-mode haskell-mode)))))
+
(provide 'reformatter-tests)
;;; reformatter-tests.el ends here
diff --git a/reformatter.el b/reformatter.el
index 8116a8f145..bcbb6ac2bd 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -143,7 +143,7 @@ WORKING-DIRECTORY see the documentation of the
`reformatter-define' macro."
(delete-file stdout-file))))
;;;###autoload
-(cl-defmacro reformatter-define (name &key program args (mode t) (stdin t)
(stdout t) input-file lighter keymap group (exit-code-success-p 'zerop)
working-directory)
+(cl-defmacro reformatter-define (name &key program args (mode t) (stdin t)
(stdout t) input-file lighter keymap group (exit-code-success-p 'zerop)
working-directory interactive-modes)
"Define a reformatter command with NAME.
When called, the reformatter will use PROGRAM and any ARGS to
@@ -241,7 +241,16 @@ WORKING-DIRECTORY
Directory where your reformatter program is started. If provided, this
should be a form that evaluates to a string at runtime. Default is the
- value of `default-directory' in the buffer."
+ value of `default-directory' in the buffer.
+
+INTERACTIVE-MODES
+
+ If provided, this is a list of mode names (as unquoted
+ symbols). The created commands for formatting regions and
+ buffers are then tagged for interactive use in these modes,
+ making them compatible with some built-in predicate functions
+ for `read-extended-command-predicate', like
+ `command-completion-default-include-p'."
(declare (indent defun))
(cl-assert (symbolp name))
(cl-assert (functionp exit-code-success-p))
@@ -282,7 +291,7 @@ might use:
"Reformats the region from BEG to END.
When called interactively, or with prefix argument
DISPLAY-ERRORS, shows a buffer if the formatting fails."
- (interactive "rp")
+ (interactive "rp" ,@interactive-modes)
(let ((input-file ,(if input-file
input-file
`(reformatter--make-temp-file ',name))))
@@ -300,7 +309,7 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
"Reformats the current buffer.
When called interactively, or with prefix argument
DISPLAY-ERRORS, shows a buffer if the formatting fails."
- (interactive "p")
+ (interactive "p" ,@interactive-modes)
(message "Formatting buffer")
(,region-fn-name (point-min) (point-max) display-errors))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/reformatter dce9c3fdd3 1/2: Integrate with `read-extended-command-predicate',
ELPA Syncer <=