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

From: Manuel Giraud <[email-masked]>
Date: Sat, 17 May 2025 16:13:15 +0200

Eli Zaretskii <[email-masked]> writes:

>> From: Manuel Giraud <[email-masked]>
>> Cc: [email-masked],  [email-masked],  [email-masked]
>> Date: Fri, 16 May 2025 21:19:32 +0200
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> From: Manuel Giraud <[email-masked]>
>> >> Cc: [email-masked],  [email-masked],  [email-masked]
>> >> Date: Fri, 16 May 2025 15:59:10 +0200
>> >> 
>> >> Eli Zaretskii <[email-masked]> writes:
>> >> 
>> >> >> +(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.
>> >> >
>> >> > Bother: the first and the 2nd sentences contradict each other.  Are we
>> >> > scrolling the window or the text shown in the window?  Their
>> >> > directions are opposite.
>> >> 
>> >> No they do not contradict: a negative argument on scroll-left command
>> >> will actually scroll right and vice versa.
>> >
>> > We are mis-communicating, I think.  My point was that the first
>> > sentence talks about scrolling the window, the second one about the
>> > calendar (i.e. the text).  
>> 
>> Ah ok, sorry about that.  It is the calendar (the text) that is scroll
>> in all these commands.  I have copy pasted the docstring from another of
>> the scroll command.  I think we should fix all of them.
>
> Yes, please.

Here is a new patch.  WDYT?
>From c0b46016ed1da10c342caf17f65bbf95efc02905 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Fri, 16 May 2025 10:31:43 +0200
Subject: [PATCH] Dedicated commands to scroll calendar by year

Follow-up to 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): Use it in the
calendar keymap.
* lisp/calendar/cal-move.el (calendar-scroll-right)
(calendar-scroll-left-three-months)
(calendar-scroll-right-three-months): Fix docstrings.
* etc/NEWS: Announce new commands.
---
 etc/NEWS                  |  5 +++++
 lisp/calendar/cal-move.el | 28 ++++++++++++++++++++++++----
 lisp/calendar/calendar.el |  4 ++--
 3 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d4e97883322..70d5a808f50 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2062,6 +2062,11 @@ is bound to 'C-l' in the calendar buffer.
 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 commands 'calendar-scroll-left-year' and 'calendar-scroll-right-year'.
+These commands scroll the calendar one year at a time.
+
 
 * New Modes and Packages in Emacs 31.1
 
diff --git a/lisp/calendar/cal-move.el b/lisp/calendar/cal-move.el
index aad05f572d6..302769949d0 100644
--- a/lisp/calendar/cal-move.el
+++ b/lisp/calendar/cal-move.el
@@ -150,7 +150,7 @@ calendar-backward-year
 
 ;;;###cal-autoload
 (defun calendar-scroll-left (&optional arg event)
-  "Scroll the displayed calendar left by ARG months.
+  "Scroll the displayed calendar left (forward in time) by 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'."
@@ -177,7 +177,7 @@ calendar-scroll-left
 
 ;;;###cal-autoload
 (defun calendar-scroll-right (&optional arg event)
-  "Scroll the displayed calendar window right by ARG months.
+  "Scroll the displayed calendar right (backward in time) by 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'."
@@ -187,7 +187,7 @@ calendar-scroll-right
 
 ;;;###cal-autoload
 (defun calendar-scroll-left-three-months (arg &optional event)
-  "Scroll the displayed calendar window left by 3*ARG months.
+  "Scroll the displayed calendar left (forward in time) by 3*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'."
@@ -209,7 +209,7 @@ calendar-scroll-toolkit-scroll
 
 ;;;###cal-autoload
 (defun calendar-scroll-right-three-months (arg &optional event)
-  "Scroll the displayed calendar window right by 3*ARG months.
+  "Scroll the displayed calendar right (backward in time) by 3*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'."
@@ -220,6 +220,26 @@ calendar-scroll-right-three-months
 (defvar calendar-recenter-last-op nil
   "Last calendar recenter operation performed.")
 
+;;;###cal-autoload
+(defun calendar-scroll-left-year (arg &optional event)
+  "Scroll the displayed calendar left (forward in time) 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 right (backward in time) 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))
+
 ;;;###cal-autoload
 (defun calendar-recenter ()
   "Scroll the calendar so that the month of the date at point is centered.
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index c448955450e..02626f547c1 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1591,14 +1591,14 @@ calendar-mode-map
     (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 [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-forward-year)
+    (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