Commit be411138 authored by João Távora's avatar João Távora
Browse files

Fix electric-pair-delete-adjacent-pairs in modes binding backspace.

* lisp/elec-pair.el (electric-pair-backward-delete-char): Delete.
(electric-pair-backward-delete-char-untabify): Delete.
(electric-pair-mode-map): Bind backspace to a menu item filtering
a new `electric-pair-delete-pair' command.
(electric-pair-delete-pair): New command.

Fixes: debbugs:16981
parent 7aecc2f6
2014-04-06 João Távora <joaotavora@gmail.com>
Fix `electric-pair-delete-adjacent-pairs' in modes binding
backspace. (bug#16981)
* elec-pair.el (electric-pair-backward-delete-char): Delete.
(electric-pair-backward-delete-char-untabify): Delete.
(electric-pair-mode-map): Bind backspace to a menu item filtering
a new `electric-pair-delete-pair' command.
(electric-pair-delete-pair): New command.
2014-04-06 João Távora <joaotavora@gmail.com> 2014-04-06 João Távora <joaotavora@gmail.com>
   
* progmodes/python.el (python-electric-pair-string-delimiter): Fix * progmodes/python.el (python-electric-pair-string-delimiter): Fix
......
...@@ -166,36 +166,6 @@ return value is considered instead." ...@@ -166,36 +166,6 @@ return value is considered instead."
quotes or comments. If lookup fails here, `electric-pair-text-pairs' will quotes or comments. If lookup fails here, `electric-pair-text-pairs' will
be considered.") be considered.")
(defun electric-pair-backward-delete-char (n &optional killflag untabify)
"Delete characters backward, and maybe also two adjacent paired delimiters.
Remaining behavior is given by `backward-delete-char' or, if UNTABIFY is
non-nil, `backward-delete-char-untabify'."
(interactive "*p\nP")
(let* ((prev (char-before))
(next (char-after))
(syntax-info (and prev
(electric-pair-syntax-info prev)))
(syntax (car syntax-info))
(pair (cadr syntax-info)))
(when (and next pair
(if (functionp electric-pair-delete-adjacent-pairs)
(funcall electric-pair-delete-adjacent-pairs)
electric-pair-delete-adjacent-pairs)
(memq syntax '(?\( ?\" ?\$))
(eq pair next))
(delete-char 1 killflag))
(if untabify
(backward-delete-char-untabify n killflag)
(backward-delete-char n killflag))))
(defun electric-pair-backward-delete-char-untabify (n &optional killflag)
"Delete characters backward, and maybe also two adjacent paired delimiters.
Remaining behavior is given by `backward-delete-char-untabify'."
(interactive "*p\nP")
(electric-pair-backward-delete-char n killflag t))
(defun electric-pair-conservative-inhibit (char) (defun electric-pair-conservative-inhibit (char)
(or (or
;; I find it more often preferable not to pair when the ;; I find it more often preferable not to pair when the
...@@ -530,14 +500,34 @@ happened." ...@@ -530,14 +500,34 @@ happened."
(memq (car (electric-pair-syntax-info last-command-event)) (memq (car (electric-pair-syntax-info last-command-event))
'(?\( ?\) ?\" ?\$)))) '(?\( ?\) ?\" ?\$))))
(defun electric-pair-delete-pair (arg &optional killp)
"When between adjacent paired delimiters, delete both of them.
ARG and KILLP are passed directly to
`backward-delete-char-untabify', which see."
(interactive "*p\nP")
(delete-char 1)
(backward-delete-char-untabify arg killp))
(defvar electric-pair-mode-map (defvar electric-pair-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map [remap backward-delete-char-untabify] (define-key map "\177"
'electric-pair-backward-delete-char-untabify) `(menu-item
(define-key map [remap backward-delete-char] "" electric-pair-delete-pair
'electric-pair-backward-delete-char) :filter
(define-key map [remap delete-backward-char] ,(lambda (cmd)
'electric-pair-backward-delete-char) (let* ((prev (char-before))
(next (char-after))
(syntax-info (and prev
(electric-pair-syntax-info prev)))
(syntax (car syntax-info))
(pair (cadr syntax-info)))
(and next pair
(memq syntax '(?\( ?\" ?\$))
(eq pair next)
(if (functionp electric-pair-delete-adjacent-pairs)
(funcall electric-pair-delete-adjacent-pairs)
electric-pair-delete-adjacent-pairs)
cmd)))))
map) map)
"Keymap used by `electric-pair-mode'.") "Keymap used by `electric-pair-mode'.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment