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 Jul 1, 2012 00:45:19 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 ;; Turning this off for a while to see if I can get used to using Howm
89 ;;(autoload 'todo-mode "todo-mode"
90 ;; "Major mode for editing TODO lists." t)
91 ;;(autoload 'todo-show "todo-mode"
92 ;; "Show TODO items." t)
93 ;;(autoload 'todo-insert-item "todo-mode"
94 ;; "Add TODO item." t)
95 ;;(global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
96 ;;(global-set-key "\C-cn" 'todo-insert-item) ;; insert new item
98 ;; todo-prefix "&%%(todo-cp)"
99 ;; todo-file-do (expand-file-name ".todo-do" (getenv "HOME"))
100 ;; todo-file-done (expand-file-name ".todo-done" (getenv "HOME"))
101 ;; todo-file-top (expand-file-name ".todo-top" (getenv "HOME"))
102 ;; todo-time-string-format "%3b, %d")
104 ;:*=======================
105 ;:* Fancy Diary with perdy colours!
106 (defun sy-hide-fancy-dashes ()
107 "Hides the long lines of dashes from todo-mode in fancy diary display."
109 (goto-char (point-min))
110 (while (re-search-forward "-----" nil t)
112 (make-extent (match-beginning 0) (1+ (match-end 0)))
115 (define-derived-mode fancy-diary-display-mode fundamental-mode "Diary"
116 "Minor mode for displaying Fancy Diary entries buffer."
117 (set (make-local-variable 'font-lock-defaults)
118 '(fancy-diary-font-lock-keywords t))
119 (sy-hide-fancy-dashes)
121 (define-key (current-local-map) "o" 'other-window)
122 (define-key (current-local-map) [space] 'scroll-up-command)
123 (define-key (current-local-map) [backspace] 'scroll-down-command))
125 (defadvice fancy-diary-display (after set-mode activate)
126 "Give the Fancy Diary Entries buffer a mode of its own.
128 It has the ever-so-original name of: `fancy-diary-display-mode', adds
129 a couple of motion keybindings, and lets you set up font lock keywords
130 for a fontified Diary buffer."
132 (set-buffer (get-buffer-create fancy-diary-buffer))
133 (fancy-diary-display-mode)))
135 (defun fancy-diary-font-lock-keywords ()
136 (let* ((today (regexp-opt (list (calendar-date-string (calendar-current-date)))))
137 (keywords `(("^---\\s-\\(.*$\\)" (1 font-lock-function-name-face))
138 ("^.*SY:" . font-lock-keyword-face)
139 ("\"\\(.*\\)\"" (1 font-lock-string-face))
140 ("`\\(.*?\\)'" (1 font-lock-reference-face))
141 ("[0-9]+:[0-9]+" . font-lock-warning-face)
142 (,today . font-lock-warning-face)
143 ("\\(^.*\\)\n=" (1 font-lock-comment-face)))))
146 (defvar fancy-diary-font-lock-keywords (fancy-diary-font-lock-keywords))
148 ;:*=======================
149 ;:* Display ISO week numbers
151 ;; I saw this code mentioned on c.e.x. I just snarfed what I needed
152 ;; and SXEmacserised it.
155 (defvar calendar-use-colours t
156 "Tries to fontify Calendar if non-nil.")
158 (defvar calendar-week-string "WK"
159 "String (up to three chars) used in calendar header to identify week numbers.")
161 (defun sy-generate-calendar-month (month year indent)
162 "Produce a calendar for ISO-week, month, year on the Gregorian calendar.
163 The calendar is inserted in the buffer starting at the line on which point
164 is currently located, but indented INDENT spaces. The indentation is done
165 from the first character on the line and does not disturb the first INDENT
166 characters on the line."
167 (let* ((blank-days ; At start of month
169 (- (calendar-day-of-week (list month 1 year))
170 calendar-week-start-day)
172 (last (calendar-last-day-of-month month year)))
173 (goto-char (point-min))
174 (calendar-insert-indented
175 (calendar-string-spread
176 (list (format "%s %d" (calendar-month-name month) year)) ? 20)
178 ;; Add colour to month name
179 (if calendar-use-colours
180 (set-extent-property (make-extent (point-min) (1- (point)))
181 'face 'calendar-header-face))
182 (calendar-insert-indented "" indent) ; Go to proper spot
185 (insert (substring (aref calendar-day-name-array
186 (mod (+ calendar-week-start-day i) 7)) 0 2))
187 ;; Add colour to week day names and sundays
188 (if calendar-use-colours
189 (set-extent-property (make-extent (- (point) 2) (point)) 'face
190 (if (= 0 (mod (+ calendar-week-start-day i) 7))
191 'calendar-sunday-face
192 'calendar-header-face)))
194 ;; Add week-string after week dates
195 (insert (concat calendar-week-string
196 (make-string (- 3 (length calendar-week-string)) ? )))
197 ;; Add colour to week-string
198 (if calendar-use-colours
199 (set-extent-property (make-extent (- (point) 3) (point))
200 'face 'calendar-week-face))
201 (calendar-insert-indented "" 0 t);; Force onto following line
202 (calendar-insert-indented "" indent);; Go to proper spot
203 ;; Add blank days before the first of the month
204 (calendar-for-loop i from 1 to blank-days do (insert " "))
205 ;; Put in the days of the month
208 (insert (format "%2d " i))
209 (if (not calendar-use-colours)
211 (put-text-property (- (point) 3) (1- (point)) 'mouse-face 'highlight)
212 ;; Add colour to sunday
213 (if (= 1 (mod (+ blank-days calendar-week-start-day i) 7))
214 (set-extent-property (make-extent (- (point) 3) (1- (point)))
215 'face 'calendar-sunday-face)))
216 (and (zerop (mod (+ i blank-days) 7))
217 ;; Add ISO-week # at the end each week entry
219 (format "%2d " (extract-calendar-month
220 (calendar-iso-from-absolute
221 (calendar-absolute-from-gregorian
222 (list month i year)))))))
223 ;; Add colour to week #
224 (if calendar-use-colours
225 (set-extent-property (make-extent (- (point) 3) (1- (point)))
226 'face 'calendar-week-face)
229 (calendar-insert-indented "" 0 t);; Force onto following line
230 (calendar-insert-indented "" indent)))));; Go to proper spot
232 (defalias 'generate-calendar-month #'sy-generate-calendar-month)
234 ;:*=======================
236 (add-hook 'diary-display-hook #'fancy-diary-display)
237 (add-hook 'diary-hook #'appt-make-list)
238 (add-hook 'list-diary-entries-hook
241 (include-other-diary-files)))
242 (add-hook 'mark-diary-entries-hook #'mark-included-diary-files)
243 (add-hook 'today-visible-calendar-hook #'calendar-mark-today)
244 (add-hook 'calendar-move-hook #'(lambda () (diary-view-entries 1)))
245 (add-hook 'calendar-mode-hook
247 (setq fancy-diary-font-lock-keywords
248 (fancy-diary-font-lock-keywords))))
250 ;:*=======================
253 (require 'balloon-help)
254 (balloon-help-mode 1)
256 balloon-help-background "BlanchedAlmond"
257 balloon-help-foreground "Black"
258 display-time-24hr-format t
259 display-time-day-and-date t
260 display-time-no-mail-balloon "What! No mail? That can't be right."
261 display-time-mail-balloon-show-gnus-group t
262 display-time-mail-balloon-max-displayed 20
263 display-time-mail-balloon-gnus-split-width 19
264 display-time-mail-balloon-enhance-gnus-group
265 '("\\(private.*\\|xemacs\\.private\\)")
266 display-time-mail-balloon-suppress-gnus-group
267 '("\\(SPAM.*\\|returned\\.mail\\)"))
271 appt-message-warning-time 30
272 appt-display-format 'echo
274 appt-display-mode-line t
275 appt-announce-method 'appt-persistent-message-announce)
277 ;:*=======================
279 (defvar displayed-month)
280 (defvar displayed-year)
283 ;; First up, a slightly re-written easter-holiday function
284 (defun sy-easter-holidays ()
285 "List of dates related to Easter, as visible in calendar window.
286 Ever-so-slightly modified to include the Easter Monday holiday."
287 (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
288 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
289 (let* ((century (1+ (/ displayed-year 100)))
290 (shifted-epact ;; Age of moon for April 5...
291 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
292 (- ;; ...corrected for the Gregorian century rule
294 (/ ;; ...corrected for Metonic cycle inaccuracy.
295 (+ 5 (* 8 century)) 25)
296 (* 30 century));; Keeps value positive.
298 (adjusted-epact ;; Adjust for 29.5 day month.
299 (if (or (= shifted-epact 0)
300 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
303 (paschal-moon ;; Day after the full moon on or after March 21.
304 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
306 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
309 (list (calendar-gregorian-from-absolute abs-easter)
311 (list (calendar-gregorian-from-absolute (- abs-easter 2))
313 (list (calendar-gregorian-from-absolute (+ abs-easter 1))
315 (list (calendar-gregorian-from-absolute (- abs-easter 46))
317 (list (calendar-gregorian-from-absolute (- abs-easter 47))
318 "Shrove Tuesday \(Pancake Tuesday\)")))
321 (list (calendar-gregorian-from-absolute (- abs-easter 63))
322 "Septuagesima Sunday")
323 (list (calendar-gregorian-from-absolute (- abs-easter 56))
325 (list (calendar-gregorian-from-absolute (- abs-easter 49))
327 (list (calendar-gregorian-from-absolute (- abs-easter 48))
329 (list (calendar-gregorian-from-absolute (- abs-easter 14))
331 (list (calendar-gregorian-from-absolute (- abs-easter 7))
333 (list (calendar-gregorian-from-absolute (- abs-easter 3))
335 (list (calendar-gregorian-from-absolute (+ abs-easter 35))
337 (list (calendar-gregorian-from-absolute (+ abs-easter 39))
339 (list (calendar-gregorian-from-absolute (+ abs-easter 49))
340 "Pentecost (Whitsunday)")
341 (list (calendar-gregorian-from-absolute (+ abs-easter 50))
343 (list (calendar-gregorian-from-absolute (+ abs-easter 56))
345 (list (calendar-gregorian-from-absolute (+ abs-easter 60))
348 (filter-visible-calendar-holidays mandatory)))
349 (if all-christian-calendar-holidays
352 (filter-visible-calendar-holidays optional)
356 ;; Get rid of all the Americanised holidays
358 christian-holidays nil
365 ;; Set up standard Aussie holidays
367 calendar-holidays '((holiday-fixed 1 1 "New Year's Day")
368 ;; If New Year's day is on a weekend the public
369 ;; holiday is the following Monday
370 (if (or (eq 0 (calendar-day-of-week (list 1 1 displayed-year)))
371 (eq 6 (calendar-day-of-week (list 1 1 displayed-year))))
372 (holiday-float 1 1 1 "New Year's Day Public Holiday"))
373 (holiday-fixed 1 26 "Australia Day")
374 ;; If Australia Day falls on a weekend, the
375 ;; holiday is the following Monday
376 (if (eq 0 (calendar-day-of-week (list 1 26 displayed-year)))
377 (holiday-fixed 1 27 "Australia Day Public Holiday"))
378 (if (eq 6 (calendar-day-of-week (list 1 26 displayed-year)))
379 (holiday-fixed 1 28 "Australia Day Public Holiday"))
380 (holiday-fixed 2 14 "Valentine's Day")
381 (holiday-fixed 3 17 "St. Patrick's Day")
382 (holiday-fixed 4 1 "April Fools' Day")
383 (holiday-fixed 4 25 "Anzac Day")
384 ;; If Anzac Day falls on a weekend, the holiday
385 ;; is the following Monday
386 (if (eq 0 (calendar-day-of-week (list 4 25 displayed-year)))
387 (holiday-fixed 4 26 "Anzac Day Public Holiday"))
388 (if (eq 6 (calendar-day-of-week (list 4 25 displayed-year)))
389 (holiday-fixed 4 27 "Anzac Day Public Holiday"))
390 (holiday-float 5 1 1 "Labour Day")
391 (holiday-float 5 0 2 "Mother's Day")
392 (holiday-float 6 1 2 "Queen's Birthday")
393 ;; Brisbane Ekka holiday is on the 2nd Wednesday
394 ;; in August, unless there are 5 Wednesdays in
395 ;; August, then it is the 3rd Wednesday.
396 (if (eq 8 (car (calendar-nth-named-day 5 3 8 displayed-year 0)))
397 (holiday-float 8 3 3 "Brisbane Show Day")
398 (holiday-float 8 3 2 "Brisbane Show Day"))
399 (holiday-float 8 3 3 "Brisbane Show Day") ; This might be wrong?
400 (holiday-float 9 0 1 "Father's Day")
401 (holiday-fixed 12 25 "Christmas Day")
402 (holiday-fixed 12 26 "Boxing Day")
403 ;; If Xmas falls on weekend, the public holiday
404 ;; is the following Mon/Tue
405 (if (or (eq 0 (calendar-day-of-week (list 12 25 displayed-year)))
406 (eq 6 (calendar-day-of-week (list 12 25 displayed-year))))
407 (holiday-fixed 12 27 "Xmas Day Public Holiday"))
408 (if (or (eq 0 (calendar-day-of-week (list 12 26 displayed-year)))
409 (eq 6 (calendar-day-of-week (list 12 26 displayed-year))))
410 (holiday-fixed 12 28 "Boxing Day Public Holiday"))
411 (solar-equinoxes-solstices)
412 (sy-easter-holidays)))
413 (setq mark-holidays-in-calendar t)
415 ;:*=======================
418 calendar-date-display-form
419 '("[" year "-" (format "%02d" (string-to-int month))
420 "-" (format "%02d" (string-to-int day)) "] "
421 (if dayname (concat dayname ", ")) day " " monthname " " year))
423 (defun howm-mark-calendar-date ()
425 (let* ((howm-schedule-types
426 howm-schedule-menu-types)
427 (raw (howm-reminder-search
428 howm-schedule-types))
429 (str nil) (yy nil) (mm nil) (dd nil))
431 (setq str (nth 1 (car raw)))
434 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)"
436 (setq yy (match-string 1 str))
437 (setq mm (match-string 2 str))
438 (setq dd (match-string 3 str)))
440 (mark-calendar-date-pattern
447 (setq raw (cdr raw)))))
449 (defadvice mark-diary-entries
450 (after mark-howm-entry activate)
451 (howm-mark-calendar-date))
454 howm-menu-display-rules
456 (cons "%hdiary[\n]?" 'howm-menu-diary)
457 howm-menu-display-rules))
459 (defun howm-menu-diary ()
460 (message "scanning diary...")
462 (match-beginning 0) (match-end 0))
463 (let* ((now (decode-time (current-time)))
465 (list (nth 4 now) (nth 3 now) (nth 5 now)))
466 (diary-display-hook 'ignore)
467 (howm-diary-entry nil)
468 (howm-diary-entry-day nil)
472 (setq howm-diary-entry
474 diary-date howm-menu-schedule-days))
477 (find-buffer-visiting diary-file))
478 (subst-char-in-region
479 (point-min) (point-max) ?\^M ?\n t)
480 (setq selective-display nil)))
481 (while howm-diary-entry
482 (setq howm-diary-entry-day (car howm-diary-entry))
483 (setq mm (nth 0 (car howm-diary-entry-day)))
484 (setq dd (nth 1 (car howm-diary-entry-day)))
485 (setq yy (nth 2 (car howm-diary-entry-day)))
486 (setq str (nth 1 howm-diary-entry-day))
487 (setq howm-diary-entry (cdr howm-diary-entry))
490 ">>d [%04d-%02d-%02d] %s\n" yy mm dd str))))
491 (message "scanning diary...done"))
493 (setq diary-date-forms
494 '((month "/" day "[^/0-9]")
495 (month "/" day "/" year "[^0-9]")
496 ("\\[" year "-" month "-" day "\\]" "[^0-9]")
497 (monthname " *" day "[^,0-9]")
498 (monthname " *" day ", *" year "[^0-9]")
501 (defun howm-open-diary (&optional dummy)
503 (let ((date-str nil) (str nil))
506 (when (re-search-forward
507 ">>d \\(\\[[-0-9]+\\]\\) " nil t)
511 (buffer-substring-no-properties
512 (point) (line-end-position))))
516 (buffer-substring-no-properties
521 (substitute-in-file-name diary-file))
523 (goto-char (point-min))
524 (if (re-search-forward date-str nil t)
526 (re-search-forward str nil t))))))
528 (defun add-diary-action-lock-rule ()
534 (if (not (member rule action-lock-default-rules))
536 (setq action-lock-default-rules
537 (cons rule action-lock-default-rules))
538 (action-lock-set-rules
539 action-lock-default-rules)))))
541 (add-hook 'action-lock-mode-on-hook
542 'add-diary-action-lock-rule)
544 (defadvice make-diary-entry
545 (after howm-mode activate)
551 ;;; ;; M-x calendar, move cursor to a certain date, and
552 ;;; ;; M-x howm-from-calendar to search that date in howm notes.
553 (defun howm-from-calendar ()
555 (let* ((mdy (calendar-cursor-to-date t))
559 (key (format-time-string
561 (encode-time 0 0 0 d m y))))
562 (howm-keyword-search key)))
564 ;; Bind howm-from-calendar to "H-d" key.
565 (add-hook 'initial-calendar-window-hook
567 (local-set-key [(hyper ?d)] 'howm-from-calendar)))
571 ;; Type "H-d" in howm menu to open calendar.
572 (add-hook 'howm-menu-hook
574 (local-set-key [(hyper ?d)] 'calendar)))
576 ;:*=======================
577 ;:* Get the show on the road
578 (defun sy-calendar-setup ()
580 (mark-calendar-holidays)
581 (diary-show-all-entries))
583 (add-hook 'calendar-load-hook 'sy-calendar-setup)
584 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
585 (message "Calendar settings loaded")