[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Advanced query-replace-regexp in code
From: |
Thierry Volpiatto |
Subject: |
Re: Advanced query-replace-regexp in code |
Date: |
Sun, 02 Aug 2009 19:14:23 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/23.1.50 (gnu/linux) |
David Kastrup <dak@gnu.org> writes:
> Nordlöw <per.nordlow@gmail.com> 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))))))
`----
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France