about summary refs log tree commit diff
path: root/tools/emacs-pkgs/dottime/dottime.el
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-27T12·04+0100
committerVincent Ambo <tazjin@google.com>2019-12-27T12·04+0100
commit100f451b0aae7a286a92c9ffd805982d3ecbc1ae (patch)
tree62204e63b6eb460db6bdfff4931236b197d5d698 /tools/emacs-pkgs/dottime/dottime.el
parenta54cc040add0662d2aff6f1028ed1192dcf2751f (diff)
fix(dottime.el): Defer package-specific setup r/312
Diffstat (limited to 'tools/emacs-pkgs/dottime/dottime.el')
-rw-r--r--tools/emacs-pkgs/dottime/dottime.el72
1 files changed, 37 insertions, 35 deletions
diff --git a/tools/emacs-pkgs/dottime/dottime.el b/tools/emacs-pkgs/dottime/dottime.el
index 1e02ece8cffa..508ee5b6937b 100644
--- a/tools/emacs-pkgs/dottime/dottime.el
+++ b/tools/emacs-pkgs/dottime/dottime.el
@@ -60,40 +60,42 @@
   (if (or (eq arg 0) (eq arg nil))
       (advice-remove 'display-time-update #'dottime--display-time-update-advice)
     (advice-add 'display-time-update :around #'dottime--display-time-update-advice))
-  (display-time-update))
-
-;; Amend the time display in telega.el to use dottime.
-;;
-;; This will never display offsets in the chat window, as those are
-;; always visible in the modeline anyways.
-(when (featurep 'telega)
-  (defun telega-ins--dottime-advice (orig timestamp)
-    (let* ((dtime (decode-time timestamp t))
-           (current-ts (time-to-seconds (current-time)))
-           (ctime (decode-time current-ts))
-           (today00 (telega--time-at00 current-ts ctime)))
-      (if (> timestamp today00)
-          (telega-ins-fmt "%02d·%02d" (nth 2 dtime) (nth 1 dtime))
-        (funcall orig timestamp))))
-
-  (advice-add 'telega-ins--date :around #'telega-ins--dottime-advice))
-
-;; Amend the time display in notmuch to use dottime.
-(when (featurep 'notmuch)
-  (defun notmuch-show--dottime-date-advice (orig header header-value)
-    (if (equal "Date" header)
-        ;; Unfortunately the header insertion functions do not have access
-        ;; to the message object, which means that the only information we
-        ;; have about the timestamp is its string rendering.
-        (-let* (((sec min hour day mon year dow dst tz)
-                 (parse-time-string header-value)))
-          (insert header ": "
-                  (dottime-format (encode-time sec min hour day mon year tz)
-                                  tz "%a, %Y-")
-                  "\n"))
-
-      (funcall orig header header-value)))
-
-  (advice-add 'notmuch-show-insert-header :around #'notmuch-show--dottime-date-advice))
+  (display-time-update)
+
+  ;; Amend the time display in telega.el to use dottime.
+  ;;
+  ;; This will never display offsets in the chat window, as those are
+  ;; always visible in the modeline anyways.
+  (when (featurep 'telega)
+    (require 'telega)
+    (defun telega-ins--dottime-advice (orig timestamp)
+      (let* ((dtime (decode-time timestamp t))
+             (current-ts (time-to-seconds (current-time)))
+             (ctime (decode-time current-ts))
+             (today00 (telega--time-at00 current-ts ctime)))
+        (if (> timestamp today00)
+            (telega-ins-fmt "%02d·%02d" (nth 2 dtime) (nth 1 dtime))
+          (funcall orig timestamp))))
+
+    (advice-add 'telega-ins--date :around #'telega-ins--dottime-advice))
+
+  ;; Amend the time display in notmuch to use dottime.
+  (when (featurep 'notmuch)
+    (require 'notmuch)
+    (defun notmuch-show--dottime-date-advice (orig header header-value)
+      (if (equal "Date" header)
+          ;; Unfortunately the header insertion functions do not have access
+          ;; to the message object, which means that the only information we
+          ;; have about the timestamp is its string rendering.
+          (-let* (((sec min hour day mon year dow dst tz)
+                   (parse-time-string header-value)))
+            (insert header ": "
+                    (dottime-format (encode-time sec min hour day mon year tz)
+                                    tz "%a, %Y-")
+                    "\n"))
+
+        (funcall orig header header-value)))
+
+    (advice-add 'notmuch-show-insert-header :around #'notmuch-show--dottime-date-advice)))
 
 (provide 'dottime)