I would like to wrap some text around selected text in emacs.
From a selection of the lines:
First item
Second item
I would like to get :
\begin{itemize}
\item First item
\item Second item
\end{itemize}
Using C-c C-e
in AucTeX collapses the 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 ")
instead, but that gives the error:
[yas] elisp error: Invalid use of '\' in replacement text
I would like to have the snippet work as I can modify it for use in other contexts also.