unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5557: <left-margin> <double-wheel-down> is undefined
@ 2010-02-10 13:01 Lennart Borgman
  2019-10-01 15:36 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 29+ messages in thread
From: Lennart Borgman @ 2010-02-10 13:01 UTC (permalink / raw)
  To: 5557

This is rather inconvenient. I would expect the default binding for
double-wheel-down the left and right margin to be the same as in the
text part of the buffer. (Ie I would expect it to be bound to
mwheel-scroll.)

Is there any reason not to bind it in the margins by default?







^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2010-02-10 13:01 bug#5557: <left-margin> <double-wheel-down> is undefined Lennart Borgman
@ 2019-10-01 15:36 ` Lars Ingebrigtsen
  2019-10-01 16:09   ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-01 15:36 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: 5557

Lennart Borgman <lennart.borgman@gmail.com> writes:

> This is rather inconvenient. I would expect the default binding for
> double-wheel-down the left and right margin to be the same as in the
> text part of the buffer. (Ie I would expect it to be bound to
> mwheel-scroll.)
>
> Is there any reason not to bind it in the margins by default?

(I'm going through old bug reports that unfortunately didn't get any
response at the time.)

I'm not quite sure what's being referred to here.  Emacs has a fringe
area, and there a "margin" concept in the indentation functions, but is
there also a "margin" concept in windows?

Hm...  I see there's a `window-margins' function.  How does one give
margins to a window, I wonder?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 15:36 ` Lars Ingebrigtsen
@ 2019-10-01 16:09   ` Eli Zaretskii
  2019-10-01 16:19     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2019-10-01 16:09 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 5557, lennart.borgman

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Date: Tue, 01 Oct 2019 17:36:49 +0200
> Cc: 5557@debbugs.gnu.org
> 
> Lennart Borgman <lennart.borgman@gmail.com> writes:
> 
> > This is rather inconvenient. I would expect the default binding for
> > double-wheel-down the left and right margin to be the same as in the
> > text part of the buffer. (Ie I would expect it to be bound to
> > mwheel-scroll.)
> >
> > Is there any reason not to bind it in the margins by default?
> 
> (I'm going through old bug reports that unfortunately didn't get any
> response at the time.)
> 
> I'm not quite sure what's being referred to here.  Emacs has a fringe
> area, and there a "margin" concept in the indentation functions, but is
> there also a "margin" concept in windows?

Yes, see set-window-margins.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:09   ` Eli Zaretskii
@ 2019-10-01 16:19     ` Lars Ingebrigtsen
  2019-10-01 16:26       ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-01 16:19 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> Yes, see set-window-margins.

Ah, thanks.

After

(set-window-margins (get-buffer-window) 10 10)

and I try to do any mouse stuff there, I get

<left-margin> <down-mouse-1> is undefined
<left-margin> <mouse-1> is undefined

(I don't have a mouse with a scroll wheel.)

So I guess what should be changed is this:

  (when mouse-wheel-mode
    (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event mouse-wheel-right-event mouse-wheel-left-event))
      (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)])
                           mouse-wheel-scroll-amount))
        (global-set-key key 'mwheel-scroll)
        (push key mwheel-installed-bindings)))))

to also work in left-margin/right-margin?  It's a bit difficult for me
to test since I don't have a scroll wheel -- can somebody who has one do
the additional key bindings?  (The code is in mwheel.el.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:19     ` Lars Ingebrigtsen
@ 2019-10-01 16:26       ` Eli Zaretskii
  2019-10-01 16:32         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2019-10-01 16:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 5557, lennart.borgman

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: lennart.borgman@gmail.com,  5557@debbugs.gnu.org
> Date: Tue, 01 Oct 2019 18:19:30 +0200
> 
> After
> 
> (set-window-margins (get-buffer-window) 10 10)
> 
> and I try to do any mouse stuff there, I get
> 
> <left-margin> <down-mouse-1> is undefined
> <left-margin> <mouse-1> is undefined
> 
> (I don't have a mouse with a scroll wheel.)
> 
> So I guess what should be changed is this:
> 
>   (when mouse-wheel-mode
>     (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event mouse-wheel-right-event mouse-wheel-left-event))
>       (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)])
>                            mouse-wheel-scroll-amount))
>         (global-set-key key 'mwheel-scroll)
>         (push key mwheel-installed-bindings)))))
> 
> to also work in left-margin/right-margin?  It's a bit difficult for me
> to test since I don't have a scroll wheel -- can somebody who has one do
> the additional key bindings?  (The code is in mwheel.el.)

I actually am not sure a click on the margins should produce the same
effect as on the text area.  The margins are used to display different
text from what's in the text area, so I'm not sure I understand the
rationale.

Does anyone else have an opinion on this?  Should we perhaps ask a
couple of people who maintain packages that display on the margins?





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:26       ` Eli Zaretskii
@ 2019-10-01 16:32         ` Lars Ingebrigtsen
  2019-10-01 16:36           ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-01 16:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> I actually am not sure a click on the margins should produce the same
> effect as on the text area.  The margins are used to display different
> text from what's in the text area, so I'm not sure I understand the
> rationale.

Oh, I assumed that this was about scrolling, but that's probably not
what <double-wheel-down> does?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:32         ` Lars Ingebrigtsen
@ 2019-10-01 16:36           ` Eli Zaretskii
  2019-10-01 17:39             ` Stefan Kangas
  2019-10-03 15:35             ` Lars Ingebrigtsen
  0 siblings, 2 replies; 29+ messages in thread
