diff options
| author | Stefan Monnier | 2012-07-10 05:26:04 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-07-10 05:26:04 -0400 |
| commit | 19faa8e8535ff2c23aa122025145e2d159c0aa77 (patch) | |
| tree | d21440d5261a2de03433008a07d6dbb5377824aa | |
| parent | 2a0213a6d0a9e36a388994445837e051d0bbe5f9 (diff) | |
| download | emacs-19faa8e8535ff2c23aa122025145e2d159c0aa77.tar.gz emacs-19faa8e8535ff2c23aa122025145e2d159c0aa77.zip | |
* lisp/emacs-lisp/pcase.el (pcase): Accept self-quoting exps as "upatterns".
(pcase--self-quoting-p): New function.
(pcase--u1): Use it.
| -rw-r--r-- | lisp/ChangeLog | 18 | ||||
| -rw-r--r-- | lisp/emacs-lisp/pcase.el | 19 |
2 files changed, 26 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3fd8534d6a0..dbe46c66d50 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2012-07-10 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * emacs-lisp/pcase.el (pcase): Accept self-quoting exps as "upatterns". | ||
| 4 | (pcase--self-quoting-p): New function. | ||
| 5 | (pcase--u1): Use it. | ||
| 6 | |||
| 1 | 2012-07-10 Glenn Morris <rgm@gnu.org> | 7 | 2012-07-10 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * emacs-lisp/authors.el (authors-fixed-entries): | 9 | * emacs-lisp/authors.el (authors-fixed-entries): |
| @@ -31,8 +37,8 @@ | |||
| 31 | 2012-07-07 Chong Yidong <cyd@gnu.org> | 37 | 2012-07-07 Chong Yidong <cyd@gnu.org> |
| 32 | 38 | ||
| 33 | * simple.el (yank-pop-change-selection): Doc fix (Bug#11361). | 39 | * simple.el (yank-pop-change-selection): Doc fix (Bug#11361). |
| 34 | (interprogram-cut-function, interprogram-paste-function): Mention | 40 | (interprogram-cut-function, interprogram-paste-function): |
| 35 | that we typically mean the clipboard. | 41 | Mention that we typically mean the clipboard. |
| 36 | 42 | ||
| 37 | 2012-07-06 Glenn Morris <rgm@gnu.org> | 43 | 2012-07-06 Glenn Morris <rgm@gnu.org> |
| 38 | 44 | ||
| @@ -71,8 +77,8 @@ | |||
| 71 | 77 | ||
| 72 | 2012-07-06 Andreas Schwab <schwab@linux-m68k.org> | 78 | 2012-07-06 Andreas Schwab <schwab@linux-m68k.org> |
| 73 | 79 | ||
| 74 | * calendar/cal-dst.el (calendar-current-time-zone): Return | 80 | * calendar/cal-dst.el (calendar-current-time-zone): |
| 75 | calendar-current-time-zone-cache if non-nil. | 81 | Return calendar-current-time-zone-cache if non-nil. |
| 76 | 82 | ||
| 77 | 2012-07-06 Glenn Morris <rgm@gnu.org> | 83 | 2012-07-06 Glenn Morris <rgm@gnu.org> |
| 78 | 84 | ||
| @@ -85,8 +91,8 @@ | |||
| 85 | * net/tramp.el (tramp-drop-volume-letter): Provide an XEmacs | 91 | * net/tramp.el (tramp-drop-volume-letter): Provide an XEmacs |
| 86 | compatible declaration. | 92 | compatible declaration. |
| 87 | 93 | ||
| 88 | * net/tramp-cmds.el (tramp-append-tramp-buffers): Protect | 94 | * net/tramp-cmds.el (tramp-append-tramp-buffers): |
| 89 | `list-load-path-shadows' call. | 95 | Protect `list-load-path-shadows' call. |
| 90 | 96 | ||
| 91 | * net/tramp-compat.el (top): Require packages, which aren't | 97 | * net/tramp-compat.el (top): Require packages, which aren't |
| 92 | autoloaded anymore for XEmacs. Protect call of | 98 | autoloaded anymore for XEmacs. Protect call of |
diff --git a/lisp/emacs-lisp/pcase.el b/lisp/emacs-lisp/pcase.el index 529c5ebdb67..59dccb35952 100644 --- a/lisp/emacs-lisp/pcase.el +++ b/lisp/emacs-lisp/pcase.el | |||
| @@ -94,6 +94,7 @@ CASES is a list of elements of the form (UPATTERN CODE...). | |||
| 94 | 94 | ||
| 95 | UPatterns can take the following forms: | 95 | UPatterns can take the following forms: |
| 96 | _ matches anything. | 96 | _ matches anything. |
| 97 | SELFQUOTING matches itself. This includes keywords, numbers, and strings. | ||
| 97 | SYMBOL matches anything and binds it to SYMBOL. | 98 | SYMBOL matches anything and binds it to SYMBOL. |
| 98 | (or UPAT...) matches if any of the patterns matches. | 99 | (or UPAT...) matches if any of the patterns matches. |
| 99 | (and UPAT...) matches if all the patterns match. | 100 | (and UPAT...) matches if all the patterns match. |
| @@ -509,6 +510,9 @@ MATCH is the pattern that needs to be matched, of the form: | |||
| 509 | (and (memq sexp vars) (not (memq sexp res)) (push sexp res)) | 510 | (and (memq sexp vars) (not (memq sexp res)) (push sexp res)) |
| 510 | res)) | 511 | res)) |
| 511 | 512 | ||
| 513 | (defun pcase--self-quoting-p (upat) | ||
| 514 | (or (keywordp upat) (numberp upat) (stringp upat))) | ||
| 515 | |||
| 512 | ;; It's very tempting to use `pcase' below, tho obviously, it'd create | 516 | ;; It's very tempting to use `pcase' below, tho obviously, it'd create |
| 513 | ;; bootstrapping problems. | 517 | ;; bootstrapping problems. |
| 514 | (defun pcase--u1 (matches code vars rest) | 518 | (defun pcase--u1 (matches code vars rest) |
| @@ -605,6 +609,9 @@ Otherwise, it defers to REST which is a list of branches of the form | |||
| 605 | `(let* ,env ,call)))) | 609 | `(let* ,env ,call)))) |
| 606 | (pcase--u1 matches code vars then-rest) | 610 | (pcase--u1 matches code vars then-rest) |
| 607 | (pcase--u else-rest)))) | 611 | (pcase--u else-rest)))) |
| 612 | ((pcase--self-quoting-p upat) | ||
| 613 | (put sym 'pcase-used t) | ||
| 614 | (pcase--q1 sym upat matches code vars rest)) | ||
| 608 | ((symbolp upat) | 615 | ((symbolp upat) |
| 609 | (put sym 'pcase-used t) | 616 | (put sym 'pcase-used t) |
| 610 | (if (not (assq upat vars)) | 617 | (if (not (assq upat vars)) |
| @@ -636,14 +643,16 @@ Otherwise, it defers to REST which is a list of branches of the form | |||
| 636 | (memq-fine t)) | 643 | (memq-fine t)) |
| 637 | (when all | 644 | (when all |
| 638 | (dolist (alt (cdr upat)) | 645 | (dolist (alt (cdr upat)) |
| 639 | (unless (and (eq (car-safe alt) '\`) | 646 | (unless (or (pcase--self-quoting-p alt) |
| 640 | (or (symbolp (cadr alt)) (integerp (cadr alt)) | 647 | (and (eq (car-safe alt) '\`) |
| 641 | (setq memq-fine nil) | 648 | (or (symbolp (cadr alt)) (integerp (cadr alt)) |
| 642 | (stringp (cadr alt)))) | 649 | (setq memq-fine nil) |
| 650 | (stringp (cadr alt))))) | ||
| 643 | (setq all nil)))) | 651 | (setq all nil)))) |
| 644 | (if all | 652 | (if all |
| 645 | ;; Use memq for (or `a `b `c `d) rather than a big tree. | 653 | ;; Use memq for (or `a `b `c `d) rather than a big tree. |
| 646 | (let* ((elems (mapcar 'cadr (cdr upat))) | 654 | (let* ((elems (mapcar (lambda (x) (if (consp x) (cadr x) x)) |
| 655 | (cdr upat))) | ||
| 647 | (splitrest | 656 | (splitrest |
| 648 | (pcase--split-rest | 657 | (pcase--split-rest |
| 649 | sym (lambda (pat) (pcase--split-member elems pat)) rest)) | 658 | sym (lambda (pat) (pcase--split-member elems pat)) rest)) |