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: Mon, 3 Apr 2017 12:58:44 +0900 (JST) Message-ID: References: <8737dr6kxx.fsf@calancha-pc> <4723d923-102a-685c-9145-7e08ca3498bb@yandex.ru> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Trace: blaine.gmane.org 1491191954 1261 195.159.176.226 (3 Apr 2017 03:59:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Apr 2017 03:59:14 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: 26338@debbugs.gnu.org, Tino Calancha , juri linkov To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 03 05:59:08 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 1cut92-0008Gt-D8 for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Apr 2017 05:59:08 +0200 Original-Received: from localhost ([::1]:57348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cut98-00080d-HF for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Apr 2017 23:59:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cut92-00080Y-NB for bug-gnu-emacs@gnu.org; Sun, 02 Apr 2017 23:59:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cut8w-0001ai-DQ for bug-gnu-emacs@gnu.org; Sun, 02 Apr 2017 23:59:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cut8w-0001aY-8k for bug-gnu-emacs@gnu.org; Sun, 02 Apr 2017 23:59:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cut8v-00014A-WD for bug-gnu-emacs@gnu.org; Sun, 02 Apr 2017 23:59:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 03 Apr 2017 03:59: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.14911919364084 (code B ref 26338); Mon, 03 Apr 2017 03:59:01 +0000 Original-Received: (at 26338) by debbugs.gnu.org; 3 Apr 2017 03:58:56 +0000 Original-Received: from localhost ([127.0.0.1]:58039 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cut8p-00013o-Rv for submit@debbugs.gnu.org; Sun, 02 Apr 2017 23:58:56 -0400 Original-Received: from mail-pg0-f68.google.com ([74.125.83.68]:34968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cut8n-00013a-Il for 26338@debbugs.gnu.org; Sun, 02 Apr 2017 23:58:54 -0400 Original-Received: by mail-pg0-f68.google.com with SMTP id g2so26792044pge.2 for <26338@debbugs.gnu.org>; Sun, 02 Apr 2017 20:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=7xdEF5m3JbzWMMx8GzNhWNOCOZOG7mI7RdB6gB3Ex8w=; b=kLVS4YzuTwrcGNUb+tieOk3gu6ZJ+byWUPlXIhjTsIv989cUv/38U82fSKfTi1p6Jr qkC5zKy6l1NksXoZN0JMS+lMvhcEY+X1yCvIGVzCRlNG1wlnuJEt6NREKAtiRtBKdzkS rIoP0CjWd9ipaoOxl9C60GL+cyB33J+PzqktRQk/bn8IexNEUTovkqVnlDxD86uuz0+o CpUszWuxN8wcATuKiVAKqwIj6Lb3ZuC/HhMAYEUWzongEK7hRsg2WQQ5hU1lufbAJSvj 6c1MIScWWTxfI9huVFo/2917KUyGfG+ofqrkW1FdVH0o2P7XfWOwq3NjnhMNioILUR1W p8SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=7xdEF5m3JbzWMMx8GzNhWNOCOZOG7mI7RdB6gB3Ex8w=; b=YBs1gG5xdk4y9SUSgsKbLrtwohZ8BbzRMMuYEnYrx4TgncwCwWdk2Ug6ebaxMscWPq bjHCRubUl7yUSvrJl0nxT/x1FIDRnZkpezhVSa66/mPgzF/PfEcbaic65i6JTYLq/dp7 Qp4xQJ0DiX6WLnSdEP5XREAUyTiQnWGWCOZZbVaK5Kg9WWD4AVN750rvyhHdANHP4ule UZOu3kJ7kQcpoFZQEiObFytn2aTzY8ofMIp4dRpIasTxzpq74s4thGjRqTN6k93PCRGv LZ4Ahc7VfoxGoyRNfFY7Ttsd8+hU8fHanMR8izMVQXR951JV7e7btJyDM3T8nykOyXlA 0vCw== X-Gm-Message-State: AFeK/H3/fjj35eWP8iBW4zLpB8seRrcz9LhuGByXpBxXpynFLt3xfVWoofdUBj3He8sX8Q== X-Received: by 10.84.194.1 with SMTP id g1mr19239774pld.98.1491191927797; Sun, 02 Apr 2017 20:58:47 -0700 (PDT) Original-Received: from calancha-pc (234.204.100.220.dy.bbexcite.jp. [220.100.204.234]) by smtp.gmail.com with ESMTPSA id x21sm22560765pgf.15.2017.04.02.20.58.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Apr 2017 20:58:47 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: <4723d923-102a-685c-9145-7e08ca3498bb@yandex.ru> 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:131237 Archived-At: On Sun, 2 Apr 2017, Dmitry Gutov wrote: > On 02.04.2017 15:41, Tino Calancha wrote: > >> we have `count-matches' in replace.el, which returns the >> number of matches of a regexp. Why not to have an standard >> function `collect-matches' as well? >> >> I know `xref-collect-matches' but it uses grep program: some users might >> not have grep installed, or they may prefer to use Emacs regexps. >> >> I've being using for a while something similar than the patch below. >> Probably it doesn't need to be a command, just a normal function. >> >> What do you think? > When used interactively, isn't M-x occur doing something like this? > > And for Elisp programs, (while (re-search-forward ...)) is usually > sufficient. That's a three-liner at worst. It might be argue the same for occur. You can just increase a counter inside (while (re-search-forward ...)) > And I've never had a need to limit the number of matches, personally. I did often while implementing Bug#25493. Let's say i am interested in the last 200 commits modifying a file foo.el. M-x: find-library foo RET C-x v l M-: (setq hashes (collect-matches "^commit \\([[:xdigit:]]+\\)" nil 1 200)) In this case, there is no need to go beyond 200 that's why the limit argument might be useful. Another example, let's say i want to know the two first defun's in subr.el M-x: find-library subr RET M-: (collect-matches "^(defun \\([^[:blank:]]+\\)" nil 1 2) RET Of course you could do: M-: (seq-take (collect-matches "^(defun \\([^[:blank:]]+\\)" nil 1) 2) RET ;; But if you just want the 2 leading defun's this is a waste.