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