From: João Távora Date: Sun, 6 Apr 2014 23:37:17 +0000 (+0100) Subject: Fix electric-pair-delete-adjacent-pairs in modes binding backspace. X-Git-Tag: emacs-24.3.90~31 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=be411138140cdcdb4e1aec682c4e41354ab709e0;p=emacs.git 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 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c30c02dcef3..92a221999ce 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2014-04-06 João Távora + + 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 * progmodes/python.el (python-electric-pair-string-delimiter): Fix diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 2c1ea7262d3..32afcd88380 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -166,36 +166,6 @@ return value is considered instead." quotes or comments. If lookup fails here, `electric-pair-text-pairs' will 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) (or ;; I find it more often preferable not to pair when the @@ -530,14 +500,34 @@ happened." (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 (let ((map (make-sparse-keymap))) - (define-key map [remap backward-delete-char-untabify] - 'electric-pair-backward-delete-char-untabify) - (define-key map [remap backward-delete-char] - 'electric-pair-backward-delete-char) - (define-key map [remap delete-backward-char] - 'electric-pair-backward-delete-char) + (define-key map "\177" + `(menu-item + "" electric-pair-delete-pair + :filter + ,(lambda (cmd) + (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) "Keymap used by `electric-pair-mode'.")