From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Navy Cheng Newsgroups: gmane.emacs.help Subject: Re: use Elisp to improve your Elisp - some code issues Date: Fri, 31 Jul 2015 20:11:17 +0800 Message-ID: <20150731121117.GA2596@debian> References: <87io91dvlm.fsf@nl106-137-147.student.uu.se> <87h9olxdmr.fsf@mbork.pl> Reply-To: Navy Cheng NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1438344716 8196 80.91.229.3 (31 Jul 2015 12:11:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Jul 2015 12:11:56 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 31 14:11:47 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZL9A9-000132-W4 for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Jul 2015 14:11:46 +0200 Original-Received: from localhost ([::1]:44276 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL9A9-0003eB-EF for geh-help-gnu-emacs@m.gmane.org; Fri, 31 Jul 2015 08:11:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37717) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL99y-0003e6-PM for help-gnu-emacs@gnu.org; Fri, 31 Jul 2015 08:11:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZL99u-00065h-FU for help-gnu-emacs@gnu.org; Fri, 31 Jul 2015 08:11:34 -0400 Original-Received: from m15-114.126.com ([220.181.15.114]:48959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZL99t-0005tm-J1 for help-gnu-emacs@gnu.org; Fri, 31 Jul 2015 08:11:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=BbLlt PRbjBMBdBApuxBqTc0ltmLt/A14QBbVznxLhrk=; b=dOPsoywZ3PF8gKLc/NWuL YErkmnoo8atKPapAo1K/ZSUv2ZQIiK3l2paVkFwK6HEEJRS9WHuiv2E/ldqZd8ws +YBt6AHkNzvAf8i+vNHrZFufNs5OA6l2BtzQ6aa7voc92Yi1ZRyrRbSGSsB5dDd9 5ODsTjjgdeVgm8a7GDcpe8= Original-Received: from localhost (unknown [140.207.196.4]) by smtp7 (Coremail) with SMTP id DsmowACn0sDiZbtVGhCXAA--.33585S3; Fri, 31 Jul 2015 20:11:14 +0800 (CST) Content-Disposition: inline In-Reply-To: <87h9olxdmr.fsf@mbork.pl> User-Agent: Mutt/1.5.23 (2014-03-12) X-CM-TRANSID: DsmowACn0sDiZbtVGhCXAA--.33585S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar1kGFWfXr17ZrW5Gry5twb_yoW8WF1DpF WYgr4Yyrs8ZFWUGrsxXrW5tr1IvF9rXw15urWY934xJr1rXayq9rW7trW5Zry7Jrn3W348 AF4jk34kWrW8ZrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j3YFAUUUUU= X-Originating-IP: [140.207.196.4] X-CM-SenderInfo: 5qdy5ubk6rjloofrz/1tbicwdIDVUwy+rZ6gAAsG X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 220.181.15.114 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106165 Archived-At: This is my code after your discuss. (defun search-regexp-in-files (wildcards regexp) "Search for regular expression REGEXP in files whose name matches WILDCARDS. The results will be print to buffer *PrivateResults*." (let ((result (or (get-buffer "*PrivateResults*") ; There will be only one result buffer (generate-new-buffer "*PrivateResults*"))) (file-list (file-expand-wildcards wildcards)) ; All matched files (buffer-to-kill nil)) ; Record the buffer to be killed (if (eq file-list nil) (with-current-buffer result (insert "Wrong file name!")) (dolist (file-path file-list) (setq file (file-name-nondirectory file-path)) ; Get the buffer name (let ((buffer (or (progn ; File buffer is exist (setq buffer-to-kill nil) (get-buffer file)) (progn ; Create buffer for a file (setq buffer-to-kill file) (find-file-noselect file))))) (with-current-buffer buffer (goto-char (point-min)) (while (re-search-forward regexp nil t) ; no BOUND, NOERROR (let ((hit-line (downcase (what-line)))) (with-current-buffer result (insert (format "file: %s (%s)\n" buffer hit-line)))))) (with-current-buffer result (if (eq (buffer-size result) 0) (insert "No hits!")))) (if buffer-to-kill (kill-buffer buffer-to-kill)))) ; Kill the buffer-to-kill (switch-to-buffer result))) On Fri, Jul 31, 2015 at 04:30:20AM +0200, Marcin Borkowski wrote: > > On 2015-07-31, at 02:22, Emanuel Berg wrote: > > > I just wrote some Elisp which can be used on a set of > > files to identify for example the construct > > > > (if a a b) > > > > if you want to replace those for > >