From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Applying macro to lines which match regexp Date: Thu, 16 Oct 2008 11:38:39 +1100 Organization: Rapt Technologies Message-ID: <87tzbdgyr4.fsf@lion.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1224117811 9933 80.91.229.12 (16 Oct 2008 00:43:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Oct 2008 00:43:31 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Oct 16 02:44:30 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KqGyb-0000JN-MM for geh-help-gnu-emacs@m.gmane.org; Thu, 16 Oct 2008 02:44:29 +0200 Original-Received: from localhost ([127.0.0.1]:40079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KqGxX-0005cx-29 for geh-help-gnu-emacs@m.gmane.org; Wed, 15 Oct 2008 20:43:23 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!news.astraweb.com!border1.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:+CFS9oteyXLaJ7K2iV2aNSIMB7Y= Original-Lines: 46 Original-NNTP-Posting-Host: 87097929.news.astraweb.com Original-X-Trace: DXC=a\GM[VZWlW]kR1VMS3E6>\L?0kYOcDh@Z; >GTR`=ZX:R9_G0=\R`Vd\Ea?; ]mMLna\o9nhBZG[flV Original-Xref: news.stanford.edu gnu.emacs.help:163490 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58832 Archived-At: Corey Foote writes: > I was reading through the Emacs manual today, and came across C-x C-k r > (apply-macro-to-region-lines) which applies the last keyboard macro to each > line that begins in the region. How would I apply the last keyboard macro to > each line that begins in the region which match a certain regular expression. > For example, say I was editing a Perl script and wanted to apply the last > macro to all line which consist solely of a comment. For example: > > 1 # Print some text > 2 print "foo"; > 3 print "foobar"; > 4 > 5 # And then a while later > 6 print "foobarbaz"; > > I would want to apply the macro to lines 1 and 6 which match the regular > expression ^\s-*#. Thanks a bunch! > > Corey Foote > Toby Software > ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ > Stay up to date on your PC, the Web, and your mobile phone with Windows Live. > See Now > I'm not sure there is a command to do that 'out of the box'. Normally, I'd probably write a function to do it. A couple of ideas though - 1. You could include in your macro definition an isearch command to find the line you are interested in. 2. See if you can find the package map-lines.el by Andreas Fuchs (part of the emacs-goodies package in Debian). This allows you to apply a command to a set of lines matching a regexp. 3. Write something in elisp using the various map* funcitons. HTH Tim -- tcross (at) rapttech dot com dot au