1

I like smart parentheses as much as the next person, but there is one situation in which I often get frustrated. Suppose I have a TeX line reading:

Lorem ipsum dolor sit amet

Now I wish to \emphasize dolor. Hence I go before it and write \emph{, resulting, with electric-pair-mode and the likes, in:

Lorem ipsum \emph{}|dolor sit amet

(where | is the point). Now the behavior I'd like to have, is that if I only thereafter move then insert }, then the automagically inserted } is removed. Graphically, I'd like to end up with:

Lorem ipsum \emph{dolor}| sit amet

rather than:

Lorem ipsum \emph{}dolor}| sit amet

Question: Is there a mode that implements that behavior? Note that I don't want to use the transient mark.

  • Consider not bothering with "smartparens" or "electric-pair", if you haven't already. Just a suggestion. – Drew Nov 17 '16 at 16:22
  • I spent the last 15 years happily emacs'ing without any smartness in my parentheses, so I certainly understand the suggestion. As a matter of fact, I'm mostly testing out electricity here; not sure I'll adopt it, especially if I cannot get the above question worked out. Thanks for the input, though! – Michaël Nov 17 '16 at 18:06
  • Lots of people do like such "smart"/"electric" pairing. Some others (maybe mostly oldtimers?) do not. (To me, they're more of a bother than a help.) Hope you get an answer that helps. – Drew Nov 17 '16 at 18:10
  • There is a specialized list for these modes: auctex@gnu.org – Andreas Röhler Nov 17 '16 at 18:32
  • 1
    Why don't you want to use transient mark? That is the most direct solution: mark dolor, then C-c C-f C-e will wrap it with \emph{} – Tyler Nov 19 '16 at 13:34
0

I don't know how to achieve that specific effect, but I often do something very similar that works with both smartparens and post-24.4 electric-pair.

In this case, I would type \emph, set the visible mark, move the point after dolor, and then press { or }. This will cause the electric mode in question to bracket the marked region.

In other words, set the following line up so that the italics represent the marked region, then press an electric paren key like {:

Lorem ipsum \emphdolor sit amet

My personal habit is to press { if I'm at the beginning of a marked region and } if I'm at the end, but it seems to work either way.

  • BTW, you can mark the word with C-M-SPC. – Stefan Aug 9 '18 at 16:31
  • Sure! However you would normally mark the relevant region. It has to be marked, though, the OP wanted something more automagical, I think. – elb Aug 10 '18 at 18:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.