]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/map.el (map--make-pcase-bindings): Fix use in Emacs<30
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 21 Feb 2024 13:49:15 +0000 (08:49 -0500)
committerEshel Yaron <me@eshelyaron.com>
Wed, 28 Feb 2024 17:37:36 +0000 (18:37 +0100)
(cherry picked from commit 3b34c5e4a583dd88f476570cbd58655a18e9a6b4)

lisp/emacs-lisp/map.el

index 95a25978d1cfea9f4c5a6172957476de6636c044..d3d71a36ee460ea03a2ca3e66e1c9ce9cc35f264 100644 (file)
@@ -608,19 +608,30 @@ This allows using default values for `map-elt', which can't be
 done using `pcase--flip'.
 
 KEY is the key sought in the map.  DEFAULT is the default value."
+  ;; It's obsolete in Emacs>29, but `map.el' is distributed via GNU ELPA
+  ;; for earlier Emacsen.
   (declare (obsolete _ "30.1"))
   `(map-elt ,map ,key ,default))
 
 (defun map--make-pcase-bindings (args)
   "Return a list of pcase bindings from ARGS to the elements of a map."
-  (mapcar (lambda (elt)
-            (cond ((consp elt)
-                   `(app (map-elt _ ,(car elt) ,(caddr elt))
-                         ,(cadr elt)))
-                  ((keywordp elt)
-                   (let ((var (intern (substring (symbol-name elt) 1))))
-                     `(app (map-elt _ ,elt) ,var)))
-                  (t `(app (map-elt _ ',elt) ,elt))))
+  (mapcar (if (< emacs-major-version 30)
+              (lambda (elt)
+                (cond ((consp elt)
+                       `(app (map--pcase-map-elt ,(car elt) ,(caddr elt))
+                             ,(cadr elt)))
+                      ((keywordp elt)
+                       (let ((var (intern (substring (symbol-name elt) 1))))
+                         `(app (pcase--flip map-elt ,elt) ,var)))
+                      (t `(app (pcase--flip map-elt ',elt) ,elt))))
+            (lambda (elt)
+              (cond ((consp elt)
+                     `(app (map-elt _ ,(car elt) ,(caddr elt))
+                           ,(cadr elt)))
+                    ((keywordp elt)
+                     (let ((var (intern (substring (symbol-name elt) 1))))
+                       `(app (map-elt _ ,elt) ,var)))
+                    (t `(app (map-elt _ ',elt) ,elt)))))
           args))
 
 (defun map--make-pcase-patterns (args)