Python electric-mode pairs and triple quotes

Is there a way to enable automatic pairing of Python triple quotes in electric pair mode?

This can be configured in fleet mode using autopair-python-triple-quote-action . Is there a similar way to turn this on in electrical pair mode?

+6
source share
1 answer

You can do the following:

 (defun python-electric-pair-string-delimiter () (when (and electric-pair-mode (memq last-command-event '(?\" ?\')) (let ((count 0)) (while (eq (char-before (- (point) count)) last-command-event) (setq count (1+ count))) (= count 3))) (save-excursion (insert (make-string 3 last-command-event))))) (add-hook 'python-mode-hook (lambda () (add-hook 'post-self-insert-hook #'python-electric-pair-string-delimiter 'append t))) 

It will be included in the next version of Emacs.

+5
source

Source: https://habr.com/ru/post/957009/


All Articles