kiwanami / emacs-calfw

A calendar framework for Emacs
1.17k stars 100 forks source link

the point moved after leaving the calfw buffer #84

Open toshjp opened 8 years ago

toshjp commented 8 years ago

Thanks for the excellent calendar interface for emacs. As I was setting up calfw, though, I became aware of a minor problem.

When I open the calfw buffer with cfw:open-calendar-buffer then leave it immediately with 'q' (= bury-buffer), I am back in the previous buffer but with the point moved to where it was in the calfw buffer. This does not happen when I go back to the previous buffer by way of the buffer list.

I am not versed in emacs lisp but 'save-excursion' in cfw:open-calendar-buffer is there to preserve the point in the previous buffer, I suppose.

Could you look into this when you have time?

There is another glitch. The latest test release of howm switched to cl-lib in preference to cl, which causes the following error:

cfw:howm-schedule-period: Symbol's function definition is void: howm-cl-remove-if

Best regards.

toshjp commented 8 years ago

I couldn't figure out a solution for a while but somehow I managed to hit upon one. In the original function, switch-to-buffer is used within the scope of save-excursion and this causes the weird behaviour when I dismiss the calfw buffer with 'q' (= bury-buffer). The following change should solve the problem:

--- calfw.el.orig   2015-09-23 19:49:36.000000000 +0900
+++ calfw.el    2016-10-24 11:30:54.276926364 +0900
@@ -2756,12 +2756,14 @@
 initially.  This function uses the function
 `cfw:create-calendar-component-buffer' internally."
   (interactive)
-  (save-excursion
-    (let ((cp (cfw:create-calendar-component-buffer
-               :date date :buffer buffer :custom-map custom-map
-               :contents-sources contents-sources
-               :annotation-sources annotation-sources :view view :sorter sorter)))
-      (switch-to-buffer (cfw:cp-get-buffer cp)))))
+  (let (buf)
+    (save-excursion
+      (let ((cp (cfw:create-calendar-component-buffer
+                 :date date :buffer buffer :custom-map custom-map
+                 :contents-sources contents-sources
+                 :annotation-sources annotation-sources :view view :sorter sorter)))
+        (setq buf cp)))
+    (switch-to-buffer (cfw:cp-get-buffer buf))))

 (defun* cfw:create-calendar-component-buffer
   (&key date buffer custom-map contents-sources annotation-sources view sorter)

I guess the same change might be applied to functions like cfw:open-howm-calendar and cfw:open-diary-calendar. Could you take a look when you have time?

kiwanami commented 8 years ago

Hi @toshjp Thank you for your report. I'm sorry for my late response.

In my environment, GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.9), I could not reproduce your situation. Would you teach me your environment? (Hmm, Is it the problem in emacs 25??)

toshjp commented 8 years ago

Hi @kiwanami,

Thanks for your reply.

I confirmed the problem on both emacs 24 and 25. I'm currently using these versions of emacs.

GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.10.7) GNU Emacs 25.1.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.14.5)

This is how to reproduce the problem:

1 Launch emacs with the "-Q" option and add the calfw directory to the load-path. Then evaluate the following in the scratch buffer:

(require 'calfw) (defun cfw-open-calendar () (interactive) (cfw:open-calendar-buffer :contents-sources (list )))

2 Move the point to the beginning of the buffer so you can see it if the point has been moved later.

3 Open the calfw calendar buffer with M-x cfw-open-calendar.

4 Dismiss the calendar buffer with "q" (= bury-buffer).

After these operations, you will be back in the scratch buffer but the point will be moved several lines below where it was, most probably to the bottom of the buffer.

If the point value was, say, 1000 in the calendar buffer, it will be the same when you are back in the scratch buffer, or rather as in this case the point will be moved to the bottom if the buffer is smaller than that.

Regards.