2

Using emacsw32.

The usual suggested way to make a selection using S-down-mouse-1 is to bind that to mouse-save-then-kill.

Is there a similar command which selects a region, but does not save the region?

The goal is to have the following scenario:

I have some text in the kill ring. I make a selection by holding shift and clicking the left mouse button. I delete the selection using <delete>. Then I paste something (using cua-paste) and this something is not the same as the region I just deleted.

  • What about (global-set-key [S-drag-mouse-1] (lambda (click) (interactive "e") (let (mouse-drag-copy-region) (mouse-set-region click))))? – Tobias Jun 24 '15 at 12:22
  • That didn't work. Shift + left mouse button, followed by delete and cua-paste produces the text that has been deleted. – zTunUiOHCJM0LidMna0V Jun 24 '15 at 16:49
1

The following works for me:

  1. Start emacs-w32 -Q
  2. Paste the following code into the *scratch*-buffer:
(progn
  (cua-mode)
  (global-set-key [S-drag-mouse-1] (lambda (click) (interactive "e") (let (mouse-drag-copy-region) (mouse-set-region click))))
  (global-set-key [S-down-mouse-1] 'mouse-set-point))

111
222
333
  1. Execute the progn-form with C-x C-e
  2. Select the string "111" with mouse-1 (down and drag) and copy with C-c
  3. Shift-select the string "222" with S-down-mouse-1 and S-drag-mouse-1
  4. Kill the shift-selected string with del
  5. Insert the string "111" from the kill-ring with the key C-v

If I execute M-x emacs-version I get:

GNU Emacs 24.5.1 (x86_64-unknown-cygwin) of 2015-04-10 on desktop-new

It also works with

GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on toyol, modified by Debian

Note, that del runs delete-forward-char while C-x runs indirectly cua-cut-region which copies the cut text to kill-ring.

delete-forward-char deletes the active region if the variable delete-active-region is set to a non-nil value other than 'kill. The standard setting is t.

  • I'm afraid this didn't really work. Using GNU Emacs 23.1.50.1 – zTunUiOHCJM0LidMna0V Jun 24 '15 at 23:25
0

It's not clear to me what S-down-mouse-1 has to do with selecting text. In emacs -Q (no init file), holding Shift and pressing mouse-1 brings up mouse-appearance-menu (menu Change Default Buffer Face).

Anyway, you can do what you want using a command that calls delete-region:

(defun del-region-no-kill (beg end)
  "Delete the active region without killing it."
  (interactive "r")
  (delete-region beg end))

For example:

(global-set-key "\C-o" 'del-region-no-kill)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.