0

Is there an easy way to wrap a buffer in emacs with text of my choice? For e.g if my selected buffer is like this,

This is the first line of a verse with ।
And here comes the second line ॥ 1.2 ॥ 

I want to add custom markers to the top and bottom of the verse like this:

\begin{myverse}
This is the first line of a verse with ।
And here comes the second line ॥ 1.2 ॥ 
\end{myverse}

I'm running evil mode in emacs 27.1 on OSX. Right now I copy each of the tags \begin{myverse} and \end{myverse} into named vim buffers, move the cursor to the right location and paste the desired text. I'm hoping there's a faster way of accomplishing this and am open to any solutions in emacs or vim.

EDIT 1: I believe there's an emacs way to move to the beginning of a buffer, add a newline insert some text, again move to the end of that buffer, add a newline and insert text.

3
  • By framing the question in terms of wrapping a buffer with text at the beginning and end thereof, the answers will be different than what would otherwise be indicated by the minimal working example (which wraps a selection with LaTeX code, and does not necessitate being the sole text within the buffer in order to wrap said text). – lawlist Jan 1 at 23:37
  • @lawlist this is my MWE. The block around which I want to add wrappers is in unicode and hence I chose to provide english text instead. – linuxfan Jan 1 at 23:39
  • I suspect you want something more complex, but the question is not written in such a manner so as to let the forum participants fully understand the context. Here is a simple example you can try out by typing M-x eval-expression RET (let ((beg-text "\\begin{myverse}") (end-text "\\end{myverse}")) (save-excursion (goto-char (point-min)) (insert beg-text "\n") (goto-char (point-max)) (insert "\n" end-text))) RET NOTE: There are built-in solutions for surrounding text with LaTeX code, as well as using the popular AUCTex library. There are also skeleton libraries designed for buffer inserts. – lawlist Jan 2 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.