1 ;;; cal-menu.el --- calendar functions for menu bar and popup menu support
3 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 ;; 2008 Free Software Foundation, Inc.
6 ;; Author: Edward M. Reingold <reingold@cs.uiuc.edu>
7 ;; Lara Rios <lrios@coewl.cen.uiuc.edu>
8 ;; Maintainer: Glenn Morris <rgm@gnu.org>
10 ;; Human-Keywords: calendar, popup menus, menu bar
12 ;; This file is part of GNU Emacs.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
35 (defconst cal-menu-moon-menu
38 ["Lunar Phases" calendar-phases-of-moon
])
39 "Key map for \"Moon\" menu in the calendar.")
41 (defconst cal-menu-diary-menu
43 ["Other File" diary-view-other-diary-entries
]
44 ["Cursor Date" diary-view-entries
]
45 ["Mark All" diary-mark-entries
]
46 ["Show All" diary-show-all-entries
]
47 ["Insert Diary Entry" diary-insert-entry
]
48 ["Insert Weekly" diary-insert-weekly-entry
]
49 ["Insert Monthly" diary-insert-monthly-entry
]
50 ["Insert Yearly" diary-insert-yearly-entry
]
51 ["Insert Anniversary" diary-insert-anniversary-entry
]
52 ["Insert Block" diary-insert-block-entry
]
53 ["Insert Cyclic" diary-insert-cyclic-entry
]
55 ["One time" diary-bahai-insert-entry
]
56 ["Monthly" diary-bahai-insert-monthly-entry
]
57 ["Yearly" diary-bahai-insert-yearly-entry
])
59 ["One time" diary-islamic-insert-entry
]
60 ["Monthly" diary-islamic-insert-monthly-entry
]
61 ["Yearly" diary-islamic-insert-yearly-entry
])
63 ["One time" diary-hebrew-insert-entry
]
64 ["Monthly" diary-hebrew-insert-monthly-entry
]
65 ["Yearly" diary-hebrew-insert-yearly-entry
]))
66 "Key map for \"Diary\" menu in the calendar.")
68 (defun cal-menu-holiday-window-suffix ()
69 "Return a string suffix for the \"Window\" entry in `cal-menu-holidays-menu'."
70 (let ((my1 (calendar-increment-month-cons -
1))
71 (my2 (calendar-increment-month-cons 1)))
72 ;; Mon1-Mon2, Year or Mon1, Year1-Mon2, Year2.
74 (calendar-month-name (car my1
) 'abbrev
)
75 (if (= (cdr my1
) (cdr my2
))
77 (format ", %d" (cdr my1
)))
78 (calendar-month-name (car my2
) 'abbrev
)
81 (defvar displayed-year
) ; from calendar-generate
83 (defconst cal-menu-holidays-menu
85 ["For Cursor Date -" calendar-cursor-holidays
86 :suffix
(calendar-date-string (calendar-cursor-to-date) t t
)
87 :visible
(calendar-cursor-to-date)]
88 ["For Window -" calendar-list-holidays
89 :suffix
(cal-menu-holiday-window-suffix)]
90 ["For Today -" (calendar-cursor-holidays (calendar-current-date))
91 :suffix
(calendar-date-string (calendar-current-date) t t
)]
94 ;; Show 11 years--5 before, 5 after year of middle month.
95 ;; We used to use :suffix rather than :label and bumped into
97 ;; http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01813.html
98 ;; The bug has since been fixed.
100 (push (vector (format "hol-year-%d" i
)
103 (holiday-list (+ displayed-year
,(- i
5))))
104 :label
`(format "For Year %d"
105 (+ displayed-year
,(- i
5))))
109 ["Unmark Calendar" calendar-unmark
]
110 ["Mark Holidays" calendar-mark-holidays
])
111 "Key map for \"Holidays\" menu in the calendar.")
113 (defconst cal-menu-goto-menu
115 ["Today" calendar-goto-today
]
116 ["Beginning of Week" calendar-beginning-of-week
]
117 ["End of Week" calendar-end-of-week
]
118 ["Beginning of Month" calendar-beginning-of-month
]
119 ["End of Month" calendar-end-of-month
]
120 ["Beginning of Year" calendar-beginning-of-year
]
121 ["End of Year" calendar-end-of-year
]
122 ["Other Date" calendar-goto-date
]
123 ["Day of Year" calendar-goto-day-of-year
]
124 ["ISO Week" calendar-iso-goto-week
]
125 ["ISO Date" calendar-iso-goto-date
]
126 ["Astronomical Date" calendar-astro-goto-day-number
]
127 ["Hebrew Date" calendar-hebrew-goto-date
]
128 ["Persian Date" calendar-persian-goto-date
]
129 ["Baha'i Date" calendar-bahai-goto-date
]
130 ["Islamic Date" calendar-islamic-goto-date
]
131 ["Julian Date" calendar-julian-goto-date
]
132 ["Chinese Date" calendar-chinese-goto-date
]
133 ["Coptic Date" calendar-coptic-goto-date
]
134 ["Ethiopic Date" calendar-ethiopic-goto-date
]
136 ["Next Tzolkin" calendar-mayan-next-tzolkin-date
]
137 ["Previous Tzolkin" calendar-mayan-previous-tzolkin-date
]
138 ["Next Haab" calendar-mayan-next-haab-date
]
139 ["Previous Haab" calendar-mayan-previous-haab-date
]
140 ["Next Round" calendar-mayan-next-round-date
]
141 ["Previous Round" calendar-mayan-previous-round-date
])
142 ["French Date" calendar-french-goto-date
])
143 "Key map for \"Go To\" menu in the calendar.")
145 (defconst cal-menu-scroll-menu
147 ["Forward 1 Month" calendar-scroll-left
]
148 ["Forward 3 Months" calendar-scroll-left-three-months
]
149 ["Forward 1 Year" (calendar-scroll-left 12) :keys
"4 C-v"]
150 ["Backward 1 Month" calendar-scroll-right
]
151 ["Backward 3 Months" calendar-scroll-right-three-months
]
152 ["Backward 1 Year" (calendar-scroll-right 12) :keys
"4 M-v"])
153 "Key map for \"Scroll\" menu in the calendar.")
155 (defmacro cal-menu-x-popup-menu
(event title
&rest body
)
156 "Call `x-popup-menu' at position EVENT, with TITLE and contents BODY.
157 Signals an error if popups are unavailable."
159 `(if (display-popup-menus-p)
160 (x-popup-menu ,event
(list ,title
(append (list ,title
) ,@body
)))
161 (error "Popup menus are not available on this system")))
163 (autoload 'calendar-check-holidays
"holidays")
164 (autoload 'diary-list-entries
"diary-lib")
165 (defvar diary-show-holidays-flag
) ; only called from calendar.el
167 (defun calendar-mouse-view-diary-entries (&optional date diary event
)
168 "Pop up menu of diary entries for mouse-selected date.
169 Use optional DATE and alternative file DIARY. EVENT is the event
170 that invoked this command. Shows holidays if `diary-show-holidays-flag'
172 (interactive "i\ni\ne")
173 (let* ((date (or date
(calendar-cursor-to-date nil event
)))
174 (diary-file (or diary diary-file
))
175 (diary-list-include-blanks nil
)
176 (diary-entries (mapcar (lambda (x) (split-string (cadr x
) "\n"))
177 (diary-list-entries date
1 'list-only
)))
178 (holidays (if diary-show-holidays-flag
179 (calendar-check-holidays date
)))
180 (title (format "Diary entries%s for %s"
181 (if diary
(format " from %s" diary
) "")
182 (calendar-date-string date
)))
183 (selection (cal-menu-x-popup-menu event title
184 (mapcar (lambda (x) (list (concat " " x
))) holidays
)
186 (list "--shadow-etched-in" "--shadow-etched-in"))
188 (mapcar 'list
(apply 'append diary-entries
))
190 (and selection
(call-interactively selection
))))
192 (defun calendar-mouse-view-other-diary-entries (&optional event
)
193 "Pop up menu of diary entries from alternative file on mouse-selected date."
195 (calendar-mouse-view-diary-entries
196 (calendar-cursor-to-date nil event
)
197 (read-file-name "Enter diary file name: " default-directory nil t
)
200 (defun cal-menu-set-date-title (menu)
201 "Convert date of last event to title suitable for MENU."
202 (easy-menu-filter-return
203 menu
(calendar-date-string (calendar-cursor-to-date t last-input-event
)
206 (easy-menu-define cal-menu-context-mouse-menu nil
207 "Pop up menu for Mouse-2 for selected date in the calendar window."
208 '("cal-menu-mouse2" :filter cal-menu-set-date-title
210 ["Holidays" calendar-cursor-holidays
]
211 ["Mark date" calendar-set-mark
]
212 ["Sunrise/sunset" calendar-sunrise-sunset
]
213 ["Other calendars" calendar-print-other-dates
]
214 ;; FIXME there is a bug (#447) with last-nonmenu-event and submenus.
215 ;; These currently don't work if called without calendar window selected.
216 ("Prepare LaTeX buffer"
217 ["Daily (1 page)" cal-tex-cursor-day
]
218 ["Weekly (1 page)" cal-tex-cursor-week
]
219 ["Weekly (2 pages)" cal-tex-cursor-week2
]
220 ["Weekly (other style; 1 page)" cal-tex-cursor-week-iso
]
221 ["Weekly (yet another style; 1 page)" cal-tex-cursor-week-monday
]
222 ["Monthly" cal-tex-cursor-month
]
223 ["Monthly (landscape)" cal-tex-cursor-month-landscape
]
224 ["Yearly" cal-tex-cursor-year
]
225 ["Yearly (landscape)" cal-tex-cursor-year-landscape
]
227 ["Filofax Daily (one-day-per-page)" cal-tex-cursor-filofax-daily
]
228 ["Filofax Weekly (2-weeks-at-a-glance)" cal-tex-cursor-filofax-2week
]
229 ["Filofax Weekly (week-at-a-glance)" cal-tex-cursor-filofax-week
]
230 ["Filofax Yearly" cal-tex-cursor-filofax-year
]))
231 ("Write HTML calendar"
232 ["For selected month" cal-html-cursor-month
]
233 ["For selected year" cal-html-cursor-year
])
234 ["Diary entries" calendar-mouse-view-diary-entries
]
235 ["Insert diary entry" diary-insert-entry
]
236 ["Other diary file entries" calendar-mouse-view-other-diary-entries
]))
238 (easy-menu-define cal-menu-global-mouse-menu nil
239 "Menu bound to a mouse event, not specific to the mouse-click location."
241 ["Scroll forward" calendar-scroll-left-three-months
]
242 ["Scroll backward" calendar-scroll-right-three-months
]
243 ["Mark diary entries" diary-mark-entries
]
244 ["List holidays" calendar-list-holidays
]
245 ["Mark holidays" calendar-mark-holidays
]
246 ["Unmark" calendar-unmark
]
247 ["Lunar phases" calendar-phases-of-moon
]
248 ["Show diary" diary-show-all-entries
]
249 ["Exit calendar" calendar-exit
]))
251 ;; Undocumented and probably useless.
252 (defvar cal-menu-load-hook nil
253 "Hook run on loading of the `cal-menu' package.")
254 (make-obsolete-variable 'cal-menu-load-hook
255 "it will be removed in future." "23.1")
257 (run-hooks 'cal-menu-load-hook
)
261 ;; arch-tag: aa81cf73-ce89-48a4-97ec-9ef861e87fe9
262 ;;; cal-menu.el ends here