GNU bug report logs - #13420
24.2.92; [PATCH] calendar-redraw moves window-point

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Sat, 12 Jan 2013 08:12:02 UTC

Severity: normal

Tags: patch

Found in version 24.2.92

Fixed in version 24.4

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Leo Liu <sdl.web <at> gmail.com>
To: 13420 <at> debbugs.gnu.org
Subject: bug#13420: 24.2.92; [PATCH] calendar-redraw moves window-point
Date: Sat, 12 Jan 2013 16:11:12 +0800
[Message part 1 (text/plain, inline)]
Due to a bug/trap as reported in http://debbugs.gnu.org/13361, here is
one bug in calendar that moves window-point to (point-min).

1. Emacs -q
2. M-x calendar
3. C-x o so that the *calendar* window is not selected
4. M-x calendar-redraw

When you C-x o back to the calendar window, your window-point is no
longer at today's date but (point-min).

Note also calendar-redraw is called when saving in the diary file where
it has a save-hook: diary-redraw-calendar; so it is not uncommon for
this annoyance to happen.

[emacs-cal-bug.png (image/png, inline)]
[Message part 3 (text/plain, inline)]
For example, I often move to a future date and `i d' to insert a
reminder in the diary file and then C-x C-s. When I switch back to
calendar for further work, point is at the inconvenient point-min.

The proposed fix is in the patch attached.

I'd bet there are more occurrences in emacs source that fall into this
trap.

Leo


diff --git a/lisp/calendar/calendar.el b/lisp/calendar/calendar.el
index 9b0eb3e9..74d3ce80 100644
--- a/lisp/calendar/calendar.el
+++ b/lisp/calendar/calendar.el
@@ -1562,11 +1562,13 @@ (defun calendar-generate-month (month year indent)
 (defun calendar-redraw ()
   "Redraw the calendar display, if `calendar-buffer' is live."
   (interactive)
-  (if (get-buffer calendar-buffer)
-      (with-current-buffer calendar-buffer
-        (let ((cursor-date (calendar-cursor-to-nearest-date)))
-          (calendar-generate-window displayed-month displayed-year)
-          (calendar-cursor-to-visible-date cursor-date)))))
+  (when (get-buffer calendar-buffer)
+    (with-current-buffer calendar-buffer
+      (let ((cursor-date (calendar-cursor-to-nearest-date)))
+        (calendar-generate-window displayed-month displayed-year)
+        (calendar-cursor-to-visible-date cursor-date))
+      (when (window-live-p (get-buffer-window))
+        (set-window-point (get-buffer-window) (point))))))
 
 (defvar calendar-mode-map
   (let ((map (make-keymap)))

This bug report was last modified 12 years and 214 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.