* calendar/calendar.el (calendar-remove-frame-by-deleting):
[bpt/emacs.git] / lisp / calendar / cal-menu.el
index 037c00a..7c7056d 100644 (file)
@@ -37,6 +37,9 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'calendar))
+(require 'easymenu)
+
 (define-key calendar-mode-map [menu-bar edit] 'undefined)
 (define-key calendar-mode-map [menu-bar search] 'undefined)
 
 (define-key calendar-mode-map [menu-bar diary view]
   '("Other File" . view-other-diary-entries))
 
-(define-key calendar-mode-map [menu-bar holidays]
+(define-key calendar-mode-map [menu-bar Holidays]
   (cons "Holidays" (make-sparse-keymap "Holidays")))
 
-(define-key calendar-mode-map [menu-bar holidays unmark]
-  '("Unmark" . calendar-unmark))
-(define-key calendar-mode-map [menu-bar holidays mark]
-  '("Mark" . mark-calendar-holidays))
-(define-key calendar-mode-map [menu-bar holidays previous-year]
-  '("Previous year" . cal-menu-list-holidays-previous-year))
-(define-key calendar-mode-map [menu-bar holidays following-year]
-  '("Following year" . cal-menu-list-holidays-following-year))
-(define-key calendar-mode-map [menu-bar holidays year]
-  '("Year" . cal-menu-list-holidays-year))
-(define-key calendar-mode-map [menu-bar holidays 3-mon]
-  '("3 Months" . list-calendar-holidays))
-(define-key calendar-mode-map [menu-bar holidays 1-day]
-  '("One Day" . calendar-cursor-holidays))
-
 (define-key calendar-mode-map [menu-bar goto]
   (cons "Goto" (make-sparse-keymap "Goto")))
 
   (let ((year (1- (extract-calendar-year (calendar-cursor-to-date)))))
     (list-holidays year year)))
 
+(defun cal-menu-update ()
+  ;; Update the holiday part of calendar menu bar for the current display.
+  (condition-case nil
+      (if (eq major-mode 'calendar-mode)
+          (let ((l))
+            (calendar-for-loop;; Show 11 years--5 before, 5 after year of
+                   ;; middle month
+             i from (- displayed-year 5) to (+ displayed-year 5) do
+             (setq l (cons (vector (format "For Year %s" i)
+                                   (list (list 'lambda 'nil '(interactive)
+                                               (list 'list-holidays i i)))
+                                   t)
+                           l)))
+            (setq l (cons ["Mark Holidays" mark-calendar-holidays t]
+                          (cons ["Unmark Calendar" calendar-unmark t]
+                                (cons ["--" '("--") t] l))))
+            (easy-menu-change nil "Holidays" (nreverse l))
+            (define-key calendar-mode-map [menu-bar Holidays separator]
+              '("--"))
+            (define-key calendar-mode-map [menu-bar Holidays today]
+                `(,(format "For Today (%s)"
+                           (calendar-date-string (calendar-current-date) t t))
+                  . cal-menu-today-holidays))
+            (let ((title
+                   (let ((m1 displayed-month)
+                         (y1 displayed-year)
+                         (m2 displayed-month)
+                         (y2 displayed-year))
+                     (increment-calendar-month m1 y1 -1)
+                     (increment-calendar-month m2 y2 1)
+                     (if (= y1 y2)
+                         (format "%s-%s, %d"
+                                 (calendar-month-name m1 3)
+                                 (calendar-month-name m2 3)
+                                 y2)
+                       (format "%s, %d-%s, %d"
+                               (calendar-month-name m1 3)
+                               y1
+                               (calendar-month-name m2 3)
+                               y2)))))
+              (define-key  calendar-mode-map [menu-bar Holidays 3-month]
+                `(,(format "For Window (%s)" title)
+                  . list-calendar-holidays)))
+            (let ((date (calendar-cursor-to-date)))
+              (if date
+                  (define-key calendar-mode-map [menu-bar Holidays 1-day]
+                    `(,(format "For Cursor Date (%s)"
+                               (calendar-date-string date t t))
+                      . calendar-cursor-holidays))))))
+    ;; Try to avoid entering infinite beep mode in case of errors.
+    (error (ding))))
+
 (defun calendar-event-to-date (&optional error)
   "Date of last event.
 If event is not on a specific date, signals an error if optional parameter
@@ -233,26 +273,71 @@ ERROR is t, otherwise just returns nil."
     (calendar-mouse-goto-date (calendar-event-to-date))
     (calendar-sunrise-sunset)))
 
-(defun calendar-mouse-holidays ()
-  "Show holidays for mouse-selected date."
+(defun cal-menu-today-holidays ()
+  "Show holidays for today's date."
   (interactive)
   (save-excursion
-    (calendar-mouse-goto-date (calendar-event-to-date))
+    (calendar-cursor-to-date (calendar-current-date))
     (calendar-cursor-holidays)))
 
+(defun calendar-mouse-holidays ()
+  "Pop up menu of holidays for mouse selected date."
+  (interactive)
+  (let* ((date (calendar-event-to-date))
+         (l (mapcar '(lambda (x) (list x))
+                    (check-calendar-holidays date)))
+         (selection
+          (x-popup-menu
+           event
+           (list
+            (format "Holidays for %s" (calendar-date-string date))
+            (append
+             (list (format "Holidays for %s" (calendar-date-string date)))
+             (if l l '("None")))))))
+    (and selection (call-interactively selection))))
+
 (defun calendar-mouse-view-diary-entries ()
-  "View diary entries on mouse-selected date."
+  "Pop up menu of diary entries for mouse selected date."
   (interactive)
-  (save-excursion
-    (calendar-mouse-goto-date (calendar-event-to-date))
-    (view-diary-entries 1)))
+  (let* ((date (calendar-event-to-date))
+         (l (mapcar '(lambda (x) (list (car (cdr x))))
+                    (let ((diary-list-include-blanks nil)
+                          (diary-display-hook 'ignore))
+                      (list-diary-entries date 1))))
+         (selection
+          (x-popup-menu
+           event
+           (list
+            (format "Diary entries for %s" (calendar-date-string date))
+            (append
+             (list (format "Diary entries for %s" (calendar-date-string date)))
+             (if l l '("None")))))))
+    (and selection (call-interactively selection))))
 
 (defun calendar-mouse-view-other-diary-entries ()
-  "View diary entries from alternative file on mouse-selected date."
+  "Pop up menu of diary entries from alternative file on mouse-selected date."
   (interactive)
-  (save-excursion
-    (calendar-mouse-goto-date (calendar-event-to-date))
-    (call-interactively 'view-other-diary-entries)))
+  (let* ((date (calendar-event-to-date))
+         (l (mapcar '(lambda (x) (list (car (cdr x))))
+                    (let ((diary-list-include-blanks nil)
+                          (diary-display-hook 'ignore)
+                          (diary-file (read-file-name
+                                       "Enter diary file name: "
+                                       default-directory nil t)))
+                      (list-diary-entries date 1))))
+         (selection
+          (x-popup-menu
+           event
+           (list
+            (format "Diary entries from %s for %s"
+                    diary-file
+                    (calendar-date-string date))
+            (append
+             (list (format "Diary entries from %s for %s"
+                            diary-file
+                           (calendar-date-string date)))
+             (if l l '("None")))))))
+    (and selection (call-interactively selection))))
 
 (defun calendar-mouse-insert-diary-entry ()
   "Insert diary entry for mouse-selected date."
@@ -306,6 +391,13 @@ Holidays are included if `cal-tex-holidays' is t."
     (calendar-mouse-goto-date (calendar-event-to-date))
     (cal-tex-cursor-week-monday nil)))
 
+(defun cal-tex-mouse-filofax-daily ()
+  "Day-per-page Filofax calendar for week indicated by cursor."
+  (interactive)
+  (save-excursion
+    (calendar-mouse-goto-date (calendar-event-to-date))
+    (cal-tex-cursor-filofax-daily nil)))
+
 (defun cal-tex-mouse-filofax-2week ()
   "One page Filofax calendar for week indicated by cursor."
   (interactive)
@@ -376,6 +468,9 @@ The output is in landscape format, one month to a page."
              (list
               (format "Astronomical (Julian) day number (at noon UTC): %s.0"
                            (calendar-astro-date-string date)))
+             (list
+              (format "Fixed (RD) date: %s"
+                      (calendar-absolute-from-gregorian date)))
              (list (format "Hebrew date (before sunset): %s"
                            (calendar-hebrew-date-string date)))
              (list (format "Persian date: %s"
@@ -468,6 +563,8 @@ The output is in landscape format, one month to a page."
            (list (calendar-date-string date t nil)
                  (list
                   ""
+                  '("Filofax Daily (one-day-per-page)" .
+                    cal-tex-mouse-filofax-daily)
                   '("Filofax Weekly (2-weeks-at-a-glance)" .
                     cal-tex-mouse-filofax-2week)
                   '("Filofax Weekly (week-at-a-glance)" .