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: Fri, 03 Dec 2010 14:17:50 -0500 Message-ID: References: <20101109.181250.505612453.Takaaki.Ota@am.sony.com> <20101202.170351.142719949.Takaaki.Ota@am.sony.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1291403892 5480 80.91.229.12 (3 Dec 2010 19:18:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 19:18:12 +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 Fri Dec 03 20:18: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 1POb8x-0007Ef-DA for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 20:18:07 +0100 Original-Received: from localhost ([127.0.0.1]:51449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POb8w-0007Nn-Nf for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 14:18:06 -0500 Original-Received: from [140.186.70.92] (port=43206 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POb8p-0007KU-Cl for emacs-devel@gnu.org; Fri, 03 Dec 2010 14:18:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POb8o-0004kc-D8 for emacs-devel@gnu.org; Fri, 03 Dec 2010 14:17:59 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:59484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POb8o-0004k9-AU for emacs-devel@gnu.org; Fri, 03 Dec 2010 14:17:58 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id oB3JHo9B014953; Fri, 3 Dec 2010 14:17:51 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 0E54AA8364; Fri, 3 Dec 2010 14:17:50 -0500 (EST) In-Reply-To: <20101202.170351.142719949.Takaaki.Ota@am.sony.com> (Tak Ota's message of "Thu, 2 Dec 2010 17:03:51 -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 RV3698=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:133350 Archived-At: Thanks, that looks pretty good now. A few more nitpicks while I'm here: > + (defvar occur-collect-submatch-history '("1") > + "The history of list of parenthesized expression numbers as a > + string in occur's collect operation") Usually history vars start at nil (and you can save them via savehist if you so prefer). > (defun occur-read-primary-args () > ! (let ((regexp) > ! (do-collect (consp current-prefix-arg))) > ! (list (setq regexp > ! (read-regexp (if do-collect > ! "Collect strings matching regexp" > ! "List lines matching regexp") > ! (car regexp-history))) Always try to set the var directly in the let rather than via a separate setq: (let* ((do-collect (consp current-prefix-arg)) (regexp (read-regexp (if do-collect "Collect strings matching regexp" "List lines matching regexp") (car regexp-history)))) (list regexp ...)) > ! (if do-collect > ! (if (zerop (regexp-opt-depth regexp)) > ! ;; no subexpression so collect entire the match Comments should start with a capital letter and end with a ".". > ! '(0) > ! ;; construct a list of subexpression integers > ! (mapcar 'string-to-number > ! (split-string > ! (let ((default (car occur-collect-submatch-history))) > ! (read-from-minibuffer > ! (format "Subexpressions to collect (default %s): " default) > ! "" nil nil 'occur-collect-submatch-history default) > ! (car occur-collect-submatch-history))))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This should be `default', right? > ! When NLINES is a list of integers or when the function is called > ! interactively with prefix argument without a number (`C-u' alone > ! as prefix) the matching strings are collected into the `*Occur*' > ! buffer. The parenthesized match strings in REGEXP indicated by > ! the integers in NLINES are collected. For example, providing > ! \"defun \\(\\S +\\)\" for REGEXP and (1) for NLINES collects all > ! the function names in a lisp program. When there is no > ! parenthesized subexpressions in REGEXP the entire match is > ! collected." Hmm... I didn't think of NLINES turning into a list of submatch-numbers, but that makes me think that maybe we should go one step further and turn it into a string, like the ones used in replace-match. Stefan