0

Selecting region, how to get a (pre)defined part before and after region?

Let's say for instance, working with LaTeX, we want \begin{frame}{} before the region and \end{frame} after region, how to get this done with Emacs by one function?

    [pre-part]"Has to be around this"[post-part] 

I would encourage use of yasnippet. Also, maybe "autopare" can give a hint, since somehow it smartly can put quote signs around the marked region when pressing ".

PascalVKooten
  • 20,643
  • 17
  • 103
  • 160
  • I'm not sure why you didn't just use yasnippet. Was the documentation not clear that this functionality is provided? If so, you should file a bug on github. – event_jr Sep 16 '12 at 14:48
  • I was not aware of the documentation. I was actually looking before how to mix some lisp power with yasnippet. Thank you. – PascalVKooten Sep 16 '12 at 19:29

2 Answers2

2

You can use yasnippet. Here is an example for an html tag snippet that can wrap or not.

# -*- mode: snippet -*-
# name: Wrap open close tags
# binding: C-c C-t
# expand-env: ((yas-wrap-around-region t))
# --
<$1>$0</${1:$(car (split-string text))}>

This works with the latest github version of yasnippet.

event_jr
  • 17,467
  • 4
  • 47
  • 62
2

In latex-mode, C-c C-o does just that.

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • Not working for me, even after turning off the outline mode and saving .emacs (C-c C-o C-l being outline mode). Curious to this functionality, though event_jr answered the question. – PascalVKooten Sep 16 '12 at 19:23
  • 1
    My guess is that you're not using latex-mode (the latex mode bundled with Emacs) by LaTeX-mode provided by AUCTeX, in which case I think the binding is `C-c C-e` instead, if memory serves. – Stefan Sep 18 '12 at 03:29
  • Using AUCTeX. I tested it, and yes it does work. Personally, I'm not a fan of that way of inserting an environment generally (I write snippets for everything), though this would be a good way of using it. – PascalVKooten Sep 19 '12 at 07:07