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: Tue, 9 Nov 2010 18:12:50 -0800 Message-ID: <20101109.181250.505612453.Takaaki.Ota@am.sony.com> References: <20101104.113654.332196908.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 1289355194 30902 80.91.229.12 (10 Nov 2010 02:13:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 10 Nov 2010 02:13:14 +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 Wed Nov 10 03:13:07 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 1PG0BN-0006Sa-EI for ged-emacs-devel@m.gmane.org; Wed, 10 Nov 2010 03:13:06 +0100 Original-Received: from localhost ([127.0.0.1]:44739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PG0BM-0004rd-Hz for ged-emacs-devel@m.gmane.org; Tue, 09 Nov 2010 21:13:04 -0500 Original-Received: from [140.186.70.92] (port=48236 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PG0BI-0004rD-69 for emacs-devel@gnu.org; Tue, 09 Nov 2010 21:13:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PG0BG-0006h3-MB for emacs-devel@gnu.org; Tue, 09 Nov 2010 21:13:00 -0500 Original-Received: from db3ehsobe006.messaging.microsoft.com ([213.199.154.144]:5320 helo=DB3EHSOBE006.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PG0BG-0006gt-9m for emacs-devel@gnu.org; Tue, 09 Nov 2010 21:12:58 -0500 Original-Received: from mail69-db3-R.bigfish.com (10.3.81.247) by DB3EHSOBE006.bigfish.com (10.3.84.26) with Microsoft SMTP Server id 14.1.225.8; Wed, 10 Nov 2010 02:12:57 +0000 Original-Received: from mail69-db3 (localhost.localdomain [127.0.0.1]) by mail69-db3-R.bigfish.com (Postfix) with ESMTP id D83D31390584; Wed, 10 Nov 2010 02:12:56 +0000 (UTC) X-SpamScore: -12 X-BigFish: VPS-12(zz1432N98dNzz1202hzzz2fh2a8h668h61h) 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 mail69-db3 (localhost.localdomain [127.0.0.1]) by mail69-db3 (MessageSwitch) id 1289355176211763_17981; Wed, 10 Nov 2010 02:12:56 +0000 (UTC) Original-Received: from DB3EHSMHS009.bigfish.com (unknown [10.3.81.243]) by mail69-db3.bigfish.com (Postfix) with ESMTP id 2682B198004E; Wed, 10 Nov 2010 02:12:56 +0000 (UTC) Original-Received: from mail7.fw-bc.sony.com (160.33.98.74) by DB3EHSMHS009.bigfish.com (10.3.87.109) with Microsoft SMTP Server (TLS) id 14.1.225.8; Wed, 10 Nov 2010 02:12:55 +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 oAA2Cq0n006219 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 10 Nov 2010 02:12:53 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 oAA2Cpvi026001; Wed, 10 Nov 2010 02:12:51 GMT In-Reply-To: X-Mailer: Mew-6.3.50 on Emacs-23.2.90.1 (i386-mingw-nt6.1.7600 built on 2010-11-09) 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:132491 Archived-At: 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