GNU bug report logs - #16981
24.3.50; electric-pair-delete-adjacent-pairs broken in c-mode, python-mode, maybe-others

Previous Next

Package: emacs;

Reported by: joaotavora <at> gmail.com (João Távora)

Date: Mon, 10 Mar 2014 19:49:01 UTC

Severity: normal

Found in version 24.3.50

Done: joaotavora <at> gmail.com (João Távora)

Bug is archived. No further changes may be made.

Full log


Message #14 received at 16981 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: joaotavora <at> gmail.com (João Távora)
Cc: 16981 <at> debbugs.gnu.org, Alan Mackenzie <acm <at> muc.de>
Subject: Re: bug#16981: 24.3.50;
 electric-pair-delete-adjacent-pairs broken in c-mode,
 python-mode,	maybe-others
Date: Sat, 05 Apr 2014 11:45:09 -0400
>> There's something funny going on here.  A minor mode's keymap should
>> normally take precedence over the major mode's keymap.  (See the page 
>> "Searching Keymaps" in the Elisp manual.)  So why is electric-pair-mode's
>> keymap being overridden by CC Mode's here?
> You're right, but I can't figure out what.

That's because it's how remapping is works: first we lookup the key
(minor-maps, local-map, global-map), then we lookup the command to see
if it's remapped (minor-maps, local-map, global-map).
So the local-map and global-map's normal bindings take precedence over the
minor-map's remapping.

>>> Perhaps a hook in `backward-delete-char' is in order. Or the other major
>>> modes can find other ways to overload the backspace key.
>> I would say it's legitimate for a major mode to bind the backspace key, but
>> it's more questionable for a minor mode to do the same.  Perhaps the minor
>> mode really ought to use defadvice rather than rebinding the key.

How 'bout

  (define-key electric-pair-mode-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))))))


-- Stefan




This bug report was last modified 11 years and 47 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.