Subject: [[email-masked]: EMACS vs. Windows GUI: Region highlight confusion]

From: Richard Stallman <[email-masked]>
Date: Sat, 17 Aug 1996 03:23:11 -0400

What do you think about this matter?

------- Start of forwarded message -------
Date: Fri, 16 Aug 1996 11:06:46 +0200 (MET DST)
From: "Kim F. Storm" <[email-masked]>
To: [email-masked]
CC: [email-masked]
Subject: EMACS vs. Windows GUI: Region highlight confusion

In windows, I think most applications behave as follows:

	When a piece of text is highlighted in a window (typically
	selected with the mouse) then pressing DELETE will delete the
	highlighted text, and entering other text will replace the
	highlighted text.

Prior to emacs 19.31, there were normally no region highlighting
(unless you had transient-mark-mode turned on, and in that case you
could use the delsel.el package to more or less get the above
behaviour).

Since emacs 19.31, selecting a region with the mouse now leaves the
region highlighted (without setting transient-mark-mode) until the
next input event occurs (e.g. hitting a key).

Now, if I select a region with the mouse, and then hit DELETE, the
highlight disappears, but it is the character which FOLLOWS the region
that is deleted!  If one is not careful, then the removal of the
highlight may easily be mentally interpreted as a deletion of the text
as well - especially because this is normal behaviour for other
windows applications!

The delsel.el package does not handle this case since it requires the
transient-mark-mode to be active - and I do not like that!

Looking at the code, the temporarily highlighting of the region
selected by the mouse is done in the mouse-show-mark function; it
simply reads the next event itself, then removes the highlight and
pushes the event back on the "unread event" queue.

So the delete-char command bound to the DELETE key is actually
executed after the region highlight has been removed; so just writing
another handler for the DELETE key (delete-char-or-mouse-region)
doesn't seem to be possible (or at least hard to do)?!

I'm really not interested in having normal text replacing the
temporarily highlighted region, so it is only the DELETE function I'm
interested in.

When 19.31 was released, I suggested to RMS to handle DELETE as a
special case directly in mouse-show-mark (mouse-drag-region in 19.31),
but he didn't want to do that (I do admit, it was a rather ugly hack).

I have since made the feature configurable via a list of keys which
should delete the highlighted mouse region and adapted my code to
mouse.el from 19.33; the updated mouse-show-mark function is attached
below.

I would like to hear whether other nt-emacs users have any opinions on
this subject, and whether you would like this to be a standard emacs
feature.

- --
Kim F. Storm <[email-masked]>

- ----- put this in mouse.el or in your .emacs ------

(defvar mouse-region-delete-keys '([delete] [backspace])
  "List of keys which shall cause the mouse region to be deleted.")

(defun mouse-show-mark ()
  (if transient-mark-mode
      (if window-system
	  (delete-overlay mouse-drag-overlay))
    (if window-system
	(let ((inhibit-quit t)
	      (echo-keystrokes 0)
	      event events key)
	  (move-overlay mouse-drag-overlay (point) (mark t))
	  (while (progn (setq event (read-event))
			(setq events (append events (list event)))
			(setq key (apply 'vector events))
			(and (memq 'down (event-modifiers event))
			     (not (key-binding key))
			     (not (member key mouse-region-delete-keys))
			     (not (mouse-undouble-last-event events)))))
	  (if (member key mouse-region-delete-keys)
	      (delete-region (overlay-start mouse-drag-overlay)
			     (overlay-end mouse-drag-overlay))
	    (setq unread-command-events
		  (nconc events unread-command-events)))
	  (setq quit-flag nil)
	  (delete-overlay mouse-drag-overlay))
      (save-excursion
       (goto-char (mark t))
       (sit-for 1)))))
------- End of forwarded message -------