diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2025-03-15 10:44:26 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2025-03-15 10:46:05 +0100 |
| commit | d8dd59279a6035bb4fee515ded74efa7824cdeca (patch) | |
| tree | 125c6049c225428108b4955456340b02df15a8ff | |
| parent | 888f3a1eda9abd93e79da0fd4bba4b9a7b1766f9 (diff) | |
compat-28: New pcase pattern cl-type
| -rw-r--r-- | NEWS.org | 1 | ||||
| -rw-r--r-- | compat-28.el | 8 | ||||
| -rw-r--r-- | compat-tests.el | 8 | ||||
| -rw-r--r-- | compat.texi | 4 |
4 files changed, 19 insertions, 2 deletions
@@ -4,6 +4,7 @@ * Development +- compat-28: New pcase pattern =cl-type=. - compat-31: New macros =static-when= and =static-unless=. - compat-31: New functions =oddp= and =evenp=. - compat-31: New functions =minusp= and =plusp=. diff --git a/compat-28.el b/compat-28.el index 9834044..ae4978d 100644 --- a/compat-28.el +++ b/compat-28.el @@ -849,5 +849,13 @@ function will never return nil." :type-error "This field should contain a nonnegative integer" :match-alternatives '(natnump))) +;;;; Defined in pcase.el + +(compat-guard t ;; <compat-tests:pcase-cl-type> + (pcase-defmacro cl-type (type) + "Pcase pattern that matches objects of TYPE. +TYPE is a type descriptor as accepted by `cl-typep', which see." + `(pred (lambda (x) (cl-typep x ',type))))) + (provide 'compat-28) ;;; compat-28.el ends here diff --git a/compat-tests.el b/compat-tests.el index eeb889b..3ea386a 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -2921,6 +2921,14 @@ (cl-with-gensyms (x y) `(let ((,x 1) (,y 2)) (+ ,x ,y)))) +(ert-deftest compat-pcase-cl-type () + (should-equal "int" (pcase 1 ((cl-type fixnum) "int"))) + (should-equal "int" (pcase 1 ((cl-type integer) "int"))) + (should-equal "int" (pcase 1 ((cl-type (integer 0 10)) "int"))) + (should-equal "bool" (pcase t ((cl-type boolean) "bool"))) + (should-equal "bool" (pcase nil ((cl-type boolean) "bool"))) + (should-not (pcase t ((cl-type fixnum) "fixnum")))) + (ert-deftest compat-cl-with-gensyms () (should-equal 3 (compat-tests--with-gensyms))) diff --git a/compat.texi b/compat.texi index a54aa93..222b799 100644 --- a/compat.texi +++ b/compat.texi @@ -1408,8 +1408,8 @@ The following functions and macros are implemented in Emacs 28.1. These functions are made available by Compat on Emacs versions older than 28.1. -The @code{defcustom} type @code{natnum} introduced in Emacs 28.1 is -made available by Compat. +The @code{defcustom} type @code{natnum} and the @code{pcase} pattern +@code{cl-type} introduced in Emacs 28.1 are made available by Compat. @c copied from lispref/processes.texi @defun process-lines-ignore-status program &rest args |
