changeset 96047:65c4c935e492

* calendar/calendar.el (calendar-cursor-to-date): Add argument `event'. (calendar-set-mark): * calendar/diary-lib.el (diary-insert-entry): * calendar/solar.el (calendar-sunrise-sunset): Use it. * calendar/cal-menu.el (calendar-mouse-sunrise/sunset) (calendar-mouse-insert-diary-entry, calendar-mouse-set-mark): Delete. (cal-menu-context-mouse-menu): Use calendar-set-mark, diary-insert-entry, and calendar-sunrise-sunset instead, to get proper key-shortcuts.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 17 Jun 2008 15:42:19 +0000
parents 422d57d537d7
children 62044a08f171
files lisp/ChangeLog lisp/calendar/cal-menu.el lisp/calendar/calendar.el lisp/calendar/diary-lib.el lisp/calendar/solar.el
diffstat 5 files changed, 36 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Jun 17 15:39:06 2008 +0000
+++ b/lisp/ChangeLog	Tue Jun 17 15:42:19 2008 +0000
@@ -1,5 +1,14 @@
 2008-06-17  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* calendar/calendar.el (calendar-cursor-to-date): Add argument `event'.
+	(calendar-set-mark):
+	* calendar/diary-lib.el (diary-insert-entry):
+	* calendar/solar.el (calendar-sunrise-sunset): Use it.
+	* calendar/cal-menu.el (calendar-mouse-sunrise/sunset)
+	(calendar-mouse-insert-diary-entry, calendar-mouse-set-mark): Delete.
+	(cal-menu-context-mouse-menu): Use calendar-set-mark,
+	diary-insert-entry, and calendar-sunrise-sunset instead.
+
 	* vc.el (vc-deduce-fileset): Add arg `only-files'.
 	(vc-next-action): Pass the new arg.
 	(vc-register): Don't use `only-files'.
--- a/lisp/calendar/cal-menu.el	Tue Jun 17 15:39:06 2008 +0000
+++ b/lisp/calendar/cal-menu.el	Tue Jun 17 15:42:19 2008 +0000
@@ -184,13 +184,6 @@
   (set-buffer (window-buffer (posn-window (event-start last-input-event))))
   (calendar-goto-date date))
 
-(defun calendar-mouse-sunrise/sunset ()
-  "Show sunrise/sunset times for mouse-selected date."
-  (interactive)
-  (save-excursion
-    (calendar-mouse-goto-date (cal-menu-event-to-date))
-    (calendar-sunrise-sunset)))
-
 (defun cal-menu-today-holidays ()
   "Show holidays for today's date."
   (interactive)
@@ -257,20 +250,6 @@
    (cal-menu-event-to-date)
    (read-file-name "Enter diary file name: " default-directory nil t)))
 
-(defun calendar-mouse-insert-diary-entry ()
-  "Insert diary entry for mouse-selected date."
-  (interactive)
-  (save-excursion
-    (calendar-mouse-goto-date (cal-menu-event-to-date))
-    (diary-insert-entry nil)))
-
-(defun calendar-mouse-set-mark ()
-  "Mark the date under the cursor."
-  (interactive)
-  (save-excursion
-    (calendar-mouse-goto-date (cal-menu-event-to-date))
-    (calendar-set-mark nil)))
-
 (defun calendar-mouse-tex-day ()
   "Make a buffer with LaTeX commands for the day mouse is on."
   (interactive)
@@ -391,8 +370,8 @@
   '("cal-menu-mouse2" :filter cal-menu-set-date-title
     "--"
     ["Holidays" calendar-mouse-holidays]
-    ["Mark date" calendar-mouse-set-mark]
-    ["Sunrise/sunset" calendar-mouse-sunrise/sunset]
+    ["Mark date" calendar-set-mark]
+    ["Sunrise/sunset" calendar-sunrise-sunset]
     ["Other calendars" calendar-mouse-print-dates]
     ("Prepare LaTeX buffer"
      ["Daily (1 page)" calendar-mouse-tex-day]
@@ -410,7 +389,7 @@
       ["Filofax Weekly (week-at-a-glance)" calendar-mouse-tex-filofax-week]
       ["Filofax Yearly" calendar-mouse-tex-filofax-year]))
     ["Diary entries" calendar-mouse-view-diary-entries]
