how to insert $$ and put the cursor between them in autopair
I often use AuCTeX to make my latex documents so i use the dollar $
sign a lot.
If autopair minor mode is enabled, when you insert a (
it automatically inserts a )
(there are some exceptions where it doesn't, for example, if you insert it after a , but i like the exceptions) and put the cursor between them, so you have
(<cursor>)
, now if you type a+b), you get (a+b)
and not (a+b))
.
I would like to have a similar behaviour with $
that works only in TeX-mode
when i enable autopair-mode
.
I've tried adding the followint to my .emacs:
(add-hook 'TeX-mode-hook
#'(lambda ()
(push '(?$ . ?$)
(getf autopair-extra-pairs :everywhere))))
but it does not work for some reason.
The problem is that you usually have a lot of expression $...$
and when you insert a single $
, all the text before that $
gets a wrong coloration which is annoying and then after you close the initial $
the text after the initial $
gets fixed.
Not sure about AuCTeX, but this works for latex-mode
(eval-after-load "tex-mode" '(modify-syntax-entry ?$ """ latex-mode-syntax-table))
Not sure what the right syntax-table is for AuCTeX.
FYI, I have code on Github for autopairing dollar signs and [] in Latex.
https://github.com/tomathan/autopair-latex/blob/master/autopair-latex.el
Hope this helps!
My solution is essentially the same as event_jr's (i tried it but it didn't work for me). The main point is change the syntax entry of $ so it is traited as " (strings). Check the very end of http://code.google.com/p/autopair/issues/detail?can=1&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=18
链接地址: http://www.djcxy.com/p/59130.html上一篇: java是否有索引最小优先级队列?