cal-menu.el 24.8 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 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
(eval-when-compile (require 'calendar))
41
(require 'easymenu)
Richard M. Stallman's avatar
Richard M. Stallman committed
42

Edward M. Reingold's avatar
Edward M. Reingold committed
43
(define-key calendar-mode-map [menu-bar edit] 'undefined)
44
(define-key calendar-mode-map [menu-bar search] 'undefined)
Edward M. Reingold's avatar
Edward M. Reingold committed
45

46
(define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
47
(define-key calendar-mode-map [mouse-2] 'ignore)
48 49 50

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

53 54 55 56
(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
57
  '("Lunar Phases" . calendar-phases-of-moon))
58

Richard M. Stallman's avatar
Richard M. Stallman committed
59 60 61 62 63 64 65 66
(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))
(define-key calendar-mode-map [menu-bar diary cyc]
Karl Heuer's avatar
Karl Heuer committed
67
  '("Insert Cyclic" . insert-cyclic-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
68
(define-key calendar-mode-map [menu-bar diary blk]
Karl Heuer's avatar
Karl Heuer committed
69
  '("Insert Block" . insert-block-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
70
(define-key calendar-mode-map [menu-bar diary ann]
Karl Heuer's avatar
Karl Heuer committed
71
  '("Insert Anniversary" . insert-anniversary-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
72
(define-key calendar-mode-map [menu-bar diary yr]
Karl Heuer's avatar
Karl Heuer committed
73
  '("Insert Yearly" . insert-yearly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
74
(define-key calendar-mode-map [menu-bar diary mon]
Karl Heuer's avatar
Karl Heuer committed
75
  '("Insert Monthly" . insert-monthly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
76
(define-key calendar-mode-map [menu-bar diary wk]
Karl Heuer's avatar
Karl Heuer committed
77
  '("Insert Weekly" . insert-weekly-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
78
(define-key calendar-mode-map [menu-bar diary ent]
79
  '("Insert Diary Entry" . insert-diary-entry))
Richard M. Stallman's avatar
Richard M. Stallman committed
80
(define-key calendar-mode-map [menu-bar diary all]
Karl Heuer's avatar
Karl Heuer committed
81
  '("Show All" . show-all-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
82
(define-key calendar-mode-map [menu-bar diary mark]
Karl Heuer's avatar
Karl Heuer committed
83
 '("Mark All" . mark-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
84
(define-key calendar-mode-map [menu-bar diary view]
Karl Heuer's avatar
Karl Heuer committed
85
  '("Cursor Date" . view-diary-entries))
86
(define-key calendar-mode-map [menu-bar diary view]
Karl Heuer's avatar
Karl Heuer committed
87
  '("Other File" . view-other-diary-entries))
Richard M. Stallman's avatar
Richard M. Stallman committed
88

89
(define-key calendar-mode-map [menu-bar Holidays]
Richard M. Stallman's avatar
Richard M. Stallman committed
90 91 92 93 94 95
  (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
96
  '("French Date" . calendar-goto-french-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
97
(define-key calendar-mode-map [menu-bar goto mayan]
Karl Heuer's avatar
Karl Heuer committed
98
  (cons "Mayan Date" (make-sparse-keymap "Mayan")))
99 100 101 102 103 104
(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
105
(define-key calendar-mode-map [menu-bar goto julian]
Karl Heuer's avatar
Karl Heuer committed
106
  '("Julian Date" . calendar-goto-julian-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
107
(define-key calendar-mode-map [menu-bar goto islamic]
Karl Heuer's avatar
Karl Heuer committed
108
  '("Islamic Date" . calendar-goto-islamic-date))
109 110
(define-key calendar-mode-map [menu-bar goto persian]
  '("Persian Date" . calendar-goto-persian-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
111
(define-key calendar-mode-map [menu-bar goto hebrew]
Karl Heuer's avatar
Karl Heuer committed
112
  '("Hebrew Date" . calendar-goto-hebrew-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
113
(define-key calendar-mode-map [menu-bar goto astro]
Karl Heuer's avatar
Karl Heuer committed
114
  '("Astronomical Date" . calendar-goto-astro-day-number))
Richard M. Stallman's avatar
Richard M. Stallman committed
115
(define-key calendar-mode-map [menu-bar goto iso]
Karl Heuer's avatar
Karl Heuer committed
116
  '("ISO Date" . calendar-goto-iso-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
117
(define-key calendar-mode-map [menu-bar goto gregorian]
Karl Heuer's avatar
Karl Heuer committed
118
  '("Other Date" . calendar-goto-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
119
(define-key calendar-mode-map [menu-bar goto end-of-year]
Karl Heuer's avatar
Karl Heuer committed
120
  '("End of Year" . calendar-end-of-year))
Richard M. Stallman's avatar
Richard M. Stallman committed
121
(define-key calendar-mode-map [menu-bar goto beginning-of-year]
Karl Heuer's avatar
Karl Heuer committed
122
  '("Beginning of Year" . calendar-beginning-of-year))
Richard M. Stallman's avatar
Richard M. Stallman committed
123
(define-key calendar-mode-map [menu-bar goto end-of-month]
Karl Heuer's avatar
Karl Heuer committed
124
  '("End of Month" . calendar-end-of-month))
Richard M. Stallman's avatar
Richard M. Stallman committed
125
(define-key calendar-mode-map [menu-bar goto beginning-of-month]
Karl Heuer's avatar
Karl Heuer committed
126
  '("Beginning of Month" . calendar-beginning-of-month))
Richard M. Stallman's avatar
Richard M. Stallman committed
127
(define-key calendar-mode-map [menu-bar goto end-of-week]
Karl Heuer's avatar
Karl Heuer committed
128
  '("End of Week" . calendar-end-of-week))
Richard M. Stallman's avatar
Richard M. Stallman committed
129
(define-key calendar-mode-map [menu-bar goto beginning-of-week]
Karl Heuer's avatar
Karl Heuer committed
130
  '("Beginning of Week" . calendar-beginning-of-week))
Richard M. Stallman's avatar
Richard M. Stallman committed
131
(define-key calendar-mode-map [menu-bar goto today]
132
  '("Today" . calendar-goto-today))
Richard M. Stallman's avatar
Richard M. Stallman committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163


(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))

164 165 166 167 168 169 170
(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)
    (error "Popup menus are not available on this system.")))

171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
(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)))

189 190 191 192 193 194 195 196 197 198 199 200 201 202
(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]
203
                          (cons ["Unmark Calendar" calendar-unmark t]
Edward M. Reingold's avatar
Edward M. Reingold committed
204
                                (cons ["--" '("--") t] l))))
205
            (easy-menu-change nil "Holidays" (nreverse l))
Edward M. Reingold's avatar
Edward M. Reingold committed
206
            (define-key calendar-mode-map [menu-bar Holidays separator]
207
              '("--"))
208
            (define-key calendar-mode-map [menu-bar Holidays today]
209 210 211
                `(,(format "For Today (%s)"
                           (calendar-date-string (calendar-current-date) t t))
                  . cal-menu-today-holidays))
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
            (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"
                                 (calendar-month-name m1 3)
                                 (calendar-month-name m2 3)
                                 y2)
                       (format "%s, %d-%s, %d"
                               (calendar-month-name m1 3)
                               y1
                               (calendar-month-name m2 3)
                               y2)))))
229 230
              (define-key  calendar-mode-map [menu-bar Holidays 3-month]
                `(,(format "For Window (%s)" title)
231 232 233
                  . list-calendar-holidays)))
            (let ((date (calendar-cursor-to-date)))
              (if date
234
                  (define-key calendar-mode-map [menu-bar Holidays 1-day]
235
                    `(,(format "For Cursor Date (%s)"
236 237 238 239 240
                               (calendar-date-string date t t))
                      . calendar-cursor-holidays))))))
    ;; Try to avoid entering infinite beep mode in case of errors.
    (error (ding))))

241 242 243 244
(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
245
  (save-excursion
246
    (set-buffer (window-buffer (posn-window (event-start last-input-event))))
Richard M. Stallman's avatar
Richard M. Stallman committed
247
    (goto-char (posn-point (event-start last-input-event)))
248
    (calendar-cursor-to-date error)))
Richard M. Stallman's avatar
Richard M. Stallman committed
249 250 251 252 253

(defun calendar-mouse-insert-hebrew-diary-entry (event)
  "Pop up menu to insert a Hebrew-date diary entry."
  (interactive "e")
  (let ((hebrew-selection
254
         (cal-menu-x-popup-menu
Richard M. Stallman's avatar
Richard M. Stallman committed
255 256 257 258 259 260 261 262 263 264 265 266
          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
267
         (cal-menu-x-popup-menu
Richard M. Stallman's avatar
Richard M. Stallman committed
268 269 270 271 272 273 274 275 276 277 278 279
          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))))

(defun calendar-mouse-sunrise/sunset ()
  "Show sunrise/sunset times for mouse-selected date."
  (interactive)
  (save-excursion
280
    (calendar-mouse-goto-date (calendar-event-to-date))
Richard M. Stallman's avatar
Richard M. Stallman committed
281 282
    (calendar-sunrise-sunset)))

283 284 285 286 287 288 289
(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
290
(defun calendar-mouse-holidays ()
291
  "Pop up menu of holidays for mouse selected date."
Richard M. Stallman's avatar
Richard M. Stallman committed
292
  (interactive)
293 294 295 296
  (let* ((date (calendar-event-to-date))
         (l (mapcar '(lambda (x) (list x))
                    (check-calendar-holidays date)))
         (selection
297
          (cal-menu-x-popup-menu
298 299 300 301 302 303 304
           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
305 306

(defun calendar-mouse-view-diary-entries ()
307
  "Pop up menu of diary entries for mouse selected date."
Richard M. Stallman's avatar
Richard M. Stallman committed
308
  (interactive)
309 310 311
  (let* ((date (calendar-event-to-date))
         (l (mapcar '(lambda (x) (list (car (cdr x))))
                    (let ((diary-list-include-blanks nil)
312
                          (diary-display-hook 'ignore))
313 314
                      (list-diary-entries date 1))))
         (selection
315
          (cal-menu-x-popup-menu
316 317 318 319 320 321 322
           event
           (list
            (format "Diary entries for %s" (calendar-date-string date))
            (append
             (list (format "Diary entries for %s" (calendar-date-string date)))
             (if l l '("None")))))))
    (and selection (call-interactively selection))))
Richard M. Stallman's avatar
Richard M. Stallman committed
323

324
(defun calendar-mouse-view-other-diary-entries ()
325
  "Pop up menu of diary entries from alternative file on mouse-selected date."
326
  (interactive)
327
  (let* ((date (calendar-event-to-date))
328 329 330 331 332 333 334 335 336 337
         (diary-list-include-blanks nil)
         (diary-display-hook 'ignore)
         (diary-file (read-file-name
                      "Enter diary file name: "
                      default-directory nil t))
         ; The following doesn't really do the right thing.  The problem is
         ; that a newline in the diary entry does not give a newline in a
         ; pop-up menu; for that you need a separate list item.  When the (car
         ; (cdr x)) contains newlines, the item should be split into a list of
         ; items.  Too minor and messy to worry about.
338
         (l (mapcar '(lambda (x) (list (car (cdr x))))
339
                    (list-diary-entries date 1)))
340
         (selection
341
          (cal-menu-x-popup-menu
342 343 344 345 346 347 348 349 350 351 352
           event
           (list
            (format "Diary entries from %s for %s"
                    diary-file
                    (calendar-date-string date))
            (append
             (list (format "Diary entries from %s for %s"
                            diary-file
                           (calendar-date-string date)))
             (if l l '("None")))))))
    (and selection (call-interactively selection))))
353

354 355 356 357
(defun calendar-mouse-insert-diary-entry ()
  "Insert diary entry for mouse-selected date."
  (interactive)
  (save-excursion
358
    (calendar-mouse-goto-date (calendar-event-to-date))
359 360
    (insert-diary-entry nil)))

361 362 363 364
(defun calendar-mouse-set-mark ()
  "Mark the date under the cursor."
  (interactive)
  (save-excursion
365
    (calendar-mouse-goto-date (calendar-event-to-date))
366 367
    (calendar-set-mark nil)))

368 369 370 371
(defun cal-tex-mouse-day ()
  "Make a buffer with LaTeX commands for the day mouse is on."
  (interactive)
  (save-excursion
372
    (calendar-mouse-goto-date (calendar-event-to-date))
373 374 375 376 377 378 379
    (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
380
    (calendar-mouse-goto-date (calendar-event-to-date))
381 382 383 384 385 386 387
    (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
388
    (calendar-mouse-goto-date (calendar-event-to-date))
389 390
    (cal-tex-cursor-week2 nil)))

391
(defun cal-tex-mouse-week-iso ()
392 393 394 395
  "One page calendar for week indicated by cursor.
Holidays are included if `cal-tex-holidays' is t."
  (interactive)
  (save-excursion
396
    (calendar-mouse-goto-date (calendar-event-to-date))
397
    (cal-tex-cursor-week-iso nil)))
398

399
(defun cal-tex-mouse-week-monday ()
400 401 402
  "One page calendar for week indicated by cursor."
  (interactive)
  (save-excursion
403
    (calendar-mouse-goto-date (calendar-event-to-date))
404
    (cal-tex-cursor-week-monday nil)))
405

406 407 408 409 410 411 412
(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)))

413
(defun cal-tex-mouse-filofax-2week ()
414 415 416
  "One page Filofax calendar for week indicated by cursor."
  (interactive)
  (save-excursion
417
    (calendar-mouse-goto-date (calendar-event-to-date))
418
    (cal-tex-cursor-filofax-2week nil)))
419

420
(defun cal-tex-mouse-filofax-week ()
421 422 423
  "Two page Filofax calendar for week indicated by cursor."
  (interactive)
  (save-excursion
424
    (calendar-mouse-goto-date (calendar-event-to-date))
425
    (cal-tex-cursor-filofax-week nil)))
426 427 428 429 430 431

(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
432
    (calendar-mouse-goto-date (calendar-event-to-date))
433 434 435 436 437 438 439
    (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
440
    (calendar-mouse-goto-date (calendar-event-to-date))
441 442 443 444 445 446
    (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
447
    (calendar-mouse-goto-date (calendar-event-to-date))
448 449 450 451 452 453
    (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
454
    (calendar-mouse-goto-date (calendar-event-to-date))
455 456 457 458 459 460
    (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
461
    (calendar-mouse-goto-date (calendar-event-to-date))
462 463
    (cal-tex-cursor-year-landscape nil)))

Richard M. Stallman's avatar
Richard M. Stallman committed
464 465 466
(defun calendar-mouse-print-dates ()
  "Pop up menu of equivalent dates to mouse selected date."
  (interactive)
467 468
  (let ((date (calendar-event-to-date))
        (selection
469
         (cal-menu-x-popup-menu
470 471
          event
          (list
472
           (concat (calendar-date-string date) " (Gregorian)")
473 474 475 476 477 478 479 480
           (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
481
              (format "Astronomical (Julian) day number (at noon UTC): %s.0"
482
                           (calendar-astro-date-string date)))
483
             (list
484
              (format "Fixed (RD) date: %s"
485
                      (calendar-absolute-from-gregorian date)))
486
             (list (format "Hebrew date (before sunset): %s"
487 488
                           (calendar-hebrew-date-string date)))
             (list (format "Persian date: %s"
489
                           (calendar-persian-date-string date))))
490 491 492
            (let ((i (calendar-islamic-date-string date)))
              (if (not (string-equal i ""))
                  (list (list (format "Islamic date (before sunset): %s" i)))))
493 494 495 496 497
            (list
             (list (format "Chinese date: %s"
                           (calendar-chinese-date-string date))))
;            (list '("Chinese date (select to echo Chinese date)"
;                    . calendar-mouse-chinese-date))
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
            (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))))

513 514 515 516
(defun calendar-mouse-chinese-date ()
  "Show Chinese equivalent for mouse-selected date."
  (interactive)
  (save-excursion
517
    (calendar-mouse-goto-date (calendar-event-to-date))
518
    (calendar-print-chinese-date)))
Richard M. Stallman's avatar
Richard M. Stallman committed
519

520 521 522 523
(defun calendar-mouse-goto-date (date)
  (set-buffer (window-buffer (posn-window (event-start last-input-event))))
  (calendar-goto-date date))

524 525
(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
526
  (interactive "e")
527 528
  (let* ((date (calendar-event-to-date t))
         (selection
529
          (cal-menu-x-popup-menu
530
           event
531
           (list (calendar-date-string date t nil)
532
                 (list
533
                  ""
534 535 536
                  '("Holidays" . calendar-mouse-holidays)
                  '("Mark date" . calendar-mouse-set-mark)
                  '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
537
                  '("Other calendars" . calendar-mouse-print-dates)
538
                  '("Prepare LaTeX buffer" . calendar-mouse-cal-tex-menu)
539 540 541 542 543
                  '("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)
                  )))))
544 545
    (and selection (call-interactively selection))))

546 547 548 549
(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
550
          (cal-menu-x-popup-menu
551
           event
552
           (list (calendar-date-string date t nil)
553
                 (list
554
                  ""
555 556 557
                  '("Daily (1 page)" . cal-tex-mouse-day)
                  '("Weekly (1 page)" . cal-tex-mouse-week)
                  '("Weekly (2 pages)" . cal-tex-mouse-week2)
558 559 560
                  '("Weekly (other style; 1 page)" . cal-tex-mouse-week-iso)
                  '("Weekly (yet another style; 1 page)" .
                    cal-tex-mouse-week-monday)
561 562 563 564 565 566 567 568 569 570 571 572
                  '("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
573
          (cal-menu-x-popup-menu
574
           event
575
           (list (calendar-date-string date t nil)
576
                 (list
577
                  ""
578 579
                  '("Filofax Daily (one-day-per-page)" .
                    cal-tex-mouse-filofax-daily)
580 581 582 583
                  '("Filofax Weekly (2-weeks-at-a-glance)" .
                    cal-tex-mouse-filofax-2week)
                  '("Filofax Weekly (week-at-a-glance)" .
                    cal-tex-mouse-filofax-week)
584 585 586 587
                  '("Filofax Yearly" . cal-tex-mouse-filofax-year)
                  )))))
    (and selection (call-interactively selection))))

588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
(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
606 607 608 609 610 611

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

(provide 'cal-menu)

;;; cal-menu.el ends here