(calendar-check-holidays): Declare rather than autoloading.
[emacs.git] / lisp / calendar / cal-menu.el
blob704c49a650147df4863de502cb494ed73b8c428d
1 ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
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
12 ;; This file is part of GNU Emacs.
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 3 of the License, or
17 ;; (at your option) any later version.
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.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;;; Commentary:
29 ;; See calendar.el.
31 ;;; Code:
33 (require 'calendar)
35 (defconst cal-menu-moon-menu
36 '("Moon"
37 ["Lunar Phases" calendar-phases-of-moon]
38 ["Sunrise/sunset for cursor date" calendar-sunrise-sunset])
39 "Key map for \"Moon\" menu in the calendar.")
41 (defconst cal-menu-diary-menu
42 '("Diary"
43 ["Other File" diary-view-other-diary-entries]
44 ["Cursor Date" diary-view-entries]
45 ["Mark All" diary-mark-entries]
46 ["Show All" diary-show-all-entries]
47 ["Insert Diary Entry" diary-insert-entry]
48 ["Insert Weekly" diary-insert-weekly-entry]
49 ["Insert Monthly" diary-insert-monthly-entry]
50 ["Insert Yearly" diary-insert-yearly-entry]
51 ["Insert Anniversary" diary-insert-anniversary-entry]
52 ["Insert Block" diary-insert-block-entry]
53 ["Insert Cyclic" diary-insert-cyclic-entry]
54 ("Insert Baha'i"
55 ["One time" diary-bahai-insert-entry]
56 ["Monthly" diary-bahai-insert-monthly-entry]
57 ["Yearly" diary-bahai-insert-yearly-entry])
58 ("Insert Islamic"
59 ["One time" diary-islamic-insert-entry]
60 ["Monthly" diary-islamic-insert-monthly-entry]
61 ["Yearly" diary-islamic-insert-yearly-entry])
62 ("Insert Hebrew"
63 ["One time" diary-hebrew-insert-entry]
64 ["Monthly" diary-hebrew-insert-monthly-entry]
65 ["Yearly" diary-hebrew-insert-yearly-entry]))
66 "Key map for \"Diary\" menu in the calendar.")
68 (defun cal-menu-holiday-window-suffix ()
69 "Return a string suffix for the \"Window\" entry in `cal-menu-holidays-menu'."
70 (let ((my1 (calendar-increment-month-cons -1))
71 (my2 (calendar-increment-month-cons 1)))
72 ;; Mon1-Mon2, Year or Mon1, Year1-Mon2, Year2.
73 (format "%s%s-%s, %d"
74 (calendar-month-name (car my1) 'abbrev)
75 (if (= (cdr my1) (cdr my2))
77 (format ", %d" (cdr my1)))
78 (calendar-month-name (car my2) 'abbrev)
79 (cdr my2))))
81 (defvar displayed-year) ; from calendar-generate
83 (defconst cal-menu-holidays-menu
84 `("Holidays"
85 ["For Cursor Date -" calendar-cursor-holidays
86 :suffix (calendar-date-string (calendar-cursor-to-date) t t)
87 :visible (calendar-cursor-to-date)]
88 ["For Window -" calendar-list-holidays
89 :suffix (cal-menu-holiday-window-suffix)]
90 ["For Today -" (calendar-cursor-holidays (calendar-current-date))
91 :suffix (calendar-date-string (calendar-current-date) t t)]
92 "--"
93 ,@(let ((l ()))
94 ;; Show 11 years--5 before, 5 after year of middle month.
95 ;; We used to use :suffix rather than :label and bumped into
96 ;; an easymenu bug:
97 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01813.html
98 ;; The bug has since been fixed.
99 (dotimes (i 11)
100 (push (vector (format "hol-year-%d" i)
101 `(lambda ()
102 (interactive)
103 (holiday-list (+ displayed-year ,(- i 5))))
104 :label `(format "For Year %d"
105 (+ displayed-year ,(- i 5))))
107 (nreverse l))
108 "--"
109 ["Unmark Calendar" calendar-unmark]
110 ["Mark Holidays" calendar-mark-holidays])
111 "Key map for \"Holidays\" menu in the calendar.")
113 (defconst cal-menu-goto-menu
114 '("Go To"
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]
124 ["ISO Week" calendar-iso-goto-week]
125 ["ISO Date" calendar-iso-goto-date]
126 ["Astronomical Date" calendar-astro-goto-day-number]
127 ["Hebrew Date" calendar-hebrew-goto-date]
128 ["Persian Date" calendar-persian-goto-date]
129 ["Baha'i Date" calendar-bahai-goto-date]
130 ["Islamic Date" calendar-islamic-goto-date]
131 ["Julian Date" calendar-julian-goto-date]
132 ["Chinese Date" calendar-chinese-goto-date]
133 ["Coptic Date" calendar-coptic-goto-date]
134 ["Ethiopic Date" calendar-ethiopic-goto-date]
135 ("Mayan Date"
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])
142 ["French Date" calendar-french-goto-date])
143 "Key map for \"Go To\" menu in the calendar.")
145 (defconst cal-menu-scroll-menu
146 '("Scroll"
147 ["Forward 1 Month" calendar-scroll-left]
148 ["Forward 3 Months" calendar-scroll-left-three-months]
149 ["Forward 1 Year" (calendar-scroll-left 12) :keys "4 C-v"]
150 ["Backward 1 Month" calendar-scroll-right]
151 ["Backward 3 Months" calendar-scroll-right-three-months]
152 ["Backward 1 Year" (calendar-scroll-right 12) :keys "4 M-v"])
153 "Key map for \"Scroll\" menu in the calendar.")
155 (defmacro cal-menu-x-popup-menu (event title &rest body)
156 "Call `x-popup-menu' at position EVENT, with TITLE and contents BODY.
157 Signals an error if popups are unavailable."
158 (declare (indent 2))
159 `(if (display-popup-menus-p)
160 (x-popup-menu ,event (list ,title (append (list ,title) ,@body)))
161 (error "Popup menus are not available on this system")))
163 (autoload 'diary-list-entries "diary-lib")
164 ;; Autoloaded in diary-lib.
165 (declare-function calendar-check-holidays "holidays" (date))
167 (defun calendar-mouse-view-diary-entries (&optional date diary event)
168 "Pop up menu of diary entries for mouse-selected date.
169 Use optional DATE and alternative file DIARY. EVENT is the event
170 that invoked this command. Shows holidays if `diary-show-holidays-flag'
171 is non-nil."
172 (interactive "i\ni\ne")
173 (let* ((date (or date (calendar-cursor-to-date nil event)))
174 (diary-file (or diary diary-file))
175 (diary-list-include-blanks nil)
176 (diary-entries (mapcar (lambda (x) (split-string (cadr x) "\n"))
177 (diary-list-entries date 1 'list-only)))
178 (holidays (if diary-show-holidays-flag
179 (calendar-check-holidays date)))
180 (title (format "Diary entries%s for %s"
181 (if diary (format " from %s" diary) "")
182 (calendar-date-string date)))
183 (selection (cal-menu-x-popup-menu event title
184 (mapcar (lambda (x) (list (concat " " x))) holidays)
185 (if holidays
186 (list "--shadow-etched-in" "--shadow-etched-in"))
187 (if diary-entries
188 (mapcar 'list (apply 'append diary-entries))
189 '("None")))))
190 (and selection (call-interactively selection))))
192 (defun calendar-mouse-view-other-diary-entries (&optional event)
193 "Pop up menu of diary entries from alternative file on mouse-selected date."
194 (interactive "e")
195 (calendar-mouse-view-diary-entries
196 (calendar-cursor-to-date nil event)
197 (read-file-name "Enter diary file name: " default-directory nil t)
198 event))
200 (defun cal-menu-set-date-title (menu)
201 "Convert date of last event to title suitable for MENU."
202 (easy-menu-filter-return
203 menu (calendar-date-string (calendar-cursor-to-date t last-input-event)
204 t nil)))
206 (easy-menu-define cal-menu-context-mouse-menu nil
207 "Pop up menu for Mouse-2 for selected date in the calendar window."
208 '("cal-menu-mouse2" :filter cal-menu-set-date-title
209 "--"
210 ["Holidays" calendar-cursor-holidays]
211 ["Mark date" calendar-set-mark]
212 ["Sunrise/sunset" calendar-sunrise-sunset]
213 ["Other calendars" calendar-print-other-dates]
214 ;; FIXME there is a bug (#447) with last-nonmenu-event and submenus.
215 ;; These currently don't work if called without calendar window selected.
216 ("Prepare LaTeX buffer"
217 ["Daily (1 page)" cal-tex-cursor-day]
218 ["Weekly (1 page)" cal-tex-cursor-week]
219 ["Weekly (2 pages)" cal-tex-cursor-week2]
220 ["Weekly (other style; 1 page)" cal-tex-cursor-week-iso]
221 ["Weekly (yet another style; 1 page)" cal-tex-cursor-week-monday]
222 ["Monthly" cal-tex-cursor-month]
223 ["Monthly (landscape)" cal-tex-cursor-month-landscape]
224 ["Yearly" cal-tex-cursor-year]
225 ["Yearly (landscape)" cal-tex-cursor-year-landscape]
226 ("Filofax styles"
227 ["Filofax Daily (one-day-per-page)" cal-tex-cursor-filofax-daily]
228 ["Filofax Weekly (2-weeks-at-a-glance)" cal-tex-cursor-filofax-2week]
229 ["Filofax Weekly (week-at-a-glance)" cal-tex-cursor-filofax-week]
230 ["Filofax Yearly" cal-tex-cursor-filofax-year]))
231 ("Write HTML calendar"
232 ["For selected month" cal-html-cursor-month]
233 ["For selected year" cal-html-cursor-year])
234 ["Diary entries" calendar-mouse-view-diary-entries :keys "d"]
235 ["Insert diary entry" diary-insert-entry]
236 ["Other diary file entries" calendar-mouse-view-other-diary-entries
237 :keys "D"]))
239 (easy-menu-define cal-menu-global-mouse-menu nil
240 "Menu bound to a mouse event, not specific to the mouse-click location."
241 '("Calendar"
242 ["Scroll forward" calendar-scroll-left-three-months]
243 ["Scroll backward" calendar-scroll-right-three-months]
244 ["Mark diary entries" diary-mark-entries]
245 ["List holidays" calendar-list-holidays]
246 ["Mark holidays" calendar-mark-holidays]
247 ["Unmark" calendar-unmark]
248 ["Lunar phases" calendar-phases-of-moon]
249 ["Show diary" diary-show-all-entries]
250 ["Exit calendar" calendar-exit]))
252 ;; Undocumented and probably useless.
253 (defvar cal-menu-load-hook nil
254 "Hook run on loading of the `cal-menu' package.")
255 (make-obsolete-variable 'cal-menu-load-hook
256 "it will be removed in future." "23.1")
258 (run-hooks 'cal-menu-load-hook)
260 (provide 'cal-menu)
262 ;; arch-tag: aa81cf73-ce89-48a4-97ec-9ef861e87fe9
263 ;;; cal-menu.el ends here