all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: nljlistbox2@gmail.com (N. Jackson)
Cc: 21275@debbugs.gnu.org
Subject: bug#21275: 24.5; Selection deleted with electric pair mode in cc mode
Date: 18 Aug 2015 15:04:31 -0000	[thread overview]
Message-ID: <20150818150431.42639.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.8417.1439731993.904.bug-gnu-emacs@gnu.org>

Hello, N.

In article <mailman.8417.1439731993.904.bug-gnu-emacs@gnu.org> 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).






  parent reply	other threads:[~2015-08-18 15:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-16 13:31 bug#21275: 24.5; Selection deleted with electric pair mode in cc mode N. Jackson
     [not found] ` <mailman.8417.1439731993.904.bug-gnu-emacs@gnu.org>
2015-08-18 15:04   ` Alan Mackenzie [this message]
2015-08-18 16:43     ` N. Jackson
2015-08-19 21:52     ` Stefan Monnier
     [not found]     ` <jwv37zfosr4.fsf-monnier+emacsbugs@gnu.org>
2015-08-20 21:35       ` Drew Adams
2015-08-20 21:55         ` Alan Mackenzie
2015-08-21  5:46           ` Drew Adams
2015-08-21 13:42             ` Stefan Monnier
2015-08-21 15:01               ` Drew Adams
2015-08-19 17:22   ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150818150431.42639.qmail@mail.muc.de \
    --to=acm@muc.de \
    --cc=21275@debbugs.gnu.org \
    --cc=nljlistbox2@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.