Commit | Line | Data |
---|---|---|
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> | |
6b8927e3 | 7 | ;; Maintainer: Glenn Morris <gmorris@ast.cam.ac.uk> |
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 EN |
24 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
25 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
26 | ;; Boston, MA 02111-1307, 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 | ||
5bb7a2d5 GM |
41 | (defvar displayed-month) |
42 | (defvar displayed-year) | |
43 | ||
dce5c916 | 44 | (eval-when-compile (require 'calendar)) |
b5305eb0 | 45 | (require 'easymenu) |
20eff799 | 46 | |
7c77d665 | 47 | (define-key calendar-mode-map [menu-bar edit] 'undefined) |
bc83970d | 48 | (define-key calendar-mode-map [menu-bar search] 'undefined) |
7c77d665 | 49 | |
89e14386 | 50 | (define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu) |
982f12d0 | 51 | (define-key calendar-mode-map [mouse-2] 'ignore) |
89e14386 RS |
52 | |
53 | (defvar calendar-mouse-3-map (make-sparse-keymap "Calendar")) | |
54 | (define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map) | |
aef1a243 | 55 | |
48b29ac0 ER |
56 | (define-key calendar-mode-map [menu-bar moon] |
57 | (cons "Moon" (make-sparse-keymap "Moon"))) | |
58 | ||
59 | (define-key calendar-mode-map [menu-bar moon moon] | |
0e520d74 | 60 | '("Lunar Phases" . calendar-phases-of-moon)) |
48b29ac0 | 61 | |
aef1a243 RS |
62 | (define-key calendar-mode-map [menu-bar diary] |
63 | (cons "Diary" (make-sparse-keymap "Diary"))) | |
64 | ||
65 | (define-key calendar-mode-map [menu-bar diary heb] | |
66 | '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry)) | |
67 | (define-key calendar-mode-map [menu-bar diary isl] | |
68 | '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry)) | |
811a8484 JW |
69 | (define-key calendar-mode-map [menu-bar diary baha] |
70 | '("Insert Baha'i" . calendar-mouse-insert-bahai-diary-entry)) | |
aef1a243 | 71 | (define-key calendar-mode-map [menu-bar diary cyc] |
0e520d74 | 72 | '("Insert Cyclic" . insert-cyclic-diary-entry)) |
aef1a243 | 73 | (define-key calendar-mode-map [menu-bar diary blk] |
0e520d74 | 74 | '("Insert Block" . insert-block-diary-entry)) |
aef1a243 | 75 | (define-key calendar-mode-map [menu-bar diary ann] |
0e520d74 | 76 | '("Insert Anniversary" . insert-anniversary-diary-entry)) |
aef1a243 | 77 | (define-key calendar-mode-map [menu-bar diary yr] |
0e520d74 | 78 | '("Insert Yearly" . insert-yearly-diary-entry)) |
aef1a243 | 79 | (define-key calendar-mode-map [menu-bar diary mon] |
0e520d74 | 80 | '("Insert Monthly" . insert-monthly-diary-entry)) |
aef1a243 | 81 | (define-key calendar-mode-map [menu-bar diary wk] |
0e520d74 | 82 | '("Insert Weekly" . insert-weekly-diary-entry)) |
aef1a243 | 83 | (define-key calendar-mode-map [menu-bar diary ent] |
9a8e2a10 | 84 | '("Insert Diary Entry" . insert-diary-entry)) |
aef1a243 | 85 | (define-key calendar-mode-map [menu-bar diary all] |
0e520d74 | 86 | '("Show All" . show-all-diary-entries)) |
aef1a243 | 87 | (define-key calendar-mode-map [menu-bar diary mark] |
0e520d74 | 88 | '("Mark All" . mark-diary-entries)) |
aef1a243 | 89 | (define-key calendar-mode-map [menu-bar diary view] |
0e520d74 | 90 | '("Cursor Date" . view-diary-entries)) |
95436630 | 91 | (define-key calendar-mode-map [menu-bar diary view] |
0e520d74 | 92 | '("Other File" . view-other-diary-entries)) |
aef1a243 | 93 | |
f8cac35a | 94 | (define-key calendar-mode-map [menu-bar Holidays] |
aef1a243 RS |
95 | (cons "Holidays" (make-sparse-keymap "Holidays"))) |
96 | ||
aef1a243 RS |
97 | (define-key calendar-mode-map [menu-bar goto] |
98 | (cons "Goto" (make-sparse-keymap "Goto"))) | |
99 | ||
100 | (define-key calendar-mode-map [menu-bar goto french] | |
0e520d74 | 101 | '("French Date" . calendar-goto-french-date)) |
aef1a243 | 102 | (define-key calendar-mode-map [menu-bar goto mayan] |
0e520d74 | 103 | (cons "Mayan Date" (make-sparse-keymap "Mayan"))) |
c29681e1 ER |
104 | (define-key calendar-mode-map [menu-bar goto ethiopic] |
105 | '("Ethiopic Date" . calendar-goto-ethiopic-date)) | |
106 | (define-key calendar-mode-map [menu-bar goto coptic] | |
107 | '("Coptic Date" . calendar-goto-coptic-date)) | |
108 | (define-key calendar-mode-map [menu-bar goto chinese] | |
109 | '("Chinese Date" . calendar-goto-chinese-date)) | |
aef1a243 | 110 | (define-key calendar-mode-map [menu-bar goto julian] |
0e520d74 | 111 | '("Julian Date" . calendar-goto-julian-date)) |
aef1a243 | 112 | (define-key calendar-mode-map [menu-bar goto islamic] |
0e520d74 | 113 | '("Islamic Date" . calendar-goto-islamic-date)) |
811a8484 JW |
114 | (define-key calendar-mode-map [menu-bar goto persian] |
115 | '("Baha'i Date" . calendar-goto-bahai-date)) | |
c21eb13d ER |
116 | (define-key calendar-mode-map [menu-bar goto persian] |
117 | '("Persian Date" . calendar-goto-persian-date)) | |
aef1a243 | 118 | (define-key calendar-mode-map [menu-bar goto hebrew] |
0e520d74 | 119 | '("Hebrew Date" . calendar-goto-hebrew-date)) |
aef1a243 | 120 | (define-key calendar-mode-map [menu-bar goto astro] |
0e520d74 | 121 | '("Astronomical Date" . calendar-goto-astro-day-number)) |
aef1a243 | 122 | (define-key calendar-mode-map [menu-bar goto iso] |
0e520d74 | 123 | '("ISO Date" . calendar-goto-iso-date)) |
6b8927e3 GM |
124 | (define-key calendar-mode-map [menu-bar goto iso-week] |
125 | '("ISO Week" . calendar-goto-iso-week)) | |
f9df0ca0 GM |
126 | (define-key calendar-mode-map [menu-bar goto day-of-year] |
127 | '("Day of Year" . calendar-goto-day-of-year)) | |
aef1a243 | 128 | (define-key calendar-mode-map [menu-bar goto gregorian] |
0e520d74 | 129 | '("Other Date" . calendar-goto-date)) |
aef1a243 | 130 | (define-key calendar-mode-map [menu-bar goto end-of-year] |
0e520d74 | 131 | '("End of Year" . calendar-end-of-year)) |
aef1a243 | 132 | (define-key calendar-mode-map [menu-bar goto beginning-of-year] |
0e520d74 | 133 | '("Beginning of Year" . calendar-beginning-of-year)) |
aef1a243 | 134 | (define-key calendar-mode-map [menu-bar goto end-of-month] |
0e520d74 | 135 | '("End of Month" . calendar-end-of-month)) |
aef1a243 | 136 | (define-key calendar-mode-map [menu-bar goto beginning-of-month] |
0e520d74 | 137 | '("Beginning of Month" . calendar-beginning-of-month)) |
aef1a243 | 138 | (define-key calendar-mode-map [menu-bar goto end-of-week] |
0e520d74 | 139 | '("End of Week" . calendar-end-of-week)) |
aef1a243 | 140 | (define-key calendar-mode-map [menu-bar goto beginning-of-week] |
0e520d74 | 141 | '("Beginning of Week" . calendar-beginning-of-week)) |
aef1a243 | 142 | (define-key calendar-mode-map [menu-bar goto today] |
e8cf82e8 | 143 | '("Today" . calendar-goto-today)) |
aef1a243 RS |
144 | |
145 | ||
146 | (define-key calendar-mode-map [menu-bar goto mayan prev-rnd] | |
147 | '("Previous Round" . calendar-previous-calendar-round-date)) | |
148 | (define-key calendar-mode-map [menu-bar goto mayan nxt-rnd] | |
149 | '("Next Round" . calendar-next-calendar-round-date)) | |
150 | (define-key calendar-mode-map [menu-bar goto mayan prev-haab] | |
151 | '("Previous Haab" . calendar-previous-haab-date)) | |
152 | (define-key calendar-mode-map [menu-bar goto mayan next-haab] | |
153 | '("Next Haab" . calendar-next-haab-date)) | |
154 | (define-key calendar-mode-map [menu-bar goto mayan prev-tzol] | |
155 | '("Previous Tzolkin" . calendar-previous-tzolkin-date)) | |
156 | (define-key calendar-mode-map [menu-bar goto mayan next-tzol] | |
157 | '("Next Tzolkin" . calendar-next-tzolkin-date)) | |
158 | ||
159 | (define-key calendar-mode-map [menu-bar scroll] | |
160 | (cons "Scroll" (make-sparse-keymap "Scroll"))) | |
161 | ||
162 | (define-key calendar-mode-map [menu-bar scroll bk-12] | |
163 | '("Backward 1 Year" . "4\ev")) | |
164 | (define-key calendar-mode-map [menu-bar scroll bk-3] | |
165 | '("Backward 3 Months" . scroll-calendar-right-three-months)) | |
166 | (define-key calendar-mode-map [menu-bar scroll bk-1] | |
167 | '("Backward 1 Month" . scroll-calendar-right)) | |
168 | (define-key calendar-mode-map [menu-bar scroll fwd-12] | |
169 | '("Forward 1 Year" . "4\C-v")) | |
170 | (define-key calendar-mode-map [menu-bar scroll fwd-3] | |
171 | '("Forward 3 Months" . scroll-calendar-left-three-months)) | |
172 | (define-key calendar-mode-map [menu-bar scroll fwd-1] | |
173 | '("Forward 1 Month" . scroll-calendar-left)) | |
174 | ||
f9df0ca0 GM |
175 | (defun calendar-flatten (list) |
176 | "Flatten LIST eliminating sublists structure; result is a list of atoms. | |
177 | This is the same as the preorder list of leaves in a rooted forest." | |
178 | (if (atom list) | |
179 | (list list) | |
180 | (if (cdr list) | |
181 | (append (calendar-flatten (car list)) (calendar-flatten (cdr list))) | |
182 | (calendar-flatten (car list))))) | |
183 | ||
87671c25 EZ |
184 | (defun cal-menu-x-popup-menu (position menu) |
185 | "Like `x-popup-menu', but prints an error message if popup menus are | |
186 | not available." | |
187 | (if (display-popup-menus-p) | |
188 | (x-popup-menu position menu) | |
3f3410a9 | 189 | (error "Popup menus are not available on this system"))) |
87671c25 | 190 | |
f10cbb4c RS |
191 | (defun cal-menu-list-holidays-year () |
192 | "Display a list of the holidays of the selected date's year." | |
193 | (interactive) | |
194 | (let ((year (extract-calendar-year (calendar-cursor-to-date)))) | |
195 | (list-holidays year year))) | |
196 | ||
197 | (defun cal-menu-list-holidays-following-year () | |
198 | "Display a list of the holidays of the following year." | |
199 | (interactive) | |
200 | (let ((year (1+ (extract-calendar-year (calendar-cursor-to-date))))) | |
201 | (list-holidays year year))) | |
202 | ||
203 | (defun cal-menu-list-holidays-previous-year () | |
204 | "Display a list of the holidays of the previous year." | |
205 | (interactive) | |
206 | (let ((year (1- (extract-calendar-year (calendar-cursor-to-date))))) | |
207 | (list-holidays year year))) | |
208 | ||
b5305eb0 ER |
209 | (defun cal-menu-update () |
210 | ;; Update the holiday part of calendar menu bar for the current display. | |
211 | (condition-case nil | |
212 | (if (eq major-mode 'calendar-mode) | |
213 | (let ((l)) | |
214 | (calendar-for-loop;; Show 11 years--5 before, 5 after year of | |
215 | ;; middle month | |
216 | i from (- displayed-year 5) to (+ displayed-year 5) do | |
217 | (setq l (cons (vector (format "For Year %s" i) | |
218 | (list (list 'lambda 'nil '(interactive) | |
219 | (list 'list-holidays i i))) | |
220 | t) | |
221 | l))) | |
222 | (setq l (cons ["Mark Holidays" mark-calendar-holidays t] | |
b67c85e9 | 223 | (cons ["Unmark Calendar" calendar-unmark t] |
9110ca11 | 224 | (cons "--" l)))) |
d5b213cc RS |
225 | (define-key calendar-mode-map [menu-bar Holidays] |
226 | (cons "Holidays" (easy-menu-create-menu "Holidays" (nreverse l)))) | |
4cb54652 | 227 | (define-key calendar-mode-map [menu-bar Holidays separator] |
b67c85e9 | 228 | '("--")) |
f8cac35a | 229 | (define-key calendar-mode-map [menu-bar Holidays today] |
07342a64 ER |
230 | `(,(format "For Today (%s)" |
231 | (calendar-date-string (calendar-current-date) t t)) | |
232 | . cal-menu-today-holidays)) | |
b5305eb0 ER |
233 | (let ((title |
234 | (let ((m1 displayed-month) | |
235 | (y1 displayed-year) | |
236 | (m2 displayed-month) | |
237 | (y2 displayed-year)) | |
238 | (increment-calendar-month m1 y1 -1) | |
239 | (increment-calendar-month m2 y2 1) | |
240 | (if (= y1 y2) | |
241 | (format "%s-%s, %d" | |
5bb7a2d5 GM |
242 | (calendar-month-name m1 'abbrev) |
243 | (calendar-month-name m2 'abbrev) | |
b5305eb0 ER |
244 | y2) |
245 | (format "%s, %d-%s, %d" | |
5bb7a2d5 | 246 | (calendar-month-name m1 'abbrev) |
b5305eb0 | 247 | y1 |
5bb7a2d5 | 248 | (calendar-month-name m2 'abbrev) |
b5305eb0 | 249 | y2))))) |
f8cac35a RS |
250 | (define-key calendar-mode-map [menu-bar Holidays 3-month] |
251 | `(,(format "For Window (%s)" title) | |
b5305eb0 ER |
252 | . list-calendar-holidays))) |
253 | (let ((date (calendar-cursor-to-date))) | |
254 | (if date | |
f8cac35a | 255 | (define-key calendar-mode-map [menu-bar Holidays 1-day] |
3f0855d5 | 256 | `(,(format "For Cursor Date (%s)" |
b5305eb0 ER |
257 | (calendar-date-string date t t)) |
258 | . calendar-cursor-holidays)))))) | |
259 | ;; Try to avoid entering infinite beep mode in case of errors. | |
260 | (error (ding)))) | |
261 | ||
a6ee0a2f ER |
262 | (defun calendar-event-to-date (&optional error) |
263 | "Date of last event. | |
264 | If event is not on a specific date, signals an error if optional parameter | |
265 | ERROR is t, otherwise just returns nil." | |
aef1a243 | 266 | (save-excursion |
a0e06fd0 | 267 | (set-buffer (window-buffer (posn-window (event-start last-input-event)))) |
aef1a243 | 268 | (goto-char (posn-point (event-start last-input-event))) |
a6ee0a2f | 269 | (calendar-cursor-to-date error))) |
aef1a243 RS |
270 | |
271 | (defun calendar-mouse-insert-hebrew-diary-entry (event) | |
272 | "Pop up menu to insert a Hebrew-date diary entry." | |
273 | (interactive "e") | |
274 | (let ((hebrew-selection | |
87671c25 | 275 | (cal-menu-x-popup-menu |
aef1a243 RS |
276 | event |
277 | (list "Hebrew insert menu" | |
278 | (list (calendar-hebrew-date-string (calendar-cursor-to-date)) | |
279 | '("One time" . insert-hebrew-diary-entry) | |
280 | '("Monthly" . insert-monthly-hebrew-diary-entry) | |
281 | '("Yearly" . insert-yearly-hebrew-diary-entry)))))) | |
282 | (and hebrew-selection (call-interactively hebrew-selection)))) | |
283 | ||
284 | (defun calendar-mouse-insert-islamic-diary-entry (event) | |
285 | "Pop up menu to insert an Islamic-date diary entry." | |
286 | (interactive "e") | |
287 | (let ((islamic-selection | |
87671c25 | 288 | (cal-menu-x-popup-menu |
aef1a243 RS |
289 | event |
290 | (list "Islamic insert menu" | |
291 | (list (calendar-islamic-date-string (calendar-cursor-to-date)) | |
292 | '("One time" . insert-islamic-diary-entry) | |
293 | '("Monthly" . insert-monthly-islamic-diary-entry) | |
294 | '("Yearly" . insert-yearly-islamic-diary-entry)))))) | |
295 | (and islamic-selection (call-interactively islamic-selection)))) | |
296 | ||
811a8484 JW |
297 | (defun calendar-mouse-insert-bahai-diary-entry (event) |
298 | "Pop up menu to insert an Baha'i-date diary entry." | |
299 | (interactive "e") | |
300 | (let ((bahai-selection | |
301 | (x-popup-menu | |
302 | event | |
303 | (list "Baha'i insert menu" | |
304 | (list (calendar-bahai-date-string (calendar-cursor-to-date)) | |
305 | '("One time" . insert-bahai-diary-entry) | |
306 | '("Monthly" . insert-monthly-bahai-diary-entry) | |
307 | '("Yearly" . insert-yearly-bahai-diary-entry)))))) | |
308 | (and bahai-selection (call-interactively bahai-selection)))) | |
309 | ||
aef1a243 RS |
310 | (defun calendar-mouse-sunrise/sunset () |
311 | "Show sunrise/sunset times for mouse-selected date." | |
312 | (interactive) | |
313 | (save-excursion | |
a0e06fd0 | 314 | (calendar-mouse-goto-date (calendar-event-to-date)) |
aef1a243 RS |
315 | (calendar-sunrise-sunset))) |
316 | ||
07342a64 ER |
317 | (defun cal-menu-today-holidays () |
318 | "Show holidays for today's date." | |
319 | (interactive) | |
320 | (save-excursion | |
321 | (calendar-cursor-to-date (calendar-current-date)) | |
322 | (calendar-cursor-holidays))) | |
323 | ||
aef1a243 | 324 | (defun calendar-mouse-holidays () |
6c8a48a6 | 325 | "Pop up menu of holidays for mouse selected date." |
aef1a243 | 326 | (interactive) |
6c8a48a6 ER |
327 | (let* ((date (calendar-event-to-date)) |
328 | (l (mapcar '(lambda (x) (list x)) | |
329 | (check-calendar-holidays date))) | |
330 | (selection | |
87671c25 | 331 | (cal-menu-x-popup-menu |
6c8a48a6 ER |
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)))) | |
aef1a243 | 339 | |
f9df0ca0 GM |
340 | (defun calendar-mouse-view-diary-entries (&optional date diary) |
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." | |
aef1a243 | 345 | (interactive) |
f9df0ca0 GM |
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 | (list-diary-entries date 1))) | |
353 | (holidays (if holidays-in-diary-buffer | |
354 | (mapcar '(lambda (x) (list x)) | |
355 | (check-calendar-holidays date)))) | |
356 | (title (concat "Diary entries " | |
357 | (if diary (format "from %s " diary) "") | |
358 | "for " | |
359 | (calendar-date-string date))) | |
6c8a48a6 | 360 | (selection |
87671c25 | 361 | (cal-menu-x-popup-menu |
6c8a48a6 | 362 | event |
f9df0ca0 GM |
363 | (list title |
364 | (append | |
365 | (list title) | |
366 | (if holidays | |
367 | (mapcar '(lambda (x) (list (concat " " (car x)))) | |
368 | holidays)) | |
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. | |
406 | Holidays 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. | |
414 | The 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. |
422 | Holidays 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. | |
458 | Calendar 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. | |
466 | The 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 |