From bfec0bd8971e93c85353f7415960fdbbfe6c3f01 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 14 Feb 2021 20:45:56 +0100 Subject: [PATCH] Add new forward compatibility package 'future-interactive' * lisp/emacs-lisp/future-interactive.el: * test/lisp/emacs-lisp/future-interactive-tests.el: New files. --- lisp/emacs-lisp/future-interactive.el | 58 +++++++++++++++++++ .../emacs-lisp/future-interactive-tests.el | 38 ++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 lisp/emacs-lisp/future-interactive.el create mode 100644 test/lisp/emacs-lisp/future-interactive-tests.el diff --git a/lisp/emacs-lisp/future-interactive.el b/lisp/emacs-lisp/future-interactive.el new file mode 100644 index 0000000000..fe12924194 --- /dev/null +++ b/lisp/emacs-lisp/future-interactive.el @@ -0,0 +1,58 @@ +;;; future-interactive.el --- Forward compatibility for `interactive' in Emacs 28. -*- lexical-binding: t; -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; Author: Stefan Kangas +;; Keywords: lisp, compatibility + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; This is a forward compatibility package to allow maintaining +;; support for older versions of Emacs while also using the new third +;; argument to the `interactive'form added in Emacs 28. +;; +;; To use this in a package, just add a dependency on this package and +;; replace `interactive' with `future-interactive': +;; +;; (require 'future-interactive) +;; +;; (defun foo-command () +;; (future-interactive nil foo-mode) +;; ... ) +;; +;; See the `future-interactive' macro for more information. + +;;; Code: + +;; This is a GNU ELPA :core package to be able to easily use this in +;; other :core packages. + +(defmacro future-interactive (arg-descriptor &rest modes) + "Use the correct `interactive' form for any Emacs version. + +This is a forward compatibility macro that allows packages to +provide the third argument to `interactive' (added in Emacs 28) +while still working on older versions of Emacs. + +To use it, simply replace `interactive' with `future-interactive'." + (if (< emacs-major-version 28) + `(interactive ,arg-descriptor) + `(interactive ,arg-descriptor ,@modes))) + +(provide 'future-interactive) +;;; future-interactive.el ends here diff --git a/test/lisp/emacs-lisp/future-interactive-tests.el b/test/lisp/emacs-lisp/future-interactive-tests.el new file mode 100644 index 0000000000..f525d03fcb --- /dev/null +++ b/test/lisp/emacs-lisp/future-interactive-tests.el @@ -0,0 +1,38 @@ +;;; future-interactive-tests.el --- Tests for future-interactive.el -*- lexical-binding: t -*- + +;; Copyright (C) 2021 Free Software Foundation, Inc. + +;; Author: Stefan Kangas + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) +(require 'future-interactive) + +(defun foo (args) + (future-interactive "P" fundamental-mode) + (message "args is %s" args)) + +(ert-deftest future-interactive-test () + (should (fboundp 'foo)) + (should (foo t))) + +(provide 'future-interactive-tests) +;;; future-interactive-tests.el ends here -- 2.30.0