From xemacs-m  Sat Jan  4 16:48:01 1997
Received: from steadfast.teradyne.com (steadfast.teradyne.com [131.101.1.200])
          by xemacs.cs.uiuc.edu (8.8.4/8.8.4) with ESMTP
	  id QAA08715 for <xemacs-beta@xemacs.org>; Sat, 4 Jan 1997 16:48:00 -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 RAA06128 for <xemacs-beta@xemacs.org>; Sat, 4 Jan 1997 17:50:56 -0500 (EST)
Received: from rafikki.icd.teradyne.com (rafikki.icd.teradyne.com [131.101.10.38]) by kiki.icd.teradyne.com (8.7.1/8.7.1) with SMTP id RAA27421 for <xemacs-beta@xemacs.org>; Sat, 4 Jan 1997 17:45:29 -0500 (EST)
Received: by rafikki.icd.teradyne.com (SMI-8.6/SMI-SVR4)
	id RAA03691; Sat, 4 Jan 1997 17:45:02 -0500
Sender: shelton@icd.teradyne.com
Newsgroups: comp.emacs.xemacs
cc: xemacs-beta@xemacs.org
Subject: mouse-track-adjust
From: Vinnie Shelton  <shelton@icd.teradyne.com>
Date: 04 Jan 1997 17:45:01 -0500
Message-ID: <545681dgivm.fsf@icd.teradyne.com>
Organization: Teradyne, Inc. Boston MA
Lines: 86
X-Newsreader: Red Gnus v0.76/XEmacs 19.15
Posted-To: comp.emacs.xemacs

The following message is a courtesy copy of an article
that has been posted as well.


Ben Wing contributed some code to the sample.emacs to mimic the FSF
emacs button3 binding:

;; If you like the FSF Emacs binding of button3 (single-click
;; extends the selection, double-click kills the selection),
;; uncomment the following:

;; Under 19.13, the following is enough:
(define-key global-map 'button3 'mouse-track-adjust)

;; Under both 19.12 and 19.13, you also need this:
(add-hook 'mouse-track-click-hook
	  (lambda (event count)
	    (if (or (/= (event-button event) 3)
		    (/= count 2))
		nil ;; do the normal operation
	      (kill-region (point) (mark))
	      t ;; don't do the normal operations.
	      )))

In case it isn't obvious, here's what's going on.  When the
mouse-track-adjust-hook is executed, the lambda function is executed,
and it checks the event count and asks "Was I called for button3?" and
"was the # of clicks equal to 2?".  Not very generic, but it will
serve.  I subsequently modified this code, because in XEmacs,
everybody assumes that button3 brings up a mode-specific menu.  I
decided I'd forgo the FSF compatibility and use double-click shift
button1 to cut the text.  To my mind, this made sense because in FSF
emacs, button3 extends the selection and button3 double-click cuts the
selection.  I decided to put those capabilities on shift button1.  The
following code accomplishes this:

      ;; Mimic the button-3 emacs behavior with shift button1 -
      ;; single click extends the selection, double click removes it.
      ;; This code is far from generic - the literal 1 below is the
      ;; mouse button it's bound to, and the literal 2 is the
      ;; number of clicks required.
      (add-hook 'mouse-track-click-hook
		(lambda (event count)
		  ;; if all the conditions are not met, "and" will
		  ;; return nil, and the following hooks will run.
		  (and (equal count 2)
		       (equal (event-button event) 1)
		       (equal (event-modifiers event) '(shift))
		       ;; Since kill-region returns non-nil, this hook
		       ;; will prevent other hooks from executing
		       (kill-region (point) (mark)))))

But, as the comment indicates, I'm dissatisfied with the way this
works.  I'd like a much more general way of doing this.  I'd like to
create a function which would install the proper handler to do this,
something like this:

  (extend-and-cut-selection KEY NUMBER_OF_CLICKS)

This would take a keysym and a number of clicks, and any newbie could
use it like so:

  (extend-and-cut-selection '(ctrl meta hyper super shift button3) 3)

Writing this function and the hook it installs have proven to be
difficult:

1) In the hook function I can figure out what modifiers have been
   depressed by using event-modifier-bits, which returns a bitmask.
   How can I figure out what the bitmask associated with a particular
   keysym is?  Alternatively, I can use event-modifiers, which returns
   something like '(shift ctrl), but then I think I have to *sort* the
   modifiers so they are always in the correct order.  In a hook -
   yuck!  I wanted to use  event-matches-key-specifier-p, but this
   doesn't work with mouse buttons.

2) How do I convert something like the symbol button3 to the proper
   event-number (3 in this case)?

Can anyone offer any help/insight/code to do this?

Thanks,
  Vin Shelton

-- 
The geometry of innocent flesh on the bone
causes Galileo's matchbook to be thrown
at Delilah who's sitting worthlessly alone,
but the tears on her cheeks are from laughter       Bob Dylan, Tombstone Blues

