]> code.delx.au - gnu-emacs/blob - lisp/calendar/cal-menu.el
Require calendar only when compiling.
[gnu-emacs] / lisp / calendar / cal-menu.el
1 ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
2
3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc.
4
5 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
6 ;; Lara Rios <lrios@coewl.cen.uiuc.edu>
7 ;; Keywords: calendar
8 ;; Human-Keywords: calendar, popup menus, menu bar
9
10 ;; This file is part of GNU Emacs.
11
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)
15 ;; any later version.
16
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.
21
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.
26
27 ;;; Commentary:
28
29 ;; This collection of functions implements menu bar and popup menu support for
30 ;; calendar.el.
31
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
37
38 ;;; Code:
39
40 (eval-when-compile (require 'calendar))
41
42 (define-key calendar-mode-map [menu-bar edit] 'undefined)
43 (define-key calendar-mode-map [menu-bar search] 'undefined)
44
45 (define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
46 (define-key calendar-mode-map [mouse-2] 'ignore)
47
48 (defvar calendar-mouse-3-map (make-sparse-keymap "Calendar"))
49 (define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map)
50 (define-key calendar-mode-map [C-down-mouse-3] calendar-mouse-3-map)
51
52 (define-key calendar-mode-map [menu-bar moon]
53 (cons "Moon" (make-sparse-keymap "Moon")))
54
55 (define-key calendar-mode-map [menu-bar moon moon]
56 '("Lunar Phases" . calendar-phases-of-moon))
57
58 (define-key calendar-mode-map [menu-bar diary]
59 (cons "Diary" (make-sparse-keymap "Diary")))
60
61 (define-key calendar-mode-map [menu-bar diary heb]
62 '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry))
63 (define-key calendar-mode-map [menu-bar diary isl]
64 '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry))
65 (define-key calendar-mode-map [menu-bar diary cyc]
66 '("Insert Cyclic" . insert-cyclic-diary-entry))
67 (define-key calendar-mode-map [menu-bar diary blk]
68 '("Insert Block" . insert-block-diary-entry))
69 (define-key calendar-mode-map [menu-bar diary ann]
70 '("Insert Anniversary" . insert-anniversary-diary-entry))
71 (define-key calendar-mode-map [menu-bar diary yr]
72 '("Insert Yearly" . insert-yearly-diary-entry))
73 (define-key calendar-mode-map [menu-bar diary mon]
74 '("Insert Monthly" . insert-monthly-diary-entry))
75 (define-key calendar-mode-map [menu-bar diary wk]
76 '("Insert Weekly" . insert-weekly-diary-entry))
77 (define-key calendar-mode-map [menu-bar diary ent]
78 '("Insert Daily". insert-diary-entry))
79 (define-key calendar-mode-map [menu-bar diary all]
80 '("Show All" . show-all-diary-entries))
81 (define-key calendar-mode-map [menu-bar diary mark]
82 '("Mark All" . mark-diary-entries))
83 (define-key calendar-mode-map [menu-bar diary view]
84 '("Cursor Date" . view-diary-entries))
85 (define-key calendar-mode-map [menu-bar diary view]
86 '("Other File" . view-other-diary-entries))
87
88 (define-key calendar-mode-map [menu-bar holidays]
89 (cons "Holidays" (make-sparse-keymap "Holidays")))
90
91 (define-key calendar-mode-map [menu-bar holidays unmark]
92 '("Unmark" . calendar-unmark))
93 (define-key calendar-mode-map [menu-bar holidays mark]
94 '("Mark" . mark-calendar-holidays))
95 (define-key calendar-mode-map [menu-bar holidays previous-year]
96 '("Previous year" . cal-menu-list-holidays-previous-year))
97 (define-key calendar-mode-map [menu-bar holidays following-year]
98 '("Following year" . cal-menu-list-holidays-following-year))
99 (define-key calendar-mode-map [menu-bar holidays year]
100 '("Year" . cal-menu-list-holidays-year))
101 (define-key calendar-mode-map [menu-bar holidays 3-mon]
102 '("3 Months" . list-calendar-holidays))
103 (define-key calendar-mode-map [menu-bar holidays 1-day]
104 '("One Day" . calendar-cursor-holidays))
105
106 (define-key calendar-mode-map [menu-bar goto]
107 (cons "Goto" (make-sparse-keymap "Goto")))
108
109 (define-key calendar-mode-map [menu-bar goto french]
110 '("French Date" . calendar-goto-french-date))
111 (define-key calendar-mode-map [menu-bar goto mayan]
112 (cons "Mayan Date" (make-sparse-keymap "Mayan")))
113 (define-key calendar-mode-map [menu-bar goto ethiopic]
114 '("Ethiopic Date" . calendar-goto-ethiopic-date))
115 (define-key calendar-mode-map [menu-bar goto coptic]
116 '("Coptic Date" . calendar-goto-coptic-date))
117 (define-key calendar-mode-map [menu-bar goto chinese]
118 '("Chinese Date" . calendar-goto-chinese-date))
119 (define-key calendar-mode-map [menu-bar goto julian]
120 '("Julian Date" . calendar-goto-julian-date))
121 (define-key calendar-mode-map [menu-bar goto islamic]
122 '("Islamic Date" . calendar-goto-islamic-date))
123 (define-key calendar-mode-map [menu-bar goto persian]
124 '("Persian Date" . calendar-goto-persian-date))
125 (define-key calendar-mode-map [menu-bar goto hebrew]
126 '("Hebrew Date" . calendar-goto-hebrew-date))
127 (define-key calendar-mode-map [menu-bar goto astro]
128 '("Astronomical Date" . calendar-goto-astro-day-number))
129 (define-key calendar-mode-map [menu-bar goto iso]
130 '("ISO Date" . calendar-goto-iso-date))
131 (define-key calendar-mode-map [menu-bar goto gregorian]
132 '("Other Date" . calendar-goto-date))
133 (define-key calendar-mode-map [menu-bar goto end-of-year]
134 '("End of Year" . calendar-end-of-year))
135 (define-key calendar-mode-map [menu-bar goto beginning-of-year]
136 '("Beginning of Year" . calendar-beginning-of-year))
137 (define-key calendar-mode-map [menu-bar goto end-of-month]
138 '("End of Month" . calendar-end-of-month))
139 (define-key calendar-mode-map [menu-bar goto beginning-of-month]
140 '("Beginning of Month" . calendar-beginning-of-month))
141 (define-key calendar-mode-map [menu-bar goto end-of-week]
142 '("End of Week" . calendar-end-of-week))
143 (define-key calendar-mode-map [menu-bar goto beginning-of-week]
144 '("Beginning of Week" . calendar-beginning-of-week))
145 (define-key calendar-mode-map [menu-bar goto today]
146 '("Today" . calendar-goto-today))
147
148
149 (define-key calendar-mode-map [menu-bar goto mayan prev-rnd]
150 '("Previous Round" . calendar-previous-calendar-round-date))
151 (define-key calendar-mode-map [menu-bar goto mayan nxt-rnd]
152 '("Next Round" . calendar-next-calendar-round-date))
153 (define-key calendar-mode-map [menu-bar goto mayan prev-haab]
154 '("Previous Haab" . calendar-previous-haab-date))
155 (define-key calendar-mode-map [menu-bar goto mayan next-haab]
156 '("Next Haab" . calendar-next-haab-date))
157 (define-key calendar-mode-map [menu-bar goto mayan prev-tzol]
158 '("Previous Tzolkin" . calendar-previous-tzolkin-date))
159 (define-key calendar-mode-map [menu-bar goto mayan next-tzol]
160 '("Next Tzolkin" . calendar-next-tzolkin-date))
161
162 (define-key calendar-mode-map [menu-bar scroll]
163 (cons "Scroll" (make-sparse-keymap "Scroll")))
164
165 (define-key calendar-mode-map [menu-bar scroll bk-12]
166 '("Backward 1 Year" . "4\ev"))
167 (define-key calendar-mode-map [menu-bar scroll bk-3]
168 '("Backward 3 Months" . scroll-calendar-right-three-months))
169 (define-key calendar-mode-map [menu-bar scroll bk-1]
170 '("Backward 1 Month" . scroll-calendar-right))
171 (define-key calendar-mode-map [menu-bar scroll fwd-12]
172 '("Forward 1 Year" . "4\C-v"))
173 (define-key calendar-mode-map [menu-bar scroll fwd-3]
174 '("Forward 3 Months" . scroll-calendar-left-three-months))
175 (define-key calendar-mode-map [menu-bar scroll fwd-1]
176 '("Forward 1 Month" . scroll-calendar-left))
177
178 (defun cal-menu-list-holidays-year ()
179 "Display a list of the holidays of the selected date's year."
180 (interactive)
181 (let ((year (extract-calendar-year (calendar-cursor-to-date))))
182 (list-holidays year year)))
183
184 (defun cal-menu-list-holidays-following-year ()
185 "Display a list of the holidays of the following year."
186 (interactive)
187 (let ((year (1+ (extract-calendar-year (calendar-cursor-to-date)))))
188 (list-holidays year year)))
189
190 (defun cal-menu-list-holidays-previous-year ()
191 "Display a list of the holidays of the previous year."
192 (interactive)
193 (let ((year (1- (extract-calendar-year (calendar-cursor-to-date)))))
194 (list-holidays year year)))
195
196 (defun calendar-event-to-date (&optional error)
197 "Date of last event.
198 If event is not on a specific date, signals an error if optional parameter
199 ERROR is t, otherwise just returns nil."
200 (save-excursion
201 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
202 (goto-char (posn-point (event-start last-input-event)))
203 (calendar-cursor-to-date error)))
204
205 (defun calendar-mouse-insert-hebrew-diary-entry (event)
206 "Pop up menu to insert a Hebrew-date diary entry."
207 (interactive "e")
208 (let ((hebrew-selection
209 (x-popup-menu
210 event
211 (list "Hebrew insert menu"
212 (list (calendar-hebrew-date-string (calendar-cursor-to-date))
213 '("One time" . insert-hebrew-diary-entry)
214 '("Monthly" . insert-monthly-hebrew-diary-entry)
215 '("Yearly" . insert-yearly-hebrew-diary-entry))))))
216 (and hebrew-selection (call-interactively hebrew-selection))))
217
218 (defun calendar-mouse-insert-islamic-diary-entry (event)
219 "Pop up menu to insert an Islamic-date diary entry."
220 (interactive "e")
221 (let ((islamic-selection
222 (x-popup-menu
223 event
224 (list "Islamic insert menu"
225 (list (calendar-islamic-date-string (calendar-cursor-to-date))
226 '("One time" . insert-islamic-diary-entry)
227 '("Monthly" . insert-monthly-islamic-diary-entry)
228 '("Yearly" . insert-yearly-islamic-diary-entry))))))
229 (and islamic-selection (call-interactively islamic-selection))))
230
231 (defun calendar-mouse-sunrise/sunset ()
232 "Show sunrise/sunset times for mouse-selected date."
233 (interactive)
234 (save-excursion
235 (calendar-mouse-goto-date (calendar-event-to-date))
236 (calendar-sunrise-sunset)))
237
238 (defun calendar-mouse-holidays ()
239 "Show holidays for mouse-selected date."
240 (interactive)
241 (save-excursion
242 (calendar-mouse-goto-date (calendar-event-to-date))
243 (calendar-cursor-holidays)))
244
245 (defun calendar-mouse-view-diary-entries ()
246 "View diary entries on mouse-selected date."
247 (interactive)
248 (save-excursion
249 (calendar-mouse-goto-date (calendar-event-to-date))
250 (view-diary-entries 1)))
251
252 (defun calendar-mouse-view-other-diary-entries ()
253 "View diary entries from alternative file on mouse-selected date."
254 (interactive)
255 (save-excursion
256 (calendar-mouse-goto-date (calendar-event-to-date))
257 (call-interactively 'view-other-diary-entries)))
258
259 (defun calendar-mouse-insert-diary-entry ()
260 "Insert diary entry for mouse-selected date."
261 (interactive)
262 (save-excursion
263 (calendar-mouse-goto-date (calendar-event-to-date))
264 (insert-diary-entry nil)))
265
266 (defun calendar-mouse-set-mark ()
267 "Mark the date under the cursor."
268 (interactive)
269 (save-excursion
270 (calendar-mouse-goto-date (calendar-event-to-date))
271 (calendar-set-mark nil)))
272
273 (defun cal-tex-mouse-day ()
274 "Make a buffer with LaTeX commands for the day mouse is on."
275 (interactive)
276 (save-excursion
277 (calendar-mouse-goto-date (calendar-event-to-date))
278 (cal-tex-cursor-day nil)))
279
280 (defun cal-tex-mouse-week ()
281 "One page calendar for week indicated by cursor.
282 Holidays are included if `cal-tex-holidays' is t."
283 (interactive)
284 (save-excursion
285 (calendar-mouse-goto-date (calendar-event-to-date))
286 (cal-tex-cursor-week nil)))
287
288 (defun cal-tex-mouse-week2 ()
289 "Make a buffer with LaTeX commands for the week cursor is on.
290 The printed output will be on two pages."
291 (interactive)
292 (save-excursion
293 (calendar-mouse-goto-date (calendar-event-to-date))
294 (cal-tex-cursor-week2 nil)))
295
296 (defun cal-tex-mouse-week-iso ()
297 "One page calendar for week indicated by cursor.
298 Holidays are included if `cal-tex-holidays' is t."
299 (interactive)
300 (save-excursion
301 (calendar-mouse-goto-date (calendar-event-to-date))
302 (cal-tex-cursor-week-iso nil)))
303
304 (defun cal-tex-mouse-week-monday ()
305 "One page calendar for week indicated by cursor."
306 (interactive)
307 (save-excursion
308 (calendar-mouse-goto-date (calendar-event-to-date))
309 (cal-tex-cursor-week-monday nil)))
310
311 (defun cal-tex-mouse-filofax-2week ()
312 "One page Filofax calendar for week indicated by cursor."
313 (interactive)
314 (save-excursion
315 (calendar-mouse-goto-date (calendar-event-to-date))
316 (cal-tex-cursor-filofax-2week nil)))
317
318 (defun cal-tex-mouse-filofax-week ()
319 "Two page Filofax calendar for week indicated by cursor."
320 (interactive)
321 (save-excursion
322 (calendar-mouse-goto-date (calendar-event-to-date))
323 (cal-tex-cursor-filofax-week nil)))
324
325 (defun cal-tex-mouse-month ()
326 "Make a buffer with LaTeX commands for the month cursor is on.
327 Calendar is condensed onto one page."
328 (interactive)
329 (save-excursion
330 (calendar-mouse-goto-date (calendar-event-to-date))
331 (cal-tex-cursor-month nil)))
332
333 (defun cal-tex-mouse-month-landscape ()
334 "Make a buffer with LaTeX commands for the month cursor is on.
335 The output is in landscape format, one month to a page."
336 (interactive)
337 (save-excursion
338 (calendar-mouse-goto-date (calendar-event-to-date))
339 (cal-tex-cursor-month-landscape nil)))
340
341 (defun cal-tex-mouse-year ()
342 "Make a buffer with LaTeX commands for the year cursor is on."
343 (interactive)
344 (save-excursion
345 (calendar-mouse-goto-date (calendar-event-to-date))
346 (cal-tex-cursor-year nil)))
347
348 (defun cal-tex-mouse-filofax-year ()
349 "Make a buffer with LaTeX commands for Filofax calendar of year cursor is on."
350 (interactive)
351 (save-excursion
352 (calendar-mouse-goto-date (calendar-event-to-date))
353 (cal-tex-cursor-filofax-year nil)))
354
355 (defun cal-tex-mouse-year-landscape ()
356 "Make a buffer with LaTeX commands for the year cursor is on."
357 (interactive)
358 (save-excursion
359 (calendar-mouse-goto-date (calendar-event-to-date))
360 (cal-tex-cursor-year-landscape nil)))
361
362 (defun calendar-mouse-print-dates ()
363 "Pop up menu of equivalent dates to mouse selected date."
364 (interactive)
365 (let ((date (calendar-event-to-date))
366 (selection
367 (x-popup-menu
368 event
369 (list
370 (concat (calendar-date-string date) " (Gregorian)")
371 (append
372 (list
373 (concat (calendar-date-string date) " (Gregorian)")
374 (list (calendar-day-of-year-string date))
375 (list (format "ISO date: %s" (calendar-iso-date-string date)))
376 (list (format "Julian date: %s"
377 (calendar-julian-date-string date)))
378 (list
379 (format "Astronomical (Julian) day number (at noon UTC): %s.0"
380 (calendar-astro-date-string date)))
381 (list (format "Hebrew date (before sunset): %s"
382 (calendar-hebrew-date-string date)))
383 (list (format "Persian date: %s"
384 (calendar-persian-date-string date))))
385 (let ((i (calendar-islamic-date-string date)))
386 (if (not (string-equal i ""))
387 (list (list (format "Islamic date (before sunset): %s" i)))))
388 (list
389 (list (format "Chinese date: %s"
390 (calendar-chinese-date-string date))))
391 ; (list '("Chinese date (select to echo Chinese date)"
392 ; . calendar-mouse-chinese-date))
393 (let ((c (calendar-coptic-date-string date)))
394 (if (not (string-equal c ""))
395 (list (list (format "Coptic date: %s" c)))))
396 (let ((e (calendar-ethiopic-date-string date)))
397 (if (not (string-equal e ""))
398 (list (list (format "Ethiopic date: %s" e)))))
399 (let ((f (calendar-french-date-string date)))
400 (if (not (string-equal f ""))
401 (list (list (format "French Revolutionary date: %s" f)))))
402 (list
403 (list
404 (format "Mayan date: %s"
405 (calendar-mayan-date-string date)))))))))
406 (and selection (call-interactively selection))))
407
408 (defun calendar-mouse-chinese-date ()
409 "Show Chinese equivalent for mouse-selected date."
410 (interactive)
411 (save-excursion
412 (calendar-mouse-goto-date (calendar-event-to-date))
413 (calendar-print-chinese-date)))
414
415 (defun calendar-mouse-goto-date (date)
416 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
417 (calendar-goto-date date))
418
419 (defun calendar-mouse-2-date-menu (event)
420 "Pop up menu for Mouse-2 for selected date in the calendar window."
421 (interactive "e")
422 (let* ((date (calendar-event-to-date t))
423 (selection
424 (x-popup-menu
425 event
426 (list (calendar-date-string date t nil)
427 (list
428 ""
429 '("Holidays" . calendar-mouse-holidays)
430 '("Mark date" . calendar-mouse-set-mark)
431 '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
432 '("Other calendars" . calendar-mouse-print-dates)
433 '("Prepare LaTeX buffer" . calendar-mouse-cal-tex-menu)
434 '("Diary entries" . calendar-mouse-view-diary-entries)
435 '("Insert diary entry" . calendar-mouse-insert-diary-entry)
436 '("Other diary file entries"
437 . calendar-mouse-view-other-diary-entries)
438 )))))
439 (and selection (call-interactively selection))))
440
441 (defun calendar-mouse-cal-tex-menu (event)
442 "Pop up submenu for Mouse-2 for cal-tex commands for selected date in the calendar window."
443 (interactive "e")
444 (let* ((selection
445 (x-popup-menu
446 event
447 (list (calendar-date-string date t nil)
448 (list
449 ""
450 '("Daily (1 page)" . cal-tex-mouse-day)
451 '("Weekly (1 page)" . cal-tex-mouse-week)
452 '("Weekly (2 pages)" . cal-tex-mouse-week2)
453 '("Weekly (other style; 1 page)" . cal-tex-mouse-week-iso)
454 '("Weekly (yet another style; 1 page)" .
455 cal-tex-mouse-week-monday)
456 '("Monthly" . cal-tex-mouse-month)
457 '("Monthly (landscape)" . cal-tex-mouse-month-landscape)
458 '("Yearly" . cal-tex-mouse-year)
459 '("Yearly (landscape)" . cal-tex-mouse-year-landscape)
460 '("Filofax styles" . cal-tex-mouse-filofax)
461 )))))
462 (and selection (call-interactively selection))))
463
464 (defun cal-tex-mouse-filofax (event)
465 "Pop up sub-submenu for Mouse-2 for Filofax cal-tex commands for selected date."
466 (interactive "e")
467 (let* ((selection
468 (x-popup-menu
469 event
470 (list (calendar-date-string date t nil)
471 (list
472 ""
473 '("Filofax Weekly (2-weeks-at-a-glance)" .
474 cal-tex-mouse-filofax-2week)
475 '("Filofax Weekly (week-at-a-glance)" .
476 cal-tex-mouse-filofax-week)
477 '("Filofax Yearly" . cal-tex-mouse-filofax-year)
478 )))))
479 (and selection (call-interactively selection))))
480
481 (define-key calendar-mouse-3-map [exit-calendar]
482 '("Exit calendar" . exit-calendar))
483 (define-key calendar-mouse-3-map [show-diary]
484 '("Show diary" . show-all-diary-entries))
485 (define-key calendar-mouse-3-map [lunar-phases]
486 '("Lunar phases" . calendar-phases-of-moon))
487 (define-key calendar-mouse-3-map [unmark]
488 '("Unmark" . calendar-unmark))
489 (define-key calendar-mouse-3-map [mark-holidays]
490 '("Mark holidays" . mark-calendar-holidays))
491 (define-key calendar-mouse-3-map [list-holidays]
492 '("List holidays" . list-calendar-holidays))
493 (define-key calendar-mouse-3-map [mark-diary-entries]
494 '("Mark diary entries" . mark-diary-entries))
495 (define-key calendar-mouse-3-map [scroll-backward]
496 '("Scroll backward" . scroll-calendar-right-three-months))
497 (define-key calendar-mouse-3-map [scroll-forward]
498 '("Scroll forward" . scroll-calendar-left-three-months))
499
500 (run-hooks 'cal-menu-load-hook)
501
502 (provide 'cal-menu)
503
504 ;;; cal-menu.el ends here