unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: martin rudalics <rudalics@gmx.at>
Cc: 5557@debbugs.gnu.org, Lars Ingebrigtsen <larsi@gnus.org>,
	lennart.borgman@gmail.com
Subject: bug#5557: <left-margin> <double-wheel-down> is undefined
Date: Wed, 12 Aug 2020 22:34:10 -0700	[thread overview]
Message-ID: <CADwFkmmrmej6O9GFhiuRekxzUCW5wTs+8SUdZtVDkPcRTPA6+g@mail.gmail.com> (raw)
In-Reply-To: <ffe6bd47-aa40-32b3-47cb-0c7205834462@gmx.at> (martin rudalics's message of "Thu, 3 Oct 2019 20:11:08 +0200")

[-- 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


  reply	other threads:[~2020-08-13  5:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADwFkmmrmej6O9GFhiuRekxzUCW5wTs+8SUdZtVDkPcRTPA6+g@mail.gmail.com \
    --to=stefan@marxist.se \
    --cc=5557@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=lennart.borgman@gmail.com \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).