Subject: bug#21275: 24.5; Selection deleted with electric pair mode in cc mode

From: [email-masked] (N. Jackson)
Date: Sun, 16 Aug 2015 10:31:38 -0300

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.

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)

Configured using:
 `configure --prefix=/home/nlj/local/ --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3 -ggdb''

Important settings:
  value of $LC_MONETARY: en_DK.utf8
  value of $LC_NUMERIC: en_DK.utf8
  value of $LC_TIME: en_DK.utf8
  value of $LANG: en_CA.utf8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: C/l

Minor modes in effect:
  flyspell-mode: t
  recentf-mode: t
  delete-selection-mode: t
  show-paren-mode: t
  savehist-mode: t
  electric-pair-mode: t
  display-time-mode: t
  display-battery-mode: t
  desktop-save-mode: t
  cua-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  size-indication-mode: t
  column-number-mode: t
  line-number-mode: t
  global-visual-line-mode: t
  visual-line-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent messages:
Auto-saving...done
Making completion list...
Type C-x 1 to delete the help window.
Undo! [2 times]
Auto-saving...
Updating buffer list...done
Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help
Mark set
Mark saved where search started
Mark set
call-interactively: End of buffer

Load-path shadows:
/home/nlj/.emacs.d/elpa/org-20150810/ob-gnuplot hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-gnuplot
/home/nlj/.emacs.d/elpa/org-20150810/org-eshell hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-eshell
/home/nlj/.emacs.d/elpa/org-20150810/ox-md hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-md
/home/nlj/.emacs.d/elpa/org-20150810/ob-shen hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-shen
/home/nlj/.emacs.d/elpa/org-20150810/org-timer hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-timer
/home/nlj/.emacs.d/elpa/org-20150810/ob-ruby hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-ruby
/home/nlj/.emacs.d/elpa/org-20150810/ox hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox
/home/nlj/.emacs.d/elpa/org-20150810/ox-html hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-html
/home/nlj/.emacs.d/elpa/org-20150810/ob-latex hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-latex
/home/nlj/.emacs.d/elpa/org-20150810/org-archive hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-archive
/home/nlj/.emacs.d/elpa/org-20150810/ob-org hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-org
/home/nlj/.emacs.d/elpa/org-20150810/org-install hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-install
/home/nlj/.emacs.d/elpa/org-20150810/ox-latex hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-latex
/home/nlj/.emacs.d/elpa/org-20150810/ob-sass hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-sass
/home/nlj/.emacs.d/elpa/org-20150810/ox-icalendar hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-icalendar
/home/nlj/.emacs.d/elpa/org-20150810/ob-screen hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-screen
/home/nlj/.emacs.d/elpa/org-20150810/org-bibtex hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-bibtex
/home/nlj/.emacs.d/elpa/org-20150810/org-footnote hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-footnote
/home/nlj/.emacs.d/elpa/org-20150810/org-datetree hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-datetree
/home/nlj/.emacs.d/elpa/org-20150810/org-colview hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-colview
/home/nlj/.emacs.d/elpa/org-20150810/org-attach hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-attach
/home/nlj/.emacs.d/elpa/org-20150810/org-mouse hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-mouse
/home/nlj/.emacs.d/elpa/org-20150810/ob-dot hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-dot
/home/nlj/.emacs.d/elpa/org-20150810/ob-scala hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-scala
/home/nlj/.emacs.d/elpa/org-20150810/org-compat hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-compat
/home/nlj/.emacs.d/elpa/org-20150810/ob-core hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-core
/home/nlj/.emacs.d/elpa/org-20150810/ob-awk hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-awk
/home/nlj/.emacs.d/elpa/org-20150810/ob-makefile hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-makefile
/home/nlj/.emacs.d/elpa/org-20150810/org-macro hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-macro
/home/nlj/.emacs.d/elpa/org-20150810/org-ctags hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-ctags
/home/nlj/.emacs.d/elpa/org-20150810/org-capture hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-capture
/home/nlj/.emacs.d/elpa/org-20150810/ox-beamer hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-beamer
/home/nlj/.emacs.d/elpa/org-20150810/org-mobile hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-mobile
/home/nlj/.emacs.d/elpa/org-20150810/org-indent hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-indent
/home/nlj/.emacs.d/elpa/org-20150810/ob-lilypond hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-lilypond
/home/nlj/.emacs.d/elpa/org-20150810/ob-asymptote hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-asymptote
/home/nlj/.emacs.d/elpa/org-20150810/ox-odt hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-odt
/home/nlj/.emacs.d/elpa/org-20150810/org-w3m hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-w3m
/home/nlj/.emacs.d/elpa/org-20150810/ob-plantuml hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-plantuml
/home/nlj/.emacs.d/elpa/org-20150810/ob-table hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-table
/home/nlj/.emacs.d/elpa/org-20150810/ob-ocaml hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-ocaml
/home/nlj/.emacs.d/elpa/org-20150810/org-crypt hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-crypt
/home/nlj/.emacs.d/elpa/org-20150810/ob-js hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-js
/home/nlj/.emacs.d/elpa/org-20150810/ob-clojure hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-clojure
/home/nlj/.emacs.d/elpa/org-20150810/ob-haskell hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-haskell
/home/nlj/.emacs.d/elpa/org-20150810/org-version hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-version
/home/nlj/.emacs.d/elpa/org-20150810/ob-scheme hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-scheme
/home/nlj/.emacs.d/elpa/org-20150810/org-table hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-table
/home/nlj/.emacs.d/elpa/org-20150810/ob-C hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-C
/home/nlj/.emacs.d/elpa/org-20150810/ob-ledger hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-ledger
/home/nlj/.emacs.d/elpa/org-20150810/ob-fortran hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-fortran
/home/nlj/.emacs.d/elpa/org-20150810/ob-sql hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-sql
/home/nlj/.emacs.d/elpa/org-20150810/org hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org
/home/nlj/.emacs.d/elpa/org-20150810/org-loaddefs hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-loaddefs
/home/nlj/.emacs.d/elpa/org-20150810/org-list hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-list
/home/nlj/.emacs.d/elpa/org-20150810/ob-lisp hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-lisp
/home/nlj/.emacs.d/elpa/org-20150810/org-docview hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-docview
/home/nlj/.emacs.d/elpa/org-20150810/ob-eval hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-eval
/home/nlj/.emacs.d/elpa/org-20150810/org-element hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-element
/home/nlj/.emacs.d/elpa/org-20150810/ob hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob
/home/nlj/.emacs.d/elpa/org-20150810/ox-ascii hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-ascii
/home/nlj/.emacs.d/elpa/org-20150810/org-info hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-info
/home/nlj/.emacs.d/elpa/org-20150810/ob-css hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-css
/home/nlj/.emacs.d/elpa/org-20150810/org-rmail hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-rmail
/home/nlj/.emacs.d/elpa/org-20150810/org-irc hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-irc
/home/nlj/.emacs.d/elpa/org-20150810/ob-tangle hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-tangle
/home/nlj/.emacs.d/elpa/org-20150810/ob-ditaa hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-ditaa
/home/nlj/.emacs.d/elpa/org-20150810/org-feed hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-feed
/home/nlj/.emacs.d/elpa/org-20150810/org-clock hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-clock
/home/nlj/.emacs.d/elpa/org-20150810/org-habit hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-habit
/home/nlj/.emacs.d/elpa/org-20150810/org-pcomplete hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-pcomplete
/home/nlj/.emacs.d/elpa/org-20150810/org-entities hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-entities
/home/nlj/.emacs.d/elpa/org-20150810/ob-io hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-io
/home/nlj/.emacs.d/elpa/org-20150810/ob-octave hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-octave
/home/nlj/.emacs.d/elpa/org-20150810/org-faces hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-faces
/home/nlj/.emacs.d/elpa/org-20150810/ob-perl hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-perl
/home/nlj/.emacs.d/elpa/org-20150810/org-src hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-src
/home/nlj/.emacs.d/elpa/org-20150810/org-protocol hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-protocol
/home/nlj/.emacs.d/elpa/org-20150810/ox-man hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-man
/home/nlj/.emacs.d/elpa/org-20150810/ob-python hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-python
/home/nlj/.emacs.d/elpa/org-20150810/ob-mscgen hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-mscgen
/home/nlj/.emacs.d/elpa/org-20150810/ox-texinfo hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-texinfo
/home/nlj/.emacs.d/elpa/org-20150810/ob-exp hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-exp
/home/nlj/.emacs.d/elpa/org-20150810/org-inlinetask hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-inlinetask
/home/nlj/.emacs.d/elpa/org-20150810/ox-publish hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-publish
/home/nlj/.emacs.d/elpa/org-20150810/ob-java hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-java
/home/nlj/.emacs.d/elpa/org-20150810/ob-sqlite hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-sqlite
/home/nlj/.emacs.d/elpa/org-20150810/org-mhe hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-mhe
/home/nlj/.emacs.d/elpa/org-20150810/ox-org hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ox-org
/home/nlj/.emacs.d/elpa/org-20150810/ob-R hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-R
/home/nlj/.emacs.d/elpa/org-20150810/ob-lob hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-lob
/home/nlj/.emacs.d/elpa/org-20150810/ob-picolisp hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-picolisp
/home/nlj/.emacs.d/elpa/org-20150810/org-agenda hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-agenda
/home/nlj/.emacs.d/elpa/org-20150810/ob-matlab hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-matlab
/home/nlj/.emacs.d/elpa/org-20150810/org-gnus hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-gnus
/home/nlj/.emacs.d/elpa/org-20150810/org-macs hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-macs
/home/nlj/.emacs.d/elpa/org-20150810/org-id hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-id
/home/nlj/.emacs.d/elpa/org-20150810/ob-keys hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-keys
/home/nlj/.emacs.d/elpa/org-20150810/ob-comint hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-comint
/home/nlj/.emacs.d/elpa/org-20150810/ob-ref hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-ref
/home/nlj/.emacs.d/elpa/org-20150810/org-bbdb hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-bbdb
/home/nlj/.emacs.d/elpa/org-20150810/ob-calc hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-calc
/home/nlj/.emacs.d/elpa/org-20150810/ob-emacs-lisp hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-emacs-lisp
/home/nlj/.emacs.d/elpa/org-20150810/ob-maxima hides /data/projects/vc/emacs/emacs-24.5/lisp/org/ob-maxima
/home/nlj/.emacs.d/elpa/org-20150810/org-plot hides /data/projects/vc/emacs/emacs-24.5/lisp/org/org-plot
~/.emacs.d/modules/emms/lisp/tq hides /data/projects/vc/emacs/emacs-24.5/lisp/emacs-lisp/tq

Features:
(shadow emacsbug help-mode url-queue eww gnus-fun flow-fill shr-color
color mailalias smtpmail bbdb-message sendmail nnir gnus-dup solar
cal-dst holidays hol-loaddefs mule-util cal-move bookmark org-clock
tabify org-capture ibuf-ext ibuffer shr gnus-html browse-url smiley
gnus-cite gnus-bcklg pp gnus-async qp mail-extr gnus-ml disp-table
misearch multi-isearch nndraft nnmh mm-archive url-http url-gw url-cache
url-auth url-handlers nnrss xml mm-url utf-7 nnimap utf7 gnutls nnfolder
parse-time bbdb-gnus bbdb-mua epa-file epa derived epg netrc
network-stream starttls tls gnus-agent gnus-srvr gnus-score score-mode
nnvirtual gnus-msg gnus-art mm-uu mml2015 epg-config mm-view mml-smime
smime dig nntp gnus-cache gnus-sum nnoo gnus-group gnus-undo nnmail
mail-source gnus-start gnus-spec gnus-int gnus-range message rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums gmm-utils mailheader gnus-win gnus gnus-ems nnheader
mail-utils flyspell ispell cc-langs cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs sage sage-load cl
rx emms-bookmarks emms-cue emms-mode-line-icon emms-browser sort
emms-playlist-sort emms-last-played emms-player-xine emms-player-mpd tq
emms-playing-time emms-lyrics emms-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
url-parse auth-source eieio byte-opt bytecomp byte-compile cl-extra
cconv eieio-core mm-util mail-prsvr password-cache url-vars mailcap
emms-streams emms-tag-editor emms-mark emms-mode-line emms-cache
emms-info-ogginfo emms-info-mp3info emms-info later-do
emms-playlist-mode emms-player-vlc emms-player-mplayer
emms-player-simple emms-source-playlist emms-source-file locate
emms-setup emms emms-compat compile cl-macs gv org-rmail org-mhe org-irc
org-info org-gnus gnus-util org-docview doc-view jka-compr image-mode
dired org-bibtex bibtex org-bbdb org-element avl-tree org-w3m org-agenda
org advice help-fns org-macro org-footnote org-pcomplete pcomplete
org-list org-faces org-entities noutline outline easy-mmode org-version
ob-emacs-lisp ob ob-tangle ob-ref ob-lob ob-table ob-exp org-src ob-keys
ob-comint comint ansi-color ring ob-core ob-eval org-compat org-macs
org-loaddefs format-spec find-func bbdb-anniv diary-lib diary-loaddefs
cal-menu calendar cal-loaddefs bbdb-com crm mailabbrev bbdb bbdb-site
timezone bbdb-loaddefs tex-site info package edmacro kmacro recentf
tree-widget wid-edit easymenu saveplace wheatgrass-theme delsel paren
savehist elec-pair time battery desktop frameset cl-loaddefs cl-lib
cua-base cus-start cus-load time-date tooltip electric uniquify
ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 555789 98749)
 (symbols 48 60041 0)
 (miscs 40 6345 6191)
 (strings 32 143249 27034)
 (string-bytes 1 5112701)
 (vectors 16 49403)
 (vector-slots 8 1734765 261112)
 (floats 8 922 1502)
 (intervals 56 9732 685)
 (buffers 960 103)
 (heap 1024 112144 35561))