From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#21275: 24.5; Selection deleted with electric pair mode in cc mode Date: 18 Aug 2015 15:04:31 -0000 Organization: muc.de e.V. Message-ID: <20150818150431.42639.qmail@mail.muc.de> References: <87a8trcqbp.fsf@moondust.localdomain> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1439910345 6021 80.91.229.3 (18 Aug 2015 15:05:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Aug 2015 15:05:45 +0000 (UTC) Cc: 21275@debbugs.gnu.org To: nljlistbox2@gmail.com (N. Jackson) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Aug 18 17:05:31 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZRiS1-0001QN-5O for geb-bug-gnu-emacs@m.gmane.org; Tue, 18 Aug 2015 17:05:21 +0200 Original-Received: from localhost ([::1]:57725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRiS0-0006Q8-Dm for geb-bug-gnu-emacs@m.gmane.org; Tue, 18 Aug 2015 11:05:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRiRt-0006Ow-16 for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2015 11:05:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZRiRm-0005aY-Sc for bug-gnu-emacs@gnu.org; Tue, 18 Aug 2015 11:05:12 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38679) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZRiRi-0005Nt-19; Tue, 18 Aug 2015 11:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZRiRh-0001y6-Nz; Tue, 18 Aug 2015 11:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Tue, 18 Aug 2015 15:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21275 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 21275-submit@debbugs.gnu.org id=B21275.14399102777522 (code B ref 21275); Tue, 18 Aug 2015 15:05:01 +0000 Original-Received: (at 21275) by debbugs.gnu.org; 18 Aug 2015 15:04:37 +0000 Original-Received: from localhost ([127.0.0.1]:59122 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZRiRH-0001xA-To for submit@debbugs.gnu.org; Tue, 18 Aug 2015 11:04:36 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:49177) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZRiRF-0001x0-CN for 21275@debbugs.gnu.org; Tue, 18 Aug 2015 11:04:34 -0400 Original-Received: (qmail 42640 invoked by uid 3782); 18 Aug 2015 15:04:31 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.1-RELEASE-p6 (amd64)) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:105563 Archived-At: Hello, N. In article you wrote: > In cc mode, with delete selection mode and electric pair mode both on, > entering a "(" when there is an active selection erroneously deletes the > selection (and inserts "()" in the buffer) rather than inserting a "(" > before the selection and a ")" after it. This is inconsistent with the > seemingly correct [1] and useful behaviour in (for example) text mode, > fundamental mode, and lisp mode. > The bug affects both code and in comments. And it also affects braces as well as parens. Thanks for taking the trouble to report this bug, and thanks even more for making your report so clear and well structured. > STEPS TO REPRODUCE: > $ cat > test.c > /* This is a short comment. */ > int test(void){ > return 0; > } > ^D > $ emacs -Q > M-x delete-selection-mode > M-x electric-pair-mode > C-x f test.c RET > ;; Select the word "short" in the first line. > ( > ;; Now select the "0" in the return statement. > ( > EXPECTED RESULT: > /* This is a (short) comment. */ > int test(void){ > return (0); > } > OBSERVED RESULT: > /* This is a () comment. */ > int test(void){ > return (); > } > [1] http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11520 > In GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.14.14) > of 2015-07-25 on moondust > Windowing system distributor `Fedora Project', version 11.0.11603000 > System Description: Fedora release 21 (Twenty One) I think the following patch should fix it. To apply it, go to the directory ..../emacs-24.5/lisp and apply the patch from there. If `patch' complains at not finding the second file, and prompts you for it, this will be .../emacs-24.5/lisp/progmodes/cc-cmds.el. After byte-compiling both files (either with M-x byte-compile-file from inside emacs, or with $ emacs -Q -batch -f batch-byte-compile delsel.el progmodes/cc-cmds.el from a command line), just load the two files.elc into Emacs with M-x load-file (or restart Emacs). Would you please confirm that the problem has been fixed, or tell us what is still not working. Thanks in advance! Here's the patch: diff --git a/lisp/delsel.el b/lisp/delsel.el index 740b603..6a77d75 100644 --- a/lisp/delsel.el +++ b/lisp/delsel.el @@ -231,10 +231,15 @@ See `delete-selection-helper'." (delete-selection-helper (and (symbolp this-command) (get this-command 'delete-selection))))) -(put 'self-insert-command 'delete-selection - (lambda () - (not (run-hook-with-args-until-success - 'self-insert-uses-region-functions)))) +(defun delete-selection-uses-region-p () + "Return non-nil when the current command uses the region. +This function is intended for use as the value of the + `delete-selection' property of a command, and shouldn't be used for + anything else." + (not (run-hook-with-args-until-success + 'self-insert-uses-region-functions))) + +(put 'self-insert-command 'delete-selection 'delete-selection-uses-region-p) (put 'insert-char 'delete-selection t) (put 'quoted-insert 'delete-selection t) diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index c9f5945..40ec4bd 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -2860,13 +2860,18 @@ sentence motion in or near comments and multiline strings." (put sym 'delete-selection t) ; for delsel (Emacs) (put sym 'pending-delete t))) ; for pending-del (XEmacs) '(c-electric-pound - c-electric-brace +; c-electric-brace c-electric-slash c-electric-star c-electric-semi&comma c-electric-lt-gt c-electric-colon - c-electric-paren)) +; c-electric-paren + )) +(put 'c-electric-brace 'delete-selection 'delete-selection-uses-region-p) +(put 'c-electric-brace 'pending-delete 't) +(put 'c-electric-paren 'delete-selection 'delete-selection-uses-region-p) +(put 'c-electric-paren 'pending-delete 't) (put 'c-electric-delete 'delete-selection 'supersede) ; delsel (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del (put 'c-electric-backspace 'delete-selection 'supersede) ; delsel -- Alan Mackenzie (Nuremberg, Germany).