changeset 52230:75388c0f3104

Edward M. Reingold <reingold@emr.cs.iit.edu> (calendar-mode-map): Add `calendar-goto-day-of-year' to menu. (calendar-flatten): New function. (calendar-mouse-view-other-diary-entries) (calendar-mouse-view-diary-entries): Rewritten to put any holidays in the menu title and to show multi-line diary entries correctly in the menu.
author Glenn Morris <rgm@gnu.org>
date Sun, 17 Aug 2003 22:48:54 +0000
parents fec3d4a11b70
children 9529ff0804c2
files lisp/calendar/cal-menu.el
diffstat 1 files changed, 44 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/calendar/cal-menu.el	Sun Aug 17 22:46:42 2003 +0000
+++ b/lisp/calendar/cal-menu.el	Sun Aug 17 22:48:54 2003 +0000
@@ -117,6 +117,8 @@
   '("Astronomical Date" . calendar-goto-astro-day-number))
 (define-key calendar-mode-map [menu-bar goto iso]
   '("ISO Date" . calendar-goto-iso-date))
+(define-key calendar-mode-map [menu-bar goto day-of-year]
+  '("Day of Year" . calendar-goto-day-of-year))
 (define-key calendar-mode-map [menu-bar goto gregorian]
   '("Other Date" . calendar-goto-date))
 (define-key calendar-mode-map [menu-bar goto end-of-year]
@@ -164,6 +166,15 @@
 (define-key calendar-mode-map [menu-bar scroll fwd-1]
   '("Forward 1 Month" . scroll-calendar-left))
 
+(defun calendar-flatten (list)
+  "Flatten LIST eliminating sublists structure; result is a list of atoms.
+This is the same as the preorder list of leaves in a rooted forest."
+  (if (atom list)
+      (list list)
+    (if (cdr list)
+        (append (calendar-flatten (car list)) (calendar-flatten (cdr list)))
+      (calendar-flatten (car list)))))
+
 (defun cal-menu-x-popup-menu (position menu)
   "Like `x-popup-menu', but prints an error message if popup menus are
 not available."
@@ -307,53 +318,48 @@
              (if l l '("None")))))))
     (and selection (call-interactively selection))))
 
-(defun calendar-mouse-view-diary-entries ()
-  "Pop up menu of diary entries for mouse selected date."
+(defun calendar-mouse-view-diary-entries (&optional date diary)
+  "Pop up menu of diary entries for mouse-selected date.
+Use optional DATE and alternative file DIARY.
+
+Any holidays are shown if `holidays-in-diary-buffer' is t."
   (interactive)
-  (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))))
+  (let* ((date (if date date (calendar-event-to-date)))
+         (diary-file (if diary diary diary-file))
+         (diary-list-include-blanks nil)
+         (diary-display-hook 'ignore)
+         (diary-entries
+          (mapcar '(lambda (x) (split-string (car (cdr x)) "\^M\\|\n"))
+                  (list-diary-entries date 1)))
+         (holidays (if holidays-in-diary-buffer
+                       (mapcar '(lambda (x) (list x))
+                               (check-calendar-holidays date))))
+         (title (concat "Diary entries "
+                        (if diary (format "from %s " diary) "")
+                        "for "
+                        (calendar-date-string date)))
          (selection
           (cal-menu-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")))))))
+           (list title
+                 (append
+                  (list title)
+                  (if holidays
+                      (mapcar '(lambda (x) (list (concat "     " (car x))))
+                              holidays))
+                  (if holidays
+                      (list "--shadow-etched-in" "--shadow-etched-in"))
+                  (if diary-entries
+                      (mapcar 'list (calendar-flatten diary-entries))
+                    '("None")))))))
     (and selection (call-interactively selection))))
 
 (defun calendar-mouse-view-other-diary-entries ()
   "Pop up menu of diary entries from alternative file on mouse-selected date."
   (interactive)
-  (let* ((date (calendar-event-to-date))
-         (diary-list-include-blanks nil)
-         (diary-display-hook 'ignore)
-         (diary-file (read-file-name
-                      "Enter diary file name: "
-                      default-directory nil t))
-         ; The following doesn't really do the right thing.  The problem is
-         ; that a newline in the diary entry does not give a newline in a
-         ; pop-up menu; for that you need a separate list item.  When the (car
-         ; (cdr x)) contains newlines, the item should be split into a list of
-         ; items.  Too minor and messy to worry about.
-         (l (mapcar '(lambda (x) (list (car (cdr x))))
-                    (list-diary-entries date 1)))
-         (selection
-          (cal-menu-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))))
+  (calendar-mouse-view-diary-entries
+   (calendar-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."