From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tak Ota Newsgroups: gmane.emacs.devel Subject: Re: simple useful functions Date: Tue, 2 Nov 2010 17:38:45 -0700 Message-ID: <20101102.173845.392894510.Takaaki.Ota@am.sony.com> References: <20101029.111346.113803171.Takaaki.Ota@am.sony.com> <20101101.174010.322416312.Takaaki.Ota@am.sony.com> <87fwvkjwh8.fsf@uwakimon.sk.tsukuba.ac.jp> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1288744746 6847 80.91.229.12 (3 Nov 2010 00:39:06 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 3 Nov 2010 00:39:06 +0000 (UTC) Cc: emacs-devel@gnu.org To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 03 01:39:02 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PDRNV-0003gB-PV for ged-emacs-devel@m.gmane.org; Wed, 03 Nov 2010 01:39:02 +0100 Original-Received: from localhost ([127.0.0.1]:50529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDRNV-0002xI-28 for ged-emacs-devel@m.gmane.org; Tue, 02 Nov 2010 20:39:01 -0400 Original-Received: from [140.186.70.92] (port=56648 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDRNO-0002xD-W9 for emacs-devel@gnu.org; Tue, 02 Nov 2010 20:38:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDRNM-0004uL-HE for emacs-devel@gnu.org; Tue, 02 Nov 2010 20:38:54 -0400 Original-Received: from db3ehsobe004.messaging.microsoft.com ([213.199.154.142]:54966 helo=DB3EHSOBE004.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDRNM-0004u3-7p for emacs-devel@gnu.org; Tue, 02 Nov 2010 20:38:52 -0400 Original-Received: from mail28-db3-R.bigfish.com (10.3.81.247) by DB3EHSOBE004.bigfish.com (10.3.84.24) with Microsoft SMTP Server id 14.1.225.8; Wed, 3 Nov 2010 00:38:50 +0000 Original-Received: from mail28-db3 (localhost.localdomain [127.0.0.1]) by mail28-db3-R.bigfish.com (Postfix) with ESMTP id 517846B028C; Wed, 3 Nov 2010 00:38:50 +0000 (UTC) X-SpamScore: -12 X-BigFish: VPS-12(zz1432N98dNzz1202hzzz2fh2a8h61h) Original-Received: from mail28-db3 (localhost.localdomain [127.0.0.1]) by mail28-db3 (MessageSwitch) id 1288744729889202_20888; Wed, 3 Nov 2010 00:38:49 +0000 (UTC) Original-Received: from DB3EHSMHS006.bigfish.com (unknown [10.3.81.247]) by mail28-db3.bigfish.com (Postfix) with ESMTP id D6BA416F0046; Wed, 3 Nov 2010 00:38:49 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by DB3EHSMHS006.bigfish.com (10.3.87.106) with Microsoft SMTP Server (TLS) id 14.0.482.44; Wed, 3 Nov 2010 00:38:49 +0000 Original-Received: from mail1x.bc.in.sel.sony.com ([43.144.65.112]) by mail7.fw-bc.sony.com (Switch-3.4.2/Switch-3.3.2mp) with ESMTP id oA30clfB029944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 3 Nov 2010 00:38:48 GMT Original-Received: from localhost (tak-vaio-z790-043191018003.am.sony.com [43.191.18.3]) by mail1x.bc.in.sel.sony.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id oA30clJd028665; Wed, 3 Nov 2010 00:38:47 GMT In-Reply-To: <87fwvkjwh8.fsf@uwakimon.sk.tsukuba.ac.jp> X-Mailer: Mew-6.3.50 on Emacs-23.2.1 (i386-mingw-nt6.1.7600 built on 2010-06-30) X-Reverse-DNS: mail7.fw-bc.sony.com X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP2+, XP SP1+ (seldom 98) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:132304 Archived-At: Don't you like the simplicity? How about simply adding collect-string to replace.el instead of trying to associate it with occur in a clumsy way? -Tak Mon, 1 Nov 2010 19:22:11 -0700: "Stephen J. Turnbull" wrote: > Tak Ota writes: > > Could you teach me how to perform collect-string equivalent operation > > with occur mode? > > I don't know if you can, maybe there's something in Emacs's version of > `occur' that would allow it. I didn't understand your requirements, > that's why I asked. > > Rather than a separate function, I think it would be useful to augment > occur-mode here, by saving the occur regexp (say to occur-mode-regexp) > and adding the following command to occur mode (untested): > > (defun occur-mode-matchers-only () > "Leave only text that matches the first group in the occur regexp. > If there is no group, use the whole match. > With more than one group, you should use shy groups for the others. > Be careful with repeated groups; only one of them will be left." > (interactive) > (save-excursion > (toggle-read-only -1) > (goto-char (point-min)) > (save-match-data > ;; don't look at this code lest you be turned to stone, bletch > (re-search-forward occur-mode-regexp nil t) > (let* ((group (if (match-end 1) 1 0)) > (previous-end (progn (goto-char (match-end group)) > (point-marker))) > temp) > (delete-region (point-min) (match-beginning group)) > (while (re-search-forward occur-mode-regexp nil t) > (setq temp (progn (goto-char (match-end group)) (point-marker))) > (delete-region previous-end (match-beginning group)) > (goto-char previous-end) > (insert ?\n) > (setq previous-end temp)) > (delete-region previous-end (point-max)) > (insert ?\n) > (goto-char (point-max)) > (insert ?\n) > (toggle-read-only 1))))) >