cal-menu.el 26.1 KB
Newer Older
Richard M. Stallman's avatar
Richard M. Stallman committed
1 2
;;; cal-menu.el --- calendar functions for menu bar and popup menu support

3
;; Copyright (C) 1994, 1995, 2001, 2003 Free Software Foundation, Inc.
Richard M. Stallman's avatar
Richard M. Stallman committed
4 5 6 7 8 9 10 11

;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
;;	Lara Rios <lrios@coewl.cen.uiuc.edu>
;; Keywords: calendar
;; Human-Keywords: calendar, popup menus, menu bar

;; This file is part of GNU Emacs.

12 13 14 15 16
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

Richard M. Stallman's avatar
Richard M. Stallman committed
17
;; GNU Emacs is distributed in the hope that it will be useful,
18 19 20 21 22
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
Erik Naggum's avatar
Erik Naggum committed
23 24 25
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
Richard M. Stallman's avatar
Richard M. Stallman committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39

;;; Commentary:

;; This collection of functions implements menu bar and popup menu support for
;; calendar.el.

;; Comments, corrections, and improvements should be sent to
;;  Edward M. Reingold               Department of Computer Science
;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
;;                                   Urbana, Illinois 61801

;;; Code:

40 41 42
(defvar displayed-month)
(defvar displayed-year)

