Copy selected text into Emacs

I want to use Emacs for simple text annotation. Is there a command that surrounds the selected area of ​​text with brackets or other characters?

+3


source to share


2 answers


I don't know if there is a standard emacs command for this, but this should do the trick:

(defun surround-brackets ()
  "Surround current region with brackets"
  (interactive)
  (when (use-region-p)
    (save-excursion
      (let ((beg (region-beginning))
            (end (region-end)))
        (goto-char end)
        (insert "]")
        (goto-char beg)
        (insert "[")))))

      



EDIT As noted in the comments, this question suggests the following solution, which is much simpler, but requires the use of a key binding ending in[

(global-set-key (kbd "M-[") 'insert-pair)

      

+2


source


The most structured and flexible way to do this is with autopair . I will say that this has become the canonical solution to insert paired delimiters and wrap content in paired delimiters.

Joao ( autopair

author) also wrote yasnippet , which is a very popular template library in Emacs. yasnippet

can be used to wrap an area in free text.



Both libraries model their behavior in Textmate.

+4


source







All Articles