1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-04-25 15:52:01 -07:00

Fix the date in the calendar mode line (bug#80069)

* lisp/calendar/calendar.el (calendar-redraw)
(calendar-other-month): Make sure that the mode line is updated
after cursor motion in case 'date' is used in
'calendar-mode-line-format'.
(calendar-set-date-style): Delete call to
calendar-update-mode-line because it is called in calendar-draw.
(calendar-generate-window): Delete calls to
calendar-update-mode-line and calendar-cursor-to-visible-date.
It's better for the caller to do it.
(calendar-basic-setup): Update cursor position and mode line.
* lisp/calendar/cal-move.el (calendar-goto-today): Delete
calendar-update-mode-line because calendar-move-hook is called
last.  This is consistent with other cal-move commands.
* test/lisp/calendar/calendar-tests.el
(calendar-test-date-in-mode-line): New test.
This commit is contained in:
Liu Hui 2025-12-29 17:50:00 +08:00 committed by Sean Whitton
parent e119514ae8
commit 1fb98f2002
3 changed files with 42 additions and 13 deletions

View file

@ -30,5 +30,36 @@
(should (eq (calendar-date-is-valid-p (list 1 2)) nil))
(should (eq (calendar-date-is-valid-p (list 5 1 2025)) t)))
(ert-deftest calendar-test-date-in-calendar-mode-line ()
"Test whether the calendar mode line displays `date' correctly."
(save-window-excursion
(unwind-protect
(let* ((calendar-mode-line-format (list '(calendar-date-string date)))
(calendar-move-hook '(calendar-update-mode-line))
(today (calendar-current-date))
(month (calendar-extract-month today))
(year (calendar-extract-year today))
(cursor-date (calendar-gregorian-from-absolute
(1+ (calendar-absolute-from-gregorian today)))))
(calendar)
(should (equal (string-trim mode-line-format)
(calendar-date-string today)))
(calendar-forward-day 1)
(should (equal (string-trim mode-line-format)
(calendar-date-string cursor-date)))
(calendar-goto-today)
(should (equal (string-trim mode-line-format)
(calendar-date-string today)))
(calendar-cursor-to-visible-date cursor-date)
(calendar-redraw)
(should (equal (string-trim mode-line-format)
(calendar-date-string cursor-date)))
(calendar-cursor-to-visible-date cursor-date)
(calendar-scroll-left)
(calendar-other-month month year)
(should (equal (string-trim mode-line-format)
(calendar-date-string cursor-date))))
(kill-buffer calendar-buffer))))
(provide 'calendar-tests)
;;; calendar-tests.el ends here