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