Last active
October 6, 2023 20:47
-
-
Save rtrppl/99f4eae2acea76eb6ec0ff2aa9161197 to your computer and use it in GitHub Desktop.
wttr+world_clock.el
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun lt/wttr () | |
| "A tiny wrapper for wttr and world clock." | |
| (interactive) | |
| (with-current-buffer (get-buffer-create "*wttr*") | |
| (erase-buffer) | |
| (insert (shell-command-to-string "curl -s de.wttr.in/Freiburg?3nFqT")) | |
| (insert "\n") | |
| (lt/world-clock-display (time--display-world-list))) | |
| (switch-to-buffer "*wttr*") | |
| (read-char "") | |
| (previous-buffer)) | |
| (defun lt/world-clock-display (alist) | |
| "Insert times in various zones, based on ALIST." | |
| (insert "\n\n") | |
| (let ((inhibit-read-only t) | |
| (buffer-undo-list t) | |
| (now (current-time)) | |
| (max-width 0) | |
| result fmt) | |
| (dolist (zone alist) | |
| (let* ((label (cadr zone)) | |
| (width (string-width label))) | |
| (push (cons label | |
| (format-time-string world-clock-time-format | |
| now (car zone))) | |
| result) | |
| (when (> width max-width) | |
| (setq max-width width)))) | |
| (setq fmt (concat "%-" (int-to-string max-width) "s %s\n")) | |
| (dolist (timedata (nreverse result)) | |
| (insert (format fmt | |
| (propertize (car timedata) | |
| 'face 'world-clock-label) | |
| (cdr timedata)))) | |
| (delete-char -1)) | |
| (goto-char (point-min))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment