Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autopair and Python strings

I use autopair-mode globally for intelligent quote/paren/bracket pairing. It helps in most situations, except one.

It's kind of a pain in the ass using Python's multi-quote strings. Typing quote once gives me "|", another quote gets me ""|, a third quote gets me """|", a fourth quote gies """"|, a fifth quote gives me """""|, and a sixth quote finally gets me to """"""|. At which point I need to hop back three spaces to get what I actually wanted the whole time, which is """|""".

Is there a pre-built (or easy) way of getting autopair to have the behavior that hitting quote three times automatically gives me """|""" instead of the quote-shuffle described above?

like image 259
Inaimathi Avatar asked Mar 25 '26 09:03

Inaimathi


1 Answers

Adding the following to my .emacs gave me the desired behavior:

(add-hook 'python-mode-hook
          #'(lambda ()
              (setq autopair-handle-action-fns
                    (list #'autopair-default-handle-action
                          #'autopair-python-triple-quote-action))))

Found in the More Tricks section of the documentation linked by immerrr in their comment.

like image 197
Inaimathi Avatar answered Mar 27 '26 23:03

Inaimathi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!