From xemacs-m  Mon Jan 13 21:52:57 1997
Received: from steadfast.teradyne.com (steadfast.teradyne.com [131.101.1.200])
          by xemacs.org (8.8.4/8.8.4) with ESMTP
	  id VAA08877 for <xemacs-beta@xemacs.org>; Mon, 13 Jan 1997 21:52:57 -0600 (CST)
Received: from kiki.icd.teradyne.com (kiki.icd.teradyne.com [131.101.1.30]) by steadfast.teradyne.com (8.7.1/8.7.1) with ESMTP id WAA04199 for <xemacs-beta@xemacs.org>; Mon, 13 Jan 1997 22:55:51 -0500 (EST)
Received: from spacely.icd.teradyne.com (spacely.icd.teradyne.com [131.101.10.9]) by kiki.icd.teradyne.com (8.7.1/8.7.1) with SMTP id WAA10870 for <xemacs-beta@xemacs.org>; Mon, 13 Jan 1997 22:50:15 -0500 (EST)
Received: from spacely by spacely.icd.teradyne.com (SMI-8.6/SMI-SVR4)
	id WAA17258; Mon, 13 Jan 1997 22:52:31 -0500
Message-Id: <199701140352.WAA17258@spacely.icd.teradyne.com>
X-Mailer: exmh version 2.0beta 12/23/96
To: xemacs-beta@xemacs.org
reply-to: acs@acm.org
Subject: mouse-extend-and-cut
Mime-Version: 1.0
Content-Type: multipart/mixed ;
	boundary="==_Exmh_13434681560"
Date: Mon, 13 Jan 1997 22:52:30 -0500
From: Vinnie Shelton  <shelton@icd.teradyne.com>

This is a multipart MIME message.

--==_Exmh_13434681560
Content-Type: text/plain; charset=us-ascii

Steve,
    I refined my mouse selection stuff.  I hope you can put this function 
in one of: the FAQ, sample.emacs, or perhaps even in lisp/prim/mouse.el.  
The basic idea is that the should be able to easily define a key (like 
button3 in FSF emacs) which will with one click extend the selection, and 
with a double-click cut the selection.  The docstring mentions possible 
XEmacs and FSF-compatible bindings.  Lemme know what you think.



--==_Exmh_13434681560
Content-Type: application/octet-stream ; name="mouse.el"
Content-Description: mouse.el
Content-Disposition: attachment; filename="mouse.el"

(defun mouse-extend-and-cut (key)
  "Extend and cut a selection via a mouse key.
Clicking the specified button once will extend the selection.
Double-clicking the specified button will cut the selection.
An XEmacs-style default for this is: (mouse-extend-and-cut '(shift button1)).
An FSF-compatible binding is: (mouse-extend-and-cut 'button3)."
	(interactive)

	;; Define the variables needed by the hook function
	(let* ((modifiers (if (listp key)
			      (nreverse (copy-sequence key))
			    (list key)))
	       (button (let
			   ((k (car modifiers)))
			 (cond ((equal k 'button1) 1)
			       ((equal k 'button2) 2)
			       ((equal k 'button3) 3)
			       ((equal k 'button4) 4)
			       ((equal k 'button5) 5)
			       ((error "Illegal mouse button %s" k)))))
	       (modifiers (sort (cdr modifiers) 'string<)))

	  ;; Now make sure the key is defined
	  (define-key global-map key 'mouse-track-adjust)

	  ;; Now add the hook function
	  (add-hook 'mouse-track-click-hook
		    `(lambda (ev cnt)
		       (and (= cnt 2)
			    (= (event-button ev) ,button)
			    (equal (sort (event-modifiers ev) 'string<)
				   ',modifiers)

			    ;; Since kill-region returns non-nil, this hook
			    ;; will prevent following hooks from executing
			    (kill-region (point) (mark)))))))
--==_Exmh_13434681560--


