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

From: Manuel Giraud <[email-masked]>
Date: Thu, 08 May 2025 17:23:00 +0200

Eli Zaretskii <[email-masked]> writes:

>> Cc: [email-masked]
>> From: Juri Linkov <[email-masked]>
>> Date: Wed, 07 May 2025 19:13:33 +0300
>> 
>> > Here is simple patch that adds mouse wheel scroll to calendar.
>> > [wheel-up/down] scrolls by 3 months and [S-wheel-up/down] scrolls by 1
>> > month.
>> 
>> Thanks.  It would be nice also for M-wheel to scroll by year.
>> 
>> Do these changes need a NEWS announcement?
>
> Yes, I think so.

Here is an updated version.  I'm not quite sure about my formulation in
the NEWS entry.
>From 2f1aceb1d24874329699c288b30db2bb3c945db4 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/cal-move.el (calendar-scroll-left-year)
(calendar-scroll-right-year): New commands to scroll the
calendar by year.
* lisp/calendar/calendar.el (calendar-mode-map): Add scroll with
mouse wheel.
* etc/NEWS: Announce the change.
---
 etc/NEWS                  | 10 ++++++++++
 lisp/calendar/cal-move.el | 20 ++++++++++++++++++++
 lisp/calendar/calendar.el |  6 ++++++
 3 files changed, 36 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index d1b0189da0c..9e838ef04b1 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,15 @@ 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.
 
+---
+*** New commands 'calendar-scroll-left-year' and 'calendar-scroll-right-year'.
+These commands scroll the calendar one year at a time.
+
+---
+*** 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/cal-move.el b/lisp/calendar/cal-move.el
index aad05f572d6..b1972ab2c09 100644
--- a/lisp/calendar/cal-move.el
+++ b/lisp/calendar/cal-move.el
@@ -217,6 +217,26 @@ calendar-scroll-right-three-months
                      last-nonmenu-event))
   (calendar-scroll-left (* -3 arg) event))
 
+;;;###cal-autoload
+(defun calendar-scroll-left-year (arg &optional event)
+  "Scroll the displayed calendar window left by 12*ARG months.
+If ARG is negative the calendar is scrolled right.  Maintains the relative
+position of the cursor with respect to the calendar as well as possible.
+EVENT is an event like `last-nonmenu-event'."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (calendar-scroll-left (* 12 arg) event))
+
+;;;###cal-autoload
+(defun calendar-scroll-right-year (arg &optional event)
+  "Scroll the displayed calendar window right by 12*ARG months.
+If ARG is negative the calendar is scrolled left.  Maintains the relative
+position of the cursor with respect to the calendar as well as possible.
+EVENT is an event like `last-nonmenu-event'."
+  (interactive (list (prefix-numeric-value current-prefix-arg)
+                     last-nonmenu-event))
+  (calendar-scroll-left (* -12 arg) event))
+
 (defvar calendar-recenter-last-op nil
   "Last calendar recenter operation performed.")
 
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index b0f6a9152d5..02626f547c1 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-scroll-right-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-scroll-left-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