From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#26338: 26.0.50; Collect all matches for REGEXP in current buffer Date: Sat, 08 Apr 2017 22:49:48 +0900 Message-ID: <87k26vqa9v.fsf@gmail.com> References: <8737dr6kxx.fsf@calancha-pc> <87h926cvgl.fsf@localhost> <87k272ow7g.fsf@calancha-pc> <87fuhpcbem.fsf@localhost> <87lgrheyvn.fsf@calancha-pc> <87pogsmefn.fsf@jane> <871st6342v.fsf@localhost> <87a87sqnpn.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1491659425 27427 195.159.176.226 (8 Apr 2017 13:50:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 8 Apr 2017 13:50:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: 26338@debbugs.gnu.org, Dmitry Gutov , Marcin Borkowski , Juri Linkov To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 08 15:50:20 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwqkl-00063v-Aw for geb-bug-gnu-emacs@m.gmane.org; Sat, 08 Apr 2017 15:50:11 +0200 Original-Received: from localhost ([::1]:54918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwqkr-0004vn-3c for geb-bug-gnu-emacs@m.gmane.org; Sat, 08 Apr 2017 09:50:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cwqkg-0004tA-Gq for bug-gnu-emacs@gnu.org; Sat, 08 Apr 2017 09:50:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cwqkd-0004cM-CE for bug-gnu-emacs@gnu.org; Sat, 08 Apr 2017 09:50:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cwqkd-0004cH-9T for bug-gnu-emacs@gnu.org; Sat, 08 Apr 2017 09:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cwqkd-0000eJ-1d for bug-gnu-emacs@gnu.org; Sat, 08 Apr 2017 09:50:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 08 Apr 2017 13:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26338 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 26338-submit@debbugs.gnu.org id=B26338.14916594002466 (code B ref 26338); Sat, 08 Apr 2017 13:50:02 +0000 Original-Received: (at 26338) by debbugs.gnu.org; 8 Apr 2017 13:50:00 +0000 Original-Received: from localhost ([127.0.0.1]:37288 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwqka-0000di-0i for submit@debbugs.gnu.org; Sat, 08 Apr 2017 09:50:00 -0400 Original-Received: from mail-pg0-f67.google.com ([74.125.83.67]:35804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwqkZ-0000dT-0O for 26338@debbugs.gnu.org; Sat, 08 Apr 2017 09:49:59 -0400 Original-Received: by mail-pg0-f67.google.com with SMTP id g2so20242555pge.2 for <26338@debbugs.gnu.org>; Sat, 08 Apr 2017 06:49:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=JvaWYSZs+6dYyTe13/bs05MH8dG/IG8FJjv7MDTtGzE=; b=NtgllsMUksUsbSsEYBCp27hhNL5hFyQlWtFPAQGPrJ9M8y3wBWTbeAOjBQXcKYRFWc fYH4KgtyGzkeit/V4mpEm+tQ2wy5Ez1oTWQ8X7n56ZAHLidobnckOCzSwN8wqGHGsFLb 7y0muncwzcu/bkniKYtcgUW5nEbIeaFzQb5M6ZN4b5CsxjX7yPiYjgxKx9bp9QcjPz9a 5AxKgwaINjpFOtxazsiKpT43FBMQKzDF5/lkmLQIOOrPvdXzI4nU3e60Fk5fPMGAwBgJ XCkmLZoB/7/1mKmBjUjkpLxKyveEFQlxon2KtebVHNxNE5BgNanQhgroTkshxta3ac1i 41sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=JvaWYSZs+6dYyTe13/bs05MH8dG/IG8FJjv7MDTtGzE=; b=SWoglAP9f/kN+2aYqD2qZFNZKeRPF1KpBnijn8DPhY0Icwx1dMxeJdv4tl7XyxuqpP 50Sd7pwsIJ1SbuALfOBNBD7XIQpWeblpV3KhVE88cwsz64QjYfyezs9Qu880puGviHrc CecU5YImniW/XfglFqmuKtm0XdqIaQAr/xojdz9E2ehxlYsXKp1l9SbWgr0ZGXcRXanc /8hD0jb94aWdcTs5h0Dd6rggYZlXO3Dy0szHnNT3DzF40nsqRh6RtjnBHFFHULeuel8f vQv3Pe6F7qgQfqzmkcjBj5tFRSYqoyl7B8/y/Yb38JacLkx8nWbR4YR48qcA+A4yhEsZ qz+A== X-Gm-Message-State: AFeK/H1AQNgT8TYqzoGk6DBvWIf2Uq3p0Ctmn9IN3U3VJ7W7KX/bktSJdZN0cZ7dS/EAuQ== X-Received: by 10.84.236.1 with SMTP id q1mr56274847plk.135.1491659392885; Sat, 08 Apr 2017 06:49:52 -0700 (PDT) Original-Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id c16sm15327410pfl.7.2017.04.08.06.49.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 08 Apr 2017 06:49:52 -0700 (PDT) In-Reply-To: (Noam Postavsky's message of "Fri, 7 Apr 2017 11:28:46 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131362 Archived-At: Noam Postavsky writes: > On Fri, Apr 7, 2017 at 10:47 AM, Tino Calancha wrote: >> + >> +@example >> +(cl-loop for x being the matches of "^(defun \\(\\S +\\)" >> + using '(group 1 limit 10) >> + collect x) >> +@end example > > You can reuse the existing 'repeat N' clause instead of 'using (limit N)'. > > (cl-loop for x being the matches of "^(defun \\(\\S +\\)" using (group 1) > repeat 10 > collect x) Right! Thank you. I fixed some other parts of the patch as well. --8<-----------------------------cut here---------------start------------->8--- commit fc2eed78e8c5591c3aad358a885b4b5bae6c1041 Author: Tino Calancha Date: Sat Apr 8 22:49:10 2017 +0900 New clause in cl-loop to iterate in the matches of a regexp Add new clause in cl-loop facility to loop over the matches for REGEXP in the current buffer (Bug#26338). * lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause): Add new clause. (cl-loop): update docstring. * doc/misc/cl.texi (For Clauses): Document the new clause. * etc/NEWS: Mention this change. diff --git a/doc/misc/cl.texi b/doc/misc/cl.texi index 2339d57631..40b90d6003 100644 --- a/doc/misc/cl.texi +++ b/doc/misc/cl.texi @@ -2030,6 +2030,22 @@ For Clauses This clause iterates over a sequence, with @var{var} a @code{setf}-able reference onto the elements; see @code{in-ref} above. +@item for @var{var} being the matches of @var{regexp} +This clause iterates over the matches for @var{regexp} in the current buffer. +By default, @var{var} is bound to the full match. Optionally, @var{var} +might be bound to a subpart of the match. +For example, + +@example +(cl-loop for x being the matches of "^(defun \\(\\S +\\)" using (group 1) + repeat 10 + collect x) +@end example + +@noindent +collects the next 10 function names after point. +This clause is an extension to standard Common Lisp. + @item for @var{var} being the symbols [of @var{obarray}] This clause iterates over symbols, either over all interned symbols or over all symbols in @var{obarray}. The loop is executed with @@ -2487,8 +2503,8 @@ Other Clauses This package's @code{cl-loop} macro is compatible with that of Common Lisp, except that a few features are not implemented: @code{loop-finish} and data-type specifiers. Naturally, the @code{for} clauses that -iterate over keymaps, overlays, intervals, frames, windows, and -buffers are Emacs-specific extensions. +iterate over keymaps, overlays, intervals, frames, windows, buffers, and +matches for a regexp in the current buffer are Emacs-specific extensions. @node Multiple Values @section Multiple Values diff --git a/etc/NEWS b/etc/NEWS index e351abc159..b8298bf180 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -862,6 +862,10 @@ instead of its first. * Lisp Changes in Emacs 26.1 +++ +** New clause in cl-loop to iterate in the matches for a regexp +in the current buffer. + ++++ ** Emacs now supports records for user-defined types, via the new functions 'make-record', 'record', and 'recordp'. Records are now used internally to represent cl-defstruct and defclass instances, for diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index ecb89fd51d..4710efd0a9 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -892,6 +892,7 @@ cl-loop the overlays/intervals [of BUFFER] [from POS1] [to POS2] the frames/buffers the windows [of FRAME] + the matches of/for REGEXP [using (group GROUP)] Iteration clauses: repeat INTEGER while/until/always/never/thereis CONDITION @@ -1339,6 +1340,24 @@ cl--parse-loop-clause (push (list temp-idx `(1+ ,temp-idx)) loop-for-steps))) + ((memq word '(match matches)) + (let* ((_ (or (and (not (memq (car cl--loop-args) '(of for))) + (error "Expected `of'")))) + (regexp `(if (stringp ,(cadr cl--loop-args)) + ,(cl--pop2 cl--loop-args) + (error "Regexp must be an string"))) + (group + (if (eq (car cl--loop-args) 'using) + (if (and (= (length (cadr cl--loop-args)) 2) + (eq (cl-caadr cl--loop-args) 'group)) + (cadr (cl--pop2 cl--loop-args)) + (error "Bad `using' clause")) + 0))) + (push (list var nil) loop-for-bindings) + (push `(re-search-forward ,regexp nil t) cl--loop-body) + (push (list var `(match-string-no-properties ,group)) + loop-for-sets))) + ((memq word hash-types) (or (memq (car cl--loop-args) '(in of)) (error "Expected `of'")) --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 26.0.50 (build 14, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-04-08 Repository revision: 4fbfd7ad53810153371a588a9bd1a69230f60dd5