From da0e75e7410226d7fd6d760f0ebe8a04d815506d Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 13 Sep 2020 20:21:41 +0200 Subject: Add facility to make module functions interactive (Bug#23486). * src/module-env-28.h: Add field for 'make_interactive' function. * src/emacs-module.c (Lisp_Module_Function): Add new field holding the interactive form. (allocate_module_function): Adapt to structure layout change. (module_make_interactive, module_function_interactive_form): New functions. (initialize_environment): Use them. * src/eval.c (Fcommandp): * src/data.c (Finteractive_form): Also handle interactive module functions. * test/data/emacs-module/mod-test.c (Fmod_test_identity): New test function. (emacs_module_init): Create two interactive module test functions. * test/src/emacs-module-tests.el (module/interactive/return-t) (module/interactive/return-t-int, module/interactive/identity): New unit tests. * doc/lispref/internals.texi (Module Functions): Document new function. Rework paragraph about wrapping module functions, as the example no longer applies. * etc/NEWS: Document new facility. --- test/src/emacs-module-tests.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'test/src') diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el index 096c6b30574..1eebb418cf3 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -468,4 +468,36 @@ See Bug#36226." (should (equal (buffer-string) "data from thread"))) (delete-process process))))) +(ert-deftest module/interactive/return-t () + (should (functionp (symbol-function #'mod-test-return-t))) + (should (module-function-p (symbol-function #'mod-test-return-t))) + (should-not (commandp #'mod-test-return-t)) + (should-not (commandp (symbol-function #'mod-test-return-t))) + (should-not (interactive-form #'mod-test-return-t)) + (should-not (interactive-form (symbol-function #'mod-test-return-t))) + (should-error (call-interactively #'mod-test-return-t) + :type 'wrong-type-argument)) + +(ert-deftest module/interactive/return-t-int () + (should (functionp (symbol-function #'mod-test-return-t-int))) + (should (module-function-p (symbol-function #'mod-test-return-t-int))) + (should (commandp #'mod-test-return-t-int)) + (should (commandp (symbol-function #'mod-test-return-t-int))) + (should (equal (interactive-form #'mod-test-return-t-int) '(interactive))) + (should (equal (interactive-form (symbol-function #'mod-test-return-t-int)) + '(interactive))) + (should (eq (mod-test-return-t-int) t)) + (should (eq (call-interactively #'mod-test-return-t-int) t))) + +(ert-deftest module/interactive/identity () + (should (functionp (symbol-function #'mod-test-identity))) + (should (module-function-p (symbol-function #'mod-test-identity))) + (should (commandp #'mod-test-identity)) + (should (commandp (symbol-function #'mod-test-identity))) + (should (equal (interactive-form #'mod-test-identity) '(interactive "i"))) + (should (equal (interactive-form (symbol-function #'mod-test-identity)) + '(interactive "i"))) + (should (eq (mod-test-identity 123) 123)) + (should-not (call-interactively #'mod-test-identity))) + ;;; emacs-module-tests.el ends here -- cgit v1.2.1