1 ;; 12-cal-sy.el --- Calendar Settings -*- Emacs-Lisp -*-
3 ;; Copyright (C) 2007 - 2012 Steve Youngs
5 ;; Author: Steve Youngs <steve@sxemacs.org>
6 ;; Maintainer: Steve Youngs <steve@sxemacs.org>
7 ;; Created: <2007-12-02>
8 ;; Time-stamp: <Sunday Jun 10, 2012 10:58:53 steve>
9 ;; Download: <http://bastard.steveyoungs.com/~steve/SXEmacs/inits/>
10 ;; HTMLised: <http://bastard.steveyoungs.com/~steve/SXEmacs/htmlinits/12-cal-sy.html>
11 ;; Git Repo: git clone http://git.sxemacs.org/syinit
12 ;; Keywords: init, compile
14 ;; This file is part of SYinit
16 ;; Redistribution and use in source and binary forms, with or without
17 ;; modification, are permitted provided that the following conditions
20 ;; 1. Redistributions of source code must retain the above copyright
21 ;; notice, this list of conditions and the following disclaimer.
23 ;; 2. Redistributions in binary form must reproduce the above copyright
24 ;; notice, this list of conditions and the following disclaimer in the
25 ;; documentation and/or other materials provided with the distribution.
27 ;; 3. Neither the name of the author nor the names of any contributors
28 ;; may be used to endorse or promote products derived from this
29 ;; software without specific prior written permission.
31 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
32 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
41 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 ;; My calendar/diary settings
50 ;; The HTML version of this file was created with Hrvoje Niksic's
51 ;; htmlize.el which is part of the XEmacs "text-modes" package.
59 ;:*=======================
64 calendar-latitude -27.3
65 calendar-longitude 153.0
66 calendar-location-name "Brisbane"
67 calendar-time-zone 600
68 calendar-standard-time-zone-name "EST"
70 ; calendar-date-display-form
71 ; '((if dayname (concat dayname ", ")) day " " monthname " " year)
72 calendar-time-display-form
73 '(24-hours ":" minutes
74 (if time-zone " (") time-zone (if time-zone ")"))
75 calendar-week-start-day 1
76 diary-file (expand-file-name "etc/SXEmacs/.diary"
78 diary-mail-addr "steve"
80 european-calendar-style t
81 mark-diary-entries-in-calendar t
82 number-of-diary-entries 7
83 view-diary-entries-initially t)
85 ;:*=======================
87 (autoload 'todo-mode "todo-mode"
88 "Major mode for editing TODO lists." t)
89 (autoload 'todo-show "todo-mode"
91 (autoload 'todo-insert-item "todo-mode"
93 (global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
94 (global-set-key "\C-cn" 'todo-insert-item) ;; insert new item
96 todo-prefix "&%%(todo-cp)"
97 todo-file-do (expand-file-name ".todo-do" (getenv "HOME"))
98 todo-file-done (expand-file-name ".todo-done" (getenv "HOME"))
99 todo-file-top (expand-file-name ".todo-top" (getenv "HOME"))
100 todo-time-string-format "%3b, %d")
102 ;:*=======================
103 ;:* Fancy Diary with perdy colours!
104 (defun sy-hide-fancy-dashes ()
105 "Hides the long lines of dashes from todo-mode in fancy diary display."
107 (goto-char (point-min))
108 (while (re-search-forward "-----" nil t)
110 (make-extent (match-beginning 0) (1+ (match-end 0)))
113 (define-derived-mode fancy-diary-display-mode fundamental-mode "Diary"
114 "Minor mode for displaying Fancy Diary entries buffer."
115 (set (make-local-variable 'font-lock-defaults)
116 '(fancy-diary-font-lock-keywords t))
117 (sy-hide-fancy-dashes)
119 (define-key (current-local-map) "o" 'other-window)
120 (define-key (current-local-map) [space] 'scroll-up-command)
121 (define-key (current-local-map) [backspace] 'scroll-down-command))
123 (defadvice fancy-diary-display (after set-mode activate)
124 "Give the Fancy Diary Entries buffer a mode of its own.
126 It has the ever-so-original name of: `fancy-diary-display-mode', adds
127 a couple of motion keybindings, and lets you set up font lock keywords
128 for a fontified Diary buffer."
130 (set-buffer (get-buffer-create fancy-diary-buffer))
131 (fancy-diary-display-mode)))
133 (defun fancy-diary-font-lock-keywords ()
134 (let* ((today (regexp-opt (list (calendar-date-string (calendar-current-date)))))
135 (keywords `(("^---\\s-\\(.*$\\)" (1 font-lock-function-name-face))
136 ("^.*SY:" . font-lock-keyword-face)
137 ("\"\\(.*\\)\"" (1 font-lock-string-face))
138 ("`\\(.*?\\)'" (1 font-lock-reference-face))
139 ("[0-9]+:[0-9]+" . font-lock-warning-face)
140 (,today . font-lock-warning-face)
141 ("\\(^.*\\)\n=" (1 font-lock-comment-face)))))
144 (defvar fancy-diary-font-lock-keywords (fancy-diary-font-lock-keywords))
146 (defun sy-update-diary-font-lock-keywords ()
148 (setq fancy-diary-font-lock-keywords (fancy-diary-font-lock-keywords))
149 (with-current-buffer (get-buffer-create fancy-diary-buffer)
150 (font-lock-fontify-buffer)))
152 (run-at-time "23:59:59" 86400 'sy-update-diary-font-lock-keywords)
154 ;:*=======================
155 ;:* Display ISO week numbers
157 ;; I saw this code mentioned on c.e.x. I just snarfed what I needed
158 ;; and SXEmacserised it.
161 (defvar calendar-use-colours t
162 "Tries to fontify Calendar if non-nil.")
164 (defvar calendar-week-string "WK"
165 "String (up to three chars) used in calendar header to identify week numbers.")
167 (defun sy-generate-calendar-month (month year indent)
168 "Produce a calendar for ISO-week, month, year on the Gregorian calendar.
169 The calendar is inserted in the buffer starting at the line on which point
170 is currently located, but indented INDENT spaces. The indentation is done
171 from the first character on the line and does not disturb the first INDENT
172 characters on the line."
173 (let* ((blank-days ; At start of month
175 (- (calendar-day-of-week (list month 1 year))
176 calendar-week-start-day)
178 (last (calendar-last-day-of-month month year)))
179 (goto-char (point-min))
180 (calendar-insert-indented
181 (calendar-string-spread
182 (list (format "%s %d" (calendar-month-name month) year)) ? 20)
184 ;; Add colour to month name
185 (if calendar-use-colours
186 (set-extent-property (make-extent (point-min) (1- (point)))
187 'face 'calendar-header-face))
188 (calendar-insert-indented "" indent) ; Go to proper spot
191 (insert (substring (aref calendar-day-name-array
192 (mod (+ calendar-week-start-day i) 7)) 0 2))
193 ;; Add colour to week day names and sundays
194 (if calendar-use-colours
195 (set-extent-property (make-extent (- (point) 2) (point)) 'face
196 (if (= 0 (mod (+ calendar-week-start-day i) 7))
197 'calendar-sunday-face
198 'calendar-header-face)))
200 ;; Add week-string after week dates
201 (insert (concat calendar-week-string
202 (make-string (- 3 (length calendar-week-string)) ? )))
203 ;; Add colour to week-string
204 (if calendar-use-colours
205 (set-extent-property (make-extent (- (point) 3) (point))
206 'face 'calendar-week-face))
207 (calendar-insert-indented "" 0 t);; Force onto following line
208 (calendar-insert-indented "" indent);; Go to proper spot
209 ;; Add blank days before the first of the month
210 (calendar-for-loop i from 1 to blank-days do (insert " "))
211 ;; Put in the days of the month
214 (insert (format "%2d " i))
215 (if (not calendar-use-colours)
217 (put-text-property (- (point) 3) (1- (point)) 'mouse-face 'highlight)
218 ;; Add colour to sunday
219 (if (= 1 (mod (+ blank-days calendar-week-start-day i) 7))
220 (set-extent-property (make-extent (- (point) 3) (1- (point)))
221 'face 'calendar-sunday-face)))
222 (and (zerop (mod (+ i blank-days) 7))
223 ;; Add ISO-week # at the end each week entry
225 (format "%2d " (extract-calendar-month
226 (calendar-iso-from-absolute
227 (calendar-absolute-from-gregorian
228 (list month i year)))))))
229 ;; Add colour to week #
230 (if calendar-use-colours
231 (set-extent-property (make-extent (- (point) 3) (1- (point)))
232 'face 'calendar-week-face)
235 (calendar-insert-indented "" 0 t);; Force onto following line
236 (calendar-insert-indented "" indent)))));; Go to proper spot
238 (defalias 'generate-calendar-month #'sy-generate-calendar-month)
240 ;:*=======================
242 (add-hook 'diary-display-hook #'fancy-diary-display)
243 (add-hook 'diary-hook #'appt-make-list)
244 (add-hook 'list-diary-entries-hook
247 (include-other-diary-files)))
248 (add-hook 'mark-diary-entries-hook #'mark-included-diary-files)
249 (add-hook 'today-visible-calendar-hook #'calendar-mark-today)
251 ;:*=======================
254 (require 'balloon-help)
255 (balloon-help-mode 1)
257 balloon-help-background "BlanchedAlmond"
258 balloon-help-foreground "Black"
259 display-time-24hr-format t
260 display-time-day-and-date t
261 display-time-no-mail-balloon "What! No mail? That can't be right."
262 display-time-mail-balloon-show-gnus-group t
263 display-time-mail-balloon-max-displayed 20
264 display-time-mail-balloon-gnus-split-width 19
265 display-time-mail-balloon-enhance-gnus-group
266 '("\\(private.*\\|xemacs\\.private\\)")
267 display-time-mail-balloon-suppress-gnus-group
268 '("\\(SPAM.*\\|returned\\.mail\\)"))
272 appt-message-warning-time 30
273 appt-display-format 'echo
275 appt-display-mode-line t
276 appt-announce-method 'appt-persistent-message-announce)
278 ;:*=======================
280 (defvar displayed-month)
281 (defvar displayed-year)
284 ;; First up, a slightly re-written easter-holiday function
285 (defun sy-easter-holidays ()
286 "List of dates related to Easter, as visible in calendar window.
287 Ever-so-slightly modified to include the Easter Monday holiday."
288 (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
289 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
290 (let* ((century (1+ (/ displayed-year 100)))
291 (shifted-epact ;; Age of moon for April 5...
292 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
293 (- ;; ...corrected for the Gregorian century rule
295 (/ ;; ...corrected for Metonic cycle inaccuracy.
296 (+ 5 (* 8 century)) 25)
297 (* 30 century));; Keeps value positive.
299 (adjusted-epact ;; Adjust for 29.5 day month.
300 (if (or (= shifted-epact 0)
301 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
304 (paschal-moon ;; Day after the full moon on or after March 21.
305 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
307 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
310 (list (calendar-gregorian-from-absolute abs-easter)
312 (list (calendar-gregorian-from-absolute (- abs-easter 2))
314 (list (calendar-gregorian-from-absolute (+ abs-easter 1))
316 (list (calendar-gregorian-from-absolute (- abs-easter 46))
318 (list (calendar-gregorian-from-absolute (- abs-easter 47))
319 "Shrove Tuesday \(Pancake Tuesday\)")))
322 (list (calendar-gregorian-from-absolute (- abs-easter 63))
323 "Septuagesima Sunday")
324 (list (calendar-gregorian-from-absolute (- abs-easter 56))
326 (list (calendar-gregorian-from-absolute (- abs-easter 49))
328 (list (calendar-gregorian-from-absolute (- abs-easter 48))
330 (list (calendar-gregorian-from-absolute (- abs-easter 14))
332 (list (calendar-gregorian-from-absolute (- abs-easter 7))
334 (list (calendar-gregorian-from-absolute (- abs-easter 3))
336 (list (calendar-gregorian-from-absolute (+ abs-easter 35))
338 (list (calendar-gregorian-from-absolute (+ abs-easter 39))
340 (list (calendar-gregorian-from-absolute (+ abs-easter 49))
341 "Pentecost (Whitsunday)")
342 (list (calendar-gregorian-from-absolute (+ abs-easter 50))
344 (list (calendar-gregorian-from-absolute (+ abs-easter 56))
346 (list (calendar-gregorian-from-absolute (+ abs-easter 60))
349 (filter-visible-calendar-holidays mandatory)))
350 (if all-christian-calendar-holidays
353 (filter-visible-calendar-holidays optional)
357 ;; Get rid of all the Americanised holidays
359 christian-holidays nil
366 ;; Set up standard Aussie holidays
368 calendar-holidays '((holiday-fixed 1 1 "New Year's Day")
369 ;; If New Year's day is on a weekend the public
370 ;; holiday is the following Monday
371 (if (or (eq 0 (calendar-day-of-week (list 1 1 displayed-year)))
372 (eq 6 (calendar-day-of-week (list 1 1 displayed-year))))
373 (holiday-float 1 1 1 "New Year's Day Public Holiday"))
374 (holiday-fixed 1 26 "Australia Day")
375 ;; If Australia Day falls on a weekend, the
376 ;; holiday is the following Monday
377 (if (eq 0 (calendar-day-of-week (list 1 26 displayed-year)))
378 (holiday-fixed 1 27 "Australia Day Public Holiday"))
379 (if (eq 6 (calendar-day-of-week (list 1 26 displayed-year)))
380 (holiday-fixed 1 28 "Australia Day Public Holiday"))
381 (holiday-fixed 2 14 "Valentine's Day")
382 (holiday-fixed 3 17 "St. Patrick's Day")
383 (holiday-fixed 4 1 "April Fools' Day")
384 (holiday-fixed 4 25 "Anzac Day")
385 ;; If Anzac Day falls on a weekend, the holiday
386 ;; is the following Monday
387 (if (eq 0 (calendar-day-of-week (list 4 25 displayed-year)))
388 (holiday-fixed 4 26 "Anzac Day Public Holiday"))
389 (if (eq 6 (calendar-day-of-week (list 4 25 displayed-year)))
390 (holiday-fixed 4 27 "Anzac Day Public Holiday"))
391 (holiday-float 5 1 1 "Labour Day")
392 (holiday-float 5 0 2 "Mother's Day")
393 (holiday-float 6 1 2 "Queen's Birthday")
394 ;; Brisbane Ekka holiday is on the 2nd Wednesday
395 ;; in August, unless there are 5 Wednesdays in
396 ;; August, then it is the 3rd Wednesday.
397 (if (eq 8 (car (calendar-nth-named-day 5 3 8 displayed-year 0)))
398 (holiday-float 8 3 3 "Brisbane Show Day")
399 (holiday-float 8 3 2 "Brisbane Show Day"))
400 (holiday-float 8 3 3 "Brisbane Show Day") ; This might be wrong?
401 (holiday-float 9 0 1 "Father's Day")
402 (holiday-fixed 12 25 "Christmas Day")
403 (holiday-fixed 12 26 "Boxing Day")
404 ;; If Xmas falls on weekend, the public holiday
405 ;; is the following Mon/Tue
406 (if (or (eq 0 (calendar-day-of-week (list 12 25 displayed-year)))
407 (eq 6 (calendar-day-of-week (list 12 25 displayed-year))))
408 (holiday-fixed 12 27 "Xmas Day Public Holiday"))
409 (if (or (eq 0 (calendar-day-of-week (list 12 26 displayed-year)))
410 (eq 6 (calendar-day-of-week (list 12 26 displayed-year))))
411 (holiday-fixed 12 28 "Boxing Day Public Holiday"))
412 (solar-equinoxes-solstices)
413 (sy-easter-holidays)))
414 (setq mark-holidays-in-calendar t)
416 ;:*=======================
419 calendar-date-display-form
420 '("[" year "-" (format "%02d" (string-to-int month))
421 "-" (format "%02d" (string-to-int day)) "] "
422 (if dayname (concat dayname ", ")) day " " monthname " " year))
424 (defun howm-mark-calendar-date ()
426 (let* ((howm-schedule-types
427 howm-schedule-menu-types)
428 (raw (howm-reminder-search
429 howm-schedule-types))
430 (str nil) (yy nil) (mm nil) (dd nil))
432 (setq str (nth 1 (car raw)))
435 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)"
437 (setq yy (match-string 1 str))
438 (setq mm (match-string 2 str))
439 (setq dd (match-string 3 str)))
441 (mark-calendar-date-pattern
448 (setq raw (cdr raw)))))
450 (defadvice mark-diary-entries
451 (after mark-howm-entry activate)
452 (howm-mark-calendar-date))
455 howm-menu-display-rules
457 (cons "%hdiary[\n]?" 'howm-menu-diary)
458 howm-menu-display-rules))
460 (defun howm-menu-diary ()
461 (message "scanning diary...")
463 (match-beginning 0) (match-end 0))
464 (let* ((now (decode-time (current-time)))
466 (list (nth 4 now) (nth 3 now) (nth 5 now)))
467 (diary-display-hook 'ignore)
468 (howm-diary-entry nil)
469 (howm-diary-entry-day nil)
473 (setq howm-diary-entry
475 diary-date howm-menu-schedule-days))
478 (find-buffer-visiting diary-file))
479 (subst-char-in-region
480 (point-min) (point-max) ?\^M ?\n t)
481 (setq selective-display nil)))
482 (while howm-diary-entry
483 (setq howm-diary-entry-day (car howm-diary-entry))
484 (setq mm (nth 0 (car howm-diary-entry-day)))
485 (setq dd (nth 1 (car howm-diary-entry-day)))
486 (setq yy (nth 2 (car howm-diary-entry-day)))
487 (setq str (nth 1 howm-diary-entry-day))
488 (setq howm-diary-entry (cdr howm-diary-entry))
491 ">>d [%04d-%02d-%02d] %s\n" yy mm dd str))))
492 (message "scanning diary...done"))
494 (setq diary-date-forms
495 '((month "/" day "[^/0-9]")
496 (month "/" day "/" year "[^0-9]")
497 ("\\[" year "-" month "-" day "\\]" "[^0-9]")
498 (monthname " *" day "[^,0-9]")
499 (monthname " *" day ", *" year "[^0-9]")
502 (defun howm-open-diary (&optional dummy)
504 (let ((date-str nil) (str nil))
507 (when (re-search-forward
508 ">>d \\(\\[[-0-9]+\\]\\) " nil t)
512 (buffer-substring-no-properties
513 (point) (line-end-position))))
517 (buffer-substring-no-properties
522 (substitute-in-file-name diary-file))
524 (goto-char (point-min))
525 (if (re-search-forward date-str nil t)
527 (re-search-forward str nil t))))))
529 (defun add-diary-action-lock-rule ()
535 (if (not (member rule action-lock-default-rules))
537 (setq action-lock-default-rules
538 (cons rule action-lock-default-rules))
539 (action-lock-set-rules
540 action-lock-default-rules)))))
542 (add-hook 'action-lock-mode-on-hook
543 'add-diary-action-lock-rule)
545 (defadvice make-diary-entry
546 (after howm-mode activate)
552 ;;; ;; M-x calendar, move cursor to a certain date, and
553 ;;; ;; M-x howm-from-calendar to search that date in howm notes.
554 (defun howm-from-calendar ()
556 (let* ((mdy (calendar-cursor-to-date t))
560 (key (format-time-string
562 (encode-time 0 0 0 d m y))))
563 (howm-keyword-search key)))
565 ;; Bind howm-from-calendar to "H-d" key.
566 (add-hook 'initial-calendar-window-hook
568 (local-set-key [(hyper ?d)] 'howm-from-calendar)))
572 ;; Type "H-d" in howm menu to open calendar.
573 (add-hook 'howm-menu-hook
575 (local-set-key [(hyper ?d)] 'calendar)))
577 ;:*=======================
578 ;:* Get the show on the road
579 (defun sy-calendar-setup ()
581 (mark-calendar-holidays)
582 (diary-show-all-entries))
584 (add-hook 'calendar-load-hook 'sy-calendar-setup)
585 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
586 (message "Calendar settings loaded")