Non-interactive functions as actions
Alternatively, Embark does support one other type of action: a non-interactive function of a single argument. The target is passed as argument to the function. For example:
emacs-lisp
(defun example-action-function (target)
(message "The target was `%s'." target))
(keymap-set embark-symbol-map "X 4" #'example-action-function)Note that normally binding non-interactive functions in a keymap is useless, since when attempting to run them using the key binding you get an error message similar to "Wrong type argument: commandp, example-action-function". In general it is more flexible to write any new Embark actions as commands, that is, as interactive functions, because that way you can also run them directly, without Embark. But there are a couple of reasons to use non-interactive functions as actions:
- You may already have the function lying around, and it is convenient to simply reuse it.
- For command actions the targets can only be simple string, with no text properties. For certain advanced uses you may want the action to receive a string with some text properties, or even a non-string target.