From: Eshel Yaron Date: Sun, 16 Mar 2025 18:04:23 +0000 (+0100) Subject: Bump electric-pair-mode definition up a bit X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4d26a2d762a2ec83ceec0e4c73d5a352005ddd76;p=emacs.git Bump electric-pair-mode definition up a bit --- diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 4093add536a..c5d5f66d2ee 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -260,6 +260,32 @@ inside a comment or string." (list ?\( (cdr direct) t string-or-comment))) (reverse (list ?\) (car reverse) t string-or-comment))))) +;;;###autoload +(define-minor-mode electric-pair-mode + "Toggle automatic parens pairing (Electric Pair mode)." + :group 'electricity + (if electric-pair-mode + (progn + (add-hook 'post-self-insert-hook + #'electric-pair-post-self-insert-function + 50 t) + (add-hook 'post-self-insert-hook + #'electric-pair-open-newline-between-pairs-psif + 50 t) + (add-hook 'self-insert-uses-region-functions + #'electric-pair-will-use-region t)) + (remove-hook 'post-self-insert-hook + #'electric-pair-post-self-insert-function t) + (remove-hook 'post-self-insert-hook + #'electric-pair-open-newline-between-pairs-psif t) + (remove-hook 'self-insert-uses-region-functions + #'electric-pair-will-use-region t))) + +;;;###autoload +(define-globalized-minor-mode global-electric-pair-mode + electric-pair-mode electric-pair-mode + :group 'electricity) + (defun electric-pair--insert (char times) (let ((last-command-event char) (blink-matching-paren nil) @@ -644,32 +670,6 @@ ARG and KILLP are passed directly to map) "Keymap used by `electric-pair-mode'.") -;;;###autoload -(define-minor-mode electric-pair-mode - "Toggle automatic parens pairing (Electric Pair mode)." - :group 'electricity - (if electric-pair-mode - (progn - (add-hook 'post-self-insert-hook - #'electric-pair-post-self-insert-function - 50 t) - (add-hook 'post-self-insert-hook - #'electric-pair-open-newline-between-pairs-psif - 50 t) - (add-hook 'self-insert-uses-region-functions - #'electric-pair-will-use-region t)) - (remove-hook 'post-self-insert-hook - #'electric-pair-post-self-insert-function t) - (remove-hook 'post-self-insert-hook - #'electric-pair-open-newline-between-pairs-psif t) - (remove-hook 'self-insert-uses-region-functions - #'electric-pair-will-use-region t))) - -;;;###autoload -(define-globalized-minor-mode global-electric-pair-mode - electric-pair-mode electric-pair-mode - :group 'electricity) - (provide 'elec-pair) ;;; elec-pair.el ends here