1 ;; 11-cal.el --- Calendar Settings
3 ;; Copyright (C) 2007 - 2020 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 11 Apr 2021 14:13:59 (steve)>
9 ;; Download: <https://downloads.sxemacs.org/SYinits>
10 ;; HTMLised: <https://www.sxemacs.org/SYinits/11-cal.html>
11 ;; Git Repo: git clone https://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 ;:*=======================
61 (require 'cedet-compat)
65 calendar-latitude [27 35.33 south]
66 calendar-longitude [153 7.29 east]
67 calendar-location-name "Rochedale South"
68 calendar-time-zone 600
70 ; calendar-date-display-form ; see: "Howm Integration" below
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 "diary" user-init-directory)
77 diary-mail-addr "steve"
79 european-calendar-style t
80 mark-diary-entries-in-calendar t
81 number-of-diary-entries 7
82 view-diary-entries-initially t)
84 ;; Use a dedicated frame for my calendar
85 (setq calendar-and-diary-frame-parameters
91 (default-toolbar-visible-p . nil)
92 (default-gutter-visible-p . nil)
93 (menubar-visible-p . t))
94 calendar-setup 'one-frame)
96 ;:*=======================
98 ;; Turning this off for a while to see if I can get used to using Howm
100 ;;(autoload 'todo-mode "todo-mode"
101 ;; "Major mode for editing TODO lists." t)
102 ;;(autoload 'todo-show "todo-mode"
103 ;; "Show TODO items." t)
104 ;;(autoload 'todo-insert-item "todo-mode"
105 ;; "Add TODO item." t)
106 ;;(global-set-key "\C-ct" 'todo-show) ;; switch to TODO buffer
107 ;;(global-set-key "\C-cn" 'todo-insert-item) ;; insert new item
109 ;; todo-prefix "&%%(todo-cp)"
110 ;; todo-file-do (expand-file-name "todo-do" (paths-construct-path
111 ;; (list user-init-directory
113 ;; todo-file-done (expand-file-name "todo-done" (paths-construct-path
114 ;; (list user-init-directory
116 ;; todo-file-top (expand-file-name "todo-top" (paths-construct-path
117 ;; (list user-init-directory
119 ;; todo-time-string-format "%3b, %d")
121 ;:*=======================
122 ;:* Fancy Diary with perdy colours!
123 (defun sy-hide-fancy-dashes ()
124 "Hides the long lines of dashes from todo-mode in fancy diary display."
126 (goto-char (point-min))
127 (while (re-search-forward "-----" nil t)
129 (make-extent (match-beginning 0) (1+ (match-end 0)))
132 (define-derived-mode fancy-diary-display-mode fundamental-mode "Diary"
133 "Minor mode for displaying Fancy Diary entries buffer."
134 (set (make-local-variable 'font-lock-defaults)
135 '(fancy-diary-font-lock-keywords t))
136 (sy-hide-fancy-dashes)
138 (define-key (current-local-map) "o" 'other-window)
139 (define-key (current-local-map) [space] 'scroll-up-command)
140 (define-key (current-local-map) [backspace] 'scroll-down-command))
142 (defadvice fancy-diary-display (after set-mode activate)
143 "Give the Fancy Diary Entries buffer a mode of its own.
145 It has the ever-so-original name of: `fancy-diary-display-mode', adds
146 a couple of motion keybindings, and lets you set up font lock keywords
147 for a fontified Diary buffer."
149 (set-buffer (get-buffer-create fancy-diary-buffer))
150 (fancy-diary-display-mode)))
152 (defun fancy-diary-font-lock-keywords ()
153 (let* ((today (regexp-opt (list (calendar-date-string (calendar-current-date)))))
154 (keywords `(("^---\\s-\\(.*$\\)" (1 font-lock-function-name-face))
155 ("^.*SY:" . font-lock-keyword-face)
156 ("\"\\(.*\\)\"" (1 font-lock-string-face))
157 ("`\\(.*?\\)'" (1 font-lock-reference-face))
158 ("[0-9]+:[0-9]+" . font-lock-warning-face)
159 (,today . font-lock-warning-face)
160 ("\\(^.*\\)\n=" (1 font-lock-comment-face)))))
163 (defvar fancy-diary-font-lock-keywords (fancy-diary-font-lock-keywords))
165 ;:*=======================
166 ;:* Display ISO week numbers
168 ;; I saw this code mentioned on c.e.x. I just snarfed what I needed
169 ;; and SXEmacserised it.
172 (defvar calendar-use-colours t
173 "Tries to fontify Calendar if non-nil.")
175 (defvar calendar-week-string "WK"
176 "String (up to three chars) used in calendar header to identify week numbers.")
178 (defun sy-generate-calendar-month (month year indent)
179 "Produce a calendar for ISO-week, month, year on the Gregorian calendar.
180 The calendar is inserted in the buffer starting at the line on which point
181 is currently located, but indented INDENT spaces. The indentation is done
182 from the first character on the line and does not disturb the first INDENT
183 characters on the line."
184 (let* ((blank-days ; At start of month
186 (- (calendar-day-of-week (list month 1 year))
187 calendar-week-start-day)
189 (last (calendar-last-day-of-month month year)))
190 (goto-char (point-min))
191 (calendar-insert-indented
192 (calendar-string-spread
193 (list (format "%s %d" (calendar-month-name month) year)) ? 20)
195 ;; Add colour to month name
196 (if calendar-use-colours
197 (set-extent-property (make-extent (point-min) (1- (point)))
198 'face 'calendar-header-face))
199 (calendar-insert-indented "" indent) ; Go to proper spot
202 (insert (substring (aref calendar-day-name-array
203 (mod (+ calendar-week-start-day i) 7)) 0 2))
204 ;; Add colour to week day names and sundays
205 (if calendar-use-colours
206 (set-extent-property (make-extent (- (point) 2) (point)) 'face
207 (if (= 0 (mod (+ calendar-week-start-day i) 7))
208 'calendar-sunday-face
209 'calendar-header-face)))
211 ;; Add week-string after week dates
212 (insert (concat calendar-week-string
213 (make-string (- 3 (length calendar-week-string)) ? )))
214 ;; Add colour to week-string
215 (if calendar-use-colours
216 (set-extent-property (make-extent (- (point) 3) (point))
217 'face 'calendar-week-face))
218 (calendar-insert-indented "" 0 t);; Force onto following line
219 (calendar-insert-indented "" indent);; Go to proper spot
220 ;; Add blank days before the first of the month
221 (calendar-for-loop i from 1 to blank-days do (insert " "))
222 ;; Put in the days of the month
225 (insert (format "%2d " i))
226 (if (not calendar-use-colours)
228 (put-text-property (- (point) 3) (1- (point)) 'mouse-face 'highlight)
229 ;; Add colour to sunday
230 (if (= 1 (mod (+ blank-days calendar-week-start-day i) 7))
231 (set-extent-property (make-extent (- (point) 3) (1- (point)))
232 'face 'calendar-sunday-face)))
233 (and (zerop (mod (+ i blank-days) 7))
234 ;; Add ISO-week # at the end each week entry
236 (format "%2d " (extract-calendar-month
237 (calendar-iso-from-absolute
238 (calendar-absolute-from-gregorian
239 (list month i year)))))))
240 ;; Add colour to week #
241 (if calendar-use-colours
242 (set-extent-property (make-extent (- (point) 3) (1- (point)))
243 'face 'calendar-week-face)
246 (calendar-insert-indented "" 0 t);; Force onto following line
247 (calendar-insert-indented "" indent)))));; Go to proper spot
249 (defalias 'generate-calendar-month #'sy-generate-calendar-month)
251 ;:*=======================
253 (add-hook 'diary-display-hook #'fancy-diary-display)
254 (add-hook 'diary-hook #'appt-make-list)
255 (add-hook 'list-diary-entries-hook
258 (include-other-diary-files)))
259 (add-hook 'mark-diary-entries-hook #'mark-included-diary-files)
260 (add-hook 'today-visible-calendar-hook #'calendar-mark-today)
261 (add-hook 'calendar-move-hook #'(lambda () (diary-view-entries 1)))
262 (add-hook 'calendar-mode-hook
264 (setq fancy-diary-font-lock-keywords
265 (fancy-diary-font-lock-keywords))))
267 ;:*=======================
269 (defvar displayed-month)
270 (defvar displayed-year)
273 ;; First up, a slightly re-written easter-holiday function
274 (defun sy-easter-holidays ()
275 "List of dates related to Easter, as visible in calendar window.
276 Ever-so-slightly modified to include the Easter Monday holiday."
277 (if (and (> displayed-month 5) (not all-christian-calendar-holidays))
278 nil;; Ash Wednesday, Good Friday, and Easter are not visible.
279 (let* ((century (1+ (/ displayed-year 100)))
280 (shifted-epact ;; Age of moon for April 5...
281 (% (+ 14 (* 11 (% displayed-year 19));; ...by Nicaean rule
282 (- ;; ...corrected for the Gregorian century rule
284 (/ ;; ...corrected for Metonic cycle inaccuracy.
285 (+ 5 (* 8 century)) 25)
286 (* 30 century));; Keeps value positive.
288 (adjusted-epact ;; Adjust for 29.5 day month.
289 (if (or (= shifted-epact 0)
290 (and (= shifted-epact 1) (< 10 (% displayed-year 19))))
293 (paschal-moon ;; Day after the full moon on or after March 21.
294 (- (calendar-absolute-from-gregorian (list 4 19 displayed-year))
296 (abs-easter (calendar-dayname-on-or-before 0 (+ paschal-moon 7)))
299 (list (calendar-gregorian-from-absolute abs-easter)
301 (list (calendar-gregorian-from-absolute (- abs-easter 2))
303 (list (calendar-gregorian-from-absolute (+ abs-easter 1))
305 (list (calendar-gregorian-from-absolute (- abs-easter 46))
307 (list (calendar-gregorian-from-absolute (- abs-easter 47))
308 "Shrove Tuesday \(Pancake Tuesday\)")))
311 (list (calendar-gregorian-from-absolute (- abs-easter 63))
312 "Septuagesima Sunday")
313 (list (calendar-gregorian-from-absolute (- abs-easter 56))
315 (list (calendar-gregorian-from-absolute (- abs-easter 49))
317 (list (calendar-gregorian-from-absolute (- abs-easter 48))
319 (list (calendar-gregorian-from-absolute (- abs-easter 14))
321 (list (calendar-gregorian-from-absolute (- abs-easter 7))
323 (list (calendar-gregorian-from-absolute (- abs-easter 3))
325 (list (calendar-gregorian-from-absolute (+ abs-easter 35))
327 (list (calendar-gregorian-from-absolute (+ abs-easter 39))
329 (list (calendar-gregorian-from-absolute (+ abs-easter 49))
330 "Pentecost (Whitsunday)")
331 (list (calendar-gregorian-from-absolute (+ abs-easter 50))
333 (list (calendar-gregorian-from-absolute (+ abs-easter 56))
335 (list (calendar-gregorian-from-absolute (+ abs-easter 60))
338 (filter-visible-calendar-holidays mandatory)))
339 (if all-christian-calendar-holidays
342 (filter-visible-calendar-holidays optional)
346 ;; Get rid of all the Americanised holidays
348 christian-holidays nil
353 oriental-holidays nil
356 ;; Set up standard Aussie holidays
357 (setq calendar-holidays
358 '((holiday-fixed 1 1 "New Year's Day")
359 ;; If New Year's day is on a weekend the public
360 ;; holiday is the following Monday
361 (if (or (eq 0 (calendar-day-of-week (list 1 1 displayed-year)))
362 (eq 6 (calendar-day-of-week (list 1 1 displayed-year))))
363 (holiday-float 1 1 1 "New Year's Day Public Holiday"))
364 (holiday-fixed 1 26 "Australia Day")
365 ;; If Australia Day falls on a weekend, the
366 ;; holiday is the following Monday
367 (if (eq 0 (calendar-day-of-week (list 1 26 displayed-year)))
368 (holiday-fixed 1 27 "Australia Day Public Holiday"))
369 (if (eq 6 (calendar-day-of-week (list 1 26 displayed-year)))
370 (holiday-fixed 1 28 "Australia Day Public Holiday"))
371 (holiday-fixed 2 14 "Valentine's Day")
372 (holiday-fixed 3 17 "St. Patrick's Day")
373 (holiday-fixed 4 1 "April Fools' Day")
374 (holiday-fixed 4 25 "Anzac Day")
375 ;; If Anzac Day falls on a weekend, the holiday
376 ;; is the following Monday
377 (if (eq 0 (calendar-day-of-week (list 4 25 displayed-year)))
378 (holiday-fixed 4 26 "Anzac Day Public Holiday"))
379 (if (eq 6 (calendar-day-of-week (list 4 25 displayed-year)))
380 (holiday-fixed 4 27 "Anzac Day Public Holiday"))
381 (holiday-float 5 1 1 "Labour Day")
382 (holiday-float 5 0 2 "Mother's Day")
383 (holiday-float 6 1 2 "Queen's Birthday")
384 ;; Brisbane Ekka holiday is on the 2nd Wednesday
385 ;; in August, unless there are 5 Wednesdays in
386 ;; August, then it is the 3rd Wednesday.
387 (if (eq 8 (car (calendar-nth-named-day 5 3 8 displayed-year)))
388 (holiday-float 8 3 3 "Brisbane Show Day")
389 (holiday-float 8 3 2 "Brisbane Show Day"))
390 (holiday-float 9 0 1 "Father's Day")
391 (holiday-fixed 12 25 "Christmas Day")
392 (holiday-fixed 12 26 "Boxing Day")
393 ;; If Xmas falls on weekend, the public holiday
394 ;; is the following Mon/Tue
395 (if (or (eq 0 (calendar-day-of-week (list 12 25 displayed-year)))
396 (eq 6 (calendar-day-of-week (list 12 25 displayed-year))))
397 (holiday-fixed 12 27 "Xmas Day Public Holiday"))
398 (if (or (eq 0 (calendar-day-of-week (list 12 26 displayed-year)))
399 (eq 6 (calendar-day-of-week (list 12 26 displayed-year))))
400 (holiday-fixed 12 28 "Boxing Day Public Holiday"))
401 (solar-equinoxes-solstices)
402 (sy-easter-holidays)))
403 (setq mark-holidays-in-calendar t)
405 ;:*=======================
408 (require 'balloon-help)
409 (balloon-help-mode 1)
411 balloon-help-background "BlanchedAlmond"
412 balloon-help-foreground "Black"
413 display-time-24hr-format t
414 display-time-day-and-date t
415 display-time-no-mail-balloon "What! No mail? That can't be right."
416 display-time-mail-balloon-show-gnus-group t
417 display-time-mail-balloon-max-displayed 20
418 display-time-mail-balloon-gnus-split-width 19
419 display-time-mail-balloon-enhance-gnus-group
421 display-time-mail-balloon-suppress-gnus-group
422 '("\\(SPAM.*\\|returned\\.mail\\)"))
426 appt-message-warning-time 30
427 appt-display-format 'echo
429 appt-display-mode-line t
430 appt-announce-method 'appt-persistent-message-announce)
431 (add-hook 'appt-make-list-hook #'appt-included-diary-entries)
434 ;:*=======================
437 calendar-date-display-form
438 '("[" year "-" (format "%02d" (string-to-int month))
439 "-" (format "%02d" (string-to-int day)) "] "
440 (if dayname (concat dayname ", ")) day " " monthname " " year))
442 (defun howm-mark-calendar-date ()
444 (let* ((howm-schedule-types
445 howm-schedule-menu-types)
446 (raw (howm-reminder-search
447 howm-schedule-types))
448 (str nil) (yy nil) (mm nil) (dd nil))
450 (setq str (nth 1 (car raw)))
453 "\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)"
455 (setq yy (match-string 1 str))
456 (setq mm (match-string 2 str))
457 (setq dd (match-string 3 str)))
459 (mark-calendar-date-pattern
466 (setq raw (cdr raw)))))
468 (defadvice mark-diary-entries
469 (after mark-howm-entry activate)
470 (howm-mark-calendar-date))
472 (and-boundp 'howm-menu-display-rules
474 howm-menu-display-rules
476 (cons "%hdiary[\n]?" 'howm-menu-diary)
477 howm-menu-display-rules)))
479 (defun howm-menu-diary ()
480 (message "scanning diary...")
482 (match-beginning 0) (match-end 0))
483 (let* ((now (decode-time (current-time)))
485 (list (nth 4 now) (nth 3 now) (nth 5 now)))
486 (diary-display-hook 'ignore)
487 (howm-diary-entry nil)
488 (howm-diary-entry-day nil)
492 (setq howm-diary-entry
494 diary-date howm-menu-schedule-days))
497 (find-buffer-visiting diary-file))
498 (subst-char-in-region
499 (point-min) (point-max) ?\^M ?\n t)
500 (setq selective-display nil)))
501 (while howm-diary-entry
502 (setq howm-diary-entry-day (car howm-diary-entry))
503 (setq mm (nth 0 (car howm-diary-entry-day)))
504 (setq dd (nth 1 (car howm-diary-entry-day)))
505 (setq yy (nth 2 (car howm-diary-entry-day)))
506 (setq str (nth 1 howm-diary-entry-day))
507 (setq howm-diary-entry (cdr howm-diary-entry))
510 ">>d [%04d-%02d-%02d] %s\n" yy mm dd str))))
511 (message "scanning diary...done"))
513 (setq diary-date-forms
514 '((month "/" day "[^/0-9]")
515 (month "/" day "/" year "[^0-9]")
516 ("\\[" year "-" month "-" day "\\]" "[^0-9]")
517 (monthname " *" day "[^,0-9]")
518 (monthname " *" day ", *" year "[^0-9]")
521 (defun howm-open-diary (&optional dummy)
523 (let ((date-str nil) (str nil))
526 (when (re-search-forward
527 ">>d \\(\\[[-0-9]+\\]\\) " nil t)
531 (buffer-substring-no-properties
532 (point) (line-end-position))))
536 (buffer-substring-no-properties
541 (substitute-in-file-name diary-file))
543 (goto-char (point-min))
544 (if (re-search-forward date-str nil t)
546 (re-search-forward str nil t))))))
548 (defun add-diary-action-lock-rule ()
554 (if (not (member rule action-lock-default-rules))
556 (setq action-lock-default-rules
557 (cons rule action-lock-default-rules))
558 (action-lock-set-rules
559 action-lock-default-rules)))))
561 (add-hook 'action-lock-mode-on-hook
562 'add-diary-action-lock-rule)
564 (defadvice make-diary-entry
565 (after howm-mode activate)
571 ;;; ;; M-x calendar, move cursor to a certain date, and
572 ;;; ;; M-x howm-from-calendar to search that date in howm notes.
573 (defun howm-from-calendar ()
575 (let* ((mdy (calendar-cursor-to-date t))
579 (key (format-time-string
581 (encode-time 0 0 0 d m y))))
582 (howm-keyword-search key)))
584 ;; Bind howm-from-calendar to "H-d" key.
585 (add-hook 'initial-calendar-window-hook
587 (local-set-key [(hyper ?d)] 'howm-from-calendar)))
589 ;; Type "H-d" in howm menu to open calendar.
590 (add-hook 'howm-menu-hook
592 (local-set-key [(hyper ?d)] 'calendar)))
594 ;:*=======================
595 ;:* timeclock (keybindings in 90-keys.el)
596 ;; I tried using it for a while but I found that because it wasn't
597 ;; automated I never remembered to "clock-in" or "clock-out" and
598 ;; change tasks. I would probably use it if it were a lot more like
601 ;; Track time spent doing certain things
602 ;; (require 'timeclock)
603 ;; (setq timeclock-file (expand-file-name "timelog" user-init-directory))
604 ;; (setq timeclock-relative nil)
605 ;; (add-hook 'kill-emacs-query-functions 'timeclock-query-out)
606 ;; (timeclock-modeline-display)
608 ;:*=======================
609 ;:* Start itimer to refresh just after midnight
610 ;; This needs my `future-run-at-time' advice.
611 (run-at-time "00:01" 86400 #'redraw-calendar)
613 ;:*=======================
614 ;:* Get the show on the road
615 (defun sy-calendar-setup ()
617 (mark-calendar-holidays)
618 (diary-show-all-entries))
620 (add-hook 'calendar-load-hook #'sy-calendar-setup)
622 ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*
623 (message "Calendar settings loaded")