diff --git a/unravel-emacs.org b/unravel-emacs.org index 06ba20b..4d50803 100644 --- a/unravel-emacs.org +++ b/unravel-emacs.org @@ -4195,6 +4195,7 @@ title of the task, and the like. The documentation string of ~yasnippet~ is the primary tool I use when I need templates of any kind. Since most of my templating is in ~org-mode~, it makes sense to keep YAS in this section. #+begin_src emacs-lisp :tangle "unravel-modules/unravel-org.el" + ;;; YASnippets for daily life improvements (use-package yasnippet :ensure t :config @@ -4205,6 +4206,36 @@ title of the task, and the like. The documentation string of (use-package yasnippet-snippets :ensure t :after yasnippet) + + ;; I use timestamp functions from ts.el in my snippets + (use-package ts + :ensure t + :config + (defun this-week-range (&optional week-num) + "Return timestamps \(BEG . END\) spanning the WEEK-NUM calendar work week. + If WEEK-NUM is not provided, use the current week." + (let* ((now (ts-now)) + ;; Navigate to the date we need to + (curr-week (string-to-number (ts-format "%W" now))) + (days-to-adjust (if week-num (* 7 (- curr-week week-num)) 0)) + ;; We start by calculating the offsets for the beginning and + ;; ending timestamps using the current day of the week. Note + ;; that the `ts-dow' slot uses the "%w" format specifier, which + ;; counts from Sunday to Saturday as a number from 0 to 6. + (adjust-beg-day (- (- (ts-dow now) 1))) + (adjust-end-day (- 5 (ts-dow now))) + ;; Make beginning/end timestamps based on `now', with adjusted + ;; day and hour/minute/second values. These functions return + ;; new timestamps, so `now' is unchanged. + (beg (thread-last now + ;; `ts-adjust' makes relative adjustments to timestamps. + (ts-adjust 'day (- adjust-beg-day days-to-adjust)) + ;; `ts-apply' applies absolute values to timestamps. + (ts-apply :hour 0 :minute 0 :second 0))) + (end (thread-last now + (ts-adjust 'day (- adjust-end-day days-to-adjust)) + (ts-apply :hour 23 :minute 59 :second 59)))) + (cons beg end)))) #+end_src ** The =unravel-org.el= Org agenda settings diff --git a/unravel-modules/unravel-org.el b/unravel-modules/unravel-org.el index f7bd8ec..daa73e1 100644 --- a/unravel-modules/unravel-org.el +++ b/unravel-modules/unravel-org.el @@ -348,6 +348,7 @@ Skips capture tasks and tasks with subtasks" :ensure nil :bind ("C-c c" . org-capture)) +;;; YASnippets for daily life improvements (use-package yasnippet :ensure t :config @@ -359,6 +360,36 @@ Skips capture tasks and tasks with subtasks" :ensure t :after yasnippet) +;; I use timestamp functions from ts.el in my snippets +(use-package ts + :ensure t + :config + (defun this-week-range (&optional week-num) + "Return timestamps \(BEG . END\) spanning the WEEK-NUM calendar work week. +If WEEK-NUM is not provided, use the current week." + (let* ((now (ts-now)) + ;; Navigate to the date we need to + (curr-week (string-to-number (ts-format "%W" now))) + (days-to-adjust (if week-num (* 7 (- curr-week week-num)) 0)) + ;; We start by calculating the offsets for the beginning and + ;; ending timestamps using the current day of the week. Note + ;; that the `ts-dow' slot uses the "%w" format specifier, which + ;; counts from Sunday to Saturday as a number from 0 to 6. + (adjust-beg-day (- (- (ts-dow now) 1))) + (adjust-end-day (- 5 (ts-dow now))) + ;; Make beginning/end timestamps based on `now', with adjusted + ;; day and hour/minute/second values. These functions return + ;; new timestamps, so `now' is unchanged. + (beg (thread-last now + ;; `ts-adjust' makes relative adjustments to timestamps. + (ts-adjust 'day (- adjust-beg-day days-to-adjust)) + ;; `ts-apply' applies absolute values to timestamps. + (ts-apply :hour 0 :minute 0 :second 0))) + (end (thread-last now + (ts-adjust 'day (- adjust-end-day days-to-adjust)) + (ts-apply :hour 23 :minute 59 :second 59)))) + (cons beg end)))) + ;;;; agenda (use-package org-agenda :ensure nil