Commit 10979c74 authored by Stefan Monnier's avatar Stefan Monnier

* 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.
parent de7a9afa
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'.
......
......@@ -184,13 +184,6 @@ ERROR is non-nil, otherwise just returns nil."
(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 @@ is non-nil."
(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 @@ EVENT is the event that invoked this command."
'("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 @@ EVENT is the event that invoked this command."
["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
......
......@@ -1571,10 +1571,17 @@ the STRINGS are just concatenated and the result truncated."
(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 @@ ERROR is non-nil, otherwise just returns nil."
((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 @@ EVENT is an event like `last-nonmenu-event'."
((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")
......
......@@ -1998,11 +1998,12 @@ If omitted, NONMARKING defaults to nil and FILE defaults to
(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
......
......@@ -853,13 +853,13 @@ This function is suitable for execution in a .emacs file."
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))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment