home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / lisp / cal-menu.el < prev    next >
Lisp/Scheme  |  1996-09-28  |  14KB  |  317 lines

  1. ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
  2.  
  3. ;; Copyright (C) 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
  6. ;;    Lara Rios <lrios@coewl.cen.uiuc.edu>
  7. ;; Keywords: calendar
  8. ;; Human-Keywords: calendar, popup menus, menu bar
  9.  
  10. ;; This file is part of GNU Emacs.
  11.  
  12. ;; GNU Emacs is free software; you can redistribute it and/or modify
  13. ;; it under the terms of the GNU General Public License as published by
  14. ;; the Free Software Foundation; either version 2, or (at your option)
  15. ;; any later version.
  16.  
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. ;; GNU General Public License for more details.
  21.  
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  24. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; This collection of functions implements menu bar and popup menu support for
  29. ;; calendar.el.
  30.  
  31. ;; Comments, corrections, and improvements should be sent to
  32. ;;  Edward M. Reingold               Department of Computer Science
  33. ;;  (217) 333-6733                   University of Illinois at Urbana-Champaign
  34. ;;  reingold@cs.uiuc.edu             1304 West Springfield Avenue
  35. ;;                                   Urbana, Illinois 61801
  36.  
  37. ;;; Code:
  38.  
  39. (define-key calendar-mode-map [down-mouse-2] 'calendar-mouse-2-date-menu)
  40. (define-key calendar-mode-map [mouse-2] 'ignore)
  41.  
  42. (defvar calendar-mouse-3-map (make-sparse-keymap "Calendar"))
  43. (define-key calendar-mode-map [down-mouse-3] calendar-mouse-3-map)
  44.  
  45. (define-key calendar-mode-map [menu-bar moon]
  46.   (cons "Moon" (make-sparse-keymap "Moon")))
  47.  
  48. (define-key calendar-mode-map [menu-bar moon moon]
  49.   '("Lunar phases" . calendar-phases-of-moon))
  50.  
  51. (define-key calendar-mode-map [menu-bar diary]
  52.   (cons "Diary" (make-sparse-keymap "Diary")))
  53.  
  54. (define-key calendar-mode-map [menu-bar diary heb]
  55.   '("Insert Hebrew" . calendar-mouse-insert-hebrew-diary-entry))
  56. (define-key calendar-mode-map [menu-bar diary isl]
  57.   '("Insert Islamic" . calendar-mouse-insert-islamic-diary-entry))
  58. (define-key calendar-mode-map [menu-bar diary cyc]
  59.   '("Insert cyclic" . insert-cyclic-diary-entry))
  60. (define-key calendar-mode-map [menu-bar diary blk]
  61.   '("Insert block" . insert-block-diary-entry))
  62. (define-key calendar-mode-map [menu-bar diary ann]
  63.   '("Insert anniversary" . insert-anniversary-diary-entry))
  64. (define-key calendar-mode-map [menu-bar diary yr]
  65.   '("Insert yearly" . insert-yearly-diary-entry))
  66. (define-key calendar-mode-map [menu-bar diary mon]
  67.   '("Insert monthly" . insert-monthly-diary-entry))
  68. (define-key calendar-mode-map [menu-bar diary wk]
  69.   '("Insert weekly" . insert-weekly-diary-entry))
  70. (define-key calendar-mode-map [menu-bar diary ent]
  71.   '("Insert daily". insert-diary-entry))
  72. (define-key calendar-mode-map [menu-bar diary all]
  73.   '("Show all" . show-all-diary-entries))
  74. (define-key calendar-mode-map [menu-bar diary mark]
  75.  '("Mark all" . mark-diary-entries))
  76. (define-key calendar-mode-map [menu-bar diary view]
  77.   '("Cursor date" . view-diary-entries))
  78.  
  79. (define-key calendar-mode-map [menu-bar holidays]
  80.   (cons "Holidays" (make-sparse-keymap "Holidays")))
  81.  
  82. (define-key calendar-mode-map [menu-bar holidays unmark]
  83.   '("Unmark" . calendar-unmark))
  84. (define-key calendar-mode-map [menu-bar holidays mark]
  85.   '("Mark" . mark-calendar-holidays))
  86. (define-key calendar-mode-map [menu-bar holidays 3-mon]
  87.   '("3 months" . list-calendar-holidays))
  88. (define-key calendar-mode-map [menu-bar holidays 1-day]
  89.   '("One day" . calendar-cursor-holidays))
  90.  
  91. (define-key calendar-mode-map [menu-bar goto]
  92.   (cons "Goto" (make-sparse-keymap "Goto")))
  93.  
  94. (define-key calendar-mode-map [menu-bar goto french]
  95.   '("French date" . calendar-goto-french-date))
  96. (define-key calendar-mode-map [menu-bar goto mayan]
  97.   (cons "Mayan date" (make-sparse-keymap "Mayan")))
  98. (define-key calendar-mode-map [menu-bar goto julian]
  99.   '("Julian date" . calendar-goto-julian-date))
  100. (define-key calendar-mode-map [menu-bar goto islamic]
  101.   '("Islamic date" . calendar-goto-islamic-date))
  102. (define-key calendar-mode-map [menu-bar goto hebrew]
  103.   '("Hebrew date" . calendar-goto-hebrew-date))
  104. (define-key calendar-mode-map [menu-bar goto astro]
  105.   '("Astronomical date" . calendar-goto-astro-day-number))
  106. (define-key calendar-mode-map [menu-bar goto iso]
  107.   '("ISO date" . calendar-goto-iso-date))
  108. (define-key calendar-mode-map [menu-bar goto gregorian]
  109.   '("Other date" . calendar-goto-date))
  110. (define-key calendar-mode-map [menu-bar goto end-of-year]
  111.   '("End of year" . calendar-end-of-year))
  112. (define-key calendar-mode-map [menu-bar goto beginning-of-year]
  113.   '("Beginning of year" . calendar-beginning-of-year))
  114. (define-key calendar-mode-map [menu-bar goto end-of-month]
  115.   '("End of month" . calendar-end-of-month))
  116. (define-key calendar-mode-map [menu-bar goto beginning-of-month]
  117.   '("Beginning of month" . calendar-beginning-of-month))
  118. (define-key calendar-mode-map [menu-bar goto end-of-week]
  119.   '("End of week" . calendar-end-of-week))
  120. (define-key calendar-mode-map [menu-bar goto beginning-of-week]
  121.   '("Beginning of week" . calendar-beginning-of-week))
  122. (define-key calendar-mode-map [menu-bar goto today]
  123.   '("Today" . calendar-goto-today))
  124.  
  125.  
  126. (define-key calendar-mode-map [menu-bar goto mayan prev-rnd]
  127.   '("Previous Round" . calendar-previous-calendar-round-date))
  128. (define-key calendar-mode-map [menu-bar goto mayan nxt-rnd]
  129.   '("Next Round" . calendar-next-calendar-round-date))
  130. (define-key calendar-mode-map [menu-bar goto mayan prev-haab]
  131.   '("Previous Haab" . calendar-previous-haab-date))
  132. (define-key calendar-mode-map [menu-bar goto mayan next-haab]
  133.   '("Next Haab" . calendar-next-haab-date))
  134. (define-key calendar-mode-map [menu-bar goto mayan prev-tzol]
  135.   '("Previous Tzolkin" . calendar-previous-tzolkin-date))
  136. (define-key calendar-mode-map [menu-bar goto mayan next-tzol]
  137.   '("Next Tzolkin" . calendar-next-tzolkin-date))
  138.  
  139. (define-key calendar-mode-map [menu-bar scroll]
  140.   (cons "Scroll" (make-sparse-keymap "Scroll")))
  141.  
  142. (define-key calendar-mode-map [menu-bar scroll bk-12]
  143.   '("Backward 1 Year" . "4\ev"))
  144. (define-key calendar-mode-map [menu-bar scroll bk-3]
  145.   '("Backward 3 Months" . scroll-calendar-right-three-months))
  146. (define-key calendar-mode-map [menu-bar scroll bk-1]
  147.   '("Backward 1 Month" . scroll-calendar-right))
  148. (define-key calendar-mode-map [menu-bar scroll fwd-12]
  149.   '("Forward 1 Year" . "4\C-v"))
  150. (define-key calendar-mode-map [menu-bar scroll fwd-3]
  151.   '("Forward 3 Months" . scroll-calendar-left-three-months))
  152. (define-key calendar-mode-map [menu-bar scroll fwd-1]
  153.   '("Forward 1 Month" . scroll-calendar-left))
  154.  
  155. (put 'calendar-forward-day 'menu-enable '(calendar-cursor-to-date))
  156. (put 'calendar-backward-day 'menu-enable '(calendar-cursor-to-date))
  157. (put 'calendar-forward-week 'menu-enable '(calendar-cursor-to-date))
  158. (put 'calendar-backward-week 'menu-enable '(calendar-cursor-to-date))
  159. (put 'calendar-forward-month 'menu-enable '(calendar-cursor-to-date))
  160. (put 'calendar-backward-month 'menu-enable '(calendar-cursor-to-date))
  161. (put 'calendar-forward-year 'menu-enable '(calendar-cursor-to-date))
  162. (put 'calendar-backward-year 'menu-enable '(calendar-cursor-to-date))
  163. (put 'calendar-beginning-of-year 'menu-enable '(calendar-cursor-to-date))
  164. (put 'calendar-end-of-year 'menu-enable '(calendar-cursor-to-date))
  165. (put 'calendar-beginning-of-month 'menu-enable '(calendar-cursor-to-date))
  166. (put 'calendar-end-of-month 'menu-enable '(calendar-cursor-to-date))
  167. (put 'calendar-end-of-week 'menu-enable '(calendar-cursor-to-date))
  168. (put 'calendar-beginning-of-week 'menu-enable '(calendar-cursor-to-date))
  169. (put 'calendar-mouse-print-dates 'menu-enable '(calendar-event-to-date))
  170. (put 'calendar-sunrise-sunset 'menu-enable '(calendar-event-to-date))
  171. (put 'calendar-cursor-holidays 'menu-enable '(calendar-cursor-to-date))
  172. (put 'view-diary-entries 'menu-enable '(calendar-cursor-to-date))
  173. (put 'calendar-mouse-insert-hebrew-diary-entry
  174.      'menu-enable
  175.      '(calendar-cursor-to-date))
  176. (put 'calendar-mouse-insert-islamic-diary-entry
  177.      'menu-enable
  178.      '(calendar-cursor-to-date))
  179. (put 'insert-cyclic-diary-entry 'menu-enable '(calendar-cursor-to-date))
  180. (put 'insert-block-diary-entry 'menu-enable '(calendar-cursor-to-date))
  181. (put 'insert-anniversary-diary-entry 'menu-enable '(calendar-cursor-to-date))
  182. (put 'insert-yearly-diary-entry 'menu-enable '(calendar-cursor-to-date))
  183. (put 'insert-monthly-diary-entry 'menu-enable '(calendar-cursor-to-date))
  184. (put 'insert-weekly-diary-entry 'menu-enable '(calendar-cursor-to-date))
  185.  
  186. (defun calendar-event-to-date (&optional error)
  187.   "Date of last event.
  188. If event is not on a specific date, signals an error if optional parameter
  189. ERROR is t, otherwise just returns nil."
  190.   (save-excursion
  191.     (goto-char (posn-point (event-start last-input-event)))
  192.     (calendar-cursor-to-date error)))
  193.  
  194. (defun calendar-mouse-insert-hebrew-diary-entry (event)
  195.   "Pop up menu to insert a Hebrew-date diary entry."
  196.   (interactive "e")
  197.   (let ((hebrew-selection
  198.          (x-popup-menu
  199.           event
  200.           (list "Hebrew insert menu"
  201.                 (list (calendar-hebrew-date-string (calendar-cursor-to-date))
  202.                       '("One time" . insert-hebrew-diary-entry)
  203.                       '("Monthly" . insert-monthly-hebrew-diary-entry)
  204.                       '("Yearly" . insert-yearly-hebrew-diary-entry))))))
  205.     (and hebrew-selection (call-interactively hebrew-selection))))
  206.  
  207. (defun calendar-mouse-insert-islamic-diary-entry (event)
  208.   "Pop up menu to insert an Islamic-date diary entry."
  209.   (interactive "e")
  210.   (let ((islamic-selection
  211.          (x-popup-menu
  212.           event
  213.           (list "Islamic insert menu"
  214.                 (list (calendar-islamic-date-string (calendar-cursor-to-date))
  215.                       '("One time" . insert-islamic-diary-entry)
  216.                       '("Monthly" . insert-monthly-islamic-diary-entry)
  217.                       '("Yearly" . insert-yearly-islamic-diary-entry))))))
  218.     (and islamic-selection (call-interactively islamic-selection))))
  219.  
  220. (defun calendar-mouse-sunrise/sunset ()
  221.   "Show sunrise/sunset times for mouse-selected date."
  222.   (interactive)
  223.   (save-excursion
  224.     (calendar-goto-date (calendar-event-to-date))
  225.     (calendar-sunrise-sunset)))
  226.  
  227. (defun calendar-mouse-holidays ()
  228.   "Show holidays for mouse-selected date."
  229.   (interactive)
  230.   (save-excursion
  231.     (calendar-goto-date (calendar-event-to-date))
  232.     (calendar-cursor-holidays)))
  233.  
  234. (defun calendar-mouse-view-diary-entries ()
  235.   "View diary entries on mouse-selected date."
  236.   (interactive)
  237.   (save-excursion
  238.     (calendar-goto-date (calendar-event-to-date))
  239.     (view-diary-entries 1)))
  240.  
  241. (defun calendar-mouse-set-mark ()
  242.   "Mark the date under the cursor."
  243.   (interactive)
  244.   (save-excursion
  245.     (calendar-goto-date (calendar-event-to-date))
  246.     (calendar-set-mark nil)))
  247.  
  248. (defun calendar-mouse-print-dates ()
  249.   "Pop up menu of equivalent dates to mouse selected date."
  250.   (interactive)
  251.   (let ((date (calendar-event-to-date)))
  252.     (x-popup-menu
  253.      event
  254.      (list
  255.       "Date Menu"
  256.       (append
  257.        (list
  258.         (concat (calendar-date-string date) " (Gregorian)")
  259.         (list (calendar-day-of-year-string date))
  260.         (list (format "ISO date: %s" (calendar-iso-date-string date)))
  261.         (list (format "Julian date: %s" (calendar-julian-date-string date)))
  262.         (list (format "Astronomical (Julian) date (before noon): %s"
  263.                       (calendar-astro-date-string date)))
  264.         (list (format "Hebrew date (before sunset): %s"
  265.                       (calendar-hebrew-date-string date))))
  266.        (let ((i (calendar-islamic-date-string date)))
  267.          (if (not (string-equal i ""))
  268.              (list (list (format "Islamic date (before sunset): %s" i)))))
  269.        (let ((f (calendar-french-date-string date)))
  270.          (if (not (string-equal f ""))
  271.              (list (list (format "French Revolutionary date: %s" f)))))
  272.        (list
  273.     (list
  274.          (format "Mayan date: %s" (calendar-mayan-date-string date)))))))))
  275.  
  276. (defun calendar-mouse-2-date-menu (event)
  277.   "Pop up menu for Mouse-2 for selected date in the calendar window."
  278.   (interactive "e")
  279.   (let* ((date (calendar-event-to-date t))
  280.          (selection
  281.           (x-popup-menu
  282.            event
  283.            (list "Menu"
  284.                  (list
  285.                   (calendar-date-string date t t)
  286.                   '("Diary entries" . calendar-mouse-view-diary-entries)
  287.                   '("Holidays" . calendar-mouse-holidays)
  288.                   '("Mark date" . calendar-mouse-set-mark)
  289.                   '("Sunrise/sunset" . calendar-mouse-sunrise/sunset)
  290.                   '("Other calendars" . calendar-mouse-print-dates))))))
  291.     (and selection (call-interactively selection))))
  292.  
  293. (define-key calendar-mouse-3-map [exit-calendar]
  294.   '("Exit calendar" . exit-calendar))
  295. (define-key calendar-mouse-3-map [show-diary]
  296.   '("Show diary" . show-all-diary-entries))
  297. (define-key calendar-mouse-3-map [lunar-phases]
  298.   '("Lunar phases" . calendar-phases-of-moon))
  299. (define-key calendar-mouse-3-map [unmark]
  300.   '("Unmark" . calendar-unmark))
  301. (define-key calendar-mouse-3-map [mark-holidays]
  302.   '("Mark holidays" . mark-calendar-holidays))
  303. (define-key calendar-mouse-3-map [list-holidays]
  304.   '("List holidays" . list-calendar-holidays))
  305. (define-key calendar-mouse-3-map [mark-diary-entries]
  306.   '("Mark diary entries" . mark-diary-entries))
  307. (define-key calendar-mouse-3-map [scroll-backward]
  308.   '("Scroll backward" . scroll-calendar-right-three-months))
  309. (define-key calendar-mouse-3-map [scroll-forward]
  310.   '("Scroll forward" . scroll-calendar-left-three-months))
  311.  
  312. (run-hooks 'cal-menu-load-hook)
  313.  
  314. (provide 'cal-menu)
  315.  
  316. ;;; cal-menu.el ends here
  317.