Subject: 24.3; delete-region is altering the kill ring

From: Jeff B <[email-masked]>
Date: Mon, 29 Apr 2013 23:36:55 -0400

Hi,

A while back I upgraded my Linux installation to the latest version of
Slackware. With that came a new Emacs. Right away two of my eLisp
functions failed. I use them all the time and they have been working
for years. I was unable to get a reproducible fault sequence out of
them so I just kind of ignored the problem by not using those functions.

Then I was loaned a Windows laptop to do some work I had to do on
Windows so I installed the latest Emacs there and noticed that my
two functions were working. So I came back to my Linux machine (from
which this eMail is coming) and installed the latest Emacs here thinking
that the bug was fixed. No such luck.

The simpler of the two functions is this:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

;; Convenience function to delete words without a trace, like 
delete-char does
;; not (normally) alter kill ring or mark.
(defun my-erase-word (count) "
    Erases <count> forward words without affecting the kill ring or mark.
    Useful for deleting words after inserting new words in front of the 
old."
    (interactive "p")
    (mark-word count)
    (delete-region (mark) (point))
    (set-mark-command 2)
)
(global-set-key [kp-delete] 'my-erase-word) ;; Conveniently next to 
[kp-insert]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

Usually I use the above to replace a string or strings of words with a
single string I have copied onto the kill ring. It's kind of like
query-replace except that I can be replacing different things. It's
convenient too: Left hand on mouse, right hand on keypad Ins/Del.

Anyway delete-region seems to be making a record of what it deletes the
first time I do the delete after the first insert so that when I do the
second insert it gives me the first thing I deleted. Usually. It will
rarely do what it used to do and is supposed to do. The first thing I
delete with the function above does not show up in the kill ring until
AFTER I do the second insert. ????

Anyway delete-region is documented as not affecting the kill ring,

      (delete-region START END)

      Delete the text between START and END.
      If called interactively, delete the region between point and mark.
      This command deletes buffer text without modifying the kill ring.

which is why I used it in the first place. It didn't used to affect the
kill ring and so each insert would get me the original string which I
wanted to use over and over.

Now clearly somehow delete-region does set something up to go into the
kill ring, tho as I've said above it doesn't appear there until I do the
second insert. Mostly.

I need to emphasize that this problem is NOT ALWAYS reproducible (which
is why I gave up trying to send you something nice and neat to fix back
when I first ran into the problem) and that what shows up in the kill
ring can be different from test to test.

Thanks for looking at this. I wish I could give you better information.

Jeff Barry
[email-masked]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

In GNU Emacs 24.3.1 (i486-slackware-linux-gnu, GTK+ Version 2.24.17)
of 2013-04-23 on hive
Windowing system distributor `The X.Org Foundation', version 11.0.11203000
Configured using:
`configure '--prefix=/usr' '--sysconfdir=/etc' '--localstatedir=/var'
'--program-prefix=' '--program-suffix=' '--mandir=/usr/man'
'--infodir=/usr/info' '--without-gconf' '--without-gsettings'
'--with-x' '--with-x-toolkit=gtk2' '--build=i486-slackware-linux'
'build_alias=i486-slackware-linux' 'CFLAGS=-O2 -march=i486
-mtune=i686''

Important settings:
value of $LC_COLLATE: C
value of $LANG: en_US
locale-coding-system: iso-latin-1-unix
default enable-multibyte-characters: t

Major mode: Fundamental

Minor modes in effect:
tooltip-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t

Recent input:
C-s C-s C-s <return> <return> C-x 1 <help-echo> <switch-frame>
<down-mouse-1> <mouse-movement> <mouse-1> C-z C-z C-z
C-z C-z C-z C-z C-z C-z C-z C-z C-z C-z C-z C-z C-z
C-z C-z C-z C-z C-z <down-mouse-1> <mouse-movement>
<mouse-movement> <drag-mouse-1> <down-mouse-1> <mouse-1>
<escape> d C-y C-f <escape> d <escape> x y a n k <tab>
- p o p <return> <switch-frame> <down-mouse-1> <mouse-movement>
<mouse-1> <help-echo> <down-mouse-1> <mouse-2> <switch-frame>
<down-mouse-1> <mouse-movement> <mouse-1> C-z C-z C-z
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <down-mouse-1>
<mouse-1> <escape> d C-y C-f <escape> d <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <escape>
x y a n k <tab> - <tab> p o p <return> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
C-z <switch-frame> <down-mouse-1> <mouse-movement>
<mouse-1> <down-mouse-5> <mouse-5> <double-down-mouse-5>
<double-mouse-5> <triple-down-mouse-5> <triple-mouse-5>
<down-mouse-4> <mouse-4> <double-down-mouse-4> <double-mouse-4>
<triple-down-mouse-4> <triple-mouse-4> <down-mouse-4>
<mouse-4> <down-mouse-5> <mouse-5> <down-mouse-5> <mouse-5>
<double-down-mouse-5> <double-mouse-5> <down-mouse-4>
<mouse-4> <double-down-mouse-4> <double-mouse-4> <triple-down-mouse-4>
<triple-mouse-4> <triple-down-mouse-4> <triple-mouse-4>
<triple-down-mouse-4> <triple-mouse-4> <switch-frame>
<down-mouse-1> <mouse-movement> <mouse-1> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <help-echo>
<help-echo> <help-echo> <help-echo> <help-echo> <down-mouse-1>
<mouse-1> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> 4 <down-mouse-1> <mouse-1>
<return> <return> <down-mouse-1> <mouse-1> <escape>
x d p f <return> m K a r + F * ^ & v i n 3 = m a g
i k SPC <return> C-s f s f <help-echo> <down-mouse-1>
<mouse-movement> <mouse-movement> <drag-mouse-1> <help-echo>
<help-echo> <help-echo> <help-echo> <down-mouse-1>
<mouse-movement> <mouse-1> <help-echo> <down-mouse-1>
<mouse-1> <escape> x r e p o r t <tab> <return> <help-echo>
<down-mouse-1> <mouse-1> C-x b <help-echo> <help-echo>
<help-echo> <switch-frame> <help-echo> <help-echo>
C-x b q b . <tab> <return> <down-mouse-1> <mouse-movement>
<mouse-movement> <drag-mouse-1> <help-echo> <switch-frame>
<down-mouse-1> <mouse-movement> <mouse-1> <escape>
x l k j s a d l j k s d l j <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> r e p o r t <tab> <return>

Recent messages:
Mark set
Making completion list...
yank-pop: Previous command was not a yank
Undo!
byte-code: Beginning of buffer [3 times]
Mark set
Modification-flag cleared
Mark set [3 times]
Done!
Mark saved where search started
byte-code: Command attempted to use minibuffer while in minibuffer

Load-path shadows:
/usr/share/emacs/site-lisp/t-mouse hides /usr/share/emacs/24.3/lisp/t-mouse

Features:
(shadow sort gnus-util mail-extr emacsbug message idna cl-macs gv
format-spec rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse
rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils info cus-edit cus-start
cus-load wid-edit apropos misearch multi-isearch help-mode parse-time
vc-cvs uniquify advice help-fns advice-preload cc-langs cl cl-lib
cc-mode cc-fonts easymenu cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs time-stamp jka-compr time-date tooltip
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
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 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
dynamic-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)