Wrapping text around selection in emacs
I would like to wrap some text around the selected text in emacs.
From row selection:
First item
Second item
I would like to get:
\begin{itemize}
\item First item
\item Second item
\end{itemize}
Usage C-c C-e
in AucTeX collapses selection into one line:
\begin{itemize}
\item First item Second item
\end{itemize}
The following snippet in yasnippet:
# -*- mode: snippet -*-
# name : wrap item
# expand-env : ((yas-wrap-around-region nil) (item-string "\item "))
# binding : C-M-z
# --
\begin{itemize}
`(let ((text (yas-selected-text))) (when text (replace-regexp-in-string "^" item-string text)))` $0
\end{itemize}
gives:
\begin{itemize}
item First item
item Second item
\end{itemize}
I tried using (item-string "\\item ")
this instead, but it gives an error:
[yas] elisp error: Invalid use of '\' in replacement text
I would like to be able to work with fragments, since I can modify it for use in other contexts.
source to share
I just wrote a starter code to solve this problem in general. It's at https://github.com/abo-abo/latex-wrap . It already works for the specific case you're describing, and you can help me extend it by posting issues .
source to share