GNU bug report logs - #4478
23.1; key bindings for mouse wheel - unclear

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Severity: minor; Reported by: "Drew Adams" <drew.adams@HIDDEN>; dated Fri, 18 Sep 2009 07:55:05 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 4478@HIDDEN:


Received: (at 4478) by emacsbugs.donarmstrong.com; 18 Sep 2009 13:34:22 +0000
From monnier@HIDDEN Fri Sep 18 06:34:21 2009
X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02
	(2008-06-10) on rzlab.ucr.edu
X-Spam-Level: 
X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available.
	hammytokens:Tokens not available.
X-Spam-Status: No, score=-3.6 required=4.0 tests=AWL,FOURLA,HAS_BUG_NUMBER
	autolearn=ham version=3.2.5-bugs.debian.org_2005_01_02
Received: from ironport2-out.pppoe.ca (ironport2-out.teksavvy.com [206.248.154.181])
	by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n8IDYK73022268
	for <4478@HIDDEN>; Fri, 18 Sep 2009 06:34:21 -0700
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AtYEACcps0pLd/GK/2dsb2JhbACBUs1JhBwFh34
X-IronPort-AV: E=Sophos;i="4.44,409,1249272000"; 
   d="scan'208";a="46009611"
Received: from 75-119-241-138.dsl.teksavvy.com (HELO pastel.home) ([75.119.241.138])
  by ironport2-out.pppoe.ca with ESMTP; 18 Sep 2009 09:34:14 -0400
Received: by pastel.home (Postfix, from userid 20848)
	id 6BB2E801B; Fri, 18 Sep 2009 09:34:14 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Drew Adams <drew.adams@HIDDEN>
Cc: 4478 <at> debbugs.gnu.org, <bug-gnu-emacs@HIDDEN>
Subject: Re: bug#4478: 23.1; key bindings for mouse wheel - unclear
Message-ID: <jwv7hvwxu1w.fsf-monnier+emacsbugreports@HIDDEN>
References: <625E5DF5465B4A1CBF3FBB6015CBB87D@HIDDEN>
Date: Fri, 18 Sep 2009 09:34:14 -0400
In-Reply-To: <625E5DF5465B4A1CBF3FBB6015CBB87D@HIDDEN> (Drew Adams's
	message of "Fri, 18 Sep 2009 00:48:12 -0700")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

> 1. Doc bug: The doc is not clear about how to bind the mouse wheel
> (rotations).

Indeed.  The way to do it is currently messy and ugly.
 
> I've been using bindings such as this:
 
> (define-key map [wheel-down]   'aaa)
> (define-key map [wheel-down]   'bbb)
> (define-key map [C-wheel-down] 'ccc)
> (define-key map [C-wheel-down] 'ddd)

IIUC this is "the right way".  And it works under w32 and ns.
Under X11, sadly, mouse-wheel events are usually represented as mouse
clicks for buttons 4 and 5, and there's no way for Emacs to know whether
these correspond to mouse clicks (on mice with more than 3 buttons) or
mouse-wheel events.  Worse yet, Emacs doesn't offer an easy way to map
all the variants of `mouse-4' and `mouse-5' (with and without each of
the possible modifiers) to wheel-up and wheel-down.

The code appended below does manage to do such a remap, but as you can
see it's ugly, and worse yet: there can only be one such thing because
it uses the "default" binding.  [ And it probably won't work with
xterm-mouse-mode. ]
 
> (define-key map (vector mouse-wheel-down-event) 'aaa)
> (define-key map (vector mouse-wheel-up-event)   'bbb)
> (define-key map
>   (vector (list 'control mouse-wheel-down-event)) 'ccc)
> (define-key map
>   (vector (list 'control mouse-wheel-up-event)) 'ddd)
 
> I haven't tested on GNU/Linux, but I'm assuming this is what to use
> for portable code. Is there a shorter or better way to say this and
> still be portable? 

I think this is about as good as it gets for now, yes.
 
> 1. If there is not, there should be (a shorter way to do this).

The [wheel-down] and friends shown above is what there should be.
 

        Stefan


(define-key function-key-map [t]
	 '(menu-item "" nil
	   :filter sm-rewrite-mwheel))

(defun sm-rewrite-mwheel (ignore)
  (let* ((events (this-single-command-raw-keys))
         (event (unless (zerop (length events))
                  (aref events (1- (length events))))))
    (message "sm-rewrite-mwheel: key=%s" event)
    (case (event-basic-type event)
      (mouse-4
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-up))))
              (new-event (cons new-key (cdr event))))
         (vector new-event)))
      (mouse-5
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-down))))
              (new-event (cons new-key (cdr event))))
         (vector new-event))))))



Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs@HIDDEN>. Full text available.
Information forwarded to bug-submit-list@HIDDEN, Emacs Bugs <bug-gnu-emacs@HIDDEN>:
bug#4478; Package emacs. Full text available.

