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: collect-string Date: Mon, 29 Nov 2010 18:14:53 -0800 Message-ID: <20101129.181453.300448974.Takaaki.Ota@am.sony.com> References: <20101104.113654.332196908.Takaaki.Ota@am.sony.com> <20101109.181250.505612453.Takaaki.Ota@am.sony.com> 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 1291083322 24670 80.91.229.12 (30 Nov 2010 02:15:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 30 Nov 2010 02:15:22 +0000 (UTC) Cc: stephen@xemacs.org, emacs-devel@gnu.org To: Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 30 03:15:17 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 1PNFkQ-0005wM-QP for ged-emacs-devel@m.gmane.org; Tue, 30 Nov 2010 03:15:17 +0100 Original-Received: from localhost ([127.0.0.1]:36781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNFkQ-0000ts-21 for ged-emacs-devel@m.gmane.org; Mon, 29 Nov 2010 21:15:14 -0500 Original-Received: from [140.186.70.92] (port=33201 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNFkG-0000nn-2x for emacs-devel@gnu.org; Mon, 29 Nov 2010 21:15:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNFkE-0000P7-IJ for emacs-devel@gnu.org; Mon, 29 Nov 2010 21:15:04 -0500 Original-Received: from am1ehsobe003.messaging.microsoft.com ([213.199.154.206]:34594 helo=AM1EHSOBE003.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNFkE-0000Od-26 for emacs-devel@gnu.org; Mon, 29 Nov 2010 21:15:02 -0500 Original-Received: from mail7-am1-R.bigfish.com (10.3.201.240) by AM1EHSOBE003.bigfish.com (10.3.204.23) with Microsoft SMTP Server id 14.1.225.8; Tue, 30 Nov 2010 02:15:00 +0000 Original-Received: from mail7-am1 (localhost.localdomain [127.0.0.1]) by mail7-am1-R.bigfish.com (Postfix) with ESMTP id 0A7CD7402D6; Tue, 30 Nov 2010 02:15:00 +0000 (UTC) X-SpamScore: -12 X-BigFish: VPS-12(zz1432N98dNzz1202hzz8275bhz2fh2a8h691h668h67dh61h) X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:mail7.fw-bc.sony.com; RD:mail7.fw-bc.sony.com; EFVD:NLI Original-Received: from mail7-am1 (localhost.localdomain [127.0.0.1]) by mail7-am1 (MessageSwitch) id 1291083298789450_31127; Tue, 30 Nov 2010 02:14:58 +0000 (UTC) Original-Received: from AM1EHSMHS004.bigfish.com (unknown [10.3.201.252]) by mail7-am1.bigfish.com (Postfix) with ESMTP id B9BB853004F; Tue, 30 Nov 2010 02:14:58 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by AM1EHSMHS004.bigfish.com (10.3.207.104) with Microsoft SMTP Server (TLS) id 14.1.225.8; Tue, 30 Nov 2010 02:14:57 +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 oAU2Etxi003193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Tue, 30 Nov 2010 02:14:55 GMT Original-Received: from localhost (us0013a98d05a1.am.sony.com [43.191.17.95] (may be forged)) by mail1x.bc.in.sel.sony.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id oAU2EsRD008084; Tue, 30 Nov 2010 02:14:54 GMT In-Reply-To: <20101109.181250.505612453.Takaaki.Ota@am.sony.com> X-Mailer: Mew-6.3.50 on Emacs-23.2.90.1 (i386-mingw-nt6.1.7600 built on 2010-11-22) X-OriginatorOrg: am.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:133247 Archived-At: Please somebody comment on this. -Tak Tue, 09 Nov 2010 18:12:50 -0800: Tak Ota wrote: > Mon, 8 Nov 2010 10:36:08 -0800: Stefan Monnier wrote: > > > > Now I am convinced. How about the change below? > > > > Could you send it as a context patch? > > > How about this? > > -Tak > > > *** replace.el.orig Tue Nov 9 11:41:08 2010 > --- replace.el Tue Nov 9 18:09:30 2010 > *************** > *** 527,532 **** > --- 527,535 ---- > Maximum length of the history list is determined by the value > of `history-length', which see.") > > + (defvar last-collect-number 0 > + "The last parenthesized expression number.") > + > (defun read-regexp (prompt &optional default-value) > "Read regexp as a string using the regexp history and some useful defaults. > Prompt for a regular expression with PROMPT (without a colon and > *************** > *** 1031,1037 **** > (list (read-regexp "List lines matching regexp" > (car regexp-history)) > (when current-prefix-arg > ! (prefix-numeric-value current-prefix-arg)))) > > (defun occur-rename-buffer (&optional unique-p interactive-p) > "Rename the current *Occur* buffer to *Occur: original-buffer-name*. > --- 1034,1044 ---- > (list (read-regexp "List lines matching regexp" > (car regexp-history)) > (when current-prefix-arg > ! (prefix-numeric-value current-prefix-arg)) > ! (and current-prefix-arg > ! (listp current-prefix-arg) > ! (setq last-collect-number > ! (read-number "Collect" last-collect-number))))) > > (defun occur-rename-buffer (&optional unique-p interactive-p) > "Rename the current *Occur* buffer to *Occur: original-buffer-name*. > *************** > *** 1050,1056 **** > "*") > (or unique-p (not interactive-p))))) > > ! (defun occur (regexp &optional nlines) > "Show all lines in the current buffer containing a match for REGEXP. > This function can not handle matches that span more than one line. > > --- 1057,1063 ---- > "*") > (or unique-p (not interactive-p))))) > > ! (defun occur (regexp &optional nlines collect) > "Show all lines in the current buffer containing a match for REGEXP. > This function can not handle matches that span more than one line. > > *************** > *** 1064,1074 **** > \\\\[describe-mode] in that buffer will explain how. > > If REGEXP contains upper case characters (excluding those preceded by `\\') > ! and `search-upper-case' is non-nil, the matching is case-sensitive." > (interactive (occur-read-primary-args)) > ! (occur-1 regexp nlines (list (current-buffer)))) > > ! (defun multi-occur (bufs regexp &optional nlines) > "Show all lines in buffers BUFS containing a match for REGEXP. > This function acts on multiple buffers; otherwise, it is exactly like > `occur'. When you invoke this command interactively, you must specify > --- 1071,1087 ---- > \\\\[describe-mode] in that buffer will explain how. > > If REGEXP contains upper case characters (excluding those preceded by `\\') > ! and `search-upper-case' is non-nil, the matching is case-sensitive. > ! > ! When prefix argument is provided without a number (`C-u' alone as > ! prefix) the matching strings are collected into the `*Occur*' > ! buffer. When COLLECT is zero the entire matched strings are > ! collected otherwise COLLECTth pair of parenthesized match in the > ! REGEXP is collected." > (interactive (occur-read-primary-args)) > ! (occur-1 regexp nlines (list (current-buffer)) nil collect)) > > ! (defun multi-occur (bufs regexp &optional nlines collect) > "Show all lines in buffers BUFS containing a match for REGEXP. > This function acts on multiple buffers; otherwise, it is exactly like > `occur'. When you invoke this command interactively, you must specify > *************** > *** 1090,1098 **** > (setq ido-ignore-item-temp-list bufs)) > (nreverse (mapcar #'get-buffer bufs))) > (occur-read-primary-args))) > ! (occur-1 regexp nlines bufs)) > > ! (defun multi-occur-in-matching-buffers (bufregexp regexp &optional allbufs) > "Show all lines matching REGEXP in buffers specified by BUFREGEXP. > Normally BUFREGEXP matches against each buffer's visited file name, > but if you specify a prefix argument, it matches against the buffer name. > --- 1103,1111 ---- > (setq ido-ignore-item-temp-list bufs)) > (nreverse (mapcar #'get-buffer bufs))) > (occur-read-primary-args))) > ! (occur-1 regexp nlines bufs nil collect)) > > ! (defun multi-occur-in-matching-buffers (bufregexp regexp &optional allbufs collect) > "Show all lines matching REGEXP in buffers specified by BUFREGEXP. > Normally BUFREGEXP matches against each buffer's visited file name, > but if you specify a prefix argument, it matches against the buffer name. > *************** > *** 1124,1132 **** > (string-match bufregexp > (buffer-file-name buf)))) > buf)) > ! (buffer-list)))))) > > ! (defun occur-1 (regexp nlines bufs &optional buf-name) > (unless (and regexp (not (equal regexp ""))) > (error "Occur doesn't work with the empty regexp")) > (unless buf-name > --- 1137,1146 ---- > (string-match bufregexp > (buffer-file-name buf)))) > buf)) > ! (buffer-list))) > ! nil collect))) > > ! (defun occur-1 (regexp nlines bufs &optional buf-name collect) > (unless (and regexp (not (equal regexp ""))) > (error "Occur doesn't work with the empty regexp")) > (unless buf-name > *************** > *** 1145,1181 **** > ;; If we just renamed that buffer, we will make a new one here. > (setq occur-buf (get-buffer-create buf-name)) > > ! (with-current-buffer occur-buf > ! (occur-mode) > ! (let ((inhibit-read-only t) > ! ;; Don't generate undo entries for creation of the initial contents. > ! (buffer-undo-list t)) > ! (erase-buffer) > ! (let ((count (occur-engine > ! regexp active-bufs occur-buf > ! (or nlines list-matching-lines-default-context-lines) > ! (if (and case-fold-search search-upper-case) > ! (isearch-no-upper-case-p regexp t) > ! case-fold-search) > ! list-matching-lines-buffer-name-face > ! nil list-matching-lines-face > ! (not (eq occur-excluded-properties t))))) > ! (let* ((bufcount (length active-bufs)) > ! (diff (- (length bufs) bufcount))) > ! (message "Searched %d buffer%s%s; %s match%s for `%s'" > ! bufcount (if (= bufcount 1) "" "s") > ! (if (zerop diff) "" (format " (%d killed)" diff)) > ! (if (zerop count) "no" (format "%d" count)) > ! (if (= count 1) "" "es") > ! regexp)) > ! (setq occur-revert-arguments (list regexp nlines bufs)) > ! (if (= count 0) > ! (kill-buffer occur-buf) > ! (display-buffer occur-buf) > ! (setq next-error-last-buffer occur-buf) > ! (setq buffer-read-only t) > ! (set-buffer-modified-p nil) > ! (run-hooks 'occur-hook))))))) > > (defun occur-engine-add-prefix (lines) > (mapcar > --- 1159,1214 ---- > ;; If we just renamed that buffer, we will make a new one here. > (setq occur-buf (get-buffer-create buf-name)) > > ! (if collect > ! (with-current-buffer occur-buf > ! (fundamental-mode) > ! (let ((inhibit-read-only t) > ! (buffer-undo-list t)) > ! (erase-buffer) > ! (while active-bufs > ! (with-current-buffer (car active-bufs) > ! (save-excursion > ! (goto-char (point-min)) > ! (while (re-search-forward regexp nil t) > ! (let ((str (match-string collect))) > ! (if str > ! (with-current-buffer occur-buf > ! (insert str) > ! (or (zerop (current-column)) > ! (insert "\n")))))))) > ! (setq active-bufs (cdr active-bufs)))) > ! (display-buffer occur-buf)) > ! (with-current-buffer occur-buf > ! (occur-mode) > ! (let ((inhibit-read-only t) > ! ;; Don't generate undo entries for creation of the initial contents. > ! (buffer-undo-list t)) > ! (erase-buffer) > ! (let ((count (occur-engine > ! regexp active-bufs occur-buf > ! (or nlines list-matching-lines-default-context-lines) > ! (if (and case-fold-search search-upper-case) > ! (isearch-no-upper-case-p regexp t) > ! case-fold-search) > ! list-matching-lines-buffer-name-face > ! nil list-matching-lines-face > ! (not (eq occur-excluded-properties t))))) > ! (let* ((bufcount (length active-bufs)) > ! (diff (- (length bufs) bufcount))) > ! (message "Searched %d buffer%s%s; %s match%s for `%s'" > ! bufcount (if (= bufcount 1) "" "s") > ! (if (zerop diff) "" (format " (%d killed)" diff)) > ! (if (zerop count) "no" (format "%d" count)) > ! (if (= count 1) "" "es") > ! regexp)) > ! (setq occur-revert-arguments (list regexp nlines bufs)) > ! (if (= count 0) > ! (kill-buffer occur-buf) > ! (display-buffer occur-buf) > ! (setq next-error-last-buffer occur-buf) > ! (setq buffer-read-only t) > ! (set-buffer-modified-p nil) > ! (run-hooks 'occur-hook)))))))) > > (defun occur-engine-add-prefix (lines) > (mapcar