summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/pcase.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2019-06-26 10:03:48 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2019-06-26 10:03:48 -0400
commit698ff554ac2699ec48fefc85a1307cbc4a183b0d (patch)
treea7b7592f7973f81cad4410366d313e790616907e /lisp/emacs-lisp/pcase.el
parent9233865b7005831e63755eb84ae7da060f878a55 (diff)
downloademacs-698ff554ac2699ec48fefc85a1307cbc4a183b0d.tar.gz
* lisp/calc/calc-ext.el (math-scalarp): Fix typo
Diffstat (limited to 'lisp/emacs-lisp/pcase.el')
-rw-r--r--lisp/emacs-lisp/pcase.el29
1 files changed, 26 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index ae2cf8eb02f..07beb722fc3 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -97,11 +97,34 @@
(declare-function get-edebug-spec "edebug" (symbol))
(declare-function edebug-match "edebug" (cursor specs))
+(defun pcase--get-macroexpander (s)
+ "Return the macroexpander for pcase pattern head S, or nil"
+ (let ((em (assoc s (assq :pcase-macroexpander macroexpand-all-environment))))
+ (if em (cdr em)
+ (get s 'pcase-macroexpander))))
+
+(defmacro pcase-macrolet (bindings &rest body)
+ (let ((new-macros (if (consp (car-safe bindings))
+ (mapcar (lambda (binding)
+ (cons (car binding)
+ (eval (if (cddr binding)
+ `(lambda ,(cadr binding)
+ ,@(cddr binding))
+ (cadr binding))
+ lexical-binding)))
+ bindings)
+ (eval bindings lexical-binding)))
+ (old-pme (assq :pcase-macroexpander macroexpand-all-environment)))
+ (macroexpand-all (macroexp-progn body)
+ (cons (cons :pcase-macroexpander
+ (append new-macros old-pme))
+ macroexpand-all-environment))))
+
(defun pcase--edebug-match-macro (cursor)
(let (specs)
(mapatoms
(lambda (s)
- (let ((m (get s 'pcase-macroexpander)))
+ (let ((m (pcase--get-macroexpander s)))
(when (and m (get-edebug-spec m))
(push (cons (symbol-name s) (get-edebug-spec m))
specs)))))
@@ -193,7 +216,7 @@ Emacs Lisp manual for more information and examples."
(let (more)
;; Collect all the extensions.
(mapatoms (lambda (symbol)
- (let ((me (get symbol 'pcase-macroexpander)))
+ (let ((me (pcase--get-macroexpander symbol)))
(when me
(push (cons symbol me)
more)))))
@@ -419,7 +442,7 @@ of the elements of LIST is performed as if by `pcase-let'.
((eq head 'let) `(let ,(pcase--macroexpand (cadr pat)) ,@(cddr pat)))
((eq head 'app) `(app ,(nth 1 pat) ,(pcase--macroexpand (nth 2 pat))))
(t
- (let* ((expander (get head 'pcase-macroexpander))
+ (let* ((expander (pcase--get-macroexpander head))
(npat (if expander (apply expander (cdr pat)))))
(if (null npat)
(error (if expander