From: Eli Zaretskii @ 2019-10-01 16:36 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 5557, lennart.borgman

> From: Lars Ingebrigtsen <larsi@gnus.org>
> Cc: lennart.borgman@gmail.com,  5557@debbugs.gnu.org
> Date: Tue, 01 Oct 2019 18:32:24 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > I actually am not sure a click on the margins should produce the same
> > effect as on the text area.  The margins are used to display different
> > text from what's in the text area, so I'm not sure I understand the
> > rationale.
> 
> Oh, I assumed that this was about scrolling, but that's probably not
> what <double-wheel-down> does?

Sorry for confusing wording: it _is_ about scrolling.
double-wheel-down means turning the wheel more than one click down.

What holds me back is that no other area of the display reacts to
mouse-wheel as the text area.  E.g., turning the wheel on the fringes
or on the scroll bar produces the same "undefined" message as for
margins.

I'm guessing that the OP wanted to have the display scrolled no matter
where on display the user turns the mouse wheel, but evidently that's
not how things are defined by default.  If we decide to change that,
it IMO makes little sense to do that only for the margins, but not for
the fringes or the scroll bar.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:36           ` Eli Zaretskii
@ 2019-10-01 17:39             ` Stefan Kangas
  2019-10-01 18:31               ` Eli Zaretskii
  2019-10-03 15:35             ` Lars Ingebrigtsen
  1 sibling, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2019-10-01 17:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, Lars Ingebrigtsen, Lennart Borgman

Eli Zaretskii <eliz@gnu.org> writes:

> What holds me back is that no other area of the display reacts to
> mouse-wheel as the text area.  E.g., turning the wheel on the fringes
> or on the scroll bar produces the same "undefined" message as for
> margins.

FWIW, I personally think it makes sense to add this binding also to
the fringes and the scroll bar.  If the user tries to use the mouse
wheel there, it's it my opinion most likely just a case of missing the
window by a couple of pixels.

> I'm guessing that the OP wanted to have the display scrolled no matter
> where on display the user turns the mouse wheel, but evidently that's
> not how things are defined by default.  If we decide to change that,
> it IMO makes little sense to do that only for the margins, but not for
> the fringes or the scroll bar.

I'm not seeing this when I use the mouse wheel on the scroll bar on
GTK 3.  Instead, the "bar" (inside the scroll bar) that indicates the
current position strangely moves downwards slowly.  I get no error
message, and the window doesn't scroll.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 17:39             ` Stefan Kangas
@ 2019-10-01 18:31               ` Eli Zaretskii
  2019-10-01 18:43                 ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2019-10-01 18:31 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Tue, 1 Oct 2019 19:39:17 +0200
> Cc: Lars Ingebrigtsen <larsi@gnus.org>, 5557@debbugs.gnu.org, 
> 	Lennart Borgman <lennart.borgman@gmail.com>
> 
> FWIW, I personally think it makes sense to add this binding also to
> the fringes and the scroll bar.  If the user tries to use the mouse
> wheel there, it's it my opinion most likely just a case of missing the
> window by a couple of pixels.

Maybe.  I'd like to hear more opinions, because we didn't have that
since Emacs 21 till now.

> > I'm guessing that the OP wanted to have the display scrolled no matter
> > where on display the user turns the mouse wheel, but evidently that's
> > not how things are defined by default.  If we decide to change that,
> > it IMO makes little sense to do that only for the margins, but not for
> > the fringes or the scroll bar.
> 
> I'm not seeing this when I use the mouse wheel on the scroll bar on
> GTK 3.  Instead, the "bar" (inside the scroll bar) that indicates the
> current position strangely moves downwards slowly.  I get no error
> message, and the window doesn't scroll.

That's because in your build these gestures on the scroll bar are
processed by GTK, not by Emacs.  Try some other toolkit, or maybe
no-toolkit, and you will see what I see.

But you do see what I described on the fringes, right?





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 18:31               ` Eli Zaretskii
@ 2019-10-01 18:43                 ` Stefan Kangas
  2019-10-01 19:06                   ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2019-10-01 18:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, Lars Ingebrigtsen, Lennart Borgman

Eli Zaretskii <eliz@gnu.org> writes:

> That's because in your build these gestures on the scroll bar are
> processed by GTK, not by Emacs.  Try some other toolkit, or maybe
> no-toolkit, and you will see what I see.

Is that expected behaviour on GTK?  It seems weird to get graphical
feedback when nothing is happening in Emacs.

If I have a long buffer, and I scroll *a lot* to get the bar to move
down.  When I then drag the bar using mouse-1, the buffer jumps to a
location corresponding to the current placement of the bar.  That
doesn't seem right to me?

> But you do see what I described on the fringes, right?

Yes.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 18:43                 ` Stefan Kangas
@ 2019-10-01 19:06                   ` Eli Zaretskii
  2019-10-02  8:55                     ` martin rudalics
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2019-10-01 19:06 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Tue, 1 Oct 2019 20:43:36 +0200
> Cc: Lars Ingebrigtsen <larsi@gnus.org>, 5557@debbugs.gnu.org, 
> 	Lennart Borgman <lennart.borgman@gmail.com>
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > That's because in your build these gestures on the scroll bar are
> > processed by GTK, not by Emacs.  Try some other toolkit, or maybe
> > no-toolkit, and you will see what I see.
> 
> Is that expected behaviour on GTK?  It seems weird to get graphical
> feedback when nothing is happening in Emacs.

