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: Tue, 04 Apr 2017 11:20:18 +0900 Message-ID: <878tng9an1.fsf@calancha-pc> References: <8737dr6kxx.fsf@calancha-pc> <87h926cvgl.fsf@localhost> <87k272ow7g.fsf@calancha-pc> <87fuhpcbem.fsf@localhost> <87lgrheyvn.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1491272478 3520 195.159.176.226 (4 Apr 2017 02:21:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Apr 2017 02:21:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 26338@debbugs.gnu.org, tino.calancha@gmail.com To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 04 04:21:14 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 1cvE5j-0008Ks-G0 for geb-bug-gnu-emacs@m.gmane.org; Tue, 04 Apr 2017 04:21:07 +0200 Original-Received: from localhost ([::1]:33673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvE5p-0006mO-BY for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Apr 2017 22:21:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvE5h-0006lK-U4 for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2017 22:21:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvE5e-0004RY-Ax for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2017 22:21:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33265) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cvE5e-0004RE-6l for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2017 22:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cvE5d-0003Eu-VG for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2017 22:21:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 04 Apr 2017 02:21:01 +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.149127243312397 (code B ref 26338); Tue, 04 Apr 2017 02:21:01 +0000 Original-Received: (at 26338) by debbugs.gnu.org; 4 Apr 2017 02:20:33 +0000 Original-Received: from localhost ([127.0.0.1]:59697 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvE59-0003Ds-Fn for submit@debbugs.gnu.org; Mon, 03 Apr 2017 22:20:33 -0400 Original-Received: from mail-pg0-f43.google.com ([74.125.83.43]:33294) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvE56-0003Df-Tw for 26338@debbugs.gnu.org; Mon, 03 Apr 2017 22:20:29 -0400 Original-Received: by mail-pg0-f43.google.com with SMTP id x125so137644179pgb.0 for <26338@debbugs.gnu.org>; Mon, 03 Apr 2017 19:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-transfer-encoding; bh=MgLmTOSvzjjgimUbgM+J5I3gVIYUj/DUVTun6D8wz1M=; b=WYSEdx8svZOncP8q6eEIcUi0BvvEDfxfB9HU0IkDcMb6hJpoaxMa318qtQhuBEQvaW wedamJse44d3MLiARRW29XpmiWqN1jYuuGobT7M7Yfps95UtSfByq9DlKhZxjvXPIdBv mSAbcbgqnIMJyz4ujwxFl8tyPJnet56K/sbP0hWc1No5YrXzqGHQRVpjJo5i9pugeiAm 6TNBOGZNFbE1Z8xVnXDs8uZ1B0UjsAp6Wage9JR9UGDIX+le+WkpyfIUrnkNzlVjfYtH qawmZkEbbuYhfaqX8b/1MdhnfTFg1cOGQyvt5KHi/BkFySy1g1pgU0ucQpjW/RDYBbft MAog== 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:in-reply-to:references :user-agent:date:message-id:mime-version:content-transfer-encoding; bh=MgLmTOSvzjjgimUbgM+J5I3gVIYUj/DUVTun6D8wz1M=; b=FMOlcwOWW5aW/8/nWv8fAehFJo/sAhqfnDjKtkQ1Yu3Y5e8ykw4aIqIUwZdZeHjoVk Ebo2PUrKUhNPOSuKBMfg/bFOZZByf2o5F62T6PXFYzgLPT9YuCPVh4wdqJnkpAVmRlmG FS4HpVz0N+Hf6b82tCCLg5tJNGg752ZBAFlaqdQI11wYOTf1ftT8y+OORwXhNPC12cVD KROJ4+hKcjkXDWAd7tJRRKU2rYMlfnS28LepXrfPPGRsDrJcqLisaDR2z5cmVtVBJRs8 i5CPLmMRwsi7fW6fDWqw1tSoFyKMe8z9nD9t9pPJ21cTeBMz0ZNWcX1/JPbmgoi+lByq p4Fw== X-Gm-Message-State: AFeK/H27IP5Mx3aRjvqyP/IwLS5vVR2JHvVQoPMkdfbEo5L+YWlRfz0wvYXucJmCwo5yYA== X-Received: by 10.99.155.17 with SMTP id r17mr20979215pgd.193.1491272423170; Mon, 03 Apr 2017 19:20:23 -0700 (PDT) Original-Received: from calancha-pc (MAR89-178.kek.jp. [130.87.89.178]) by smtp.gmail.com with ESMTPSA id i3sm28135012pfk.47.2017.04.03.19.20.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Apr 2017 19:20:22 -0700 (PDT) In-Reply-To: <87lgrheyvn.fsf@calancha-pc> (Tino Calancha's message of "Tue, 04 Apr 2017 10:37:48 +0900") 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:131260 Archived-At: Tino Calancha writes: > Juri Linkov writes: >> occur-collect is intended for interactive use. As for programmatic use, >> Dmitry is right: a universal idiom is (while (re-search-forward ...)). >> This is why e.g. the docstring of =E2=80=98replace-regexp=E2=80=99 recom= mends to use >> an explicit loop like (while (re-search-forward ...) (replace-match ...)) > OK thanks. Let me ask you my last proposal before come back to my dark > cave and start painting animals in the walls. > > Any interest in something like this?: > > (defmacro with-collect-matches (regexp &optional group &rest body) > "Collect matches for REGEXP and eval BODY for each match. > BODY is evaluated with `it' bound to the match. > Optional GROUP if non-nil, then is the regexp group to save. Otherwise, > save the whole match." Sorry, i was paiting a mammoth and i forgot something in the docstring: --8<-----------------------------cut here---------------start------------->= 8--- (defmacro with-collect-matches (regexp &optional group &rest body) "Collect matches for REGEXP and eval BODY for each match. BODY is evaluated with `it' bound to the match. Optional GROUP if non-nil, then is the regexp group to save. Otherwise, save the whole match. Return a list with the matches." --8<-----------------------------cut here---------------end---------------= >8--- So, for instance: M-x find-library replace RET M-: (length (with-collect-matches "^(defun \\(\\S +\\)" 1)) RET =3D> 52 M-x find-library replace RET M-: (length (with-collect-matches "^(defun \\(\\S +\\)" 1 (with-current-buffer (get-buffer-create "*Matches*") (when (string-match "\\`query-" it) (insert (format "%s\n" it))))) =3D> 52 ;; Same return as before but only write into *Matches* those ;; functions with name starting with "query-".