20091126

emacs regex replace

On Nov 23, 5:41 am, m121212 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/

automation may not be easy (emacs)

On Nov 23, 4:02 pm, Matthew Dempsky wrote:
> Whenever I'm composing a changelog entry for vc-mode, I like to be
> able to view the corresponding diff. Currently, after I use 'C-x v v'
> to create the *VC-Log* buffer, I immediately press 'C-c C-d' to open
> the *VC-Diff* buffer. Then after entering my changelog entry and
> committing with 'C-c C-c', I always immediately close the *VC-Diff*
> buffer.
>
> I was wondering about ways to automate the extra steps. I'd
> appreciate any concrete suggestions on how I could achieve this
> behavior.
>
> Thanks.

i've never used vc-mode... don't know what it is except just reading about it's inline doc now. I suppose many others here haven't either so maybe you are not getting answer...

you could define easy shortcut keys, for example, f4 for going log buffer, f5 for going to diff buffer, f6 for closing the current buffer... (if you don't know how to do that, see: http://xahlee.org/emacs/keyboard_shortcuts.html )

might involve a bit elisp code since the buffer you want may depend on the current buffer's name. But to give concrete elisp code i need to know...

ohterwise, if you can explain more abtractly what you need without reader having knowledge of vc-mode... i could help more. For example, in what exact situation in tech terms you want what action to be taken. (if, your need actually do have such unique description. Because sometimes something seems simple on the surface but there's a lot implicit assumptions that makes automation hard or impossible.)

Xah
∑ http://xahlee.org/