Update for hebrew name changes.
[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
965c8899
GM
3;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4;; 2008 Free Software Foundation, Inc.
aef1a243
RS
5
6;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
71ea27ee 7;; Lara Rios <lrios@coewl.cen.uiuc.edu>
aff88519 8;; Maintainer: Glenn Morris <rgm@gnu.org>
aef1a243
RS
9;; Keywords: calendar
10;; Human-Keywords: calendar, popup menus, menu bar
11
12;; This file is part of GNU Emacs.
13
59243403
RS
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
075969b4 16;; the Free Software Foundation; either version 3, or (at your option)
59243403
RS
17;; any later version.
18
aef1a243 19;; GNU Emacs is distributed in the hope that it will be useful,
59243403
RS
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
b578f267 25;; along with GNU Emacs; see the file COPYING. If not, write to the
3a35cf56
LK
26;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27;; Boston, MA 02110-1301, USA.
aef1a243
RS
28
29;;; Commentary:
30
714b5034 31;; See calendar.el.
aef1a243 32
aef1a243
RS
33;;; Code:
34
7ff651d0 35(require 'calendar)
f086f609 36
05efa389
SM
37(defconst cal-menu-moon-menu
38 '("Moon"
39 ["Lunar Phases" calendar-phases-of-moon]))
40
41(defconst cal-menu-diary-menu
42 '("Diary"
43 ["Other File" view-other-diary-entries]
44 ["Cursor Date" diary-view-entries]
45 ["Mark All" mark-diary-entries]
46 ["Show All" diary-show-all-entries]
47 ["Insert Diary Entry" insert-diary-entry]
48 ["Insert Weekly" insert-weekly-diary-entry]
49 ["Insert Monthly" insert-monthly-diary-entry]
50 ["Insert Yearly" insert-yearly-diary-entry]
51 ["Insert Anniversary" insert-anniversary-diary-entry]
52 ["Insert Block" insert-block-diary-entry]
53 ["Insert Cyclic" insert-cyclic-diary-entry]
54 ("Insert Baha'i"
4aefe5e2
GM
55 ["One time" diary-bahai-insert-entry]
56 ["Monthly" diary-bahai-insert-monthly-entry]
57 ["Yearly" diary-bahai-insert-yearly-entry])
05efa389 58 ("Insert Islamic"
c2bfc7e3
GM
59 ["One time" diary-islamic-insert-entry]
60 ["Monthly" diary-islamic-insert-monthly-entry]
61 ["Yearly" diary-islamic-insert-yearly-entry])
05efa389 62 ("Insert Hebrew"
05efa389
SM
63 ["One time" insert-hebrew-diary-entry]
64 ["Monthly" insert-monthly-hebrew-diary-entry]
65 ["Yearly" insert-yearly-hebrew-diary-entry])))
66
67(defun cal-menu-holiday-window-suffix ()
5bbcf603 68 "Return a string suffix for the \"Window\" entry in `cal-menu-holidays-menu'."
05efa389
SM
69 (let ((my1 (calendar-increment-month -1))
70 (my2 (calendar-increment-month 1)))
71 (if (= (cdr my1) (cdr my2))
72 (format "%s-%s, %d"
73 (calendar-month-name (car my1) 'abbrev)
74 (calendar-month-name (car my2) 'abbrev)
75 (cdr my2))
76 (format "%s, %d-%s, %d"
77 (calendar-month-name (car my1) 'abbrev)
78 (cdr my1)
79 (calendar-month-name (car my2) 'abbrev)
80 (cdr my2)))))
81
6cd61ebd
GM
82(defvar displayed-year) ; from generate-calendar
83
05efa389
SM
84(defconst cal-menu-holidays-menu
85 `("Holidays"
86 ["For Cursor Date -" calendar-cursor-holidays
87 :suffix (calendar-date-string (calendar-cursor-to-date) t t)
88 :visible (calendar-cursor-to-date)]
175ede29 89 ["For Window -" calendar-list-holidays
05efa389
SM
90 :suffix (cal-menu-holiday-window-suffix)]
91 ["For Today -" cal-menu-today-holidays
92 :suffix (calendar-date-string (calendar-current-date) t t)]
93 "--"
94 ,@(let ((l ()))
95 ;; Show 11 years--5 before, 5 after year of middle month.
29ca115f
SM
96 ;; We used to use :suffix rather than :label and bumped into
97 ;; an easymenu bug:
60806b73 98 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01813.html
29ca115f 99 ;; The bug has since been fixed.
05efa389 100 (dotimes (i 11)
60806b73 101 (push (vector (format "hol-year-%d" i)
771e1882
GM
102 `(lambda ()
103 (interactive)
fdbe82c9 104 (holiday-list (+ displayed-year ,(- i 5))))
60806b73
GM
105 :label `(format "For Year %d"
106 (+ displayed-year ,(- i 5))))
771e1882 107 l))
05efa389
SM
108 (nreverse l))
109 "--"
110 ["Unmark Calendar" calendar-unmark]
714b5034 111 ["Mark Holidays" calendar-mark-holidays]))
05efa389
SM
112
113(defconst cal-menu-goto-menu
965c8899 114 '("Go To"
05efa389
SM
115 ["Today" calendar-goto-today]
116 ["Beginning of Week" calendar-beginning-of-week]
117 ["End of Week" calendar-end-of-week]
118 ["Beginning of Month" calendar-beginning-of-month]
119 ["End of Month" calendar-end-of-month]
120 ["Beginning of Year" calendar-beginning-of-year]
121 ["End of Year" calendar-end-of-year]
122 ["Other Date" calendar-goto-date]
123 ["Day of Year" calendar-goto-day-of-year]
c2bfc7e3
GM
124 ["ISO Week" calendar-iso-goto-week]
125 ["ISO Date" calendar-iso-goto-date]
126 ["Astronomical Date" calendar-astro-goto-day-number]
05efa389 127 ["Hebrew Date" calendar-goto-hebrew-date]
c2bfc7e3 128 ["Persian Date" calendar-persian-goto-date]
4aefe5e2 129 ["Baha'i Date" calendar-bahai-goto-date]
c2bfc7e3
GM
130 ["Islamic Date" calendar-islamic-goto-date]
131 ["Julian Date" calendar-julian-goto-date]
05efa389 132 ["Chinese Date" calendar-goto-chinese-date]
06bfc982
GM
133 ["Coptic Date" calendar-coptic-goto-date]
134 ["Ethiopic Date" calendar-ethiopic-goto-date]
05efa389 135 ("Mayan Date"
c2bfc7e3
GM
136 ["Next Tzolkin" calendar-mayan-next-tzolkin-date]
137 ["Previous Tzolkin" calendar-mayan-previous-tzolkin-date]
138 ["Next Haab" calendar-mayan-next-haab-date]
139 ["Previous Haab" calendar-mayan-previous-haab-date]
140 ["Next Round" calendar-mayan-next-round-date]
141 ["Previous Round" calendar-mayan-previous-round-date])
06bfc982 142 ["French Date" calendar-french-goto-date]))
05efa389
SM
143
144(defconst cal-menu-scroll-menu
145 '("Scroll"
cca1dde0
SM
146 ["Forward 1 Month" calendar-scroll-left]
147 ["Forward 3 Months" calendar-scroll-left-three-months]
05efa389 148 ["Forward 1 Year" "4\C-v"]
cca1dde0
SM
149 ["Backward 1 Month" calendar-scroll-right]
150 ["Backward 3 Months" calendar-scroll-right-three-months]
05efa389 151 ["Backward 1 Year" "4\ev"]))
f9df0ca0 152
87671c25 153(defun cal-menu-x-popup-menu (position menu)
5bbcf603
GM
154 "Like `x-popup-menu', but print an error message if popups are unavailable.
155POSITION and MENU are passed to `x-popup-menu'."
87671c25
EZ
156 (if (display-popup-menus-p)
157 (x-popup-menu position menu)
3f3410a9 158 (error "Popup menus are not available on this system")))
87671c25 159
f10cbb4c
RS
160(defun cal-menu-list-holidays-year ()
161 "Display a list of the holidays of the selected date's year."
162 (interactive)
fdbe82c9 163 (holiday-list (extract-calendar-year (calendar-cursor-to-date))))
f10cbb4c
RS
164
165(defun cal-menu-list-holidays-following-year ()
166 "Display a list of the holidays of the following year."
167 (interactive)
fdbe82c9 168 (holiday-list (1+ (extract-calendar-year (calendar-cursor-to-date)))))
f10cbb4c
RS
169
170(defun cal-menu-list-holidays-previous-year ()
171 "Display a list of the holidays of the previous year."
172 (interactive)
fdbe82c9 173 (holiday-list (1- (extract-calendar-year (calendar-cursor-to-date)))))
f10cbb4c 174
a6ee0a2f
ER
175(defun calendar-event-to-date (&optional error)
176 "Date of last event.
177If event is not on a specific date, signals an error if optional parameter
6cd61ebd 178ERROR is non-nil, otherwise just returns nil."
05efa389
SM
179 (with-current-buffer
180 (window-buffer (posn-window (event-start last-input-event)))
aef1a243 181 (goto-char (posn-point (event-start last-input-event)))
a6ee0a2f 182 (calendar-cursor-to-date error)))
aef1a243 183
6cd61ebd 184(defun calendar-mouse-goto-date (date)
965c8899 185 "Go to DATE in the buffer specified by `last-input-event'."
6cd61ebd
GM
186 (set-buffer (window-buffer (posn-window (event-start last-input-event))))
187 (calendar-goto-date date))
188
aef1a243
RS
189(defun calendar-mouse-sunrise/sunset ()
190 "Show sunrise/sunset times for mouse-selected date."
191 (interactive)
192 (save-excursion
a0e06fd0 193 (calendar-mouse-goto-date (calendar-event-to-date))
aef1a243
RS
194 (calendar-sunrise-sunset)))
195
07342a64
ER
196(defun cal-menu-today-holidays ()
197 "Show holidays for today's date."
198 (interactive)
199 (save-excursion
200 (calendar-cursor-to-date (calendar-current-date))
201 (calendar-cursor-holidays)))
202
175ede29 203(autoload 'calendar-check-holidays "holidays")
ed1cd40c 204
e9f8d300 205(defun calendar-mouse-holidays (&optional event)
5bbcf603
GM
206 "Pop up menu of holidays for mouse selected date.
207EVENT is the event that invoked this command."
e9f8d300 208 (interactive "e")
6c8a48a6 209 (let* ((date (calendar-event-to-date))
f328a783 210 (title (format "Holidays for %s" (calendar-date-string date)))
6c8a48a6 211 (selection
87671c25 212 (cal-menu-x-popup-menu
6c8a48a6 213 event
f328a783 214 (list title
fdbe82c9
GM
215 (append (list title)
216 (or (mapcar 'list (calendar-check-holidays date))
217 '("None")))))))
6c8a48a6 218 (and selection (call-interactively selection))))
aef1a243 219
fdbe82c9 220(autoload 'diary-list-entries "diary-lib")
f7ae31df
GM
221(defvar holidays-in-diary-buffer) ; only called from calendar.el
222
e9f8d300 223(defun calendar-mouse-view-diary-entries (&optional date diary event)
f9df0ca0 224 "Pop up menu of diary entries for mouse-selected date.
5bbcf603
GM
225Use optional DATE and alternative file DIARY. EVENT is the event
226that invoked this command. Shows holidays if `holidays-in-diary-buffer'
227is non-nil."
e9f8d300 228 (interactive "i\ni\ne")
05efa389 229 (let* ((date (or date (calendar-event-to-date)))
f328a783 230 (diary-file (or diary diary-file))
f9df0ca0
GM
231 (diary-list-include-blanks nil)
232 (diary-display-hook 'ignore)
233 (diary-entries
05efa389 234 (mapcar (lambda (x) (split-string (cadr x) "\n"))
a04b6191 235 (diary-list-entries date 1 'list-only)))
f9df0ca0 236 (holidays (if holidays-in-diary-buffer
175ede29 237 (calendar-check-holidays date)))
f9df0ca0
GM
238 (title (concat "Diary entries "
239 (if diary (format "from %s " diary) "")
240 "for "
241 (calendar-date-string date)))
6c8a48a6 242 (selection
87671c25 243 (cal-menu-x-popup-menu
6c8a48a6 244 event
f9df0ca0
GM
245 (list title
246 (append
247 (list title)
ed1cd40c 248 (mapcar (lambda (x) (list (concat " " x))) holidays)
f9df0ca0
GM
249 (if holidays
250 (list "--shadow-etched-in" "--shadow-etched-in"))
251 (if diary-entries
05efa389 252 (mapcar 'list (apply 'append diary-entries))
f9df0ca0 253 '("None")))))))
6c8a48a6 254 (and selection (call-interactively selection))))
aef1a243 255
95436630 256(defun calendar-mouse-view-other-diary-entries ()
6c8a48a6 257 "Pop up menu of diary entries from alternative file on mouse-selected date."
95436630 258 (interactive)
f9df0ca0
GM
259 (calendar-mouse-view-diary-entries
260 (calendar-event-to-date)
261 (read-file-name "Enter diary file name: " default-directory nil t)))
95436630 262
d960f279
ER
263(defun calendar-mouse-insert-diary-entry ()
264 "Insert diary entry for mouse-selected date."
265 (interactive)
266 (save-excursion
a0e06fd0 267 (calendar-mouse-goto-date (calendar-event-to-date))
d960f279
ER
268 (insert-diary-entry nil)))
269
b61631a7
RS
270(defun calendar-mouse-set-mark ()
271 "Mark the date under the cursor."
272 (interactive)
273 (save-excursion
a0e06fd0 274 (calendar-mouse-goto-date (calendar-event-to-date))
b61631a7
RS
275 (calendar-set-mark nil)))
276
e519449d
ER
277(defun cal-tex-mouse-day ()
278 "Make a buffer with LaTeX commands for the day mouse is on."
279 (interactive)
280 (save-excursion
a0e06fd0 281 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
282 (cal-tex-cursor-day nil)))
283
284(defun cal-tex-mouse-week ()
285 "One page calendar for week indicated by cursor.
6cd61ebd 286Holidays are included if `cal-tex-holidays' is non-nil."
e519449d
ER
287 (interactive)
288 (save-excursion
a0e06fd0 289 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
290 (cal-tex-cursor-week nil)))
291
292(defun cal-tex-mouse-week2 ()
293 "Make a buffer with LaTeX commands for the week cursor is on.
294The printed output will be on two pages."
295 (interactive)
296 (save-excursion
a0e06fd0 297 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
298 (cal-tex-cursor-week2 nil)))
299
bc83970d 300(defun cal-tex-mouse-week-iso ()
e519449d 301 "One page calendar for week indicated by cursor.
6cd61ebd 302Holidays are included if `cal-tex-holidays' is non-nil."
e519449d
ER
303 (interactive)
304 (save-excursion
a0e06fd0 305 (calendar-mouse-goto-date (calendar-event-to-date))
bc83970d 306 (cal-tex-cursor-week-iso nil)))
e519449d 307
bc83970d 308(defun cal-tex-mouse-week-monday ()
e519449d
ER
309 "One page calendar for week indicated by cursor."
310 (interactive)
311 (save-excursion
a0e06fd0 312 (calendar-mouse-goto-date (calendar-event-to-date))
bc83970d 313 (cal-tex-cursor-week-monday nil)))
e519449d 314
a137e62c
KH
315(defun cal-tex-mouse-filofax-daily ()
316 "Day-per-page Filofax calendar for week indicated by cursor."
317 (interactive)
318 (save-excursion
319 (calendar-mouse-goto-date (calendar-event-to-date))
320 (cal-tex-cursor-filofax-daily nil)))
321
610d0966 322(defun cal-tex-mouse-filofax-2week ()
e519449d
ER
323 "One page Filofax calendar for week indicated by cursor."
324 (interactive)
325 (save-excursion
a0e06fd0 326 (calendar-mouse-goto-date (calendar-event-to-date))
610d0966 327 (cal-tex-cursor-filofax-2week nil)))
e519449d 328
610d0966 329(defun cal-tex-mouse-filofax-week ()
e519449d
ER
330 "Two page Filofax calendar for week indicated by cursor."
331 (interactive)
332 (save-excursion
a0e06fd0 333 (calendar-mouse-goto-date (calendar-event-to-date))
610d0966 334 (cal-tex-cursor-filofax-week nil)))
e519449d
ER
335
336(defun cal-tex-mouse-month ()
337 "Make a buffer with LaTeX commands for the month cursor is on.
338Calendar is condensed onto one page."
339 (interactive)
340 (save-excursion
a0e06fd0 341 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
342 (cal-tex-cursor-month nil)))
343
344(defun cal-tex-mouse-month-landscape ()
345 "Make a buffer with LaTeX commands for the month cursor is on.
346The output is in landscape format, one month to a page."
347 (interactive)
348 (save-excursion
a0e06fd0 349 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
350 (cal-tex-cursor-month-landscape nil)))
351
352(defun cal-tex-mouse-year ()
353 "Make a buffer with LaTeX commands for the year cursor is on."
354 (interactive)
355 (save-excursion
a0e06fd0 356 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
357 (cal-tex-cursor-year nil)))
358
359(defun cal-tex-mouse-filofax-year ()
360 "Make a buffer with LaTeX commands for Filofax calendar of year cursor is on."
361 (interactive)
362 (save-excursion
a0e06fd0 363 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
364 (cal-tex-cursor-filofax-year nil)))
365
366(defun cal-tex-mouse-year-landscape ()
367 "Make a buffer with LaTeX commands for the year cursor is on."
368 (interactive)
369 (save-excursion
a0e06fd0 370 (calendar-mouse-goto-date (calendar-event-to-date))
e519449d
ER
371 (cal-tex-cursor-year-landscape nil)))
372
e9f8d300 373(defun calendar-mouse-print-dates (&optional event)
5bbcf603
GM
374 "Pop up menu of equivalent dates to mouse selected date.
375EVENT is the event that invoked this command."
e9f8d300
SM
376 (interactive "e")
377 (let* ((date (calendar-event-to-date))
f328a783
GM
378 (title (format "%s (Gregorian)" (calendar-date-string date)))
379 (selection
380 (cal-menu-x-popup-menu
381 event
382 (list title
383 (append (list title)
384 (mapcar 'list (calendar-other-dates date)))))))
385 (and selection (call-interactively selection))))
aef1a243 386
5bbcf603
GM
387(defun cal-menu-set-date-title (menu)
388 "Convert date of last event to title suitable for MENU."
389 (easy-menu-filter-return
390 menu (calendar-date-string (calendar-event-to-date t) t nil)))
391
05efa389 392(easy-menu-define cal-menu-context-mouse-menu nil
a6ee0a2f 393 "Pop up menu for Mouse-2 for selected date in the calendar window."
05efa389
SM
394 '("foo" :filter cal-menu-set-date-title
395 "--"
396 ["Holidays" calendar-mouse-holidays]
397 ["Mark date" calendar-mouse-set-mark]
398 ["Sunrise/sunset" calendar-mouse-sunrise/sunset]
399 ["Other calendars" calendar-mouse-print-dates]
400 ("Prepare LaTeX buffer"
401 ["Daily (1 page)" cal-tex-mouse-day]
402 ["Weekly (1 page)" cal-tex-mouse-week]
403 ["Weekly (2 pages)" cal-tex-mouse-week2]
404 ["Weekly (other style; 1 page)" cal-tex-mouse-week-iso]
405 ["Weekly (yet another style; 1 page)" cal-tex-mouse-week-monday]
406 ["Monthly" cal-tex-mouse-month]
407 ["Monthly (landscape)" cal-tex-mouse-month-landscape]
408 ["Yearly" cal-tex-mouse-year]
409 ["Yearly (landscape)" cal-tex-mouse-year-landscape]
410 ("Filofax styles"
411 ["Filofax Daily (one-day-per-page)" cal-tex-mouse-filofax-daily]
412 ["Filofax Weekly (2-weeks-at-a-glance)" cal-tex-mouse-filofax-2week]
413 ["Filofax Weekly (week-at-a-glance)" cal-tex-mouse-filofax-week]
414 ["Filofax Yearly" cal-tex-mouse-filofax-year]))
415 ["Diary entries" calendar-mouse-view-diary-entries]
416 ["Insert diary entry" calendar-mouse-insert-diary-entry]
417 ["Other diary file entries" calendar-mouse-view-other-diary-entries]))
418
05efa389
SM
419(easy-menu-define cal-menu-global-mouse-menu nil
420 "Menu bound to a mouse event, not specific to the mouse-click location."
421 '("Calendar"
cca1dde0
SM
422 ["Scroll forward" calendar-scroll-left-three-months]
423 ["Scroll backward" calendar-scroll-right-three-months]
05efa389 424 ["Mark diary entries" mark-diary-entries]
175ede29
GM
425 ["List holidays" calendar-list-holidays]
426 ["Mark holidays" calendar-mark-holidays]
05efa389
SM
427 ["Unmark" calendar-unmark]
428 ["Lunar phases" calendar-phases-of-moon]
429 ["Show diary" diary-show-all-entries]
430 ["Exit calendar" exit-calendar]))
aef1a243 431
f328a783
GM
432;; Undocumented and probably useless.
433(defvar cal-menu-load-hook nil
434 "Hook run on loading of the `cal-menu' package.")
435(make-obsolete-variable 'cal-menu-load-hook
436 "it will be removed in future." "23.1")
437
aef1a243
RS
438(run-hooks 'cal-menu-load-hook)
439
440(provide 'cal-menu)
441
e9f8d300 442;; arch-tag: aa81cf73-ce89-48a4-97ec-9ef861e87fe9
aef1a243 443;;; cal-menu.el ends here