Merged from emacs@sv.gnu.org
[bpt/emacs.git] / lisp / calendar / cal-menu.el
1 ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
2
3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Lara Rios <lrios@coewl.cen.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
9 ;; Keywords: calendar
10 ;; Human-Keywords: calendar, popup menus, menu bar
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
28
29 ;;; Commentary:
30
31 ;; This collection of functions implements menu bar and popup menu support for
32 ;; calendar.el.
33
34 ;; Comments, corrections, and improvements should be sent to
35 ;; Edward M. Reingold Department of Computer Science
36 ;; (217) 333-6733 University of Illinois at Urbana-Champaign
37 ;; reingold@cs.uiuc.edu 1304 West Springfield Avenue
38 ;; Urbana, Illinois 61801
39
40 ;;; Code:
41
42 (defvar displayed-month)
43 (defvar displayed-year)
44
45 ;; Don't require calendar because calendar requires us.
46 ;; (eval-when-compile (require 'calendar))
47 (defvar calendar-mode-map)
48
49 (define-key calendar-mode-map [menu-bar edit] 'undefined)
50 (define-key calendar-mode-map [menu-bar search] 'undefined)
51
52 (define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
53 (define-key calendar-mode-map [mouse-2] 'ignore)
54
55 (defvar calendar-mouse-3-map (make-sparse-keymap "Calendar"))
56 (define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map)
57
58 (define-key calendar-mode-map [menu-bar moon]
59 (cons "Moon" (make-sparse-keymap "Moon")))
60
61 (define-key calendar-mode-map [menu-bar moon moon]
62 '("Lunar Phases" . calendar-phases-of-moon))
63
64 (define-key calendar-mode-map [menu-bar diary]
65 (cons "Diary" (make-sparse-keymap "Diary")))
66
67 (define-key calendar-mode-map [menu-bar diary heb]
68 '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry))
69 (define-key calendar-mode-map [menu-bar diary isl]
70 '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry))
71 (define-key calendar-mode-map [menu-bar diary baha]
72 '("Insert Baha'i" . calendar-mouse-insert-bahai-diary-entry))
73 (define-key calendar-mode-map [menu-bar diary cyc]
74 '("Insert Cyclic" . insert-cyclic-diary-entry))
75 (define-key calendar-mode-map [menu-bar diary blk]
76 '("Insert Block" . insert-block-diary-entry))
77 (define-key calendar-mode-map [menu-bar diary ann]
78 '("Insert Anniversary" . insert-anniversary-diary-entry))
79 (define-key calendar-mode-map [menu-bar diary yr]
80 '("Insert Yearly" . insert-yearly-diary-entry))
81 (define-key calendar-mode-map [menu-bar diary mon]
82 '("Insert Monthly" . insert-monthly-diary-entry))
83 (define-key calendar-mode-map [menu-bar diary wk]
84 '("Insert Weekly" . insert-weekly-diary-entry))
85 (define-key calendar-mode-map [menu-bar diary ent]
86 '("Insert Diary Entry" . insert-diary-entry))
87 (define-key calendar-mode-map [menu-bar diary all]
88 '("Show All" . show-all-diary-entries))
89 (define-key calendar-mode-map [menu-bar diary mark]
90 '("Mark All" . mark-diary-entries))
91 (define-key calendar-mode-map [menu-bar diary view]
92 '("Cursor Date" . diary-view-entries))
93 (define-key calendar-mode-map [menu-bar diary view]
94 '("Other File" . view-other-diary-entries))
95
96 (define-key calendar-mode-map [menu-bar Holidays]
97 (cons "Holidays" (make-sparse-keymap "Holidays")))
98
99 (define-key calendar-mode-map [menu-bar goto]
100 (cons "Goto" (make-sparse-keymap "Goto")))
101
102 (define-key calendar-mode-map [menu-bar goto french]
103 '("French Date" . calendar-goto-french-date))
104 (define-key calendar-mode-map [menu-bar goto mayan]
105 (cons "Mayan Date" (make-sparse-keymap "Mayan")))
106 (define-key calendar-mode-map [menu-bar goto ethiopic]
107 '("Ethiopic Date" . calendar-goto-ethiopic-date))
108 (define-key calendar-mode-map [menu-bar goto coptic]
109 '("Coptic Date" . calendar-goto-coptic-date))
110 (define-key calendar-mode-map [menu-bar goto chinese]
111 '("Chinese Date" . calendar-goto-chinese-date))
112 (define-key calendar-mode-map [menu-bar goto julian]
113 '("Julian Date" . calendar-goto-julian-date))
114 (define-key calendar-mode-map [menu-bar goto islamic]
115 '("Islamic Date" . calendar-goto-islamic-date))
116 (define-key calendar-mode-map [menu-bar goto persian]
117 '("Baha'i Date" . calendar-goto-bahai-date))
118 (define-key calendar-mode-map [menu-bar goto persian]
119 '("Persian Date" . calendar-goto-persian-date))
120 (define-key calendar-mode-map [menu-bar goto hebrew]
121 '("Hebrew Date" . calendar-goto-hebrew-date))
122 (define-key calendar-mode-map [menu-bar goto astro]
123 '("Astronomical Date" . calendar-goto-astro-day-number))
124 (define-key calendar-mode-map [menu-bar goto iso]
125 '("ISO Date" . calendar-goto-iso-date))
126 (define-key calendar-mode-map [menu-bar goto iso-week]
127 '("ISO Week" . calendar-goto-iso-week))
128 (define-key calendar-mode-map [menu-bar goto day-of-year]
129 '("Day of Year" . calendar-goto-day-of-year))
130 (define-key calendar-mode-map [menu-bar goto gregorian]
131 '("Other Date" . calendar-goto-date))
132 (define-key calendar-mode-map [menu-bar goto end-of-year]
133 '("End of Year" . calendar-end-of-year))
134 (define-key calendar-mode-map [menu-bar goto beginning-of-year]
135 '("Beginning of Year" . calendar-beginning-of-year))
136 (define-key calendar-mode-map [menu-bar goto end-of-month]
137 '("End of Month" . calendar-end-of-month))
138 (define-key calendar-mode-map [menu-bar goto beginning-of-month]
139 '("Beginning of Month" . calendar-beginning-of-month))
140 (define-key calendar-mode-map [menu-bar goto end-of-week]
141 '("End of Week" . calendar-end-of-week))
142 (define-key calendar-mode-map [menu-bar goto beginning-of-week]
143 '("Beginning of Week" . calendar-beginning-of-week))
144 (define-key calendar-mode-map [menu-bar goto today]
145 '("Today" . calendar-goto-today))
146
147
148 (define-key calendar-mode-map [menu-bar goto mayan prev-rnd]
149 '("Previous Round" . calendar-previous-calendar-round-date))
150 (define-key calendar-mode-map [menu-bar goto mayan nxt-rnd]
151 '("Next Round" . calendar-next-calendar-round-date))
152 (define-key calendar-mode-map [menu-bar goto mayan prev-haab]
153 '("Previous Haab" . calendar-previous-haab-date))
154 (define-key calendar-mode-map [menu-bar goto mayan next-haab]
155 '("Next Haab" . calendar-next-haab-date))
156 (define-key calendar-mode-map [menu-bar goto mayan prev-tzol]
157 '("Previous Tzolkin" . calendar-previous-tzolkin-date))
158 (define-key calendar-mode-map [menu-bar goto mayan next-tzol]
159 '("Next Tzolkin" . calendar-next-tzolkin-date))
160
161 (define-key calendar-mode-map [menu-bar scroll]
162 (cons "Scroll" (make-sparse-keymap "Scroll")))
163
164 (define-key calendar-mode-map [menu-bar scroll bk-12]
165 '("Backward 1 Year" . "4\ev"))
166 (define-key calendar-mode-map [menu-bar scroll bk-3]
167 '("Backward 3 Months" . scroll-calendar-right-three-months))
168 (define-key calendar-mode-map [menu-bar scroll bk-1]
169 '("Backward 1 Month" . scroll-calendar-right))
170 (define-key calendar-mode-map [menu-bar scroll fwd-12]
171 '("Forward 1 Year" . "4\C-v"))
172 (define-key calendar-mode-map [menu-bar scroll fwd-3]
173 '("Forward 3 Months" . scroll-calendar-left-three-months))
174 (define-key calendar-mode-map [menu-bar scroll fwd-1]
175 '("Forward 1 Month" . scroll-calendar-left))
176
177 (defun calendar-flatten (list)
178 "Flatten LIST eliminating sublists structure; result is a list of atoms.
179 This is the same as the preorder list of leaves in a rooted forest."
180 (if (atom list)
181 (list list)
182 (if (cdr list)
183 (append (calendar-flatten (car list)) (calendar-flatten (cdr list)))
184 (calendar-flatten (car list)))))
185
186 (defun cal-menu-x-popup-menu (position menu)
187 "Like `x-popup-menu', but prints an error message if popup menus are
188 not available."
189 (if (display-popup-menus-p)
190 (x-popup-menu position menu)
191 (error "Popup menus are not available on this system")))
192
193 (defun cal-menu-list-holidays-year ()
194 "Display a list of the holidays of the selected date's year."
195 (interactive)
196 (let ((year (extract-calendar-year (calendar-cursor-to-date))))
197 (list-holidays year year)))
198
199 (defun cal-menu-list-holidays-following-year ()
200 "Display a list of the holidays of the following year."
201 (interactive)
202 (let ((year (1+ (extract-calendar-year (calendar-cursor-to-date)))))
203 (list-holidays year year)))
204
205 (defun cal-menu-list-holidays-previous-year ()
206 "Display a list of the holidays of the previous year."
207 (interactive)
208 (let ((year (1- (extract-calendar-year (calendar-cursor-to-date)))))
209 (list-holidays year year)))
210
211 (defun cal-menu-update ()
212 ;; Update the holiday part of calendar menu bar for the current display.
213 (condition-case nil
214 (if (eq major-mode 'calendar-mode)
215 (let ((l))
216 ;; Show 11 years--5 before, 5 after year of middle month
217 (dotimes (i 11)
218 (let ((y (+ displayed-year -5 i)))
219 (push (vector (format "For Year %s" y)
220 (list (list 'lambda 'nil '(interactive)
221 (list 'list-holidays y y)))
222 t)
223 l)))
224 (setq l (cons ["Mark Holidays" mark-calendar-holidays t]
225 (cons ["Unmark Calendar" calendar-unmark t]
226 (cons "--" l))))
227 (define-key calendar-mode-map [menu-bar Holidays]
228 (cons "Holidays" (easy-menu-create-menu "Holidays" (nreverse l))))
229 (define-key calendar-mode-map [menu-bar Holidays separator]
230 '("--"))
231 (define-key calendar-mode-map [menu-bar Holidays today]
232 `(,(format "For Today (%s)"
233 (calendar-date-string (calendar-current-date) t t))
234 . cal-menu-today-holidays))
235 (let ((title
236 (let ((my1 (calendar-increment-month -1))
237 (my2 (calendar-increment-month 1)))
238 (if (= (cdr my1) (cdr my2))
239 (format "%s-%s, %d"
240 (calendar-month-name (car my1) 'abbrev)
241 (calendar-month-name (car my2) 'abbrev)
242 (cdr my2))
243 (format "%s, %d-%s, %d"
244 (calendar-month-name (car my1) 'abbrev)
245 (cdr my1)
246 (calendar-month-name (car my2) 'abbrev)
247 (cdr my2))))))
248 (define-key calendar-mode-map [menu-bar Holidays 3-month]
249 `(,(format "For Window (%s)" title)
250 . list-calendar-holidays)))
251 (let ((date (calendar-cursor-to-date)))
252 (if date
253 (define-key calendar-mode-map [menu-bar Holidays 1-day]
254 `(,(format "For Cursor Date (%s)"
255 (calendar-date-string date t t))
256 . calendar-cursor-holidays))))))
257 ;; Try to avoid entering infinite beep mode in case of errors.
258 (error (ding))))
259
260 (defun calendar-event-to-date (&optional error)
261 "Date of last event.
262 If event is not on a specific date, signals an error if optional parameter
263 ERROR is t, otherwise just returns nil."
264 (save-excursion
265 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
266 (goto-char (posn-point (event-start last-input-event)))
267 (calendar-cursor-to-date error)))
268
269 (defun calendar-mouse-insert-hebrew-diary-entry (event)
270 "Pop up menu to insert a Hebrew-date diary entry."
271 (interactive "e")
272 (let ((hebrew-selection
273 (cal-menu-x-popup-menu
274 event
275 (list "Hebrew insert menu"
276 (list (calendar-hebrew-date-string (calendar-cursor-to-date))
277 '("One time" . insert-hebrew-diary-entry)
278 '("Monthly" . insert-monthly-hebrew-diary-entry)
279 '("Yearly" . insert-yearly-hebrew-diary-entry))))))
280 (and hebrew-selection (call-interactively hebrew-selection))))
281
282 (defun calendar-mouse-insert-islamic-diary-entry (event)
283 "Pop up menu to insert an Islamic-date diary entry."
284 (interactive "e")
285 (let ((islamic-selection
286 (cal-menu-x-popup-menu
287 event
288 (list "Islamic insert menu"
289 (list (calendar-islamic-date-string (calendar-cursor-to-date))
290 '("One time" . insert-islamic-diary-entry)
291 '("Monthly" . insert-monthly-islamic-diary-entry)
292 '("Yearly" . insert-yearly-islamic-diary-entry))))))
293 (and islamic-selection (call-interactively islamic-selection))))
294
295 (defun calendar-mouse-insert-bahai-diary-entry (event)
296 "Pop up menu to insert an Baha'i-date diary entry."
297 (interactive "e")
298 (let ((bahai-selection
299 (x-popup-menu
300 event
301 (list "Baha'i insert menu"
302 (list (calendar-bahai-date-string (calendar-cursor-to-date))
303 '("One time" . insert-bahai-diary-entry)
304 '("Monthly" . insert-monthly-bahai-diary-entry)
305 '("Yearly" . insert-yearly-bahai-diary-entry))))))
306 (and bahai-selection (call-interactively bahai-selection))))
307
308 (defun calendar-mouse-sunrise/sunset ()
309 "Show sunrise/sunset times for mouse-selected date."
310 (interactive)
311 (save-excursion
312 (calendar-mouse-goto-date (calendar-event-to-date))
313 (calendar-sunrise-sunset)))
314
315 (defun cal-menu-today-holidays ()
316 "Show holidays for today's date."
317 (interactive)
318 (save-excursion
319 (calendar-cursor-to-date (calendar-current-date))
320 (calendar-cursor-holidays)))
321
322 (autoload 'check-calendar-holidays "holidays")
323 (autoload 'diary-list-entries "diary-lib")
324
325 (defun calendar-mouse-holidays (&optional event)
326 "Pop up menu of holidays for mouse selected date."
327 (interactive "e")
328 (let* ((date (calendar-event-to-date))
329 (l (mapcar 'list (check-calendar-holidays date)))
330 (selection
331 (cal-menu-x-popup-menu
332 event
333 (list
334 (format "Holidays for %s" (calendar-date-string date))
335 (append
336 (list (format "Holidays for %s" (calendar-date-string date)))
337 (if l l '("None")))))))
338 (and selection (call-interactively selection))))
339
340 (defun calendar-mouse-view-diary-entries (&optional date diary event)
341 "Pop up menu of diary entries for mouse-selected date.
342 Use optional DATE and alternative file DIARY.
343
344 Any holidays are shown if `holidays-in-diary-buffer' is t."
345 (interactive "i\ni\ne")
346 (let* ((date (if date date (calendar-event-to-date)))
347 (diary-file (if diary diary diary-file))
348 (diary-list-include-blanks nil)
349 (diary-display-hook 'ignore)
350 (diary-entries
351 (mapcar (lambda (x) (split-string (car (cdr x)) "\^M\\|\n"))
352 (diary-list-entries date 1 'list-only)))
353 (holidays (if holidays-in-diary-buffer
354 (check-calendar-holidays date)))
355 (title (concat "Diary entries "
356 (if diary (format "from %s " diary) "")
357 "for "
358 (calendar-date-string date)))
359 (selection
360 (cal-menu-x-popup-menu
361 event
362 (list title
363 (append
364 (list title)
365 (mapcar (lambda (x) (list (concat " " x))) holidays)
366 (if holidays
367 (list "--shadow-etched-in" "--shadow-etched-in"))
368 (if diary-entries
369 (mapcar 'list (calendar-flatten diary-entries))
370 '("None")))))))
371 (and selection (call-interactively selection))))
372
373 (defun calendar-mouse-view-other-diary-entries ()
374 "Pop up menu of diary entries from alternative file on mouse-selected date."
375 (interactive)
376 (calendar-mouse-view-diary-entries
377 (calendar-event-to-date)
378 (read-file-name "Enter diary file name: " default-directory nil t)))
379
380 (defun calendar-mouse-insert-diary-entry ()
381 "Insert diary entry for mouse-selected date."
382 (interactive)
383 (save-excursion
384 (calendar-mouse-goto-date (calendar-event-to-date))
385 (insert-diary-entry nil)))
386
387 (defun calendar-mouse-set-mark ()
388 "Mark the date under the cursor."
389 (interactive)
390 (save-excursion
391 (calendar-mouse-goto-date (calendar-event-to-date))
392 (calendar-set-mark nil)))
393
394 (defun cal-tex-mouse-day ()
395 "Make a buffer with LaTeX commands for the day mouse is on."
396 (interactive)
397 (save-excursion
398 (calendar-mouse-goto-date (calendar-event-to-date))
399 (cal-tex-cursor-day nil)))
400
401 (defun cal-tex-mouse-week ()
402 "One page calendar for week indicated by cursor.
403 Holidays are included if `cal-tex-holidays' is t."
404 (interactive)
405 (save-excursion
406 (calendar-mouse-goto-date (calendar-event-to-date))
407 (cal-tex-cursor-week nil)))
408
409 (defun cal-tex-mouse-week2 ()
410 "Make a buffer with LaTeX commands for the week cursor is on.
411 The printed output will be on two pages."
412 (interactive)
413 (save-excursion
414 (calendar-mouse-goto-date (calendar-event-to-date))
415 (cal-tex-cursor-week2 nil)))
416
417 (defun cal-tex-mouse-week-iso ()
418 "One page calendar for week indicated by cursor.
419 Holidays are included if `cal-tex-holidays' is t."
420 (interactive)
421 (save-excursion
422 (calendar-mouse-goto-date (calendar-event-to-date))
423 (cal-tex-cursor-week-iso nil)))
424
425 (defun cal-tex-mouse-week-monday ()
426 "One page calendar for week indicated by cursor."
427 (interactive)
428 (save-excursion
429 (calendar-mouse-goto-date (calendar-event-to-date))
430 (cal-tex-cursor-week-monday nil)))
431
432 (defun cal-tex-mouse-filofax-daily ()
433 "Day-per-page Filofax calendar for week indicated by cursor."
434 (interactive)
435 (save-excursion
436 (calendar-mouse-goto-date (calendar-event-to-date))
437 (cal-tex-cursor-filofax-daily nil)))
438
439 (defun cal-tex-mouse-filofax-2week ()
440 "One page Filofax calendar for week indicated by cursor."
441 (interactive)
442 (save-excursion
443 (calendar-mouse-goto-date (calendar-event-to-date))
444 (cal-tex-cursor-filofax-2week nil)))
445
446 (defun cal-tex-mouse-filofax-week ()
447 "Two page Filofax calendar for week indicated by cursor."
448 (interactive)
449 (save-excursion
450 (calendar-mouse-goto-date (calendar-event-to-date))
451 (cal-tex-cursor-filofax-week nil)))
452
453 (defun cal-tex-mouse-month ()
454 "Make a buffer with LaTeX commands for the month cursor is on.
455 Calendar is condensed onto one page."
456 (interactive)
457 (save-excursion
458 (calendar-mouse-goto-date (calendar-event-to-date))
459 (cal-tex-cursor-month nil)))
460
461 (defun cal-tex-mouse-month-landscape ()
462 "Make a buffer with LaTeX commands for the month cursor is on.
463 The output is in landscape format, one month to a page."
464 (interactive)
465 (save-excursion
466 (calendar-mouse-goto-date (calendar-event-to-date))
467 (cal-tex-cursor-month-landscape nil)))
468
469 (defun cal-tex-mouse-year ()
470 "Make a buffer with LaTeX commands for the year cursor is on."
471 (interactive)
472 (save-excursion
473 (calendar-mouse-goto-date (calendar-event-to-date))
474 (cal-tex-cursor-year nil)))
475
476 (defun cal-tex-mouse-filofax-year ()
477 "Make a buffer with LaTeX commands for Filofax calendar of year cursor is on."
478 (interactive)
479 (save-excursion
480 (calendar-mouse-goto-date (calendar-event-to-date))
481 (cal-tex-cursor-filofax-year nil)))
482
483 (defun cal-tex-mouse-year-landscape ()
484 "Make a buffer with LaTeX commands for the year cursor is on."
485 (interactive)
486 (save-excursion
487 (calendar-mouse-goto-date (calendar-event-to-date))
488 (cal-tex-cursor-year-landscape nil)))
489
490 (defun calendar-mouse-print-dates (&optional event)
491 "Pop up menu of equivalent dates to mouse selected date."
492 (interactive "e")
493 (let* ((date (calendar-event-to-date))
494 (selection
495 (cal-menu-x-popup-menu
496 event
497 (list
498 (concat (calendar-date-string date) " (Gregorian)")
499 (append
500 (list
501 (concat (calendar-date-string date) " (Gregorian)")
502 (list (calendar-day-of-year-string date))
503 (list (format "ISO date: %s" (calendar-iso-date-string date)))
504 (list (format "Julian date: %s"
505 (calendar-julian-date-string date)))
506 (list
507 (format "Astronomical (Julian) day number (at noon UTC): %s.0"
508 (calendar-astro-date-string date)))
509 (list
510 (format "Fixed (RD) date: %s"
511 (calendar-absolute-from-gregorian date)))
512 (list (format "Hebrew date (before sunset): %s"
513 (calendar-hebrew-date-string date)))
514 (list (format "Persian date: %s"
515 (calendar-persian-date-string date)))
516 (list (format "Baha'i date (before sunset): %s"
517 (calendar-bahai-date-string date))))
518 (let ((i (calendar-islamic-date-string date)))
519 (if (not (string-equal i ""))
520 (list (list (format "Islamic date (before sunset): %s" i)))))
521 (list
522 (list (format "Chinese date: %s"
523 (calendar-chinese-date-string date))))
524 ;; (list '("Chinese date (select to echo Chinese date)"
525 ;; . calendar-mouse-chinese-date))
526 (let ((c (calendar-coptic-date-string date)))
527 (if (not (string-equal c ""))
528 (list (list (format "Coptic date: %s" c)))))
529 (let ((e (calendar-ethiopic-date-string date)))
530 (if (not (string-equal e ""))
531 (list (list (format "Ethiopic date: %s" e)))))
532 (let ((f (calendar-french-date-string date)))
533 (if (not (string-equal f ""))
534 (list (list (format "French Revolutionary date: %s" f)))))
535 (list
536 (list
537 (format "Mayan date: %s"
538 (calendar-mayan-date-string date)))))))))
539 (and selection (call-interactively selection))))
540
541 (defun calendar-mouse-chinese-date ()
542 "Show Chinese equivalent for mouse-selected date."
543 (interactive)
544 (save-excursion
545 (calendar-mouse-goto-date (calendar-event-to-date))
546 (calendar-print-chinese-date)))
547
548 (defun calendar-mouse-goto-date (date)
549 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
550 (calendar-goto-date date))
551
552 (defun calendar-mouse-2-date-menu (event)
553 "Pop up menu for Mouse-2 for selected date in the calendar window."
554 (interactive "e")
555 (let* ((date (calendar-event-to-date t))
556 (selection
557 (cal-menu-x-popup-menu
558 event
559 (list (calendar-date-string date t nil)
560 (list
561 ""
562 '("Holidays" . calendar-mouse-holidays)
563 '("Mark date" . calendar-mouse-set-mark)
564 '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
565 '("Other calendars" . calendar-mouse-print-dates)
566 '("Prepare LaTeX buffer" . calendar-mouse-cal-tex-menu)
567 '("Diary entries" . calendar-mouse-view-diary-entries)
568 '("Insert diary entry" . calendar-mouse-insert-diary-entry)
569 '("Other diary file entries"
570 . calendar-mouse-view-other-diary-entries)
571 )))))
572 (and selection (call-interactively selection))))
573
574 (defun calendar-mouse-cal-tex-menu (event)
575 "Pop up submenu for Mouse-2 for cal-tex commands for selected date in the calendar window."
576 (interactive "e")
577 (let* ((selection
578 (cal-menu-x-popup-menu
579 event
580 (list (calendar-date-string (calendar-event-to-date t) t nil)
581 (list
582 ""
583 '("Daily (1 page)" . cal-tex-mouse-day)
584 '("Weekly (1 page)" . cal-tex-mouse-week)
585 '("Weekly (2 pages)" . cal-tex-mouse-week2)
586 '("Weekly (other style; 1 page)" . cal-tex-mouse-week-iso)
587 '("Weekly (yet another style; 1 page)" .
588 cal-tex-mouse-week-monday)
589 '("Monthly" . cal-tex-mouse-month)
590 '("Monthly (landscape)" . cal-tex-mouse-month-landscape)
591 '("Yearly" . cal-tex-mouse-year)
592 '("Yearly (landscape)" . cal-tex-mouse-year-landscape)
593 '("Filofax styles" . cal-tex-mouse-filofax)
594 )))))
595 (and selection (call-interactively selection))))
596
597 (defun cal-tex-mouse-filofax (event)
598 "Pop up sub-submenu for Mouse-2 for Filofax cal-tex commands for selected date."
599 (interactive "e")
600 (let* ((selection
601 (cal-menu-x-popup-menu
602 event
603 (list (calendar-date-string (calendar-event-to-date t) t nil)
604 (list
605 ""
606 '("Filofax Daily (one-day-per-page)" .
607 cal-tex-mouse-filofax-daily)
608 '("Filofax Weekly (2-weeks-at-a-glance)" .
609 cal-tex-mouse-filofax-2week)
610 '("Filofax Weekly (week-at-a-glance)" .
611 cal-tex-mouse-filofax-week)
612 '("Filofax Yearly" . cal-tex-mouse-filofax-year)
613 )))))
614 (and selection (call-interactively selection))))
615
616 (define-key calendar-mouse-3-map [exit-calendar]
617 '("Exit calendar" . exit-calendar))
618 (define-key calendar-mouse-3-map [show-diary]
619 '("Show diary" . show-all-diary-entries))
620 (define-key calendar-mouse-3-map [lunar-phases]
621 '("Lunar phases" . calendar-phases-of-moon))
622 (define-key calendar-mouse-3-map [unmark]
623 '("Unmark" . calendar-unmark))
624 (define-key calendar-mouse-3-map [mark-holidays]
625 '("Mark holidays" . mark-calendar-holidays))
626 (define-key calendar-mouse-3-map [list-holidays]
627 '("List holidays" . list-calendar-holidays))
628 (define-key calendar-mouse-3-map [mark-diary-entries]
629 '("Mark diary entries" . mark-diary-entries))
630 (define-key calendar-mouse-3-map [scroll-backward]
631 '("Scroll backward" . scroll-calendar-right-three-months))
632 (define-key calendar-mouse-3-map [scroll-forward]
633 '("Scroll forward" . scroll-calendar-left-three-months))
634
635 (run-hooks 'cal-menu-load-hook)
636
637 (provide 'cal-menu)
638
639 ;; arch-tag: aa81cf73-ce89-48a4-97ec-9ef861e87fe9
640 ;;; cal-menu.el ends here