-    ["Insert diary entry" calendar-mouse-insert-diary-entry]
+    ["Insert diary entry" diary-insert-entry]
     ["Other diary file entries" calendar-mouse-view-other-diary-entries]))
 
 (easy-menu-define cal-menu-global-mouse-menu nil
--- a/lisp/calendar/calendar.el	Tue Jun 17 15:39:06 2008 +0000
+++ b/lisp/calendar/calendar.el	Tue Jun 17 15:42:19 2008 +0000
@@ -1571,10 +1571,17 @@
   (let ((now (decode-time)))
     (list (nth 4 now) (nth 3 now) (nth 5 now))))
 
-(defun calendar-cursor-to-date (&optional error)
+(defun calendar-cursor-to-date (&optional error event)
   "Return a list (month day year) of current cursor position.
 If cursor is not on a specific date, signals an error if optional parameter
-ERROR is non-nil, otherwise just returns nil."
+ERROR is non-nil, otherwise just returns nil.
+If EVENT is non-nil, it's an event indicating the buffer position to
+use instead of point."
+  (with-current-buffer
+      (if event (window-buffer (posn-window (event-start event)))
+        (current-buffer))
+    (save-excursion
+      (if event (goto-char (posn-point (event-start event))))
   (let* ((segment (/ (current-column) 25))
          (month (% (+ displayed-month segment -1) 12))
          (month (if (zerop month) 12 month))
@@ -1583,15 +1590,14 @@
            ((and (=  12 month) (zerop segment)) (1- displayed-year))
            ((and (=   1 month) (= segment 2)) (1+ displayed-year))
            (t displayed-year))))
-    (if (and (looking-at "[ 0-9]?[0-9][^0-9]")
-             (< 2 (count-lines (point-min) (point))))
-        (save-excursion
+        (if (not (and (looking-at "[ 0-9]?[0-9][^0-9]")
+                      (< 2 (count-lines (point-min) (point)))))
+            (if error (error "Not on a date!"))
           (if (not (looking-at " "))
               (re-search-backward "[^0-9]"))
           (list month
                 (string-to-number (buffer-substring (1+ (point)) (+ 4 (point))))
-                year))
-      (if error (error "Not on a date!")))))
+                year))))))
 
 (add-to-list 'debug-ignored-errors "Not on a date!")
 
@@ -1668,12 +1674,13 @@
           ((calendar-date-is-visible-p today) today)
           (t (list month 1 year))))))))
 
-(defun calendar-set-mark (arg)
+(defun calendar-set-mark (arg &optional event)
   "Mark the date under the cursor, or jump to marked date.
 With no prefix argument, push current date onto marked date ring.
 With argument ARG, jump to mark, pop it, and put point at end of ring."
-  (interactive "P")
-  (let ((date (calendar-cursor-to-date t)))
+  (interactive
+   (list current-prefix-arg last-nonmenu-event))
+  (let ((date (calendar-cursor-to-date t event)))
     (if arg
         (if (null calendar-mark-ring)
             (error "No mark set in this buffer")
--- a/lisp/calendar/diary-lib.el	Tue Jun 17 15:39:06 2008 +0000
+++ b/lisp/calendar/diary-lib.el	Tue Jun 17 15:42:19 2008 +0000
@@ -1998,11 +1998,12 @@
 (define-obsolete-function-alias 'make-diary-entry 'diary-make-entry "23.1")
 
 ;;;###cal-autoload
-(defun diary-insert-entry (arg)
+(defun diary-insert-entry (arg &optional event)
   "Insert a diary entry for the date indicated by point.
 Prefix argument ARG makes the entry nonmarking."
-  (interactive "P")
-  (diary-make-entry (calendar-date-string (calendar-cursor-to-date t) t t)
+  (interactive
+   (list current-prefix-arg last-nonmenu-event))
+  (diary-make-entry (calendar-date-string (calendar-cursor-to-date t event) t t)
                     arg))
 
 ;;;###cal-autoload
--- a/lisp/calendar/solar.el	Tue Jun 17 15:39:06 2008 +0000
+++ b/lisp/calendar/solar.el	Tue Jun 17 15:42:19 2008 +0000
@@ -853,13 +853,13 @@
 contents of temp window."))))))
 
 ;;;###cal-autoload
-(defun calendar-sunrise-sunset ()
+(defun calendar-sunrise-sunset (&optional event)
   "Local time of sunrise and sunset for date under cursor.
 Accurate to a few seconds."
-  (interactive)
+  (interactive (list last-nonmenu-event))
   (or (and calendar-latitude calendar-longitude calendar-time-zone)
       (solar-setup))
-  (let ((date (calendar-cursor-to-date t)))
+  (let ((date (calendar-cursor-to-date t event)))
     (message "%s: %s"
              (calendar-date-string date t t)
              (solar-sunrise-sunset-string date))))