diff --git a/etc/NEWS b/etc/NEWS index a34a3d73292..80b461ddadf 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2451,6 +2451,14 @@ modifier, it scrolls by year. The month and year navigation key bindings 'M-}', 'M-{', 'C-x ]' and 'C-x [' now have the alternative keys '}', '{', ']' and '['. +--- +*** Avoid modifying user options. +The user options `calendar-mark-holidays-flag' and +`calendar-mark-diary-entries-flag' are not modified anymore when +changing the marking state in the calendar buffer. We now use variables +that are reset to the user option values whenever we generate a new +calendar. + ** Calc *** New user option 'calc-string-maximum-character'. diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el index 04bbc2cb8a4..04a42fcd38a 100644 --- a/lisp/calendar/calendar.el +++ b/lisp/calendar/calendar.el @@ -456,6 +456,12 @@ LEFT is the leftmost column associated with month segment N, FIRST and LAST are the first and last columns with day digits in, and LAST is the rightmost column.") +(defvar calendar-mark-holidays nil + "Variable version of the user option `calendar-mark-holidays-flag'.") + +(defvar calendar-mark-diary-entries nil + "Variable version of the user option `calendar-mark-diary-entries-flag'.") + (defun calendar-month-edges (segment) "Compute the month edge columns for month SEGMENT. Returns a list (LEFT FIRST LAST RIGHT), where LEFT is the @@ -1436,11 +1442,11 @@ Optional integers MON and YR are used instead of today's date." ;; For a full height window or a window that is horizontally ;; combined don't fit height to that of its buffer. (set-window-vscroll nil 0))) - (and calendar-mark-holidays-flag + (and calendar-mark-holidays ;; (calendar-date-is-valid-p today) ; useful for BC dates (calendar-mark-holidays)) (unwind-protect - (if calendar-mark-diary-entries-flag (diary-mark-entries)) + (if calendar-mark-diary-entries (diary-mark-entries)) (run-hooks (if today-visible 'calendar-today-visible-hook 'calendar-today-invisible-hook))))) @@ -1833,6 +1839,9 @@ For a complete description, see the info node `Calendar/Diary'. (make-local-variable 'calendar-mark-ring) (make-local-variable 'displayed-month) ; month in middle of window (make-local-variable 'displayed-year) ; year in middle of window + ;; Init with user options. + (setq calendar-mark-holidays calendar-mark-holidays-flag + calendar-mark-diary-entries calendar-mark-diary-entries-flag) ;; Most functions only work if displayed-month and displayed-year are set, ;; so let's make sure they're always set. Most likely, this will be reset ;; soon in calendar-generate, but better safe than sorry. @@ -2431,8 +2440,8 @@ interpreted as BC; -1 being 1 BC, and so on." (defun calendar-unmark () "Delete all diary/holiday marks/highlighting from the calendar." (interactive) - (setq calendar-mark-holidays-flag nil - calendar-mark-diary-entries-flag nil) + (setq calendar-mark-holidays nil + calendar-mark-diary-entries nil) (with-current-buffer calendar-buffer (mapc #'delete-overlay (overlays-in (point-min) (point-max))))) diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index 3d8d827417e..056360bbede 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -1395,8 +1395,8 @@ marks. This is intended to deal with deleted diary entries." ;; ii) called via calendar-redraw (since calendar has already been ;; erased). ;; Use of REDRAW handles both of these cases. - (when (and redraw calendar-mark-diary-entries-flag) - (setq calendar-mark-diary-entries-flag nil) + (when (and redraw calendar-mark-diary-entries) + (setq calendar-mark-diary-entries nil) (calendar-redraw)) (let ((diary-marking-entries-flag t) (diary-buffer (find-buffer-visiting diary-file)) @@ -1417,7 +1417,7 @@ marks. This is intended to deal with deleted diary entries." ;; If including, caller has already verified it is readable. (insert-file-contents diary-file) (if (eq major-mode (default-value 'major-mode)) (diary-mode))) - (setq calendar-mark-diary-entries-flag t) + (setq calendar-mark-diary-entries t) (setq file-glob-attrs (nth 1 (diary-pull-attrs nil '()))) (with-syntax-table diary-syntax-table (save-excursion @@ -2243,7 +2243,7 @@ Prefix argument ARG makes the entry nonmarking." (defun diary-redraw-calendar () "If `calendar-buffer' is live and diary entries are marked, redraw it." - (and calendar-mark-diary-entries-flag + (and calendar-mark-diary-entries (save-excursion (calendar-redraw))) ;; Return value suitable for `write-contents-functions'. diff --git a/lisp/calendar/holidays.el b/lisp/calendar/holidays.el index b40c56abd86..28f3a0ae7f2 100644 --- a/lisp/calendar/holidays.el +++ b/lisp/calendar/holidays.el @@ -585,7 +585,7 @@ use instead of point." (with-current-buffer (if event (calendar-event-buffer event) (current-buffer)) - (setq calendar-mark-holidays-flag t) + (setq calendar-mark-holidays t) (message "Marking holidays...") (dolist (holiday (calendar-holiday-list)) (calendar-mark-visible-date (car holiday) calendar-holiday-marker))