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