From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.help Subject: Re: Advanced query-replace-regexp in code Date: Sun, 02 Aug 2009 22:25:27 +0200 Organization: ThierryVolpiatto Message-ID: <87hbwqarpk.fsf@tux.homenetwork> References: <877hxm89yj.fsf@lola.goethe.zz> <87ljm2b0k0.fsf@tux.homenetwork> 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 1249245218 7867 80.91.229.12 (2 Aug 2009 20:33:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 2 Aug 2009 20:33:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 02 22:33:31 2009 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 1MXhkC-0003Ah-Ry for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Aug 2009 22:33:27 +0200 Original-Received: from localhost ([127.0.0.1]:54918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXhk9-0004PI-3v for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Aug 2009 16:33:21 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MXhip-00043k-2j for help-gnu-emacs@gnu.org; Sun, 02 Aug 2009 16:31:59 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MXhik-00042b-1K for help-gnu-emacs@gnu.org; Sun, 02 Aug 2009 16:31:58 -0400 Original-Received: from [199.232.76.173] (port=45902 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MXhij-00042W-T5 for help-gnu-emacs@gnu.org; Sun, 02 Aug 2009 16:31:53 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:37978 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MXhij-0004Kx-8r for help-gnu-emacs@gnu.org; Sun, 02 Aug 2009 16:31:53 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MXhig-0005DH-NQ for help-gnu-emacs@gnu.org; Sun, 02 Aug 2009 20:31:51 +0000 Original-Received: from 222.211.85-79.rev.gaoland.net ([79.85.211.222]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 02 Aug 2009 20:31:50 +0000 Original-Received: from thierry.volpiatto by 222.211.85-79.rev.gaoland.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 02 Aug 2009 20:31:50 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 222.211.85-79.rev.gaoland.net Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEUHAwNfJRBVTESlTym0 RB/OwKFivhZqAAAACXBIWXMAAAsSAAALEgHS3X78AAAACXZwQWcAAAAwAAAAMADO7oxXAAABeElE QVQ4y3VTW47CMAyMwwUyTfYfUvG/wfC/ET4B0t7/KmsHurRgXFVVPRm/xglhsRj2+npW98G3+Amp tS5BXxl3SqzcXGRuEyf7n5lPA9jXetNPRhE7EJkzfz8YWnIgBSwW95TK4H79/t4GINKNADWj4PgA DiJX/ZxFDzDXeb4oYMw7kNUvyMzcaj3ioICG4hCKEShkPpwQ49Q05nnkGAQLDFDdExjm0qpowBYA Wi61bDlFU1GW0WbY2dSJYX5ZD2S0AiZL+rPyE19TpMzP2IvNWly+NkuWNgD4pO2oL73IQXoSyVX2 NHna7tgadWRXoCdvf2guqEcvGHqZwE520iRD0/QCYiiTE+U21w1Qxvg6iSp9fbIiDCnSAelDkCVF Vn+HekqXzRybwJ40xF4DMRG6SWGK9G1lYzHSxLYEm05GWbpJCB6A9tb9A3BGn2XdwJbS/WuInj74 4QNF8sVFdP3vl+5tgYp4Ev7fyrfFMkXgElDgV4uV/w8TWEeLCIGJ/AAAACV0RVh0Y3JlYXRlLWRh dGUAMjAwOC0wNS0zMVQyMjoxNDoyMiswMjowMM7uH/IAAAARdEVYdGpwZWc6Y29sb3JzcGFjZQAy LHVVnwAAACB0RVh0anBlZzpzYW1wbGluZy1mYWN0b3IAMngyLDF4MSwxeDFJ+qa0AAAAJXRFWHRt b2RpZnktZGF0ZQAyMDA3LTEwLTI4VDE3OjA4OjQ4KzAxOjAwhqNSRgAAAABJRU5ErkJggg== User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:UOThKpQoOpYdUEPvEzi2sRveTGQ= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:66673 Archived-At: Thierry Volpiatto writes: > David Kastrup writes: > >> Nordlöw writes: >> >>> I can't get the following example to work programmatically. >>> >>> M-x replace-regexp >>> Replace regexp: \(\w+\) >>> Replace regexp with: \,(capitalize \1) >>> >>> Is this only possible in interactive query-replace? >>> If so should I use a combination of while(), looking-at(), re-search- >>> forward(), replace-match(), match-string() etc. >> >> Do it interactively, then use >> >> C-x ESC ESC >> >> in order to figure out how to this non-interactively. > > An example of how to do that could be that: > > ,----[ Upcase all buffer ] > | (save-excursion > | (goto-char (point-min)) > | (while (not (eobp)) > | (when (re-search-forward "\\w+" (point-max) t) > | (replace-match (upcase (match-string 0)))))) > `---- After testing the above code, (don't break at eob) i found that better: ,---- | (save-excursion | (goto-char (point-min)) | (while (re-search-forward "\\w+" nil t) | (replace-match (upcase (match-string 0))))) `---- -- A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France