;;; Time-stamp: <2007-06-19 18:49:54 john> ;; setup up my typing breaks (require 'type-break) (require 'cl) (require 'add-lispdir) (add-lispdir "$COMMON/emacs/my-extensions-to-packages/type-break/") (require 'type-break-log) (require 'type-break-enhancements) (require 'type-break-patches) (require 'type-break-adaptive) (require 'buffer-file-sync) (require 'time-date) (setq type-break-interval (+ (* 15 60) 0) type-break-good-rest-interval (+ (* 6 60) 0) type-break-keystroke-threshold (cons 20 400) type-break-file-name (substitute-in-file-name "$COMMON/var/type-break-state")) ;; (setq type-break-debug (string= (downcase (system-name)) "hosea")) ;; (setq type-break-demo-functions '( type-break-demo-boring)) (setq type-break-demo-functions '( type-break-demo-minibuffer)) (type-break-mode t) (if (fboundp 'type-break-mode-line-message-mode) (type-break-mode-line-message-mode t)) ;;;; my hooks (defun type-break-demo-swimmers () "Go for a swim as a typing break." (require 'swimmers) (and (get-buffer "*Swimming pool*") (kill-buffer "*Swimming pool*")) (swimming)) ;; (pushnew 'type-break-demo-swimmers type-break-demo-functions) (defun get-buffer-matching (pattern) "Find a buffer whose name matched PATTERN. If several match, the mostly recently used one is returned." (let ((case-fold-search t)) (catch 'found (dolist (buf (buffer-list)) (when (string-match pattern (buffer-name buf)) ;; (message "Matching: %s" buf) (throw 'found ;; (get-buffer buf ;; ) ))) nil))) ;;;; reading during typing breaks ;;; For the first few typing breaks, at the start of the break, ;;; step through a buffer automatically, to give the user something ;;; useful to read daily without them having to do any typing to get it (require 'autocue) ;; get some files that we will look through in typing breaks (require 'type-break-reading) (defvar oremus-pending t "Whether I yet have to do the daily Oremus.") (defvar weather-pending t "Whether I have yet to read the weather page.") (defvar bbc-pending t "Whether I yet have to read the daily BBC front page.") (defvar bbc-uk-pending t "Whether I yet have to read the daily BBC UK front page.") (defvar intercessions1-pending t "Whether I yet have to do my daily intercessions list, part 1") (defvar intercessions2-pending t "Whether I yet have to do my daily intercessions list, part 2") (defvar intercessions3-pending t "Whether I yet have to do my daily intercessions list, part 3") (defvar startup-messages-pending t "Whether I have yet to read the startup messages") (defvar ringing-learning-pending t "Whether I have yet to learn about ringing") (defvar bsd-manual-pending t "Whether I have yet to read the BSD manual.") (defvar rule-pending t "Whether I have yet to read my Rule.") (defvar agenda-pending t "Whether I have yet to read my things to do list.") (makunbound 'type-break-display-buffer-items) (defvar type-break-display-buffer-items '(("Oremus: [0-9]+ [a-z]+, [0-9]+" (oremus-pending "Oremus") 1.5 1 "Oremus for") ("BBC.+Front Page" (bbc-pending "BBC News") 1 2) ("BBC News.+UK" (bbc-uk-pending "BBC News: UK") 1 2) ("Cambridge Weather" (weather-pending "Cambridge weather") 1 3) ("Things to do" (agenda-pending "Things to do") 1 3) ("intercessions-1.txt" (intercessions1-pending "Prayer list 1") 4 1) ;; ("\\*Startup Messages\\*" (startup-messages-pending "Startup messages") 2 16) ("intercessions-2.txt" (intercessions2-pending "Prayer list 2") 4 1) ;; ("from-ras.txt" (ringing-learning-pending "Ringing learning") 1 2) ("intercessions-3.txt" (intercessions3-pending "Prayer list 3") 4 1) ("book.txt" (bsd-manual-pending "BSD manual") 1 3 nil 180) ("John.+Rule of Life" (rule-pending "Rule of Life") 1 2) ;; add Rule of St Benedict? ;; add SSF principles? ) "Buffers to show in typing breaks. Each item is a list: pattern to match for buffer name list of variable name for pending flag, and how to describe that variable in stats and the remaining args are passed as the optional args to autocue") (defun type-break-dailies-reset () "Reset the dailies flags." (interactive) (mapcar (function (lambda (item) (let ((expr (car (second item)))) (when (symbolp expr) (set expr t))))) type-break-display-buffer-items)) (defvar type-break-dailies-per-n 2 "*Autocue a buffer one per type-break-dailies-per-n type breaks. This is to stop them coming in too much of a rush.") (defvar type-break-dailies-per-n-counter type-break-dailies-per-n "Counter to go with type-break-dailies-per-n.") (defun type-break-daily-examined () "Function to show web pages I look at daily, as a typing break" (if (zerop (decf type-break-dailies-per-n-counter)) (when (y-or-n-p "Reading now? ") (setq type-break-dailies-per-n-counter type-break-dailies-per-n) (catch 'done (dolist (item type-break-display-buffer-items) (let* ((buffer-to-show (first item)) (details (cdr item)) (pending-symbol (if details (car (second item)) t))) (when (eval pending-symbol) (let ((buffer (get-buffer-matching buffer-to-show))) (if (bufferp buffer) (let ((autocue:kill-buffer-at-end t)) (apply 'autocue buffer (cddr item)) (when (and (symbolp pending-symbol) (not (eq pending-symbol t))) (set pending-symbol nil)) (if (null details) (kill-buffer buffer)) (throw 'done t)) nil))))))) (message "No reading this time, %d to go" type-break-dailies-per-n-counter)) nil) (defun type-break-daily-examined-stats () "Output stats on daily web use" (dolist (item type-break-display-buffer-items) (let ((vardesc (second item))) (princ (format "%s %s\n" (second vardesc) (if (eval (first vardesc)) "pending" "seen"))))) (princ "\n")) (add-hook 'type-break-hook 'type-break-daily-examined) (add-hook 'type-break-statistics-hook 'type-break-daily-examined-stats) (makunbound 'type-break-repetitive-activities) (defvar type-break-repetitive-activities `((nil 0 ,(* 60 20) "Stretch") (nil 0 ,(* 60 45) "Exercises") (nil 0 ,(* 60 60) "Pray") (nil 0 ,(* 60 90) "Climb stairs") (nil 0 ,(* 60 120) "Drink a glass of water"))) (defun type-break-repetitive-activities () "Check for various things the user is meant to do regularly" (catch 'done (let ((now (current-time))) (message "Considering repetitive activities") (dolist (item type-break-repetitive-activities) (message " Considering activity: %s" (fourth item)) (let ((difference (if (car item) (type-break-time-difference now (car item)) 0))) (message "difference is %d" difference) (when (<= difference 0) (let ((count (1+ (cadr item)))) (when (yes-or-no-p (format "%s (%d) ?" (fourth item) count)) (let ((next (type-break-time-sum now (third item)))) ;; (message " Doing %s" (fourth item)) ;; (message "item is %S" item) (rplaca item next) ;; (message "item is now %S" item) ;; (message "(cdr item) is %S" (cdr item)) (rplaca (cdr item) count) ;; (message "(cdr item) now is %S" (cdr item)) ;; (message " Completed %s" (fourth item)) (throw 'done t))))))) (message "no repetitive activities done this time") )) (message "end of type-break-repetitive-activities") nil) (defun due-string (time-interval) "Return a string describing TIME-INTERVAL in terms of time due" (if (> time-interval 0) (format "due in %s" (type-break-format-time time-interval)) (format "overdue by %s" (type-break-format-time (- time-interval))))) (defun type-break-repetitive-activities-stats () "Report on various things the user is meant to do regularly" (let ((now (current-time))) (princ "Regular activities:\n") (dolist (item type-break-repetitive-activities) (let ((how-long (if (numberp (caar item)) (type-break-time-difference now (car item)) 0))) (princ (format " %s: %d so far, next %s\n" (fourth item) (second item) (due-string how-long))))) (princ "\n"))) (add-hook 'type-break-hook 'type-break-repetitive-activities) (add-hook 'type-break-statistics-hook 'type-break-repetitive-activities-stats) (defun type-break-get-initial-health () "Get how good your hands were at the start of the session." (let* ((previous-session (type-break-previous-session 0)) (end-of-session-health (type-break-log-eventual-health-number previous-session))) (if (< type-break-initial-health 0) (setq type-break-initial-health (handsfree-read-percentage (format "How are your hands now (was %d at end of last session)? " end-of-session-health) end-of-session-health) type-break-initial-health-comment (read-from-minibuffer "Comment about RSI? ")))) ;; now always go on to do some other kind of break: nil) (add-hook 'type-break-hook 'type-break-get-initial-health) ;; Save our changes so that they are visible to other programs that we ;; may run before finishing the typing break (if (fboundp 'save-all-buffers-no-ask) (add-hook 'type-break-start-break-hook 'save-all-buffers-no-ask)) ;; In case the user runs other programs during the typing break, that ;; affect files we are editing, pick up any new versions (if (fboundp 'up-to-date-all-buffers) (add-hook 'type-break-end-break-hook 'up-to-date-all-buffers)) (let ((key-count-display '(:eval (format "k%d " type-break-keystroke-count)))) (if (not (member key-count-display global-mode-string)) (setq global-mode-string (append global-mode-string (list key-count-display))))) (defun type-break-set-query-by-mic-state-hook (state-command) "Turn typing break query off if the microphone is on, and vice versa" (let ((state (second state-command))) (cond ((eq state 'on) (message "Turning type break query off, as the microphone is on") (setq type-break-query-mode nil)) ((eq state 'off) (message "Turning type break query on, as the microphone is off") (setq type-break-query-mode t)))) nil) (defun type-break-set-query-by-mic-state (state) "Turn typing break query off if the microphone is on, and vice versa" (cond ((eq state 'on) (message "Turning type break query off, as the microphone is on") (setq type-break-query-mode nil)) ((eq state 'off) (message "Turning type break query on, as the microphone is off") (setq type-break-query-mode t)))) (defun type-break-voice-setup () (message "Setting up interaction between type break and voice recognition") (when (boundp 'vr-cmd-mic-state-hook) ;; new system, must return nil to avoid upsetting underlying system (message "Adding hook function to turn type breaks off when microphone on, and vice versa") (add-hook 'vr-cmd-mic-state-hook 'type-break-set-query-by-mic-state-hook))) (add-hook 'vr-mode-setup-hook 'type-break-voice-setup) ;; old system, ignores result (add-hook 'vr-mic-state-hooks 'type-break-set-query-by-mic-state) (require 'day-structure-sidebrain) (add-hook 'change-activity-hook 'set-colour-scheme-for-activity) (add-hook 'change-activity-hook 'activity-task-switcher) ;; Now called from sidebrain-end-type-break. We must end the ;; typing-break task before picking up the new one, otherwise ;; typing-break gets recorded as the task for the old activity: ;;(add-hook 'type-break-end-break-hook 'day-structure-update-current-activity) ;;; end of type-break-setup.el