Example, I want to define a package-open-homepage
command, which reuses C-h P (describe-package
)'s "interactive" form. I don't want to copy-and-paste because it is too long. The following
(eval
`(defun package-open-homepage (pkg)
"Open homepage of pkg, or do nothing if none."
,(interactive-form 'describe-package)
(when-let ((desc (cadr (assq pkg package-alist)))
(extras (package-desc-extras desc))
(homepage (cdr (assoc :url extras))))
(browse-url homepage))))
works, but I never use eval
before, is this use case the reason that why eval
is needed? and is there any other way without using eval
?
By the way, I already know (put 'package-open-homepage 'interactive-form (interactive-form 'describe-package))
works.
interactive-form
symbol property, then you have an answer already. You should at least post that as an answer to your own question.advice-eval-interactive-spec
fromnadvice
can be used to evaluate interactive forms. It uses eval internally, too. You can use it as a more general solution to evaluate interactive specs.commandp
will now raise an error if a command has aninteractive-form
property. There was a question about this in bug #55925, but as of this writing that bug has never been addressed.