summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/pcase.el
diff options
context:
space:
mode:
authorLeo Liu <sdl.web@gmail.com>2014-09-14 00:30:21 +0800
committerLeo Liu <sdl.web@gmail.com>2014-09-14 00:30:21 +0800
commit85b3d352c7c0229c9c474ac97c2542befb4e99fa (patch)
tree9022f78f192e9d6cd73271e31ceac1581adbf03b /lisp/emacs-lisp/pcase.el
parent4d837e510bbc0a073828a0f581b64aa9b4651afa (diff)
downloademacs-85b3d352c7c0229c9c474ac97c2542befb4e99fa.tar.gz
emacs-85b3d352c7c0229c9c474ac97c2542befb4e99fa.tar.bz2
emacs-85b3d352c7c0229c9c474ac97c2542befb4e99fa.zip
* emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-2): Add
pcase-exhaustive. * emacs-lisp/pcase.el (pcase--dontwarn-upats): New var. (pcase--expand): Use it. (pcase-exhaustive): New macro. Fixes: debbugs:16567
Diffstat (limited to 'lisp/emacs-lisp/pcase.el')
-rw-r--r--lisp/emacs-lisp/pcase.el14
1 files changed, 13 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el
index 963d6a44041..94aedd4339a 100644
--- a/lisp/emacs-lisp/pcase.el
+++ b/lisp/emacs-lisp/pcase.el
@@ -68,6 +68,8 @@
(defconst pcase--dontcare-upats '(t _ pcase--dontcare))
+(defvar pcase--dontwarn-upats '(pcase--dontcare))
+
(def-edebug-spec
pcase-UPAT
(&or symbolp
@@ -148,6 +150,15 @@ like `(,a . ,(pred (< a))) or, with more checks:
;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2)
expansion))))
+;;;###autoload
+(defmacro pcase-exhaustive (exp &rest cases)
+ "The exhaustive version of `pcase' (which see)."
+ (declare (indent 1) (debug pcase))
+ (let* ((x (make-symbol "x"))
+ (pcase--dontwarn-upats (cons x pcase--dontwarn-upats)))
+ (pcase--expand
+ exp (append cases `((,x (error "No clause matching `%S'" ,x)))))))
+
(defun pcase--let* (bindings body)
(cond
((null bindings) (macroexp-progn body))
@@ -280,7 +291,8 @@ of the form (UPAT EXP)."
vars))))
cases))))
(dolist (case cases)
- (unless (or (memq case used-cases) (eq (car case) 'pcase--dontcare))
+ (unless (or (memq case used-cases)
+ (memq (car case) pcase--dontwarn-upats))
(message "Redundant pcase pattern: %S" (car case))))
(macroexp-let* defs main))))