From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Espen Newsgroups: gmane.emacs.help Subject: Re: how do i create keyboard shortcut to specific query-replace? Date: Mon, 30 Sep 2013 20:48:24 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1380588615 8963 80.91.229.3 (1 Oct 2013 00:50:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Oct 2013 00:50:15 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 01 02:50:19 2013 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 1VQoAM-0001tz-TB for geh-help-gnu-emacs@m.gmane.org; Tue, 01 Oct 2013 02:50:19 +0200 Original-Received: from localhost ([::1]:52199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VQoAM-0001hw-81 for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Sep 2013 20:50:18 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 48 Injection-Info: mx05.eternal-september.org; posting-host="5d070289bfddab8debea427f21ca33d2"; logging-data="22839"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+01SN67PbVoqZR2ayQmbVHG2payVVxigc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) Cancel-Lock: sha1:IQti64fYYMzNv6/F9l8XPVdfsjk= sha1:tgSQogwZy971pV+vv3Y7nGVtwuw= Original-Xref: usenet.stanford.edu gnu.emacs.help:201496 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:93765 Archived-At: Hod b writes: > Hello > I've trying to create a keyboard shortcut that replace some query that i > have in many(!) files with similar query. > Example: > > original code: > foo( type => 'bar', action => 'execute bar' ); > foo( type => 'baz', action => 'special action' ); > foo( type => 'bat', action => 'yyyyy' ); > foo( type => 'bar', action => 'bar finished' ); > > > new code: > bar( action => 'execute bar' ); > baz( action => 'special action' ); > bat( action => 'yyyyy' ); > bar( action => 'bar finished' ); > > I don't want to do that automatically to all my files, > because it depend on projects that we are work at the company. > my regex to this problem is s/foo\(\s+type\s+=>\s+'(\w+)',\s+/$1( /g > but i don't know how to save it to .emacs > > thanks for trying help me. With emacs, I've never found the need to write such complicated search/replaces. It's simpler to record a keyboard macro, name it, save it and assign a key to it. For the change you make above: foo( type => 'bar', action => 'execute bar' ); to bar( action => 'execute bar' ); move to before foo, start recording. zap to ', forward word, type (, zap to a, type space, a, move down a line go to beginning of line, end recording. Then name the macro, save it, assign key. -- Dan Espen