diff options
| author | Chong Yidong | 2011-06-18 17:12:33 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-06-18 17:12:33 -0400 |
| commit | 6420d28b9ab9c09b69992e05e0e63c3bbaf2646d (patch) | |
| tree | 876b0670dd1be06ea5de6151aacdef1b23d58a6c | |
| parent | ddb8b596be2a92a499310002e9f28abef012bfc2 (diff) | |
| download | emacs-6420d28b9ab9c09b69992e05e0e63c3bbaf2646d.tar.gz emacs-6420d28b9ab9c09b69992e05e0e63c3bbaf2646d.zip | |
Add rx.el support for numbered groups (Bug#8776).
* lisp/emacs-lisp/rx.el (rx-constituents): Add support for numbered groups.
(rx-submatch-n): New function.
(rx): Document it.
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/emacs-lisp/rx.el | 17 |
3 files changed, 25 insertions, 0 deletions
| @@ -1051,6 +1051,9 @@ deferring warnings until the main command loop is executed. | |||
| 1051 | ** `set-auto-mode' now respects mode: local variables at the end of files, | 1051 | ** `set-auto-mode' now respects mode: local variables at the end of files, |
| 1052 | as well as those in the -*- line. | 1052 | as well as those in the -*- line. |
| 1053 | 1053 | ||
| 1054 | --- | ||
| 1055 | ** rx.el has a new `group-n' construct for explicitly numbered groups. | ||
| 1056 | |||
| 1054 | 1057 | ||
| 1055 | * Changes in Emacs 24.1 on non-free operating systems | 1058 | * Changes in Emacs 24.1 on non-free operating systems |
| 1056 | 1059 | ||
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1d66ebe8039..e1a23e53649 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2011-06-18 Chong Yidong <cyd@stupidchicken.com> | 1 | 2011-06-18 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 2 | ||
| 3 | * emacs-lisp/rx.el (rx-constituents): Add support for numbered | ||
| 4 | groups (Bug#8776). | ||
| 5 | (rx-submatch-n): New function. | ||
| 6 | (rx): Document it. | ||
| 7 | |||
| 3 | * dired-x.el (dired-mark-unmarked-files): Fix interactive spec | 8 | * dired-x.el (dired-mark-unmarked-files): Fix interactive spec |
| 4 | (Bug#8768). | 9 | (Bug#8768). |
| 5 | 10 | ||
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 7122de4789c..56efd142198 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el | |||
| @@ -130,6 +130,8 @@ | |||
| 130 | (** . (rx-** 2 nil)) ; SRE | 130 | (** . (rx-** 2 nil)) ; SRE |
| 131 | (submatch . (rx-submatch 1 nil)) ; SRE | 131 | (submatch . (rx-submatch 1 nil)) ; SRE |
| 132 | (group . submatch) ; sregex | 132 | (group . submatch) ; sregex |
| 133 | (submatch-n . (rx-submatch-n 2 nil)) | ||
| 134 | (group-n . submatch-n) | ||
| 133 | (zero-or-more . (rx-kleene 1 nil)) | 135 | (zero-or-more . (rx-kleene 1 nil)) |
| 134 | (one-or-more . (rx-kleene 1 nil)) | 136 | (one-or-more . (rx-kleene 1 nil)) |
| 135 | (zero-or-one . (rx-kleene 1 nil)) | 137 | (zero-or-one . (rx-kleene 1 nil)) |
| @@ -690,6 +692,16 @@ FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'." | |||
| 690 | (mapconcat (lambda (re) (rx-form re ':)) (cdr form) nil)) | 692 | (mapconcat (lambda (re) (rx-form re ':)) (cdr form) nil)) |
| 691 | "\\)")) | 693 | "\\)")) |
| 692 | 694 | ||
| 695 | (defun rx-submatch-n (form) | ||
| 696 | "Parse and produce code from FORM, which is `(submatch-n N ...)'." | ||
| 697 | (let ((n (nth 1 form))) | ||
| 698 | (concat "\\(?" (number-to-string n) ":" | ||
| 699 | (if (= 3 (length form)) | ||
| 700 | ;; Only one sub-form. | ||
| 701 | (rx-form (nth 2 form)) | ||
| 702 | ;; Several sub-forms implicitly concatenated. | ||
| 703 | (mapconcat (lambda (re) (rx-form re ':)) (cddr form) nil)) | ||
| 704 | "\\)"))) | ||
| 693 | 705 | ||
| 694 | (defun rx-backref (form) | 706 | (defun rx-backref (form) |
| 695 | "Parse and produce code from FORM, which is `(backref N)'." | 707 | "Parse and produce code from FORM, which is `(backref N)'." |
| @@ -1072,6 +1084,11 @@ CHAR | |||
| 1072 | like `and', but makes the match accessible with `match-end', | 1084 | like `and', but makes the match accessible with `match-end', |
| 1073 | `match-beginning', and `match-string'. | 1085 | `match-beginning', and `match-string'. |
| 1074 | 1086 | ||
| 1087 | `(submatch-n N SEXP1 SEXP2 ...)' | ||
| 1088 | `(group-n N SEXP1 SEXP2 ...)' | ||
| 1089 | like `group', but make it an explicitly-numbered group with | ||
| 1090 | group number N. | ||
| 1091 | |||
| 1075 | `(or SEXP1 SEXP2 ...)' | 1092 | `(or SEXP1 SEXP2 ...)' |
| 1076 | `(| SEXP1 SEXP2 ...)' | 1093 | `(| SEXP1 SEXP2 ...)' |
| 1077 | matches anything that matches SEXP1 or SEXP2, etc. If all | 1094 | matches anything that matches SEXP1 or SEXP2, etc. If all |