Subject: bug#78298: [PATCH] Scroll with mouse wheel in calendar

From: Manuel Giraud <[email-masked]>
Date: Wed, 14 May 2025 19:50:48 +0200

Michael Heerdegen <[email-masked]> writes:

> Juri Linkov <[email-masked]> writes:
>
>> Hopefully it would be ok for Michael as well to use less code
>> by reusing calendar-[for|back]ward-year that makes mouse wheel
>> year scrolling consistent with 'C-x [' and 'C-x ]'.
>
> I actually don't have such a strong opinion about this.  Do it if you
> came to the conclusion that it's the right thing to do.

Ok.  I don't have a strong opinion myself so here is an updated version
of this patch.
>From 36cb39ffd46a6d90d7b77a6fd4a8d474d75d2518 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Thu, 8 May 2025 16:30:20 +0200
Subject: [PATCH] Scroll with mouse wheel in calendar (bug#78298)

* lisp/calendar/calendar.el (calendar-mode-map): Add scrolling
with mouse wheel.
* etc/NEWS: Announce the change.
---
 etc/NEWS                  | 6 ++++++
 lisp/calendar/calendar.el | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index d1b0189da0c..0ec11a88b98 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2040,6 +2040,7 @@ DISABLE-URI non-nil.
 When starting these debuggers (e.g., 'M-x pdb') while visiting a file,
 pressing 'M-n' in the command prompt suggests a command line including
 the file name, using the minibuffer's "future history".
+
 ** Calendar
 
 +++
@@ -2047,6 +2048,11 @@ the file name, using the minibuffer's "future history".
 This command recenters the month of the date at point.  By default, it
 is bound to 'C-l' in the calendar buffer.
 
+---
+*** Mouse wheel bindings for scrolling the calendar.
+You can now use the mouse wheel to scroll the calendar by 3 months.
+With the shift modifier, it scrolls by one month.  With the meta
+modifier, it scrolls by year.
 
 * New Modes and Packages in Emacs 31.1
 
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index b0f6a9152d5..c448955450e 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1587,12 +1587,18 @@ calendar-mode-map
       (define-key map (vector 'remap c) 'calendar-not-implemented))
     (define-key map "<"     'calendar-scroll-right)
     (define-key map "\C-x<" 'calendar-scroll-right)
+    (define-key map [S-wheel-up] 'calendar-scroll-right)
     (define-key map [prior] 'calendar-scroll-right-three-months)
     (define-key map "\ev"   'calendar-scroll-right-three-months)
+    (define-key map [wheel-up] 'calendar-scroll-right-three-months)
+    (define-key map [M-wheel-up] 'calendar-backward-year)
     (define-key map ">"     'calendar-scroll-left)
     (define-key map "\C-x>" 'calendar-scroll-left)
+    (define-key map [S-wheel-down] 'calendar-scroll-left)
     (define-key map [next]  'calendar-scroll-left-three-months)
     (define-key map "\C-v"  'calendar-scroll-left-three-months)
+    (define-key map [wheel-down] 'calendar-scroll-left-three-months)
+    (define-key map [M-wheel-down] 'calendar-forward-year)
     (define-key map "\C-l"  'calendar-recenter)
     (define-key map "\C-b"  'calendar-backward-day)
     (define-key map "\C-p"  'calendar-backward-week)
-- 
2.49.0

-- 
Manuel Giraud