* regexp/emacs selective replace
@ 2009-11-23 13:41 m121212
0 siblings, 0 replies; 10+ messages in thread
From: m121212 @ 2009-11-23 13:41 UTC (permalink / raw)
To: Help-gnu-emacs
Hi,
I have a tricky problem that I'm not sure how to solve. I have a latex
document with several figure environments that look like this:
\begin{figure}
\includegraphics{blah.ps}
\end{figure}
but need to look like this:
\begin{figure}
\begin{center} \includegraphics{blah.ps} \end{center}
\end{figure}
Some of the figure environments already have this however, and I don't want
to end up with something like this:
\begin{figure}
\begin{center}\begin{center} \includegraphics{blah.ps}
\end{center}\end{center}
\end{figure}
Any ideas? Also, is there a way Emacs can just wrap any selection with
custom, predefined tags?
thanks,
m121212
--
View this message in context: http://old.nabble.com/regexp-emacs-selective-replace-tp26478209p26478209.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
[not found] <mailman.11424.1259102060.2239.help-gnu-emacs@gnu.org>
@ 2009-11-25 1:30 ` Barry Margolin
2009-11-25 8:15 ` harven
2009-11-26 19:20 ` Xah Lee
2 siblings, 0 replies; 10+ messages in thread
From: Barry Margolin @ 2009-11-25 1:30 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.11424.1259102060.2239.help-gnu-emacs@gnu.org>,
m121212 <m121212@mailinator.com> wrote:
> Hi,
>
> I have a tricky problem that I'm not sure how to solve. I have a latex
> document with several figure environments that look like this:
>
> \begin{figure}
> \includegraphics{blah.ps}
> \end{figure}
>
> but need to look like this:
>
> \begin{figure}
> \begin{center} \includegraphics{blah.ps} \end{center}
> \end{figure}
>
> Some of the figure environments already have this however, and I don't want
> to end up with something like this:
>
> \begin{figure}
> \begin{center}\begin{center} \includegraphics{blah.ps}
> \end{center}\end{center}
> \end{figure}
>
> Any ideas?
Does query-replace-regexp do what you want? It will prompt you before
each possible replacement, and you can say whether to replace that
instance.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
[not found] <mailman.11424.1259102060.2239.help-gnu-emacs@gnu.org>
2009-11-25 1:30 ` regexp/emacs selective replace Barry Margolin
@ 2009-11-25 8:15 ` harven
2009-11-25 11:58 ` m121212
[not found] ` <mailman.11454.1259150311.2239.help-gnu-emacs@gnu.org>
2009-11-26 19:20 ` Xah Lee
2 siblings, 2 replies; 10+ messages in thread
From: harven @ 2009-11-25 8:15 UTC (permalink / raw)
To: help-gnu-emacs
m121212 <m121212@mailinator.com> writes:
> Hi,
>
> I have a tricky problem that I'm not sure how to solve. I have a latex
> document with several figure environments that look like this:
>
> \begin{figure}
> \includegraphics{blah.ps}
> \end{figure}
>
> but need to look like this:
>
> \begin{figure}
> \begin{center} \includegraphics{blah.ps} \end{center}
> \end{figure}
>
> Some of the figure environments already have this however, and I don't want
> to end up with something like this:
>
> \begin{figure}
> \begin{center}\begin{center} \includegraphics{blah.ps}
> \end{center}\end{center}
> \end{figure}
>
> Any ideas? Also, is there a way Emacs can just wrap any selection with
> custom, predefined tags?
Anchor to the beginning and end of line.
M-x replace-regexp RET
^ *\\includegraphics{[^}]*} *$ RET
\\begin{center} \& \\end{center} RET
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
2009-11-25 8:15 ` harven
@ 2009-11-25 11:58 ` m121212
[not found] ` <mailman.11454.1259150311.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 10+ messages in thread
From: m121212 @ 2009-11-25 11:58 UTC (permalink / raw)
To: Help-gnu-emacs
Thanks for your repsonses! The solution for me in the end was just to record
a keyboard macro. Do you use a particular guide for regexps? Also, could
you explain this part: {[^}]*} *$ RET ?
M-x replace-regexp RET
^ *\\includegraphics{[^}]*} *$ RET
\\begin{center} \& \\end{center} RET
Thanks,
m121212
--
View this message in context: http://old.nabble.com/regexp-emacs-selective-replace-tp26478209p26511406.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
[not found] ` <mailman.11454.1259150311.2239.help-gnu-emacs@gnu.org>
@ 2009-11-25 12:11 ` Joost Kremers
2009-11-25 12:36 ` harven
2009-11-25 12:24 ` harven
1 sibling, 1 reply; 10+ messages in thread
From: Joost Kremers @ 2009-11-25 12:11 UTC (permalink / raw)
To: help-gnu-emacs
m121212 wrote:
>
> Thanks for your repsonses! The solution for me in the end was just to record
> a keyboard macro. Do you use a particular guide for regexps?
(info "(emacs) Regexps")
> Also, could
> you explain this part: {[^}]*} *$ RET ?
see the above info node. ;-) { and the final } are just literal characters,
[...] describes a set of alternatives. ^ negates such a set, so that [^}]
matches any character other than }.
note that {[^}]*} could also have been written as {.*?} (which IHMO is a bit
clearer and easier to read).
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
[not found] ` <mailman.11454.1259150311.2239.help-gnu-emacs@gnu.org>
2009-11-25 12:11 ` Joost Kremers
@ 2009-11-25 12:24 ` harven
2009-11-25 12:32 ` Joost Kremers
1 sibling, 1 reply; 10+ messages in thread
From: harven @ 2009-11-25 12:24 UTC (permalink / raw)
To: help-gnu-emacs
m121212 <m121212@mailinator.com> writes:
> Thanks for your repsonses! The solution for me in the end was just to record
> a keyboard macro. Do you use a particular guide for regexps? Also, could
> you explain this part: {[^}]*} *$ RET ?
{[^}]*} *$ means
{ first an opening brace,
[^}]* then any number of characters that are not a closing brace
} then a closing brace,
* any number of spaces,
$ and the line ends there
RET RETURN to proceed
This matches {xxx}
but not {xxx} \end{center} because the line does not end after the brace.
See http://www.emacswiki.org/emacs/RegularExpression
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
2009-11-25 12:24 ` harven
@ 2009-11-25 12:32 ` Joost Kremers
0 siblings, 0 replies; 10+ messages in thread
From: Joost Kremers @ 2009-11-25 12:32 UTC (permalink / raw)
To: help-gnu-emacs
harven wrote:
> {[^}]*} *$ means
[...]
> This matches {xxx}
> but not {xxx} \end{center} because the line does not end after the brace.
and because there would be a } in the matching string.
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
2009-11-25 12:11 ` Joost Kremers
@ 2009-11-25 12:36 ` harven
2009-11-25 12:44 ` Joost Kremers
0 siblings, 1 reply; 10+ messages in thread
From: harven @ 2009-11-25 12:36 UTC (permalink / raw)
To: help-gnu-emacs
Joost Kremers <joostkremers@yahoo.com> writes:
> note that {[^}]*} could also have been written as {.*?} (which IHMO is a bit
> clearer and easier to read).
strictly speaking {[^}]*} is not the same as {.*?}
The first will match
{xxx
}
because emacs regexp [^...] matches newline if it is not included in the
brackets. By the way {.*?} is probably closer to what the OP asks for.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
2009-11-25 12:36 ` harven
@ 2009-11-25 12:44 ` Joost Kremers
0 siblings, 0 replies; 10+ messages in thread
From: Joost Kremers @ 2009-11-25 12:44 UTC (permalink / raw)
To: help-gnu-emacs
harven wrote:
> Joost Kremers <joostkremers@yahoo.com> writes:
>
>> note that {[^}]*} could also have been written as {.*?} (which IHMO is a bit
>> clearer and easier to read).
>
> strictly speaking {[^}]*} is not the same as {.*?}
when it comes to regexps, all that counts is "strictly speaking". ;-)
> The first will match
>
> {xxx
> }
>
> because emacs regexp [^...] matches newline if it is not included in the
> brackets.
yup, true. forgot about that...
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: regexp/emacs selective replace
[not found] <mailman.11424.1259102060.2239.help-gnu-emacs@gnu.org>
2009-11-25 1:30 ` regexp/emacs selective replace Barry Margolin
2009-11-25 8:15 ` harven
@ 2009-11-26 19:20 ` Xah Lee
2 siblings, 0 replies; 10+ messages in thread
From: Xah Lee @ 2009-11-26 19:20 UTC (permalink / raw)
To: help-gnu-emacs
On Nov 23, 5:41 am, m121212 <m121...@mailinator.com> wrote:
> Hi,
>
> I have a tricky problem that I'm not sure how to solve. I have a latex
> document with several figure environments that look like this:
>
> \begin{figure}
> \includegraphics{blah.ps}
> \end{figure}
>
> but need to look like this:
>
> \begin{figure}
> \begin{center} \includegraphics{blah.ps} \end{center}
> \end{figure}
>
> Some of the figure environments already have this however, and I don't want
> to end up with something like this:
>
> \begin{figure}
> \begin{center}\begin{center} \includegraphics{blah.ps}
> \end{center}\end{center}
> \end{figure}
This page answers your question exactly:
• Elisp Lesson: Repeated Find Replace
http://xahlee.org/emacs/elisp_repeat_replace.html
if you prefer emacs to ask you for each case, perhaps just to be sure
your regex didn't find a bad match, see:
• Lisp Lesson: Regex Replace with a Function
http://xahlee.org/emacs/lisp_regex_replace_func.html
> Any ideas? Also, is there a way Emacs can just wrap any selection with
> custom, predefined tags?
(defun wrap-markup ()
"Insert a markup <b></b> around a region."
(interactive)
(goto-char (region-end)) (insert "</b>")
(goto-char (region-beginning)) (insert "<b>")
)
the above is from a collection of simple elisp examples at
• Emacs Lisp Examples
http://xahlee.org/emacs/elisp_examples.html
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-11-26 19:20 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.11424.1259102060.2239.help-gnu-emacs@gnu.org>
2009-11-25 1:30 ` regexp/emacs selective replace Barry Margolin
2009-11-25 8:15 ` harven
2009-11-25 11:58 ` m121212
[not found] ` <mailman.11454.1259150311.2239.help-gnu-emacs@gnu.org>
2009-11-25 12:11 ` Joost Kremers
2009-11-25 12:36 ` harven
2009-11-25 12:44 ` Joost Kremers
2009-11-25 12:24 ` harven
2009-11-25 12:32 ` Joost Kremers
2009-11-26 19:20 ` Xah Lee
2009-11-23 13:41 m121212
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).