From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: collect-string Date: Thu, 02 Dec 2010 09:16:16 -0500 Message-ID: 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 X-Trace: dough.gmane.org 1291304612 9072 80.91.229.12 (2 Dec 2010 15:43:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Dec 2010 15:43:32 +0000 (UTC) Cc: stephen@xemacs.org, emacs-devel@gnu.org To: Tak Ota Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 02 16:43:28 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 1POBJf-0007Tp-3t for ged-emacs-devel@m.gmane.org; Thu, 02 Dec 2010 16:43:27 +0100 Original-Received: from localhost ([127.0.0.1]:54480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POBJe-0004bY-IG for ged-emacs-devel@m.gmane.org; Thu, 02 Dec 2010 10:43:26 -0500 Original-Received: from [140.186.70.92] (port=52020 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PO9y8-0000uG-13 for emacs-devel@gnu.org; Thu, 02 Dec 2010 09:17:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PO9xb-0002yM-7g for emacs-devel@gnu.org; Thu, 02 Dec 2010 09:17:07 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:46742) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PO9xb-0002xs-4r for emacs-devel@gnu.org; Thu, 02 Dec 2010 09:16:35 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id oB2EGHBm004181; Thu, 2 Dec 2010 09:16:17 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 85DB1A8783; Thu, 2 Dec 2010 09:16:16 -0500 (EST) In-Reply-To: <20101109.181250.505612453.Takaaki.Ota@am.sony.com> (Tak Ota's message of "Tue, 9 Nov 2010 18:12:50 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3696=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:133312 Archived-At: >> > Now I am convinced. How about the change below? >> Could you send it as a context patch? > How about this? IIUC the new arg `collect' overrides `lines' in the sense that when collect is non-nil lines is simply unused. So I suggest to just use a single argument instead (`lines') and simply give additional semantics to values that weren't supported until now. E.g. if (numberp lines) then do as before, but if (consp lines) then only keep the actual match, where (car lines) could specify which submatch to keep. > (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))))) I recommend you first check (with regexp-opt-depth) whether there is a submatch, and if not, don't `read-number'. It's likely to be a very common case. > ! (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)))))))) The "if collect" test should probably not be placed so far out: the `collect' case should output the same message, run the same hooks, etc as the non-collect case. Stefan