From dc67263ca39f129d07485b3da3a4b9b6c5b2c93f Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 10 Jan 2009 22:00:33 +0000 Subject: [PATCH] (calendar-lunar-phases): Add event handling, for when called from menus with the calendar buffer not current. --- lisp/calendar/lunar.el | 66 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/lisp/calendar/lunar.el b/lisp/calendar/lunar.el index 26710d8c9cf..1e779452886 100644 --- a/lisp/calendar/lunar.el +++ b/lisp/calendar/lunar.el @@ -178,36 +178,42 @@ remainder mod 4 gives the phase: 0 new moon, 1 first quarter, 2 full moon, (defvar displayed-year) ;;;###cal-autoload -(defun calendar-lunar-phases () - "Create a buffer with the lunar phases for the current calendar window." - (interactive) - (message "Computing phases of the moon...") - (let ((m1 displayed-month) - (y1 displayed-year) - (m2 displayed-month) - (y2 displayed-year)) - (calendar-increment-month m1 y1 -1) - (calendar-increment-month m2 y2 1) - (calendar-in-read-only-buffer lunar-phases-buffer - (calendar-set-mode-line - (if (= y1 y2) - (format "Phases of the Moon from %s to %s, %d%%-" - (calendar-month-name m1) (calendar-month-name m2) y2) - (format "Phases of the Moon from %s, %d to %s, %d%%-" - (calendar-month-name m1) y1 (calendar-month-name m2) y2))) - (insert - (mapconcat - (lambda (x) - (let ((date (car x)) - (time (cadr x)) - (phase (nth 2 x))) - (concat (calendar-date-string date) - ": " - (lunar-phase-name phase) - " " - time))) - (lunar-phase-list m1 y1) "\n"))) - (message "Computing phases of the moon...done"))) +(defun calendar-lunar-phases (&optional event) + "Create a buffer with the lunar phases for the current calendar window. +If EVENT is non-nil, it's an event indicating the buffer position to +use instead of point." + (interactive (list last-nonmenu-event)) + ;; If called from a menu, with the calendar window not selected. + (with-current-buffer + (if event (window-buffer (posn-window (event-start event))) + (current-buffer)) + (message "Computing phases of the moon...") + (let ((m1 displayed-month) + (y1 displayed-year) + (m2 displayed-month) + (y2 displayed-year)) + (calendar-increment-month m1 y1 -1) + (calendar-increment-month m2 y2 1) + (calendar-in-read-only-buffer lunar-phases-buffer + (calendar-set-mode-line + (if (= y1 y2) + (format "Phases of the Moon from %s to %s, %d%%-" + (calendar-month-name m1) (calendar-month-name m2) y2) + (format "Phases of the Moon from %s, %d to %s, %d%%-" + (calendar-month-name m1) y1 (calendar-month-name m2) y2))) + (insert + (mapconcat + (lambda (x) + (let ((date (car x)) + (time (cadr x)) + (phase (nth 2 x))) + (concat (calendar-date-string date) + ": " + (lunar-phase-name phase) + " " + time))) + (lunar-phase-list m1 y1) "\n"))) + (message "Computing phases of the moon...done")))) ;;;###cal-autoload (define-obsolete-function-alias 'calendar-phases-of-moon -- 2.39.2