43
(eval-when-compile (require 'calendar))
44
(require 'easymenu)
Richard M. Stallman's avatar
Richard M. Stallman committed
45

Edward M. Reingold's avatar
Edward M. Reingold committed
46
(define-key calendar-mode-map [menu-bar edit] 'undefined)
47
(define-key calendar-mode-map [menu-bar search] 'undefined)
Edward M. Reingold's avatar
Edward M. Reingold committed
48

49
(define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
50
(define-key calendar-mode-map [mouse-2] 'ignore)
51 52 53

(defvar calendar-mouse-3-map (make-sparse-keymap "Calendar"))
(define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map)
54
(define-key calendar-mode-map [C-down-mouse-3] calendar-mouse-3-map)
Richard M. Stallman's avatar
Richard M. Stallman committed
55

56 57 58 59
(define-key calendar-mode-map [menu-bar moon]
  (cons "Moon" (make-sparse-keymap "Moon")))

(define-key calendar-mode-map [menu-bar moon moon]
Karl Heuer's avatar
Karl Heuer committed
60
  '("Lunar Phases" . calendar-phases-of-moon))
61

Richard M. Stallman's avatar
Richard M. Stallman committed
62 63 64 65 66 67 68
(define-key calendar-mode-map [menu-bar diary]
  (cons "Diary" (make-sparse-keymap "Diary")))

(define-key calendar-mode-map [menu-bar diary heb]
  '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry))
(define-key calendar-mode-map [menu-bar diary isl]
  '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry))
69 70
(define-key calendar-mode-map [menu-bar diary baha]
  '("Insert Baha'i" . calendar-mouse-insert-bahai-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
71
(define-key calendar-mode-map [menu-bar diary cyc]
Karl Heuer's avatar
Karl Heuer committed
72
  '("Insert Cyclic" . insert-cyclic-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
73
(define-key calendar-mode-map [menu-bar diary blk]
Karl Heuer's avatar
Karl Heuer committed
74
  '("Insert Block" . insert-block-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
75
(define-key calendar-mode-map [menu-bar diary ann]
Karl Heuer's avatar
Karl Heuer committed
76
  '("Insert Anniversary" . insert-anniversary-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
77
(define-key calendar-mode-map [menu-bar diary yr]
Karl Heuer's avatar
Karl Heuer committed
78
  '("Insert Yearly" . insert-yearly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
79
(define-key calendar-mode-map [menu-bar diary mon]
Karl Heuer's avatar
Karl Heuer committed
80
  '("Insert Monthly" . insert-monthly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
81
(define-key calendar-mode-map [menu-bar diary wk]
Karl Heuer's avatar
Karl Heuer committed
82
  '("Insert Weekly" . insert-weekly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
83
(define-key calendar-mode-map [menu-bar diary ent]
84
  '("Insert Diary Entry" . insert-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
85
(define-key calendar-mode-map [menu-bar diary all]
Karl Heuer's avatar
Karl Heuer committed
86
  '("Show All" . show-all-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
87
(define-key calendar-mode-map [menu-bar diary mark]
Karl Heuer's avatar
Karl Heuer committed
88
 '("Mark All" . mark-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
89
(define-key calendar-mode-map [menu-bar diary view]
Karl Heuer's avatar
Karl Heuer committed
90
  '("Cursor Date" . view-diary-entries))
91
(define-key calendar-mode-map [menu-bar diary view]
Karl Heuer's avatar
Karl Heuer committed
92
  '("Other File" . view-other-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
93

94
(define-key calendar-mode-map [menu-bar Holidays]
Richard M. Stallman's avatar
Richard M. Stallman committed
95 96 97 98 99 100
  (cons "Holidays" (make-sparse-keymap "Holidays")))

(define-key calendar-mode-map [menu-bar goto]
  (cons "Goto" (make-sparse-keymap "Goto")))

(define-key calendar-mode-map [menu-bar goto french]
Karl Heuer's avatar
Karl Heuer committed
101
  '("French Date" . calendar-goto-french-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
102
(define-key calendar-mode-map [menu-bar goto mayan]
Karl Heuer's avatar
Karl Heuer committed
103
  (cons "Mayan Date" (make-sparse-keymap "Mayan")))
104 105 106 107 108 109
(define-key calendar-mode-map [menu-bar goto ethiopic]
  '("Ethiopic Date" . calendar-goto-ethiopic-date))
(define-key calendar-mode-map [menu-bar goto coptic]
  '("Coptic Date" . calendar-goto-coptic-date))
(define-key calendar-mode-map [menu-bar goto chinese]
  '("Chinese Date" . calendar-goto-chinese-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
110
(define-key calendar-mode-map [menu-bar goto julian]
Karl Heuer's avatar
Karl Heuer committed
111
  '("Julian Date" . calendar-goto-julian-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
112
(define-key calendar-mode-map [menu-bar goto islamic]
Karl Heuer's avatar
Karl Heuer committed
113
  '("Islamic Date" . calendar-goto-islamic-date))
114 115
(define-key calendar-mode-map [menu-bar goto persian]
  '("Baha'i Date" . calendar-goto-bahai-date))
116 117
(define-key calendar-mode-map [menu-bar goto persian]
  '("Persian Date" . calendar-goto-persian-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
118
(define-key calendar-mode-map [menu-bar goto hebrew]
Karl Heuer's avatar
Karl Heuer committed
119
  '("Hebrew Date" . calendar-goto-hebrew-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
120
(define-key calendar-mode-map [menu-bar goto astro]
Karl Heuer's avatar
Karl Heuer committed
121
  '("Astronomical Date" . calendar-goto-astro-day-number))
Richard M. Stallman's avatar
Richard M. Stallman committed
122
(define-key calendar-mode-map [menu-bar goto iso]
Karl Heuer's avatar
Karl Heuer committed
123
  '("ISO Date" . calendar-goto-iso-date))
124 125
(define-key calendar-mode-map [menu-bar goto day-of-year]
  '("Day of Year" . calendar-goto-day-of-year))
Richard M. Stallman's avatar
Richard M. Stallman committed
126
(define-key calendar-mode-map [menu-bar goto gregorian]
Karl Heuer's avatar
Karl Heuer committed
127
  '("Other Date" . calendar-goto-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
128
(define-key calendar-mode-map [menu-bar goto end-of-year]
Karl Heuer's avatar
Karl Heuer committed
129
  '("End of Year" . calendar-end-of-year))
Richard M. Stallman's avatar
Richard M. Stallman committed
130
(define-key calendar-mode-map [menu-bar goto beginning-of-year]
Karl Heuer's avatar
Karl Heuer committed
131
  '("Beginning of Year" . calendar-beginning-of-year))
Richard M. Stallman's avatar
Richard M. Stallman committed
132
(define-key calendar-mode-map [menu-bar goto end-of-month]
Karl Heuer's avatar
Karl Heuer committed
133
  '("End of Month" . calendar-end-of-month))
Richard M. Stallman's avatar
Richard M. Stallman committed
134
(define-key calendar-mode-map [menu-bar goto beginning-of-month]
Karl Heuer's avatar
Karl Heuer committed
135
  '("Beginning of Month" . calendar-beginning-of-month))
Richard M. Stallman's avatar
Richard M. Stallman committed
136
(define-key calendar-mode-map [menu-bar goto end-of-week]
Karl Heuer's avatar
Karl Heuer committed
137
  '("End of Week" . calendar-end-of-week))
Richard M. Stallman's avatar
Richard M. Stallman committed
138
(define-key calendar-mode-map [menu-bar goto beginning-of-week]
Karl Heuer's avatar
Karl Heuer committed
139
  '("Beginning of Week" . calendar-beginning-of-week))
Richard M. Stallman's avatar
Richard M. Stallman committed
140
(define-key calendar-mode-map [menu-bar goto today]
141
  '("Today" . calendar-goto-today))
Richard M. Stallman's avatar
Richard M. Stallman committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172


(define-key calendar-mode-map [menu-bar goto mayan prev-rnd]
  '("Previous Round" . calendar-previous-calendar-round-date))
(define-key calendar-mode-map [menu-bar goto mayan nxt-rnd]
  '("Next Round" . calendar-next-calendar-round-date))
(define-key calendar-mode-map [menu-bar goto mayan prev-haab]
  '("Previous Haab" . calendar-previous-haab-date))
(define-key calendar-mode-map [menu-bar goto mayan next-haab]
  '("Next Haab" . calendar-next-haab-date))
(define-key calendar-mode-map [menu-bar goto mayan prev-tzol]
  '("Previous Tzolkin" . calendar-previous-tzolkin-date))
(define-key calendar-mode-map [menu-bar goto mayan next-tzol]
  '("Next Tzolkin" . calendar-next-tzolkin-date))

(define-key calendar-mode-map [menu-bar scroll]
  (cons "Scroll" (make-sparse-keymap "Scroll")))

(define-key calendar-mode-map [menu-bar scroll bk-12]
  '("Backward 1 Year" . "4\ev"))
(define-key calendar-mode-map [menu-bar scroll bk-3]
  '("Backward 3 Months" . scroll-calendar-right-three-months))
(define-key calendar-mode-map [menu-bar scroll bk-1]
  '("Backward 1 Month" . scroll-calendar-right))
(define-key calendar-mode-map [menu-bar scroll fwd-12]
  '("Forward 1 Year" . "4\C-v"))
(define-key calendar-mode-map [menu-bar scroll fwd-3]
  '("Forward 3 Months" . scroll-calendar-left-three-months))
(define-key calendar-mode-map [menu-bar scroll fwd-1]
  '("Forward 1 Month" . scroll-calendar-left))

173 174 175 176 177 178 179 180 181
(defun calendar-flatten (list)
  "Flatten LIST eliminating sublists structure; result is a list of atoms.
This is the same as the preorder list of leaves in a rooted forest."
  (if (atom list)
      (list list)
    (if (cdr list)
        (append (calendar-flatten (car list)) (calendar-flatten (cdr list)))
      (calendar-flatten (car list)))))

182 183 184 185 186
(defun cal-menu-x-popup-menu (position menu)
  "Like `x-popup-menu', but prints an error message if popup menus are
not available."
  (if (display-popup-menus-p)
      (x-popup-menu position menu)
187
    (error "Popup menus are not available on this system")))
188

189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
(defun cal-menu-list-holidays-year ()
  "Display a list of the holidays of the selected date's year."
  (interactive)
  (let ((year (extract-calendar-year (calendar-cursor-to-date))))
    (list-holidays year year)))

(defun cal-menu-list-holidays-following-year ()
  "Display a list of the holidays of the following year."
  (interactive)
  (let ((year (1+ (extract-calendar-year (calendar-cursor-to-date)))))
    (list-holidays year year)))

(defun cal-menu-list-holidays-previous-year ()
  "Display a list of the holidays of the previous year."
  (interactive)
  (let ((year (1- (extract-calendar-year (calendar-cursor-to-date)))))
    (list-holidays year year)))

207 208 209 210 211 212 213 214 215 216 217 218 219 220
(defun cal-menu-update ()
  ;; Update the holiday part of calendar menu bar for the current display.
  (condition-case nil
      (if (eq major-mode 'calendar-mode)
          (let ((l))
            (calendar-for-loop;; Show 11 years--5 before, 5 after year of
                   ;; middle month
             i from (- displayed-year 5) to (+ displayed-year 5) do
             (setq l (cons (vector (format "For Year %s" i)
                                   (list (list 'lambda 'nil '(interactive)
                                               (list 'list-holidays i i)))
                                   t)
                           l)))
            (setq l (cons ["Mark Holidays" mark-calendar-holidays t]
221
                          (cons ["Unmark Calendar" calendar-unmark t]
Edward M. Reingold's avatar
Edward M. Reingold committed
222
                                (cons ["--" '("--") t] l))))
223 224
            (define-key calendar-mode-map [menu-bar Holidays]
	      (cons "Holidays" (easy-menu-create-menu "Holidays" (nreverse l))))
Edward M. Reingold's avatar
Edward M. Reingold committed
225
            (define-key calendar-mode-map [menu-bar Holidays separator]
226
              '("--"))
227
            (define-key calendar-mode-map [menu-bar Holidays today]
228 229 230
                `(,(format "For Today (%s)"
                           (calendar-date-string (calendar-current-date) t t))
                  . cal-menu-today-holidays))
231 232 233 234 235 236 237 238 239
            (let ((title
                   (let ((m1 displayed-month)
                         (y1 displayed-year)
                         (m2 displayed-month)
                         (y2 displayed-year))
                     (increment-calendar-month m1 y1 -1)
                     (increment-calendar-month m2 y2 1)
                     (if (= y1 y2)
                         (format "%s-%s, %d"
240 241
                                 (calendar-month-name m1 'abbrev)
                                 (calendar-month-name m2 'abbrev)
242 243
                                 y2)
                       (format "%s, %d-%s, %d"
244
                               (calendar-month-name m1 'abbrev)
245
                               y1
246
                               (calendar-month-name m2 'abbrev)
247
                               y2)))))
248 249
              (define-key  calendar-mode-map [menu-bar Holidays 3-month]
                `(,(format "For Window (%s)" title)
250 251 252
                  . list-calendar-holidays)))
            (let ((date (calendar-cursor-to-date)))
              (if date
253
                  (define-key calendar-mode-map [menu-bar Holidays 1-day]
254
                    `(,(format "For Cursor Date (%s)"
255 256 257 258 259
                               (calendar-date-string date t t))
                      . calendar-cursor-holidays))))))
    ;; Try to avoid entering infinite beep mode in case of errors.
    (error (ding))))

260 261 262 263
(defun calendar-event-to-date (&optional error)
  "Date of last event.
If event is not on a specific date, signals an error if optional parameter
ERROR is t, otherwise just returns nil."
Richard M. Stallman's avatar
Richard M. Stallman committed
264
  (save-excursion
265
    (set-buffer (window-buffer (posn-window (event-start last-input-event))))
Richard M. Stallman's avatar
Richard M. Stallman committed
266
    (goto-char (posn-point (event-start last-input-event)))
267
    (calendar-cursor-to-date error)))
Richard M. Stallman's avatar
Richard M. Stallman committed
268 269 270 271 272

(defun calendar-mouse-insert-hebrew-diary-entry (event)
  "Pop up menu to insert a Hebrew-date diary entry."
  (interactive "e")
  (let ((hebrew-selection
273
         (cal-menu-x-popup-menu
Richard M. Stallman's avatar
Richard M. Stallman committed
274 275 276 277 278 279 280 281 282 283 284 285
          event
          (list "Hebrew insert menu"
                (list (calendar-hebrew-date-string (calendar-cursor-to-date))
                      '("One time" . insert-hebrew-diary-entry)
                      '("Monthly" . insert-monthly-hebrew-diary-entry)
                      '("Yearly" . insert-yearly-hebrew-diary-entry))))))
    (and hebrew-selection (call-interactively hebrew-selection))))

(defun calendar-mouse-insert-islamic-diary-entry (event)
  "Pop up menu to insert an Islamic-date diary entry."
  (interactive "e")
  (let ((islamic-selection
286
         (cal-menu-x-popup-menu
Richard M. Stallman's avatar
Richard M. Stallman committed
287 288 289 290 291 292 293 294
          event
          (list "Islamic insert menu"
                (list (calendar-islamic-date-string (calendar-cursor-to-date))
                      '("One time" . insert-islamic-diary-entry)
                      '("Monthly" . insert-monthly-islamic-diary-entry)
                      '("Yearly" . insert-yearly-islamic-diary-entry))))))
    (and islamic-selection (call-interactively islamic-selection))))

295 296 297 298 299 300 301 302 303 304 305 306 307
(defun calendar-mouse-insert-bahai-diary-entry (event)
  "Pop up menu to insert an Baha'i-date diary entry."
  (interactive "e")
  (let ((bahai-selection
         (x-popup-menu
          event
          (list "Baha'i insert menu"
                (list (calendar-bahai-date-string (calendar-cursor-to-date))
                      '("One time" . insert-bahai-diary-entry)
                      '("Monthly" . insert-monthly-bahai-diary-entry)
                      '("Yearly" . insert-yearly-bahai-diary-entry))))))
    (and bahai-selection (call-interactively bahai-selection))))

Richard M. Stallman's avatar
Richard M. Stallman committed
308 309 310 311
(defun calendar-mouse-sunrise/sunset ()
  "Show sunrise/sunset times for mouse-selected date."
  (interactive)
  (save-excursion
312
    (calendar-mouse-goto-date (calendar-event-to-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
313 314
    (calendar-sunrise-sunset)))

315 316 317 318 319 320 321
(defun cal-menu-today-holidays ()
  "Show holidays for today's date."
  (interactive)
  (save-excursion
    (calendar-cursor-to-date (calendar-current-date))
    (calendar-cursor-holidays)))

Richard M. Stallman's avatar
Richard M. Stallman committed
322
(defun calendar-mouse-holidays ()
323
  "Pop up menu of holidays for mouse selected date."
Richard M. Stallman's avatar
Richard M. Stallman committed
324
  (interactive)
325 326 327 328
  (let* ((date (calendar-event-to-date))
         (l (mapcar '(lambda (x) (list x))
                    (check-calendar-holidays date)))
         (selection
329
          (cal-menu-x-popup-menu
330 331 332 333 334 335 336
           event
           (list
            (format "Holidays for %s" (calendar-date-string date))
            (append
             (list (format "Holidays for %s" (calendar-date-string date)))
             (if l l '("None")))))))
    (and selection (call-interactively selection))))
Richard M. Stallman's avatar
Richard M. Stallman committed
337

338 339 340 341 342
(defun calendar-mouse-view-diary-entries (&optional date diary)
  "Pop up menu of diary entries for mouse-selected date.
Use optional DATE and alternative file DIARY.

Any holidays are shown if `holidays-in-diary-buffer' is t."
Richard M. Stallman's avatar
Richard M. Stallman committed
343
  (interactive)
344 345 346 347 348 349 350 351 352 353 354 355 356 357
  (let* ((date (if date date (calendar-event-to-date)))
         (diary-file (if diary diary diary-file))
         (diary-list-include-blanks nil)
         (diary-display-hook 'ignore)
         (diary-entries
          (mapcar '(lambda (x) (split-string (car (cdr x)) "\^M\\|\n"))
                  (list-diary-entries date 1)))
         (holidays (if holidays-in-diary-buffer
                       (mapcar '(lambda (x) (list x))
                               (check-calendar-holidays date))))
         (title (concat "Diary entries "
                        (if diary (format "from %s " diary) "")
                        "for "
                        (calendar-date-string date)))
358
         (selection
359
          (cal-menu-x-popup-menu
360
           event
361 362 363 364 365 366 367 368 369 370 371
           (list title
                 (append
                  (list title)
                  (if holidays
                      (mapcar '(lambda (x) (list (concat "     " (car x))))
                              holidays))
                  (if holidays
                      (list "--shadow-etched-in" "--shadow-etched-in"))
                  (if diary-entries
                      (mapcar 'list (calendar-flatten diary-entries))
                    '("None")))))))
372
    (and selection (call-interactively selection))))
Richard M. Stallman's avatar
Richard M. Stallman committed
373

374
(defun calendar-mouse-view-other-diary-entries ()
375
  "Pop up menu of diary entries from alternative file on mouse-selected date."
376
  (interactive)
377 378 379
  (calendar-mouse-view-diary-entries
   (calendar-event-to-date)
   (read-file-name "Enter diary file name: " default-directory nil t)))
380

381 382 383 384
(defun calendar-mouse-insert-diary-entry ()
  "Insert diary entry for mouse-selected date."
  (interactive)
  (save-excursion
385
    (calendar-mouse-goto-date (calendar-event-to-date))
386 387
    (insert-diary-entry nil)))

388 389 390 391
(defun calendar-mouse-set-mark ()
  "Mark the date under the cursor."
  (interactive)
  (save-excursion
392
    (calendar-mouse-goto-date (calendar-event-to-date))
393 394
    (calendar-set-mark nil)))

395 396 397 398
(defun cal-tex-mouse-day ()
  "Make a buffer with LaTeX commands for the day mouse is on."
  (interactive)
  (save-excursion
399
    (calendar-mouse-goto-date (calendar-event-to-date))
400 401 402 403 404 405 406
    (cal-tex-cursor-day nil)))

(defun cal-tex-mouse-week ()
  "One page calendar for week indicated by cursor.
Holidays are included if `cal-tex-holidays' is t."
  (interactive)
  (save-excursion
407
    (calendar-mouse-goto-date (calendar-event-to-date))
408 409 410 411 412 413 414
    (cal-tex-cursor-week nil)))

(defun cal-tex-mouse-week2 ()
  "Make a buffer with LaTeX commands for the week cursor is on.
The printed output will be on two pages."
  (interactive)
  (save-excursion
415
    (calendar-mouse-goto-date (calendar-event-to-date))
416 417
    (cal-tex-cursor-week2 nil)))

418
(defun cal-tex-mouse-week-iso ()
419 420 421 422
  "One page calendar for week indicated by cursor.
Holidays are included if `cal-tex-holidays' is t."
  (interactive)
  (save-excursion
423
    (calendar-mouse-goto-date (calendar-event-to-date))
424
    (cal-tex-cursor-week-iso nil)))
425

426
(defun cal-tex-mouse-week-monday ()
427 428 429
  "One page calendar for week indicated by cursor."
  (interactive)
  (save-excursion
430
    (calendar-mouse-goto-date (calendar-event-to-date))
431
    (cal-tex-cursor-week-monday nil)))
432

433 434 435 436 437 438 439
(defun cal-tex-mouse-filofax-daily ()
  "Day-per-page Filofax calendar for week indicated by cursor."
  (interactive)
  (save-excursion
    (calendar-mouse-goto-date (calendar-event-to-date))
    (cal-tex-cursor-filofax-daily nil)))

440
(defun cal-tex-mouse-filofax-2week ()
441 442 443
  "One page Filofax calendar for week indicated by cursor."
  (interactive)
  (save-excursion
444
    (calendar-mouse-goto-date (calendar-event-to-date))
445
    (cal-tex-cursor-filofax-2week nil)))
446

447
(defun cal-tex-mouse-filofax-week ()
448 449 450
  "Two page Filofax calendar for week indicated by cursor."
  (interactive)
  (save-excursion
451
    (calendar-mouse-goto-date (calendar-event-to-date))
452
    (cal-tex-cursor-filofax-week nil)))
453 454 455 456 457 458

(defun cal-tex-mouse-month ()
  "Make a buffer with LaTeX commands for the month cursor is on.
Calendar is condensed onto one page."
  (interactive)
  (save-excursion
459
    (calendar-mouse-goto-date (calendar-event-to-date))
460 461 462 463 464 465 466
    (cal-tex-cursor-month nil)))

(defun cal-tex-mouse-month-landscape ()
  "Make a buffer with LaTeX commands for the month cursor is on.
The output is in landscape format, one month to a page."
  (interactive)
  (save-excursion
467
    (calendar-mouse-goto-date (calendar-event-to-date))
468 469 470 471 472 473
    (cal-tex-cursor-month-landscape nil)))

(defun cal-tex-mouse-year ()
  "Make a buffer with LaTeX commands for the year cursor is on."
  (interactive)
  (save-excursion
474
    (calendar-mouse-goto-date (calendar-event-to-date))
475 476 477 478 479 480
    (cal-tex-cursor-year nil)))

(defun cal-tex-mouse-filofax-year ()
  "Make a buffer with LaTeX commands for Filofax calendar of year cursor is on."
  (interactive)
  (save-excursion
481
    (calendar-mouse-goto-date (calendar-event-to-date))
482 483 484 485 486 487
    (cal-tex-cursor-filofax-year nil)))

(defun cal-tex-mouse-year-landscape ()
  "Make a buffer with LaTeX commands for the year cursor is on."
  (interactive)
  (save-excursion
488
    (calendar-mouse-goto-date (calendar-event-to-date))
489 490
    (cal-tex-cursor-year-landscape nil)))

Richard M. Stallman's avatar
Richard M. Stallman committed
491 492 493
(defun calendar-mouse-print-dates ()
  "Pop up menu of equivalent dates to mouse selected date."
  (interactive)
494 495
  (let ((date (calendar-event-to-date))
        (selection
496
         (cal-menu-x-popup-menu
497 498
          event
          (list
499
           (concat (calendar-date-string date) " (Gregorian)")
500 501 502 503 504 505 506 507
           (append
            (list
             (concat (calendar-date-string date) " (Gregorian)")
             (list (calendar-day-of-year-string date))
             (list (format "ISO date: %s" (calendar-iso-date-string date)))
             (list (format "Julian date: %s"
                           (calendar-julian-date-string date)))
             (list
Edward M. Reingold's avatar
Edward M. Reingold committed
508
              (format "Astronomical (Julian) day number (at noon UTC): %s.0"
509
                           (calendar-astro-date-string date)))
510
             (list
511
              (format "Fixed (RD) date: %s"
512
                      (calendar-absolute-from-gregorian date)))
513
             (list (format "Hebrew date (before sunset): %s"
514 515
                           (calendar-hebrew-date-string date)))
             (list (format "Persian date: %s"
516 517 518
                           (calendar-persian-date-string date)))
             (list (format "Baha'i date (before sunset): %s"
                           (calendar-bahai-date-string date))))
519 520 521
            (let ((i (calendar-islamic-date-string date)))
              (if (not (string-equal i ""))
                  (list (list (format "Islamic date (before sunset): %s" i)))))
522 523 524 525 526
            (list
             (list (format "Chinese date: %s"
                           (calendar-chinese-date-string date))))
;            (list '("Chinese date (select to echo Chinese date)"
;                    . calendar-mouse-chinese-date))
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
            (let ((c (calendar-coptic-date-string date)))
              (if (not (string-equal c ""))
                  (list (list (format "Coptic date: %s" c)))))
            (let ((e (calendar-ethiopic-date-string date)))
              (if (not (string-equal e ""))
                  (list (list (format "Ethiopic date: %s" e)))))
            (let ((f (calendar-french-date-string date)))
              (if (not (string-equal f ""))
                  (list (list (format "French Revolutionary date: %s" f)))))
            (list
             (list
              (format "Mayan date: %s"
                      (calendar-mayan-date-string date)))))))))
        (and selection (call-interactively selection))))

542 543 544 545
(defun calendar-mouse-chinese-date ()
  "Show Chinese equivalent for mouse-selected date."
  (interactive)
  (save-excursion
546
    (calendar-mouse-goto-date (calendar-event-to-date))
547
    (calendar-print-chinese-date)))
Richard M. Stallman's avatar
Richard M. Stallman committed
548

549 550 551 552
(defun calendar-mouse-goto-date (date)
  (set-buffer (window-buffer (posn-window (event-start last-input-event))))
  (calendar-goto-date date))

553 554
(defun calendar-mouse-2-date-menu (event)
  "Pop up menu for Mouse-2 for selected date in the calendar window."
Richard M. Stallman's avatar
Richard M. Stallman committed
555
  (interactive "e")
556 557
  (let* ((date (calendar-event-to-date t))
         (selection
558
          (cal-menu-x-popup-menu
559
           event
560
           (list (calendar-date-string date t nil)
561
                 (list
562
                  ""
563 564 565
                  '("Holidays" . calendar-mouse-holidays)
                  '("Mark date" . calendar-mouse-set-mark)
                  '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
566
                  '("Other calendars" . calendar-mouse-print-dates)
567
                  '("Prepare LaTeX buffer" . calendar-mouse-cal-tex-menu)
568 569 570 571 572
                  '("Diary entries" . calendar-mouse-view-diary-entries)
                  '("Insert diary entry" . calendar-mouse-insert-diary-entry)
                  '("Other diary file entries"
                    . calendar-mouse-view-other-diary-entries)
                  )))))
573 574
    (and selection (call-interactively selection))))

575 576 577 578
(defun calendar-mouse-cal-tex-menu (event)
  "Pop up submenu for Mouse-2 for cal-tex commands for selected date in the calendar window."
  (interactive "e")
  (let* ((selection
579
          (cal-menu-x-popup-menu
580
           event
581
           (list (calendar-date-string date t nil)
582
                 (list
583
                  ""
584 585 586
                  '("Daily (1 page)" . cal-tex-mouse-day)
                  '("Weekly (1 page)" . cal-tex-mouse-week)
                  '("Weekly (2 pages)" . cal-tex-mouse-week2)
587 588 589
                  '("Weekly (other style; 1 page)" . cal-tex-mouse-week-iso)
                  '("Weekly (yet another style; 1 page)" .
                    cal-tex-mouse-week-monday)
590 591 592 593 594 595 596 597 598 599 600 601
                  '("Monthly" . cal-tex-mouse-month)
                  '("Monthly (landscape)" . cal-tex-mouse-month-landscape)
                  '("Yearly" . cal-tex-mouse-year)
                  '("Yearly (landscape)" . cal-tex-mouse-year-landscape)
                  '("Filofax styles" . cal-tex-mouse-filofax)
                  )))))
    (and selection (call-interactively selection))))

(defun cal-tex-mouse-filofax (event)
  "Pop up sub-submenu for Mouse-2 for Filofax cal-tex commands for selected date."
  (interactive "e")
  (let* ((selection
602
          (cal-menu-x-popup-menu
603
           event
604
           (list (calendar-date-string date t nil)
605
                 (list
606
                  ""
607 608
                  '("Filofax Daily (one-day-per-page)" .
                    cal-tex-mouse-filofax-daily)
609 610 611 612
                  '("Filofax Weekly (2-weeks-at-a-glance)" .
                    cal-tex-mouse-filofax-2week)
                  '("Filofax Weekly (week-at-a-glance)" .
                    cal-tex-mouse-filofax-week)
613 614 615 616
                  '("Filofax Yearly" . cal-tex-mouse-filofax-year)
                  )))))
    (and selection (call-interactively selection))))

617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
(define-key calendar-mouse-3-map [exit-calendar]
  '("Exit calendar" . exit-calendar))
(define-key calendar-mouse-3-map [show-diary]
  '("Show diary" . show-all-diary-entries))
(define-key calendar-mouse-3-map [lunar-phases]
  '("Lunar phases" . calendar-phases-of-moon))
(define-key calendar-mouse-3-map [unmark]
  '("Unmark" . calendar-unmark))
(define-key calendar-mouse-3-map [mark-holidays]
  '("Mark holidays" . mark-calendar-holidays))
(define-key calendar-mouse-3-map [list-holidays]
  '("List holidays" . list-calendar-holidays))
(define-key calendar-mouse-3-map [mark-diary-entries]
  '("Mark diary entries" . mark-diary-entries))
(define-key calendar-mouse-3-map [scroll-backward]
  '("Scroll backward" . scroll-calendar-right-three-months))
(define-key calendar-mouse-3-map [scroll-forward]
  '("Scroll forward" . scroll-calendar-left-three-months))
Richard M. Stallman's avatar
Richard M. Stallman committed
635 636 637 638 639

(run-hooks 'cal-menu-load-hook)

(provide 'cal-menu)

Miles Bader's avatar
Miles Bader committed
640
;;; arch-tag: aa81cf73-ce89-48a4-97ec-9ef861e87fe9
Richard M. Stallman's avatar
Richard M. Stallman committed
641
;;; cal-menu.el ends here