I don't know.  Maybe Martin does.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 19:06                   ` Eli Zaretskii
@ 2019-10-02  8:55                     ` martin rudalics
  0 siblings, 0 replies; 29+ messages in thread
From: martin rudalics @ 2019-10-02  8:55 UTC (permalink / raw)
  To: Eli Zaretskii, Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

 >> Is that expected behaviour on GTK?  It seems weird to get graphical
 >> feedback when nothing is happening in Emacs.
 >
 > I don't know.  Maybe Martin does.

Sorry, no idea.

martin





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-01 16:36           ` Eli Zaretskii
  2019-10-01 17:39             ` Stefan Kangas
@ 2019-10-03 15:35             ` Lars Ingebrigtsen
  2019-10-03 18:11               ` martin rudalics
  1 sibling, 1 reply; 29+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-03 15:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> I'm guessing that the OP wanted to have the display scrolled no matter
> where on display the user turns the mouse wheel, but evidently that's
> not how things are defined by default.  If we decide to change that,
> it IMO makes little sense to do that only for the margins, but not for
> the fringes or the scroll bar.

That's true.  Hm...  perhaps the user has really big margins?  That
would make the issue more apparent there -- and it's difficult to say
what else the scroll wheel should do there other than work the same as
in the main portion of the buffer.

But I guess we should just wait and see whether the user has any
feedback on the use case here.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-03 15:35             ` Lars Ingebrigtsen
@ 2019-10-03 18:11               ` martin rudalics
  2020-08-13  5:34                 ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: martin rudalics @ 2019-10-03 18:11 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Eli Zaretskii; +Cc: 5557, lennart.borgman

 > That's true.  Hm...  perhaps the user has really big margins?  That
 > would make the issue more apparent there -- and it's difficult to say
 > what else the scroll wheel should do there other than work the same as
 > in the main portion of the buffer.

Nowadays practically all applications scroll the window vertically
regardless of where the mouse pointer is - even when it's on the
horizontal scroll bar.  The only exception is the title bar where some
window managers optionally "roll" the window in or out.

martin





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2019-10-03 18:11               ` martin rudalics
@ 2020-08-13  5:34                 ` Stefan Kangas
  2020-08-13  8:42                   ` Lars Ingebrigtsen
  2020-08-13 13:06                   ` Eli Zaretskii
  0 siblings, 2 replies; 29+ messages in thread
From: Stefan Kangas @ 2020-08-13  5:34 UTC (permalink / raw)
  To: martin rudalics; +Cc: 5557, Lars Ingebrigtsen, lennart.borgman

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

tags 5557 + patch
thanks

martin rudalics <rudalics@gmx.at> writes:

> Nowadays practically all applications scroll the window vertically
> regardless of where the mouse pointer is - even when it's on the
> horizontal scroll bar.  The only exception is the title bar where some
> window managers optionally "roll" the window in or out.

That strengthens the case for doing the same in Emacs.

I have attached a patch which implements this functionality.
Any comments?

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Bind-mwheel-scroll-also-for-fringe-and-margin.patch --]
[-- Type: text/x-diff, Size: 5361 bytes --]

From e857c79874b65f0ff8d83c5622c0748cb795d5b1 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Thu, 13 Aug 2020 07:30:03 +0200
Subject: [PATCH] Bind mwheel-scroll also for fringe and margin

* lisp/mwheel.el (mouse-wheel-mode): Bind mwheel-scroll also for
fringe and margin.
(mouse-wheel--create-scroll-keys)
(mouse-wheel--create-scroll-keys-get-key): New helper functions
for 'mouse-wheel-mode'.

* lisp/emacs-lisp/cl-lib.el (cl-mapcar): Add autoload cookie.
* test/lisp/mwheel-tests.el: New file.
---
 lisp/emacs-lisp/cl-lib.el |  1 +
 lisp/mwheel.el            | 26 ++++++++++++++++++++++++--
 test/lisp/mwheel-tests.el | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 test/lisp/mwheel-tests.el

diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index 7a26d9a90f..7595fc4ee6 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -347,6 +347,7 @@ 'cl-copy-seq
 
 (declare-function cl--mapcar-many "cl-extra" (cl-func cl-seqs &optional acc))
 
+;;;###autoload
 (defun cl-mapcar (cl-func cl-x &rest cl-rest)
   "Apply FUNCTION to each element of SEQ, and make a list of the results.
 If there are several SEQs, FUNCTION is called with that many arguments,
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 317f2cd8ed..9697126dc2 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -360,6 +360,26 @@ mouse-wheel--remove-bindings
     (when (memq (lookup-key (current-global-map) key) funs)
       (global-unset-key key))))
 
+(defun mouse-wheel--create-scroll-keys-get-key (binding event)
+  "Given BINDING and EVENT, return symbol for key.
+Arguments are like in `mouse-wheel--create-scroll-keys'."
+  (intern (concat (pcase (caar binding)
+                    ('alt "A-") ('control "C-") ('hyper "H-")
+                    ('meta "M-") ('shift "S-") ('super "s-"))
+                  (symbol-name event))))
+
+(defun mouse-wheel--create-scroll-keys (binding event)
+  "Return list of key vectors for BINDING and EVENT.
+BINDING is an element in `mouse-wheel-scroll-amount'.  EVENT is
+an event used for scrolling, e.g. `mouse-wheel-down-event'."
+  (let ((prefixes (list 'left-margin 'right-margin
+                        'left-fringe 'right-fringe))
+        (key (if (consp binding)
+                 (mouse-wheel--create-scroll-keys-get-key binding event)
+               event)))
+    (cons (vector key) ; default case: no prefix.
+          (cl-mapcar #'vector prefixes (make-list (length prefixes) key)))))
+
 (define-minor-mode mouse-wheel-mode
   "Toggle mouse wheel support (Mouse Wheel mode)."
   :init-value t
@@ -384,14 +404,16 @@ mouse-wheel-mode
        ;; Bindings for changing font size.
        ((and (consp binding) (eq (cdr binding) 'text-scale))
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+          ;; Add binding.
           (let ((key `[,(list (caar binding) event)]))
             (global-set-key key 'mouse-wheel-text-scale)
             (push key mwheel-installed-text-scale-bindings))))
        ;; Bindings for scrolling.
        (t
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                             mouse-wheel-right-event mouse-wheel-left-event))
-          (let ((key `[(,@(if (consp binding) (car binding)) ,event)]))
+                             mouse-wheel-left-event mouse-wheel-right-event))
+          (dolist (key (mouse-wheel--create-scroll-keys binding event))
+            ;; Add binding.
             (global-set-key key 'mwheel-scroll)
             (push key mwheel-installed-bindings))))))))
 
diff --git a/test/lisp/mwheel-tests.el b/test/lisp/mwheel-tests.el
new file mode 100644
index 0000000000..737154cb78
--- /dev/null
+++ b/test/lisp/mwheel-tests.el
@@ -0,0 +1,39 @@
+;;; mwheel-tests.el --- tests for mwheel.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'mwheel)
+
+(ert-deftest mwheel-test--create-scroll-keys-get-key ()
+  (should (equal (mouse-wheel--create-scroll-keys-get-key '((shift) . 1) 'mouse-7)
+                 'S-mouse-7))
+  (should (equal (mouse-wheel--create-scroll-keys-get-key '((meta) . 9) 'mouse-4)
+                 'M-mouse-4)))
+
+(ert-deftest mwheel-test--create-scroll-keys ()
+  (should (equal (mouse-wheel--create-scroll-keys '((shift) . 1) 'mouse-7)
+                 '([S-mouse-7]
+                   [left-margin S-mouse-7]
+                   [right-margin S-mouse-7]
+                   [left-fringe S-mouse-7]
+                   [right-fringe S-mouse-7]))))
+
+;;; mwheel-tests.el ends here
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-13  5:34                 ` Stefan Kangas
@ 2020-08-13  8:42                   ` Lars Ingebrigtsen
  2020-08-13 13:06                   ` Eli Zaretskii
  1 sibling, 0 replies; 29+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-13  8:42 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, lennart.borgman

Stefan Kangas <stefan@marxist.se> writes:

> I have attached a patch which implements this functionality.
> Any comments?

I don't use a scroll wheel mouse, but it sounds like a good idea to me.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-13  5:34                 ` Stefan Kangas
  2020-08-13  8:42                   ` Lars Ingebrigtsen
@ 2020-08-13 13:06                   ` Eli Zaretskii
  2020-08-14 18:38                     ` Stefan Kangas
  2020-08-17 13:30                     ` Stefan Kangas
  1 sibling, 2 replies; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-13 13:06 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Wed, 12 Aug 2020 22:34:10 -0700
> Cc: Lars Ingebrigtsen <larsi@gnus.org>, Eli Zaretskii <eliz@gnu.org>, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> > Nowadays practically all applications scroll the window vertically
> > regardless of where the mouse pointer is - even when it's on the
> > horizontal scroll bar.  The only exception is the title bar where some
> > window managers optionally "roll" the window in or out.
> 
> That strengthens the case for doing the same in Emacs.
> 
> I have attached a patch which implements this functionality.
> Any comments?

I have some:

> +(defun mouse-wheel--create-scroll-keys-get-key (binding event)
> +  "Given BINDING and EVENT, return symbol for key.
> +Arguments are like in `mouse-wheel--create-scroll-keys'."
> +  (intern (concat (pcase (caar binding)
> +                    ('alt "A-") ('control "C-") ('hyper "H-")
> +                    ('meta "M-") ('shift "S-") ('super "s-"))
> +                  (symbol-name event))))

I don't think I understand why we want to usurp mouse-wheel with every
possible modifier.  I think the request was to honor only unmodified
mouse-wheel scrolls, no?  Let's leave the modifiers to user bindings.

> +(defun mouse-wheel--create-scroll-keys (binding event)
> +  "Return list of key vectors for BINDING and EVENT.
> +BINDING is an element in `mouse-wheel-scroll-amount'.  EVENT is
> +an event used for scrolling, e.g. `mouse-wheel-down-event'."
> +  (let ((prefixes (list 'left-margin 'right-margin
> +                        'left-fringe 'right-fringe))

Martin says (and I concur) that we should also do this on horizontal
scroll bars and on the mode/header-lines.

Finally, this needs a NEWS entry.

Thanks.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-13 13:06                   ` Eli Zaretskii
@ 2020-08-14 18:38                     ` Stefan Kangas
  2020-08-14 19:13                       ` Eli Zaretskii
  2020-08-17 13:30                     ` Stefan Kangas
  1 sibling, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2020-08-14 18:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

>> Any comments?
>
> I have some:

Thank you.

>> +(defun mouse-wheel--create-scroll-keys-get-key (binding event)
>> +  "Given BINDING and EVENT, return symbol for key.
>> +Arguments are like in `mouse-wheel--create-scroll-keys'."
>> +  (intern (concat (pcase (caar binding)
>> +                    ('alt "A-") ('control "C-") ('hyper "H-")
>> +                    ('meta "M-") ('shift "S-") ('super "s-"))
>> +                  (symbol-name event))))
>
> I don't think I understand why we want to usurp mouse-wheel with every
> possible modifier.  I think the request was to honor only unmodified
> mouse-wheel scrolls, no?  Let's leave the modifiers to user bindings.

Well, it's not really all modifiers, at least not by default.  This
depends on what is configured in 'mouse-wheel-scroll-amount', so that
the user gets to decide.

My thinking is that it should be exactly the same to use the mouse wheel
(with or without modifiers) in the buffer area as on the fringe,
margins, etc.  I'm thinking that this way we are a bit preemptive, or we
risk getting bug reports saying that "sometimes scrolling doesn't
work".

IOW, I believe that the behaviour I suggest is the least surprising.
I have also checked Firefox and LibreOffice, and they also behave in
this way with regards to the modifiers.

Do you have any reason to believe anyone would specifically not like to
have those bindings there?

I agree with the rest of your comments.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-14 18:38                     ` Stefan Kangas
@ 2020-08-14 19:13                       ` Eli Zaretskii
  2020-08-14 21:34                         ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-14 19:13 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Fri, 14 Aug 2020 11:38:39 -0700
> Cc: rudalics@gmx.at, larsi@gnus.org, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> Do you have any reason to believe anyone would specifically not like to
> have those bindings there?

I just don't want us to usurp key bindings without a good reason.
Let's leave the unbound mouse gestures unbound, and leave it to the
users to decide what effect they have on different parts of the
display.  There's no reason to force them all to do the same on any
part of the display, when we don't even know what commands will be
bound to them.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-14 19:13                       ` Eli Zaretskii
@ 2020-08-14 21:34                         ` Stefan Kangas
  2020-08-15 17:40                           ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2020-08-14 21:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> I just don't want us to usurp key bindings without a good reason.

I tried arguing that being more like other applications here makes for a
better user experience.  To me that's a good reason.

Plus I really don't know why someone would want to do anything but
scroll using the mouse wheel, or why users (or package authors) can't
rebind this on specific window areas should they want to.

> Let's leave the unbound mouse gestures unbound, and leave it to the
> users to decide what effect they have on different parts of the
> display.  There's no reason to force them all to do the same on any
> part of the display, when we don't even know what commands will be
> bound to them.

OK, I guess we will have to agree to disagree.

One thing I don't understand is how binding to scroll-bar is supposed to
work.  I tried the following, but it didn't work (tested in GTK and
lucid):

    (global-set-key [vertical-scroll-bar mouse-5] 'foo-mouse-message)
    (defun foo-mouse-message (event)
      (interactive "e")
      (message "%s" (format-time-string "%H:%M:%S")))

(Change vertical-scroll-bar to left-fringe to see that it works there.)

Any ideas?

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-14 21:34                         ` Stefan Kangas
@ 2020-08-15 17:40                           ` Eli Zaretskii
  2020-08-16 13:41                             ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-15 17:40 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Fri, 14 Aug 2020 14:34:25 -0700
> Cc: rudalics@gmx.at, larsi@gnus.org, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> Plus I really don't know why someone would want to do anything but
> scroll using the mouse wheel

??? We do that already: C-wheel-up increases the font size.  It
shouldn't be hard to imagine similar bindings on the fringe, for
example.

> OK, I guess we will have to agree to disagree.

Yes.

> One thing I don't understand is how binding to scroll-bar is supposed to
> work.  I tried the following, but it didn't work (tested in GTK and
> lucid):
> 
>     (global-set-key [vertical-scroll-bar mouse-5] 'foo-mouse-message)
>     (defun foo-mouse-message (event)
>       (interactive "e")
>       (message "%s" (format-time-string "%H:%M:%S")))
> 
> (Change vertical-scroll-bar to left-fringe to see that it works there.)

First, you don't need to do anything for vertical-scroll-bar, as the
mouse wheel is already handled there, at least on my system.

On a horizontal scroll-bar, if I use this:

  (global-set-key [horizontal-scroll-bar wheel-up] 'foo-mouse-message)

I get the expected result on my system.

What do you see Emacs say if you turn the wheel on the horizontal
scroll-bar in "emacs -Q"?





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-15 17:40                           ` Eli Zaretskii
@ 2020-08-16 13:41                             ` Stefan Kangas
  2020-08-16 14:48                               ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2020-08-16 13:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> First, you don't need to do anything for vertical-scroll-bar, as the
> mouse wheel is already handled there, at least on my system.

Not here, unfortunately.  Tried emacs -Q with both GTK and Lucid: no
message from foo-mouse-message.

On GTK, I see this:

    "[The] 'bar' (inside the scroll bar) that indicates the current
    position strangely moves downwards slowly.  I get no error message,
    and the window doesn't scroll."

    https://debbugs.gnu.org/cgi/bugreport.cgi?bug=5557#28

On Lucid, nothing at all happens for the mouse wheel.  (Which is
actually better than the odd behaviour I see on GTK.)

> On a horizontal scroll-bar, if I use this:
>
>   (global-set-key [horizontal-scroll-bar wheel-up] 'foo-mouse-message)
>
> I get the expected result on my system.
>
> What do you see Emacs say if you turn the wheel on the horizontal
> scroll-bar in "emacs -Q"?

Same here: no message with the binding.  Instead:

On GTK, the horizontal scroll bar moves, but the window doesn't update.
The behaviour is similar to the vertical case: the 'bar' portion moves,
and when I then drag it with mouse-1, the window jumps to the position.

On Lucid, I see the same as for the vertical scroll bar: nothing happens.

So it's starting to sound like we have at least two separate bugs to
handle.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-16 13:41                             ` Stefan Kangas
@ 2020-08-16 14:48                               ` Eli Zaretskii
  2020-08-16 15:57                                 ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-16 14:48 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Sun, 16 Aug 2020 06:41:32 -0700
> Cc: rudalics@gmx.at, larsi@gnus.org, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> On GTK, the horizontal scroll bar moves, but the window doesn't update.
> The behaviour is similar to the vertical case: the 'bar' portion moves,
> and when I then drag it with mouse-1, the window jumps to the position.
> 
> On Lucid, I see the same as for the vertical scroll bar: nothing happens.

What about a no-toolkit version?

> So it's starting to sound like we have at least two separate bugs to
> handle.

Sounds like that, yes.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-16 14:48                               ` Eli Zaretskii
@ 2020-08-16 15:57                                 ` Stefan Kangas
  0 siblings, 0 replies; 29+ messages in thread
From: Stefan Kangas @ 2020-08-16 15:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

Eli Zaretskii <eliz@gnu.org> writes:

> What about a no-toolkit version?

The vertical-scroll-bar works as expected; I see the message in the
minibuffer from 'foo-mouse-message' and for other mouse wheel buttons it
says they are not bound.

M-x horizontal-scroll-bar-mode says:

   "Horizontal scroll bars are not implemented on this system"

>> So it's starting to sound like we have at least two separate bugs to
>> handle.
>
> Sounds like that, yes.

I will open two new bugs to track that (one for each toolkit), and
mention this bug report and the relevant findings.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-13 13:06                   ` Eli Zaretskii
  2020-08-14 18:38                     ` Stefan Kangas
@ 2020-08-17 13:30                     ` Stefan Kangas
  2020-08-22  7:32                       ` Eli Zaretskii
  1 sibling, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2020-08-17 13:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

[-- Attachment #1: Type: text/plain, Size: 244 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> I have attached a patch which implements this functionality.
>> Any comments?
>
> I have some:

Please find attached a new patch which should fix the issues you pointed
out.

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Bind-mwheel-scroll-in-more-places.patch --]
[-- Type: text/x-diff, Size: 5078 bytes --]

From c365747c282877b7d975119d2a13cfc69387403c Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Thu, 13 Aug 2020 07:30:03 +0200
Subject: [PATCH] Bind mwheel-scroll in more places

* lisp/mwheel.el (mouse-wheel-mode): Bind unmodified 'mwheel-scroll'
also for fringe, margin, header line and mode line.  (Bug#5557)
(mouse-wheel--create-scroll-keys): New helper function for
'mouse-wheel-mode'.
* test/lisp/mwheel-tests.el: New file.
---
 etc/NEWS                  |  6 ++++++
 lisp/mwheel.el            | 18 ++++++++++++++++--
 test/lisp/mwheel-tests.el | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 2 deletions(-)
 create mode 100644 test/lisp/mwheel-tests.el

diff --git a/etc/NEWS b/etc/NEWS
index 53e60cdb5c..641671c6e9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -102,6 +102,12 @@ deprecated.  Errors in the Inscript method were corrected.
 ** Rudimentary support for the 'st' terminal emulator.
 Emacs now supports 256 color display on the 'st' terminal emulator.
 
+---
+*** Mouse wheel scrolling less sensitive to positioning.
+When using 'mwheel-mode' (enabled by default), the mouse wheel will
+now scroll also when the mouse cursor is on the fringe, margin, header
+line, and mode line.
+
 \f
 * Editing Changes in Emacs 28.1
 
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 8e2039ba9d..f2dd398859 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -355,6 +355,18 @@ mouse-wheel--remove-bindings
     (when (memq (lookup-key (current-global-map) key) funs)
       (global-unset-key key))))
 
+(defun mouse-wheel--create-scroll-keys (binding event)
+  "Return list of key vectors for BINDING and EVENT.
+BINDING is an element in `mouse-wheel-scroll-amount'.  EVENT is
+an event used for scrolling, e.g. `mouse-wheel-down-event'."
+  (let ((prefixes (list 'left-margin 'right-margin
+                        'left-fringe 'right-fringe
+                        'vertical-scroll-bar 'horizontal-scroll-bar
+                        'mode-line 'header-line)))
+    (cons (vector event)                  ; default case: no prefix.
+          (when (not (consp binding))
+            (mapcar (lambda (prefix) (vector prefix event)) prefixes)))))
+
 (define-minor-mode mouse-wheel-mode
   "Toggle mouse wheel support (Mouse Wheel mode)."
   :init-value t
@@ -379,14 +391,16 @@ mouse-wheel-mode
        ;; Bindings for changing font size.
        ((and (consp binding) (eq (cdr binding) 'text-scale))
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+          ;; Add binding.
           (let ((key `[,(list (caar binding) event)]))
             (global-set-key key 'mouse-wheel-text-scale)
             (push key mwheel-installed-text-scale-bindings))))
        ;; Bindings for scrolling.
        (t
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                             mouse-wheel-right-event mouse-wheel-left-event))
-          (let ((key `[(,@(if (consp binding) (car binding)) ,event)]))
+                             mouse-wheel-left-event mouse-wheel-right-event))
+          (dolist (key (mouse-wheel--create-scroll-keys binding event))
+            ;; Add binding.
             (global-set-key key 'mwheel-scroll)
             (push key mwheel-installed-bindings))))))))
 
diff --git a/test/lisp/mwheel-tests.el b/test/lisp/mwheel-tests.el
new file mode 100644
index 0000000000..cf7fe70dd7
--- /dev/null
+++ b/test/lisp/mwheel-tests.el
@@ -0,0 +1,38 @@
+;;; mwheel-tests.el --- tests for mwheel.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'mwheel)
+
+(ert-deftest mwheel-test--create-scroll-keys ()
+  (should (equal (mouse-wheel--create-scroll-keys 10 'mouse-1)
+                 '([mouse-1]
+                   [left-margin mouse-1] [right-margin mouse-1]
+                   [left-fringe mouse-1] [right-fringe mouse-1]
+                   [vertical-scroll-bar mouse-1] [horizontal-scroll-bar mouse-1]
+                   [mode-line mouse-1] [header-line mouse-1])))
+  ;; Don't bind modifiers for fringe, etc.
+  (should (equal (mouse-wheel--create-scroll-keys '((shift) . 1) 'mouse-1)
+                 '([mouse-1])))
+  (should (equal (mouse-wheel--create-scroll-keys '((control) . 9) 'mouse-7)
+                 '([mouse-7]))))
+
+;;; mwheel-tests.el ends here
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-17 13:30                     ` Stefan Kangas
@ 2020-08-22  7:32                       ` Eli Zaretskii
  2020-08-22 11:48                         ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-22  7:32 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Mon, 17 Aug 2020 13:30:37 +0000
> Cc: rudalics@gmx.at, larsi@gnus.org, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> Please find attached a new patch which should fix the issues you pointed
> out.

Thanks.

> +*** Mouse wheel scrolling less sensitive to positioning.

I'd suggest

 Mouse-wheel scrolling now works on more parts of frame's display.

> +When using 'mwheel-mode' (enabled by default), the mouse wheel will
> +now scroll also when the mouse cursor is on the fringe, margin, header
> +line, and mode line.

The code also arranges for the scroll bars, no?  Also, please use
"fringes" and "margins", in plural.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-22  7:32                       ` Eli Zaretskii
@ 2020-08-22 11:48                         ` Stefan Kangas
  2020-08-22 11:59                           ` Eli Zaretskii
  0 siblings, 1 reply; 29+ messages in thread
From: Stefan Kangas @ 2020-08-22 11:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

[-- Attachment #1: Type: text/plain, Size: 565 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> +*** Mouse wheel scrolling less sensitive to positioning.
>
> I'd suggest
>
>  Mouse-wheel scrolling now works on more parts of frame's display.
>
>> +When using 'mwheel-mode' (enabled by default), the mouse wheel will
>> +now scroll also when the mouse cursor is on the fringe, margin, header
>> +line, and mode line.
>
> The code also arranges for the scroll bars, no?  Also, please use
> "fringes" and "margins", in plural.

Thanks for the review.  Fixed your comments in the attached patch.

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Bind-mwheel-scroll-on-more-parts-of-frame-s-display.patch --]
[-- Type: text/x-diff, Size: 5204 bytes --]

From 61fc4bf286da9081b822e9280e351ce7045868dc Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Sat, 22 Aug 2020 13:21:13 +0200
Subject: [PATCH] Bind mwheel-scroll on more parts of frame's display

* lisp/mwheel.el (mouse-wheel-mode): Bind unmodified 'mwheel-scroll'
on scroll bars, fringes, margins, header and mode line.  (Bug#5557)
(mouse-wheel--create-scroll-keys): New helper function for
'mouse-wheel-mode'.
* test/lisp/mwheel-tests.el: New file.
---
 etc/NEWS                  |  7 +++++++
 lisp/mwheel.el            | 18 ++++++++++++++++--
 test/lisp/mwheel-tests.el | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 2 deletions(-)
 create mode 100644 test/lisp/mwheel-tests.el

diff --git a/etc/NEWS b/etc/NEWS
index 0a6a7dec5c..79b3aa3732 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -102,6 +102,13 @@ deprecated.  Errors in the Inscript method were corrected.
 ** Rudimentary support for the 'st' terminal emulator.
 Emacs now supports 256 color display on the 'st' terminal emulator.
 
+---
+** Mouse wheel scrolling now works on more parts of frame's display.
+When using 'mwheel-mode', the mouse wheel will now scroll also when
+the mouse cursor is on the scroll bars, fringes, margins, header line,
+and mode line.  ('mwheel-mode' is enabled by default on most graphical
+displays.)
+
 \f
 * Editing Changes in Emacs 28.1
 
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 8e2039ba9d..c385fdfc26 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -355,6 +355,18 @@ mouse-wheel--remove-bindings
     (when (memq (lookup-key (current-global-map) key) funs)
       (global-unset-key key))))
 
+(defun mouse-wheel--create-scroll-keys (binding event)
+  "Return list of key vectors for BINDING and EVENT.
+BINDING is an element in `mouse-wheel-scroll-amount'.  EVENT is
+an event used for scrolling, such as `mouse-wheel-down-event'."
+  (let ((prefixes (list 'left-margin 'right-margin
+                        'left-fringe 'right-fringe
+                        'vertical-scroll-bar 'horizontal-scroll-bar
+                        'mode-line 'header-line)))
+    (cons (vector event)                  ; default case: no prefix.
+          (when (not (consp binding))
+            (mapcar (lambda (prefix) (vector prefix event)) prefixes)))))
+
 (define-minor-mode mouse-wheel-mode
   "Toggle mouse wheel support (Mouse Wheel mode)."
   :init-value t
@@ -379,14 +391,16 @@ mouse-wheel-mode
        ;; Bindings for changing font size.
        ((and (consp binding) (eq (cdr binding) 'text-scale))
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+          ;; Add binding.
           (let ((key `[,(list (caar binding) event)]))
             (global-set-key key 'mouse-wheel-text-scale)
             (push key mwheel-installed-text-scale-bindings))))
        ;; Bindings for scrolling.
        (t
         (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                             mouse-wheel-right-event mouse-wheel-left-event))
-          (let ((key `[(,@(if (consp binding) (car binding)) ,event)]))
+                             mouse-wheel-left-event mouse-wheel-right-event))
+          (dolist (key (mouse-wheel--create-scroll-keys binding event))
+            ;; Add binding.
             (global-set-key key 'mwheel-scroll)
             (push key mwheel-installed-bindings))))))))
 
diff --git a/test/lisp/mwheel-tests.el b/test/lisp/mwheel-tests.el
new file mode 100644
index 0000000000..f2989d608b
--- /dev/null
+++ b/test/lisp/mwheel-tests.el
@@ -0,0 +1,38 @@
+;;; mwheel-tests.el --- tests for mwheel.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'mwheel)
+
+(ert-deftest mwheel-test--create-scroll-keys ()
+  (should (equal (mouse-wheel--create-scroll-keys 10 'mouse-1)
+                 '([mouse-1]
+                   [left-margin mouse-1] [right-margin mouse-1]
+                   [left-fringe mouse-1] [right-fringe mouse-1]
+                   [vertical-scroll-bar mouse-1] [horizontal-scroll-bar mouse-1]
+                   [mode-line mouse-1] [header-line mouse-1])))
+  ;; Don't bind modifiers outside of buffer area (e.g. for fringes).
+  (should (equal (mouse-wheel--create-scroll-keys '((shift) . 1) 'mouse-1)
+                 '([mouse-1])))
+  (should (equal (mouse-wheel--create-scroll-keys '((control) . 9) 'mouse-7)
+                 '([mouse-7]))))
+
+;;; mwheel-tests.el ends here
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-22 11:48                         ` Stefan Kangas
@ 2020-08-22 11:59                           ` Eli Zaretskii
  2020-08-22 12:11                             ` Stefan Kangas
  0 siblings, 1 reply; 29+ messages in thread
From: Eli Zaretskii @ 2020-08-22 11:59 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 5557, larsi, lennart.borgman

> From: Stefan Kangas <stefan@marxist.se>
> Date: Sat, 22 Aug 2020 07:48:31 -0400
> Cc: rudalics@gmx.at, larsi@gnus.org, 5557@debbugs.gnu.org, 
> 	lennart.borgman@gmail.com
> 
> Thanks for the review.  Fixed your comments in the attached patch.

LGTM, thanks.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* bug#5557: <left-margin> <double-wheel-down> is undefined
  2020-08-22 11:59                           ` Eli Zaretskii
@ 2020-08-22 12:11                             ` Stefan Kangas
  0 siblings, 0 replies; 29+ messages in thread
From: Stefan Kangas @ 2020-08-22 12:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 5557, larsi, lennart.borgman

close 5557 28.1
thanks

Eli Zaretskii <eliz@gnu.org> writes:

> LGTM, thanks.

Thanks, pushed to master as commit 61fc4bf286.  Closing.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2020-08-22 12:11 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-10 13:01 bug#5557: <left-margin> <double-wheel-down> is undefined Lennart Borgman
2019-10-01 15:36 ` Lars Ingebrigtsen
2019-10-01 16:09   ` Eli Zaretskii
2019-10-01 16:19     ` Lars Ingebrigtsen
2019-10-01 16:26       ` Eli Zaretskii
2019-10-01 16:32         ` Lars Ingebrigtsen
2019-10-01 16:36           ` Eli Zaretskii
2019-10-01 17:39             ` Stefan Kangas
2019-10-01 18:31               ` Eli Zaretskii
2019-10-01 18:43                 ` Stefan Kangas
2019-10-01 19:06                   ` Eli Zaretskii
2019-10-02  8:55                     ` martin rudalics
2019-10-03 15:35             ` Lars Ingebrigtsen
2019-10-03 18:11               ` martin rudalics
2020-08-13  5:34                 ` Stefan Kangas
2020-08-13  8:42                   ` Lars Ingebrigtsen
2020-08-13 13:06                   ` Eli Zaretskii
2020-08-14 18:38                     ` Stefan Kangas
2020-08-14 19:13                       ` Eli Zaretskii
2020-08-14 21:34                         ` Stefan Kangas
2020-08-15 17:40                           ` Eli Zaretskii
2020-08-16 13:41                             ` Stefan Kangas
2020-08-16 14:48                               ` Eli Zaretskii
2020-08-16 15:57                                 ` Stefan Kangas
2020-08-17 13:30                     ` Stefan Kangas
2020-08-22  7:32                       ` Eli Zaretskii
2020-08-22 11:48                         ` Stefan Kangas
2020-08-22 11:59                           ` Eli Zaretskii
2020-08-22 12:11                             ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).