1 ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
6 ;; Lara Rios <lrios@coewl.cen.uiuc.edu>
8 ;; Human-Keywords: calendar, popup menus, menu bar
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This collection of functions implements menu bar and popup menu support for
32 ;; Comments, corrections, and improvements should be sent to
33 ;; Edward M. Reingold Department of Computer Science
34 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
35 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
36 ;; Urbana, Illinois 61801
40 (eval-when-compile (require 'calendar))
43 (define-key calendar-mode-map [menu-bar edit] 'undefined)
44 (define-key calendar-mode-map [menu-bar search] 'undefined)
46 (define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
47 (define-key calendar-mode-map [mouse-2] 'ignore)
49 (defvar calendar-mouse-3-map (make-sparse-keymap "Calendar"))
50 (define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map)
51 (define-key calendar-mode-map [C-down-mouse-3] calendar-mouse-3-map)
53 (define-key calendar-mode-map [menu-bar moon]
54 (cons "Moon" (make-sparse-keymap "Moon")))
56 (define-key calendar-mode-map [menu-bar moon moon]
57 '("Lunar Phases" . calendar-phases-of-moon))
59 (define-key calendar-mode-map [menu-bar diary]
60 (cons "Diary" (make-sparse-keymap "Diary")))
62 (define-key calendar-mode-map [menu-bar diary heb]
63 '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry))
64 (define-key calendar-mode-map [menu-bar diary isl]
65 '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry))
66 (define-key calendar-mode-map [menu-bar diary cyc]
67 '("Insert Cyclic" . insert-cyclic-diary-entry))
68 (define-key calendar-mode-map [menu-bar diary blk]
69 '("Insert Block" . insert-block-diary-entry))
70 (define-key calendar-mode-map [menu-bar diary ann]
71 '("Insert Anniversary" . insert-anniversary-diary-entry))
72 (define-key calendar-mode-map [menu-bar diary yr]
73 '("Insert Yearly" . insert-yearly-diary-entry))
74 (define-key calendar-mode-map [menu-bar diary mon]
75 '("Insert Monthly" . insert-monthly-diary-entry))
76 (define-key calendar-mode-map [menu-bar diary wk]
77 '("Insert Weekly" . insert-weekly-diary-entry))
78 (define-key calendar-mode-map [menu-bar diary ent]
79 '("Insert Daily". insert-diary-entry))
80 (define-key calendar-mode-map [menu-bar diary all]
81 '("Show All" . show-all-diary-entries))
82 (define-key calendar-mode-map [menu-bar diary mark]
83 '("Mark All" . mark-diary-entries))
84 (define-key calendar-mode-map [menu-bar diary view]
85 '("Cursor Date" . view-diary-entries))
86 (define-key calendar-mode-map [menu-bar diary view]
87 '("Other File" . view-other-diary-entries))
89 (define-key calendar-mode-map [menu-bar Holidays]
90 (cons "Holidays" (make-sparse-keymap "Holidays")))
92 (define-key calendar-mode-map [menu-bar goto]
93 (cons "Goto" (make-sparse-keymap "Goto")))
95 (define-key calendar-mode-map [menu-bar goto french]
96 '("French Date" . calendar-goto-french-date))
97 (define-key calendar-mode-map [menu-bar goto mayan]
98 (cons "Mayan Date" (make-sparse-keymap "Mayan")))
99 (define-key calendar-mode-map [menu-bar goto ethiopic]
100 '("Ethiopic Date" . calendar-goto-ethiopic-date))
101 (define-key calendar-mode-map [menu-bar goto coptic]
102 '("Coptic Date" . calendar-goto-coptic-date))
103 (define-key calendar-mode-map [menu-bar goto chinese]
104 '("Chinese Date" . calendar-goto-chinese-date))
105 (define-key calendar-mode-map [menu-bar goto julian]
106 '("Julian Date" . calendar-goto-julian-date))
107 (define-key calendar-mode-map [menu-bar goto islamic]
108 '("Islamic Date" . calendar-goto-islamic-date))
109 (define-key calendar-mode-map [menu-bar goto persian]
110 '("Persian Date" . calendar-goto-persian-date))
111 (define-key calendar-mode-map [menu-bar goto hebrew]
112 '("Hebrew Date" . calendar-goto-hebrew-date))
113 (define-key calendar-mode-map [menu-bar goto astro]
114 '("Astronomical Date" . calendar-goto-astro-day-number))
115 (define-key calendar-mode-map [menu-bar goto iso]
116 '("ISO Date" . calendar-goto-iso-date))
117 (define-key calendar-mode-map [menu-bar goto gregorian]
118 '("Other Date" . calendar-goto-date))
119 (define-key calendar-mode-map [menu-bar goto end-of-year]
120 '("End of Year" . calendar-end-of-year))
121 (define-key calendar-mode-map [menu-bar goto beginning-of-year]
122 '("Beginning of Year" . calendar-beginning-of-year))
123 (define-key calendar-mode-map [menu-bar goto end-of-month]
124 '("End of Month" . calendar-end-of-month))
125 (define-key calendar-mode-map [menu-bar goto beginning-of-month]
126 '("Beginning of Month" . calendar-beginning-of-month))
127 (define-key calendar-mode-map [menu-bar goto end-of-week]
128 '("End of Week" . calendar-end-of-week))
129 (define-key calendar-mode-map [menu-bar goto beginning-of-week]
130 '("Beginning of Week" . calendar-beginning-of-week))
131 (define-key calendar-mode-map [menu-bar goto today]
132 '("Today" . calendar-goto-today))
135 (define-key calendar-mode-map [menu-bar goto mayan prev-rnd]
136 '("Previous Round" . calendar-previous-calendar-round-date))
137 (define-key calendar-mode-map [menu-bar goto mayan nxt-rnd]
138 '("Next Round" . calendar-next-calendar-round-date))
139 (define-key calendar-mode-map [menu-bar goto mayan prev-haab]
140 '("Previous Haab" . calendar-previous-haab-date))
141 (define-key calendar-mode-map [menu-bar goto mayan next-haab]
142 '("Next Haab" . calendar-next-haab-date))
143 (define-key calendar-mode-map [menu-bar goto mayan prev-tzol]
144 '("Previous Tzolkin" . calendar-previous-tzolkin-date))
145 (define-key calendar-mode-map [menu-bar goto mayan next-tzol]
146 '("Next Tzolkin" . calendar-next-tzolkin-date))
148 (define-key calendar-mode-map [menu-bar scroll]
149 (cons "Scroll" (make-sparse-keymap "Scroll")))
151 (define-key calendar-mode-map [menu-bar scroll bk-12]
152 '("Backward 1 Year" . "4\ev"))
153 (define-key calendar-mode-map [menu-bar scroll bk-3]
154 '("Backward 3 Months" . scroll-calendar-right-three-months))
155 (define-key calendar-mode-map [menu-bar scroll bk-1]
156 '("Backward 1 Month" . scroll-calendar-right))
157 (define-key calendar-mode-map [menu-bar scroll fwd-12]
158 '("Forward 1 Year" . "4\C-v"))
159 (define-key calendar-mode-map [menu-bar scroll fwd-3]
160 '("Forward 3 Months" . scroll-calendar-left-three-months))
161 (define-key calendar-mode-map [menu-bar scroll fwd-1]
162 '("Forward 1 Month" . scroll-calendar-left))
164 (defun cal-menu-list-holidays-year ()
165 "Display a list of the holidays of the selected date's year."
167 (let ((year (extract-calendar-year (calendar-cursor-to-date))))
168 (list-holidays year year)))
170 (defun cal-menu-list-holidays-following-year ()
171 "Display a list of the holidays of the following year."
173 (let ((year (1+ (extract-calendar-year (calendar-cursor-to-date)))))
174 (list-holidays year year)))
176 (defun cal-menu-list-holidays-previous-year ()
177 "Display a list of the holidays of the previous year."
179 (let ((year (1- (extract-calendar-year (calendar-cursor-to-date)))))
180 (list-holidays year year)))
182 (defun cal-menu-update ()
183 ;; Update the holiday part of calendar menu bar for the current display.
185 (if (eq major-mode 'calendar-mode)
187 (calendar-for-loop;; Show 11 years--5 before, 5 after year of
189 i from (- displayed-year 5) to (+ displayed-year 5) do
190 (setq l (cons (vector (format "For Year %s" i)
191 (list (list 'lambda 'nil '(interactive)
192 (list 'list-holidays i i)))
195 (setq l (cons ["Mark Holidays" mark-calendar-holidays t]
196 (cons ["Unmark Calendar" calendar-unmark t]
197 (cons ["--" '("--") t] l))))
198 (easy-menu-change nil "Holidays" (nreverse l))
199 (define-key calendar-mode-map [menu-bar Holidays separator]
201 (define-key calendar-mode-map [menu-bar Holidays today]
202 `(,(format "For Today (%s)"
203 (calendar-date-string (calendar-current-date) t t))
204 . cal-menu-today-holidays))
206 (let ((m1 displayed-month)
210 (increment-calendar-month m1 y1 -1)
211 (increment-calendar-month m2 y2 1)
214 (calendar-month-name m1 3)
215 (calendar-month-name m2 3)
217 (format "%s, %d-%s, %d"
218 (calendar-month-name m1 3)
220 (calendar-month-name m2 3)
222 (define-key calendar-mode-map [menu-bar Holidays 3-month]
223 `(,(format "For Window (%s)" title)
224 . list-calendar-holidays)))
225 (let ((date (calendar-cursor-to-date)))
227 (define-key calendar-mode-map [menu-bar Holidays 1-day]
228 `(,(format "For Date %s"
229 (calendar-date-string date t t))
230 . calendar-cursor-holidays))))))
231 ;; Try to avoid entering infinite beep mode in case of errors.
234 (defun calendar-event-to-date (&optional error)
236 If event is not on a specific date, signals an error if optional parameter
237 ERROR is t, otherwise just returns nil."
239 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
240 (goto-char (posn-point (event-start last-input-event)))
241 (calendar-cursor-to-date error)))
243 (defun calendar-mouse-insert-hebrew-diary-entry (event)
244 "Pop up menu to insert a Hebrew-date diary entry."
246 (let ((hebrew-selection
249 (list "Hebrew insert menu"
250 (list (calendar-hebrew-date-string (calendar-cursor-to-date))
251 '("One time" . insert-hebrew-diary-entry)
252 '("Monthly" . insert-monthly-hebrew-diary-entry)
253 '("Yearly" . insert-yearly-hebrew-diary-entry))))))
254 (and hebrew-selection (call-interactively hebrew-selection))))
256 (defun calendar-mouse-insert-islamic-diary-entry (event)
257 "Pop up menu to insert an Islamic-date diary entry."
259 (let ((islamic-selection
262 (list "Islamic insert menu"
263 (list (calendar-islamic-date-string (calendar-cursor-to-date))
264 '("One time" . insert-islamic-diary-entry)
265 '("Monthly" . insert-monthly-islamic-diary-entry)
266 '("Yearly" . insert-yearly-islamic-diary-entry))))))
267 (and islamic-selection (call-interactively islamic-selection))))
269 (defun calendar-mouse-sunrise/sunset ()
270 "Show sunrise/sunset times for mouse-selected date."
273 (calendar-mouse-goto-date (calendar-event-to-date))
274 (calendar-sunrise-sunset)))
276 (defun cal-menu-today-holidays ()
277 "Show holidays for today's date."
280 (calendar-cursor-to-date (calendar-current-date))
281 (calendar-cursor-holidays)))
283 (defun calendar-mouse-holidays ()
284 "Show holidays for mouse-selected date."
287 (calendar-mouse-goto-date (calendar-event-to-date))
288 (calendar-cursor-holidays)))
290 (defun calendar-mouse-view-diary-entries ()
291 "View diary entries on mouse-selected date."
294 (calendar-mouse-goto-date (calendar-event-to-date))
295 (view-diary-entries 1)))
297 (defun calendar-mouse-view-other-diary-entries ()
298 "View diary entries from alternative file on mouse-selected date."
301 (calendar-mouse-goto-date (calendar-event-to-date))
302 (call-interactively 'view-other-diary-entries)))
304 (defun calendar-mouse-insert-diary-entry ()
305 "Insert diary entry for mouse-selected date."
308 (calendar-mouse-goto-date (calendar-event-to-date))
309 (insert-diary-entry nil)))
311 (defun calendar-mouse-set-mark ()
312 "Mark the date under the cursor."
315 (calendar-mouse-goto-date (calendar-event-to-date))
316 (calendar-set-mark nil)))
318 (defun cal-tex-mouse-day ()
319 "Make a buffer with LaTeX commands for the day mouse is on."
322 (calendar-mouse-goto-date (calendar-event-to-date))
323 (cal-tex-cursor-day nil)))
325 (defun cal-tex-mouse-week ()
326 "One page calendar for week indicated by cursor.
327 Holidays are included if `cal-tex-holidays' is t."
330 (calendar-mouse-goto-date (calendar-event-to-date))
331 (cal-tex-cursor-week nil)))
333 (defun cal-tex-mouse-week2 ()
334 "Make a buffer with LaTeX commands for the week cursor is on.
335 The printed output will be on two pages."
338 (calendar-mouse-goto-date (calendar-event-to-date))
339 (cal-tex-cursor-week2 nil)))
341 (defun cal-tex-mouse-week-iso ()
342 "One page calendar for week indicated by cursor.
343 Holidays are included if `cal-tex-holidays' is t."
346 (calendar-mouse-goto-date (calendar-event-to-date))
347 (cal-tex-cursor-week-iso nil)))
349 (defun cal-tex-mouse-week-monday ()
350 "One page calendar for week indicated by cursor."
353 (calendar-mouse-goto-date (calendar-event-to-date))
354 (cal-tex-cursor-week-monday nil)))
356 (defun cal-tex-mouse-filofax-daily ()
357 "Day-per-page Filofax calendar for week indicated by cursor."
360 (calendar-mouse-goto-date (calendar-event-to-date))
361 (cal-tex-cursor-filofax-daily nil)))
363 (defun cal-tex-mouse-filofax-2week ()
364 "One page Filofax calendar for week indicated by cursor."
367 (calendar-mouse-goto-date (calendar-event-to-date))
368 (cal-tex-cursor-filofax-2week nil)))
370 (defun cal-tex-mouse-filofax-week ()
371 "Two page Filofax calendar for week indicated by cursor."
374 (calendar-mouse-goto-date (calendar-event-to-date))
375 (cal-tex-cursor-filofax-week nil)))
377 (defun cal-tex-mouse-month ()
378 "Make a buffer with LaTeX commands for the month cursor is on.
379 Calendar is condensed onto one page."
382 (calendar-mouse-goto-date (calendar-event-to-date))
383 (cal-tex-cursor-month nil)))
385 (defun cal-tex-mouse-month-landscape ()
386 "Make a buffer with LaTeX commands for the month cursor is on.
387 The output is in landscape format, one month to a page."
390 (calendar-mouse-goto-date (calendar-event-to-date))
391 (cal-tex-cursor-month-landscape nil)))
393 (defun cal-tex-mouse-year ()
394 "Make a buffer with LaTeX commands for the year cursor is on."
397 (calendar-mouse-goto-date (calendar-event-to-date))
398 (cal-tex-cursor-year nil)))
400 (defun cal-tex-mouse-filofax-year ()
401 "Make a buffer with LaTeX commands for Filofax calendar of year cursor is on."
404 (calendar-mouse-goto-date (calendar-event-to-date))
405 (cal-tex-cursor-filofax-year nil)))
407 (defun cal-tex-mouse-year-landscape ()
408 "Make a buffer with LaTeX commands for the year cursor is on."
411 (calendar-mouse-goto-date (calendar-event-to-date))
412 (cal-tex-cursor-year-landscape nil)))
414 (defun calendar-mouse-print-dates ()
415 "Pop up menu of equivalent dates to mouse selected date."
417 (let ((date (calendar-event-to-date))
422 (concat (calendar-date-string date) " (Gregorian)")
425 (concat (calendar-date-string date) " (Gregorian)")
426 (list (calendar-day-of-year-string date))
427 (list (format "ISO date: %s" (calendar-iso-date-string date)))
428 (list (format "Julian date: %s"
429 (calendar-julian-date-string date)))
431 (format "Astronomical (Julian) day number (at noon UTC): %s.0"
432 (calendar-astro-date-string date)))
434 (format "Fixed (RD) date: %s"
435 (calendar-absolute-from-gregorian date)))
436 (list (format "Hebrew date (before sunset): %s"
437 (calendar-hebrew-date-string date)))
438 (list (format "Persian date: %s"
439 (calendar-persian-date-string date))))
440 (let ((i (calendar-islamic-date-string date)))
441 (if (not (string-equal i ""))
442 (list (list (format "Islamic date (before sunset): %s" i)))))
444 (list (format "Chinese date: %s"
445 (calendar-chinese-date-string date))))
446 ; (list '("Chinese date (select to echo Chinese date)"
447 ; . calendar-mouse-chinese-date))
448 (let ((c (calendar-coptic-date-string date)))
449 (if (not (string-equal c ""))
450 (list (list (format "Coptic date: %s" c)))))
451 (let ((e (calendar-ethiopic-date-string date)))
452 (if (not (string-equal e ""))
453 (list (list (format "Ethiopic date: %s" e)))))
454 (let ((f (calendar-french-date-string date)))
455 (if (not (string-equal f ""))
456 (list (list (format "French Revolutionary date: %s" f)))))
459 (format "Mayan date: %s"
460 (calendar-mayan-date-string date)))))))))
461 (and selection (call-interactively selection))))
463 (defun calendar-mouse-chinese-date ()
464 "Show Chinese equivalent for mouse-selected date."
467 (calendar-mouse-goto-date (calendar-event-to-date))
468 (calendar-print-chinese-date)))
470 (defun calendar-mouse-goto-date (date)
471 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
472 (calendar-goto-date date))
474 (defun calendar-mouse-2-date-menu (event)
475 "Pop up menu for Mouse-2 for selected date in the calendar window."
477 (let* ((date (calendar-event-to-date t))
481 (list (calendar-date-string date t nil)
484 '("Holidays" . calendar-mouse-holidays)
485 '("Mark date" . calendar-mouse-set-mark)
486 '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
487 '("Other calendars" . calendar-mouse-print-dates)
488 '("Prepare LaTeX buffer" . calendar-mouse-cal-tex-menu)
489 '("Diary entries" . calendar-mouse-view-diary-entries)
490 '("Insert diary entry" . calendar-mouse-insert-diary-entry)
491 '("Other diary file entries"
492 . calendar-mouse-view-other-diary-entries)
494 (and selection (call-interactively selection))))
496 (defun calendar-mouse-cal-tex-menu (event)
497 "Pop up submenu for Mouse-2 for cal-tex commands for selected date in the calendar window."
502 (list (calendar-date-string date t nil)
505 '("Daily (1 page)" . cal-tex-mouse-day)
506 '("Weekly (1 page)" . cal-tex-mouse-week)
507 '("Weekly (2 pages)" . cal-tex-mouse-week2)
508 '("Weekly (other style; 1 page)" . cal-tex-mouse-week-iso)
509 '("Weekly (yet another style; 1 page)" .
510 cal-tex-mouse-week-monday)
511 '("Monthly" . cal-tex-mouse-month)
512 '("Monthly (landscape)" . cal-tex-mouse-month-landscape)
513 '("Yearly" . cal-tex-mouse-year)
514 '("Yearly (landscape)" . cal-tex-mouse-year-landscape)
515 '("Filofax styles" . cal-tex-mouse-filofax)
517 (and selection (call-interactively selection))))
519 (defun cal-tex-mouse-filofax (event)
520 "Pop up sub-submenu for Mouse-2 for Filofax cal-tex commands for selected date."
525 (list (calendar-date-string date t nil)
528 '("Filofax Daily (one-day-per-page)" .
529 cal-tex-mouse-filofax-daily)
530 '("Filofax Weekly (2-weeks-at-a-glance)" .
531 cal-tex-mouse-filofax-2week)
532 '("Filofax Weekly (week-at-a-glance)" .
533 cal-tex-mouse-filofax-week)
534 '("Filofax Yearly" . cal-tex-mouse-filofax-year)
536 (and selection (call-interactively selection))))
538 (define-key calendar-mouse-3-map [exit-calendar]
539 '("Exit calendar" . exit-calendar))
540 (define-key calendar-mouse-3-map [show-diary]
541 '("Show diary" . show-all-diary-entries))
542 (define-key calendar-mouse-3-map [lunar-phases]
543 '("Lunar phases" . calendar-phases-of-moon))
544 (define-key calendar-mouse-3-map [unmark]
545 '("Unmark" . calendar-unmark))
546 (define-key calendar-mouse-3-map [mark-holidays]
547 '("Mark holidays" . mark-calendar-holidays))
548 (define-key calendar-mouse-3-map [list-holidays]
549 '("List holidays" . list-calendar-holidays))
550 (define-key calendar-mouse-3-map [mark-diary-entries]
551 '("Mark diary entries" . mark-diary-entries))
552 (define-key calendar-mouse-3-map [scroll-backward]
553 '("Scroll backward" . scroll-calendar-right-three-months))
554 (define-key calendar-mouse-3-map [scroll-forward]
555 '("Scroll forward" . scroll-calendar-left-three-months))
557 (run-hooks 'cal-menu-load-hook)
561 ;;; cal-menu.el ends here