Message received at submit@HIDDEN:


Received: (at submit) by emacsbugs.donarmstrong.com; 18 Sep 2009 13:34:23 +0000
From monnier@HIDDEN Fri Sep 18 06:34:23 2009
X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02
	(2008-06-10) on rzlab.ucr.edu
X-Spam-Level: 
X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available.
	hammytokens:Tokens not available.
X-Spam-Status: No, score=-3.6 required=4.0 tests=AWL,FOURLA,HAS_BUG_NUMBER
	autolearn=unavailable version=3.2.5-bugs.debian.org_2005_01_02
Received: from lists.gnu.org (lists.gnu.org [199.232.76.165])
	by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n8IDYLsW022269
	for <submit@HIDDEN>; Fri, 18 Sep 2009 06:34:22 -0700
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1ModbR-0003Tu-1z
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 09:34:21 -0400
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1ModbM-0003OI-5e
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 09:34:20 -0400
Received: from [199.232.76.173] (port=58292 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43)
	id 1ModbL-0003O3-Up
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 09:34:16 -0400
Received: from ironport2-out.teksavvy.com ([206.248.154.181]:10175 helo=ironport2-out.pppoe.ca)
	by monty-python.gnu.org with esmtp (Exim 4.60)
	(envelope-from <monnier@HIDDEN>)
	id 1ModbL-0000wR-EA
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 09:34:15 -0400
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AtYEACcps0pLd/GK/2dsb2JhbACBUs1JhBwFh34
X-IronPort-AV: E=Sophos;i="4.44,409,1249272000"; 
   d="scan'208";a="46009611"
Received: from 75-119-241-138.dsl.teksavvy.com (HELO pastel.home) ([75.119.241.138])
  by ironport2-out.pppoe.ca with ESMTP; 18 Sep 2009 09:34:14 -0400
Received: by pastel.home (Postfix, from userid 20848)
	id 6BB2E801B; Fri, 18 Sep 2009 09:34:14 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Drew Adams <drew.adams@HIDDEN>
Cc: 4478 <at> debbugs.gnu.org, <bug-gnu-emacs@HIDDEN>
Subject: Re: bug#4478: 23.1; key bindings for mouse wheel - unclear
Message-ID: <jwv7hvwxu1w.fsf-monnier+emacsbugreports@HIDDEN>
References: <625E5DF5465B4A1CBF3FBB6015CBB87D@HIDDEN>
Date: Fri, 18 Sep 2009 09:34:14 -0400
In-Reply-To: <625E5DF5465B4A1CBF3FBB6015CBB87D@HIDDEN> (Drew Adams's
	message of "Fri, 18 Sep 2009 00:48:12 -0700")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized.

> 1. Doc bug: The doc is not clear about how to bind the mouse wheel
> (rotations).

Indeed.  The way to do it is currently messy and ugly.
 
> I've been using bindings such as this:
 
