简体   繁体   English

在emacs中围绕选择包装文本

[英]Wrap text around a selection in emacs

I would like to wrap some text around selected text in emacs. 我想在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 Cc Ce in AucTeX collapses the selection into one line: 在AucTeX中使用Cc Ce将选择折叠为一行:

\begin{itemize}
\item First item Second item
\end{itemize}

The following snippet in yasnippet: 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: 我尝试使用(item-string "\\\\item ")代替,但是这给出了错误:

[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. 我想让代码片段工作,因为我可以修改它以便在其他环境中使用。

I just wrote some starter code to solve this problem in a general way. 我刚刚写了一些初学者代码来解决这个问题。 It's at https://github.com/abo-abo/latex-wrap . 它位于https://github.com/abo-abo/latex-wrap It already works for the specific case that you describe, and you can help me extend it by posting issues . 它已经适用于您描述的特定案例,您可以通过发布问题来帮助我扩展它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM