3

I'm defining a minor-mode not meant to be interactively activated. I'd like to use define-minor-mode because it's very convenient, but the downside is that it always sets the mode function as interactive.

Is there a way to make an already-defined command non-interactive?

  • isearch toggle state minor mode? :) – Kaushal Modi Jun 29 '15 at 12:41
  • @kaushalmodi Haha. No, cider-debug-mode actually. :-) – Malabarba Jun 29 '15 at 12:50
  • Not that I know of. – Stefan Jun 29 '15 at 12:54
  • I recommend having a look at the macro define-minor-mode within easy-mode.el, most specifically at the line of code (interactive (list (or current-prefix-arg 'toggle))). You may wish to consider making a new macro by copying define-minor-mode and calling it something like define-non-interactive-minor-mode -- comment out the interactive statement above and implement any other additional modifications that you see fit. – lawlist Jun 29 '15 at 14:04
  • Good question! I thought I recalled that there was a keyword or an optional arg that you could pass to the macro that would prevent inclusion of an interactive spec, but there apparently is none. You might consider filing an enhancement request: M-x report-emacs-bug. (I was mistaken, I think, because my macro icicle-define-command does accept such an optional arg. There are cases where you use the macro to define a helper function that is then used to define some commands. The helper does all the heavy lifting, and the commands that use it are wrappers that provide different contexts.) – Drew Jun 29 '15 at 15:34
5

If it's ok, that the function isn't interactive in the first place, something like this might work.

(defmacro define-noninteractive-minor-mode (mode doc &optional
                                                 init-value lighter keymap
                                                 &rest body)
  `(cl-macrolet ((interactive (&rest _)))
     (define-minor-mode ,mode ,doc ,init-value ,lighter ,keymap ,@body)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.