> (define-key map [wheel-down]   'aaa)
> (define-key map [wheel-down]   'bbb)
> (define-key map [C-wheel-down] 'ccc)
> (define-key map [C-wheel-down] 'ddd)

IIUC this is "the right way".  And it works under w32 and ns.
Under X11, sadly, mouse-wheel events are usually represented as mouse
clicks for buttons 4 and 5, and there's no way for Emacs to know whether
these correspond to mouse clicks (on mice with more than 3 buttons) or
mouse-wheel events.  Worse yet, Emacs doesn't offer an easy way to map
all the variants of `mouse-4' and `mouse-5' (with and without each of
the possible modifiers) to wheel-up and wheel-down.

The code appended below does manage to do such a remap, but as you can
see it's ugly, and worse yet: there can only be one such thing because
it uses the "default" binding.  [ And it probably won't work with
xterm-mouse-mode. ]
 
> (define-key map (vector mouse-wheel-down-event) 'aaa)
> (define-key map (vector mouse-wheel-up-event)   'bbb)
> (define-key map
>   (vector (list 'control mouse-wheel-down-event)) 'ccc)
> (define-key map
>   (vector (list 'control mouse-wheel-up-event)) 'ddd)
 
> I haven't tested on GNU/Linux, but I'm assuming this is what to use
> for portable code. Is there a shorter or better way to say this and
> still be portable? 

I think this is about as good as it gets for now, yes.
 
> 1. If there is not, there should be (a shorter way to do this).

The [wheel-down] and friends shown above is what there should be.
 

        Stefan


(define-key function-key-map [t]
	 '(menu-item "" nil
	   :filter sm-rewrite-mwheel))

(defun sm-rewrite-mwheel (ignore)
  (let* ((events (this-single-command-raw-keys))
         (event (unless (zerop (length events))
                  (aref events (1- (length events))))))
    (message "sm-rewrite-mwheel: key=%s" event)
    (case (event-basic-type event)
      (mouse-4
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-up))))
              (new-event (cons new-key (cdr event))))
         (vector new-event)))
      (mouse-5
       (let* ((mods (delete 'click (event-modifiers event)))
              (new-key (event-convert-list (append mods '(wheel-down))))
              (new-event (cons new-key (cdr event))))
         (vector new-event))))))




Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs@HIDDEN>. Full text available.
Information forwarded to bug-submit-list@HIDDEN, Emacs Bugs <bug-gnu-emacs@HIDDEN>:
bug#4478; Package emacs. Full text available.

Message received at submit@HIDDEN:


Received: (at submit) by emacsbugs.donarmstrong.com; 18 Sep 2009 07:48:22 +0000
From drew.adams@HIDDEN Fri Sep 18 00:48:22 2009
X-Spam-Checker-Version: SpamAssassin 3.2.5-bugs.debian.org_2005_01_02
	(2008-06-10) on rzlab.ucr.edu
X-Spam-Level: 
X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available.
	hammytokens:Tokens not available.
X-Spam-Status: No, score=-2.4 required=4.0 tests=AWL,FOURLA autolearn=no
	version=3.2.5-bugs.debian.org_2005_01_02
Received: from lists.gnu.org (lists.gnu.org [199.232.76.165])
	by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n8I7mLtB032172
	for <submit@HIDDEN>; Fri, 18 Sep 2009 00:48:22 -0700
Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43)
	id 1MoYCa-0003DX-P0
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 03:48:20 -0400
Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43)
	id 1MoYCV-00039m-Co
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 03:48:19 -0400
Received: from [199.232.76.173] (port=56979 helo=monty-python.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43)
	id 1MoYCV-00039j-6m
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 03:48:15 -0400
Received: from mx20.gnu.org ([199.232.41.8]:50941)
	by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32)
	(Exim 4.60)
	(envelope-from <drew.adams@HIDDEN>)
	id 1MoYCU-0006xb-Mp
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 03:48:14 -0400
Received: from acsinet12.oracle.com ([141.146.126.234])
	by mx20.gnu.org with esmtp (Exim 4.60)
	(envelope-from <drew.adams@HIDDEN>)
	id 1MoYCT-0001M3-VI
	for bug-gnu-emacs@HIDDEN; Fri, 18 Sep 2009 03:48:14 -0400
Received: from rgminet13.oracle.com (rcsinet13.oracle.com [148.87.113.125])
	by acsinet12.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n8I7lPxv020644
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <bug-gnu-emacs@HIDDEN>; Fri, 18 Sep 2009 07:47:26 GMT
Received: from abhmt010.oracle.com (abhmt010.oracle.com [141.146.116.19])
	by rgminet13.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n8I7mXHh004663
	for <bug-gnu-emacs@HIDDEN>; Fri, 18 Sep 2009 07:48:34 GMT
Received: from dradamslap1 (/141.144.80.110)
	by default (Oracle Beehive Gateway v4.0)
	with ESMTP ; Fri, 18 Sep 2009 00:48:08 -0700
From: "Drew Adams" <drew.adams@HIDDEN>
To: <bug-gnu-emacs@HIDDEN>
Subject: 23.1; key bindings for mouse wheel - unclear
Date: Fri, 18 Sep 2009 00:48:12 -0700
Message-ID: <625E5DF5465B4A1CBF3FBB6015CBB87D@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
Thread-Index: Aco4NF/AtQTgg3q3Qs+b3BAchiZxTg==
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
X-Source-IP: abhmt010.oracle.com [141.146.116.19]
X-Auth-Type: Internal IP
X-CT-RefId: str=0001.0A090204.4AB33B39.00FD:SCFSTAT5015188,ss=1,fgs=0
X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6 (newer, 1)
X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4)

1. Doc bug: The doc is not clear about how to bind the mouse wheel
(rotations).
 
2. Code bug / enhancement request: Have a shorter way to bind wheel
actions.
 
--
 
I've been using bindings such as this:
 
(define-key map [wheel-down]   'aaa)
(define-key map [wheel-down]   'bbb)
(define-key map [C-wheel-down] 'ccc)
(define-key map [C-wheel-down] 'ddd)
 
Reading some mail on (I think) help-gnu-emacs got me a bit confused,
however. It gave me the impression that such bindings were only for MS
Windows and that on GNU/Linux `mouse-4' and `mouse-5' must be used
instead of `wheel-down' and `wheel-up'. (That sounds odd; I'd expect
`mouse-4' and `mouse-5' to be a fourth and fifth mouse button, as they
are on Windows.)
 
I looked in the Elisp manual, but I didn't find anything specifically
recommending how one should bind mouse wheel events. I was assuming
that `wheel-down' was platform independent, but now I have a doubt.
 
The Elisp doc (node Misc Events) speaks about events such as (wheel-up
POSITION), but it doesn't speak about just what to use when binding
such keys.  Further, it says that events such as (wheel-up POSITION)
are not generated on some systems and that on those systems "`mouse-4'
and `mouse-5' are used instead". (Why is that?)
 
It does say this, however: "For portable code, use the variables
`mouse-wheel-up-event' and `mouse-wheel-down-event'", and then it goes
on to say where those variables are defined (why does it say where
they are defined?).
 
So after a bit of fiddling I switched to this:
 
(define-key map (vector mouse-wheel-down-event) 'aaa)
(define-key map (vector mouse-wheel-up-event)   'bbb)
(define-key map
  (vector (list 'control mouse-wheel-down-event)) 'ccc)
(define-key map
  (vector (list 'control mouse-wheel-up-event)) 'ddd)
 
I haven't tested on GNU/Linux, but I'm assuming this is what to use
for portable code. Is there a shorter or better way to say this and
still be portable? 
 
1. If there is not, there should be (a shorter way to do this).
 
2. Until then, whatever is the current best way should at least be
documented clearly as the way to bind mouse wheel events.
 
I would even expect the Emacs manual to tell you how to bind
mouse-wheel key sequences...  But AFAICT the Emacs manual isn't too
helpful for even the basics about key binding. I filed a separate bug
(#4472) about that.
 
 
 
In GNU Emacs 23.1.1 (i386-mingw-nt5.1.2600)
 of 2009-07-29 on SOFT-MJASON
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.4)'
 





Acknowledgement sent to "Drew Adams" <drew.adams@HIDDEN>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs@HIDDEN>. Full text available.
Report forwarded to bug-submit-list@HIDDEN, Emacs Bugs <bug-gnu-emacs@HIDDEN>:
bug#4478; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 31 Oct 2014 17:00:04 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.