diff options
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/pcase.el | 14 |
3 files changed, 25 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a05b7b59a27..f0b767886cb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,12 @@ | |||
| 1 | 2014-09-13 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * emacs-lisp/pcase.el (pcase--dontwarn-upats): New var. | ||
| 4 | (pcase--expand): Use it. | ||
| 5 | (pcase-exhaustive): New macro. (Bug#16567) | ||
| 6 | |||
| 7 | * emacs-lisp/lisp-mode.el (lisp-el-font-lock-keywords-2): Add | ||
| 8 | pcase-exhaustive. | ||
| 9 | |||
| 1 | 2014-09-13 Eli Zaretskii <eliz@gnu.org> | 10 | 2014-09-13 Eli Zaretskii <eliz@gnu.org> |
| 2 | 11 | ||
| 3 | * mail/rmailmm.el (rmail-mime-insert-html): Decode the HTML part | 12 | * mail/rmailmm.el (rmail-mime-insert-html): Decode the HTML part |
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 31df353321a..435730ae098 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -197,9 +197,9 @@ It has `lisp-mode-abbrev-table' as its parent." | |||
| 197 | (el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local" | 197 | (el-vdefs '("defconst" "defcustom" "defvaralias" "defvar-local" |
| 198 | "defface")) | 198 | "defface")) |
| 199 | (el-tdefs '("defgroup" "deftheme")) | 199 | (el-tdefs '("defgroup" "deftheme")) |
| 200 | (el-kw '("while-no-input" "letrec" "pcase" "pcase-let" | 200 | (el-kw '("while-no-input" "letrec" "pcase" "pcase-exhaustive" |
| 201 | "pcase-let*" "save-restriction" "save-excursion" | 201 | "pcase-let" "pcase-let*" "save-restriction" |
| 202 | "save-selected-window" | 202 | "save-excursion" "save-selected-window" |
| 203 | ;; "eval-after-load" "eval-next-after-load" | 203 | ;; "eval-after-load" "eval-next-after-load" |
| 204 | "save-window-excursion" "save-current-buffer" | 204 | "save-window-excursion" "save-current-buffer" |
| 205 | "save-match-data" "combine-after-change-calls" | 205 | "save-match-data" "combine-after-change-calls" |
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 @@ | |||
| 68 | 68 | ||
| 69 | (defconst pcase--dontcare-upats '(t _ pcase--dontcare)) | 69 | (defconst pcase--dontcare-upats '(t _ pcase--dontcare)) |
| 70 | 70 | ||
| 71 | (defvar pcase--dontwarn-upats '(pcase--dontcare)) | ||
| 72 | |||
| 71 | (def-edebug-spec | 73 | (def-edebug-spec |
| 72 | pcase-UPAT | 74 | pcase-UPAT |
| 73 | (&or symbolp | 75 | (&or symbolp |
| @@ -148,6 +150,15 @@ like `(,a . ,(pred (< a))) or, with more checks: | |||
| 148 | ;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2) | 150 | ;; (puthash (car cases) `(,exp ,cases ,@expansion) pcase--memoize-2) |
| 149 | expansion)))) | 151 | expansion)))) |
| 150 | 152 | ||
| 153 | ;;;###autoload | ||
| 154 | (defmacro pcase-exhaustive (exp &rest cases) | ||
| 155 | "The exhaustive version of `pcase' (which see)." | ||
| 156 | (declare (indent 1) (debug pcase)) | ||
| 157 | (let* ((x (make-symbol "x")) | ||
| 158 | (pcase--dontwarn-upats (cons x pcase--dontwarn-upats))) | ||
| 159 | (pcase--expand | ||
| 160 | exp (append cases `((,x (error "No clause matching `%S'" ,x))))))) | ||
| 161 | |||
| 151 | (defun pcase--let* (bindings body) | 162 | (defun pcase--let* (bindings body) |
| 152 | (cond | 163 | (cond |
| 153 | ((null bindings) (macroexp-progn body)) | 164 | ((null bindings) (macroexp-progn body)) |
| @@ -280,7 +291,8 @@ of the form (UPAT EXP)." | |||
| 280 | vars)))) | 291 | vars)))) |
| 281 | cases)))) | 292 | cases)))) |
| 282 | (dolist (case cases) | 293 | (dolist (case cases) |
| 283 | (unless (or (memq case used-cases) (eq (car case) 'pcase--dontcare)) | 294 | (unless (or (memq case used-cases) |
| 295 | (memq (car case) pcase--dontwarn-upats)) | ||
| 284 | (message "Redundant pcase pattern: %S" (car case)))) | 296 | (message "Redundant pcase pattern: %S" (car case)))) |
| 285 | (macroexp-let* defs main)))) | 297 | (macroexp-let* defs main)))) |
| 286 | 298 | ||