diff options
| author | Liu Hui | 2025-12-29 17:50:00 +0800 |
|---|---|---|
| committer | Sean Whitton | 2025-12-29 11:36:07 +0000 |
| commit | 1fb98f2002df778beb4fe0ef44c5bbb0c0eea2e6 (patch) | |
| tree | 6efa36b9cace28f05e918d7f640f2d16333e65ed | |
| parent | e119514ae8b391f41577d22d4e41cc3fea7ab9eb (diff) | |
| download | emacs-1fb98f2002df778beb4fe0ef44c5bbb0c0eea2e6.tar.gz emacs-1fb98f2002df778beb4fe0ef44c5bbb0c0eea2e6.zip | |
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.
| -rw-r--r-- | lisp/calendar/cal-move.el | 1 | ||||
| -rw-r--r-- | lisp/calendar/calendar.el | 23 | ||||
| -rw-r--r-- | test/lisp/calendar/calendar-tests.el | 31 |
3 files changed, 42 insertions, 13 deletions
diff --git a/lisp/calendar/cal-move.el b/lisp/calendar/cal-move.el index aad05f572d6..43eeb694854 100644 --- a/lisp/calendar/cal-move.el +++ b/lisp/calendar/cal-move.el | |||
| @@ -102,7 +102,6 @@ Returns the list (month day year) giving the cursor position." | |||
| 102 | (let ((today (calendar-current-date))) ; the date might have changed | 102 | (let ((today (calendar-current-date))) ; the date might have changed |
| 103 | (if (not (calendar-date-is-visible-p today)) | 103 | (if (not (calendar-date-is-visible-p today)) |
| 104 | (calendar-generate-window) | 104 | (calendar-generate-window) |
| 105 | (calendar-update-mode-line) | ||
| 106 | (calendar-cursor-to-visible-date today))) | 105 | (calendar-cursor-to-visible-date today))) |
| 107 | (run-hooks 'calendar-move-hook)) | 106 | (run-hooks 'calendar-move-hook)) |
| 108 | 107 | ||
diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 6805a84a80d..d4d38981b68 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el | |||
| @@ -1029,8 +1029,7 @@ The valid styles are described in the documentation of `calendar-date-style'." | |||
| 1029 | (symbol-value (intern-soft (format "calendar-%s-month-header" style))) | 1029 | (symbol-value (intern-soft (format "calendar-%s-month-header" style))) |
| 1030 | diary-date-forms | 1030 | diary-date-forms |
| 1031 | (symbol-value (intern-soft (format "diary-%s-date-forms" style)))) | 1031 | (symbol-value (intern-soft (format "diary-%s-date-forms" style)))) |
| 1032 | (calendar-redraw) | 1032 | (calendar-redraw)) |
| 1033 | (calendar-update-mode-line)) | ||
| 1034 | 1033 | ||
| 1035 | (defcustom diary-show-holidays-flag t | 1034 | (defcustom diary-show-holidays-flag t |
| 1036 | "Non-nil means include holidays in the diary display. | 1035 | "Non-nil means include holidays in the diary display. |
| @@ -1356,8 +1355,8 @@ display the generated calendar." | |||
| 1356 | ;; behavior as before in the non-wide case (see below). | 1355 | ;; behavior as before in the non-wide case (see below). |
| 1357 | (split-height-threshold 1000) | 1356 | (split-height-threshold 1000) |
| 1358 | (split-width-threshold calendar-split-width-threshold) | 1357 | (split-width-threshold calendar-split-width-threshold) |
| 1359 | (date (if arg (calendar-read-date t) | 1358 | (today (calendar-current-date)) |
| 1360 | (calendar-current-date))) | 1359 | (date (if arg (calendar-read-date t) today)) |
| 1361 | (month (calendar-extract-month date)) | 1360 | (month (calendar-extract-month date)) |
| 1362 | (year (calendar-extract-year date))) | 1361 | (year (calendar-extract-year date))) |
| 1363 | (calendar-increment-month month year (- calendar-offset)) | 1362 | (calendar-increment-month month year (- calendar-offset)) |
| @@ -1406,6 +1405,9 @@ display the generated calendar." | |||
| 1406 | ;; Switch to the lower window with the calendar buffer. | 1405 | ;; Switch to the lower window with the calendar buffer. |
| 1407 | (select-window win)))) | 1406 | (select-window win)))) |
| 1408 | (calendar-generate-window month year) | 1407 | (calendar-generate-window month year) |
| 1408 | (calendar-cursor-to-visible-date | ||
| 1409 | (if (calendar-date-is-visible-p today) today (list month 1 year))) | ||
| 1410 | (calendar-update-mode-line) | ||
| 1409 | (if (and calendar-view-diary-initially-flag | 1411 | (if (and calendar-view-diary-initially-flag |
| 1410 | (calendar-date-is-visible-p date)) | 1412 | (calendar-date-is-visible-p date)) |
| 1411 | ;; Do not clobber the calendar with the diary, if the diary | 1413 | ;; Do not clobber the calendar with the diary, if the diary |
| @@ -1430,14 +1432,9 @@ Optional integers MON and YR are used instead of today's date." | |||
| 1430 | (month (calendar-extract-month today)) | 1432 | (month (calendar-extract-month today)) |
| 1431 | ;; (day (calendar-extract-day today)) | 1433 | ;; (day (calendar-extract-day today)) |
| 1432 | (year (calendar-extract-year today)) | 1434 | (year (calendar-extract-year today)) |
| 1433 | (today-visible (or (not mon) | ||
| 1434 | (<= (abs (calendar-interval mon yr month year)) 1))) | ||
| 1435 | (in-calendar-window (with-current-buffer (window-buffer) | 1435 | (in-calendar-window (with-current-buffer (window-buffer) |
| 1436 | (derived-mode-p 'calendar-mode)))) | 1436 | (derived-mode-p 'calendar-mode)))) |
| 1437 | (calendar-generate (or mon month) (or yr year)) | 1437 | (calendar-generate (or mon month) (or yr year)) |
| 1438 | (calendar-cursor-to-visible-date | ||
| 1439 | (if today-visible today (list displayed-month 1 displayed-year))) | ||
| 1440 | (calendar-update-mode-line) | ||
| 1441 | (set-buffer-modified-p nil) | 1438 | (set-buffer-modified-p nil) |
| 1442 | ;; Don't do any window-related stuff if we weren't called from a | 1439 | ;; Don't do any window-related stuff if we weren't called from a |
| 1443 | ;; window displaying the calendar. | 1440 | ;; window displaying the calendar. |
| @@ -1453,7 +1450,7 @@ Optional integers MON and YR are used instead of today's date." | |||
| 1453 | (calendar-mark-holidays)) | 1450 | (calendar-mark-holidays)) |
| 1454 | (unwind-protect | 1451 | (unwind-protect |
| 1455 | (if calendar-mark-diary-entries (diary-mark-entries)) | 1452 | (if calendar-mark-diary-entries (diary-mark-entries)) |
| 1456 | (run-hooks (if today-visible | 1453 | (run-hooks (if (calendar-date-is-visible-p today) |
| 1457 | 'calendar-today-visible-hook | 1454 | 'calendar-today-visible-hook |
| 1458 | 'calendar-today-invisible-hook))))) | 1455 | 'calendar-today-invisible-hook))))) |
| 1459 | 1456 | ||
| @@ -1577,7 +1574,8 @@ first INDENT characters on the line." | |||
| 1577 | (with-current-buffer buf | 1574 | (with-current-buffer buf |
| 1578 | (let ((cursor-date (calendar-cursor-to-nearest-date))) | 1575 | (let ((cursor-date (calendar-cursor-to-nearest-date))) |
| 1579 | (calendar-generate-window displayed-month displayed-year) | 1576 | (calendar-generate-window displayed-month displayed-year) |
| 1580 | (calendar-cursor-to-visible-date cursor-date)) | 1577 | (calendar-cursor-to-visible-date cursor-date) |
| 1578 | (calendar-update-mode-line)) | ||
| 1581 | (when (window-live-p (get-buffer-window)) | 1579 | (when (window-live-p (get-buffer-window)) |
| 1582 | (set-window-point (get-buffer-window) (point)))))) | 1580 | (set-window-point (get-buffer-window) (point)))))) |
| 1583 | 1581 | ||
| @@ -2073,7 +2071,8 @@ EVENT is an event like `last-nonmenu-event'." | |||
| 2073 | (cond | 2071 | (cond |
| 2074 | ((calendar-date-is-visible-p old-date) old-date) | 2072 | ((calendar-date-is-visible-p old-date) old-date) |
| 2075 | ((calendar-date-is-visible-p today) today) | 2073 | ((calendar-date-is-visible-p today) today) |
| 2076 | (t (list month 1 year)))))))) | 2074 | (t (list month 1 year)))) |
| 2075 | (calendar-update-mode-line))))) | ||
| 2077 | 2076 | ||
| 2078 | (defun calendar-set-mark (arg &optional event) | 2077 | (defun calendar-set-mark (arg &optional event) |
| 2079 | "Mark the date under the cursor, or jump to marked date. | 2078 | "Mark the date under the cursor, or jump to marked date. |
diff --git a/test/lisp/calendar/calendar-tests.el b/test/lisp/calendar/calendar-tests.el index 2aef0bf827b..5fd974f952f 100644 --- a/test/lisp/calendar/calendar-tests.el +++ b/test/lisp/calendar/calendar-tests.el | |||
| @@ -30,5 +30,36 @@ | |||
| 30 | (should (eq (calendar-date-is-valid-p (list 1 2)) nil)) | 30 | (should (eq (calendar-date-is-valid-p (list 1 2)) nil)) |
| 31 | (should (eq (calendar-date-is-valid-p (list 5 1 2025)) t))) | 31 | (should (eq (calendar-date-is-valid-p (list 5 1 2025)) t))) |
| 32 | 32 | ||
| 33 | (ert-deftest calendar-test-date-in-calendar-mode-line () | ||
| 34 | "Test whether the calendar mode line displays `date' correctly." | ||
| 35 | (save-window-excursion | ||
| 36 | (unwind-protect | ||
| 37 | (let* ((calendar-mode-line-format (list '(calendar-date-string date))) | ||
| 38 | (calendar-move-hook '(calendar-update-mode-line)) | ||
| 39 | (today (calendar-current-date)) | ||
| 40 | (month (calendar-extract-month today)) | ||
| 41 | (year (calendar-extract-year today)) | ||
| 42 | (cursor-date (calendar-gregorian-from-absolute | ||
| 43 | (1+ (calendar-absolute-from-gregorian today))))) | ||
| 44 | (calendar) | ||
| 45 | (should (equal (string-trim mode-line-format) | ||
| 46 | (calendar-date-string today))) | ||
| 47 | (calendar-forward-day 1) | ||
| 48 | (should (equal (string-trim mode-line-format) | ||
| 49 | (calendar-date-string cursor-date))) | ||
| 50 | (calendar-goto-today) | ||
| 51 | (should (equal (string-trim mode-line-format) | ||
| 52 | (calendar-date-string today))) | ||
| 53 | (calendar-cursor-to-visible-date cursor-date) | ||
| 54 | (calendar-redraw) | ||
| 55 | (should (equal (string-trim mode-line-format) | ||
| 56 | (calendar-date-string cursor-date))) | ||
| 57 | (calendar-cursor-to-visible-date cursor-date) | ||
| 58 | (calendar-scroll-left) | ||
| 59 | (calendar-other-month month year) | ||
| 60 | (should (equal (string-trim mode-line-format) | ||
| 61 | (calendar-date-string cursor-date)))) | ||
| 62 | (kill-buffer calendar-buffer)))) | ||
| 63 | |||
| 33 | (provide 'calendar-tests) | 64 | (provide 'calendar-tests) |
| 34 | ;;; calendar-tests.el ends here | 65 | ;;; calendar-tests.el ends here |