summaryrefslogtreecommitdiff
path: root/wttrin.el
diff options
context:
space:
mode:
authorCraig Jennings <craigmartinjennings@gmail.com>2024-04-01 11:19:41 -0500
committerCraig Jennings <craigmartinjennings@gmail.com>2024-04-01 11:19:41 -0500
commit84b79776b53e83bbe9563e51ef1099f42ef40183 (patch)
tree1f561f6fed5d9eda2c4b54452770c8258623021d /wttrin.el
parent1d3a5e80256fa2af4d13a4aecb9e580a0e2d5fd2 (diff)
customize font, display date, clean requeries, license change, &c.
- changed license to GPLv3 - allow user to specify font name and height for display - place date/time stamp above location name at top of buffer - re-query with new location deletes to reduce buffer clutter - updated screenshot to show current updates - changed references from "city" to "location" in wttrin.el - removed old CI config files - removed old badges from readme file
Diffstat (limited to 'wttrin.el')
-rw-r--r--wttrin.el89
1 files changed, 69 insertions, 20 deletions
diff --git a/wttrin.el b/wttrin.el
index bfbdd70..ef6f06c 100644
--- a/wttrin.el
+++ b/wttrin.el
@@ -16,14 +16,39 @@
;;; Code:
(require 'url)
-(require 'xterm-color)
+(require 'xterm-color) ;; https://github.com/atomontage/xterm-color
(defgroup wttrin nil
"Emacs frontend for weather web service wttr.in."
:prefix "wttrin-"
:group 'comm)
-(defcustom wttrin-default-cities '("Berkeley" "New Orleans" "New York" "London" "Taipei")
+(defcustom wttrin-font-name "Liberation Mono"
+ "Preferred monospaced font name for weather display."
+ :group 'wttrin
+ :type 'string)
+
+(defcustom wttrin-font-height 130
+ "Preferred font height for weather display."
+ :group 'wttrin
+ :type 'integer)
+
+(defface wttrin-buffer-face
+ `((t :height ,wttrin-font-height :family ,wttrin-font-name))
+ "Default face for the weather display buffer."
+ :group 'wttrin)
+
+(defcustom wttrin-default-cities '("Berkeley, California"
+ "New Orleans, Louisiana"
+ "New York, New York"
+ "London, England"
+ "Paris, France"
+ "Berlin, Germany"
+ "Naples, Italy"
+ "Athens, Greece"
+ "Kyiv, Ukraine"
+ "Tainan, Taiwan"
+ "Taipei, Taiwan")
"Specify default cities list for quick completion."
:group 'wttrin
:type 'list)
@@ -43,47 +68,71 @@ Use 'm' for 'metric', 'u' for 'USCS, or nil for location based units (default)."
"Concatenates extra information into the URL."
(concat "?" wttrin-unit-system))
-(defun wttrin-fetch-raw-string (query) "Get the weather information based on your QUERY."
- (let ((url-user-agent "curl"))
- (add-to-list 'url-request-extra-headers wttrin-default-accept-language)
- (with-current-buffer
- (url-retrieve-synchronously
- (concat "http://wttr.in/" query "?A")
- (lambda (status) (switch-to-buffer (current-buffer))))
- (decode-coding-string (buffer-string) 'utf-8))))
+(defun wttrin-fetch-raw-string (query)
+ "Get the weather information based on your QUERY."
+ (let ((url-user-agent "curl"))
+ (add-to-list 'url-request-extra-headers wttrin-default-accept-language)
+ (with-current-buffer
+ (url-retrieve-synchronously
+ (concat "http://wttr.in/" query "?A")
+ (lambda (status) (switch-to-buffer (current-buffer))))
+ (decode-coding-string (buffer-string) 'utf-8))))
(defun wttrin-exit ()
"Exit the wttrin buffer."
(interactive)
(quit-window t))
+(defun wttrin-restart ()
+ "Kill buffer and restart wttrin."
+ (interactive)
+ (kill-buffer)
+ (call-interactively 'wttrin))
+
(defun wttrin-query (city-name)
"Query weather of CITY-NAME via wttrin, and display the result in new buffer."
(let ((raw-string (wttrin-fetch-raw-string city-name)))
(if (string-match "ERROR" raw-string)
- (message "Cannot retrieve weather data. Perhaps the city name was misspelled?")
+ (message "Cannot retrieve weather data. Perhaps the location was misspelled?")
(let ((buffer (get-buffer-create (format "*wttr.in - %s*" city-name))))
(switch-to-buffer buffer)
(setq buffer-read-only nil)
(erase-buffer)
- (insert (xterm-color-filter raw-string))
+
+ ;; set the preferred font attributes for this buffer only
+ (setq buffer-face-mode-face `(:family ,wttrin-font-name :height ,wttrin-font-height))
+ (buffer-face-mode t)
+
+ ;; insert weather data
+ (insert (xterm-color-filter raw-string))
+
+ ;; remove all info lines except date and location
+ (goto-char (point-min))
+ (kill-whole-line 4)
+ (forward-line)
+ (kill-whole-line)
+
+ ;; provide user instructions
+ (goto-char (point-max))
+ (insert "\n")
+ (insert "Press 'g' for another location's weather, 'q' to quit.")
+
+ ;; align buffer to top
(goto-char (point-min))
- (re-search-forward "^$")
- (delete-region (point-min) (1+ (point)))
- (goto-char (point-max))
- (insert "\n")
- (insert "Press 'g' for another city's weather, 'q' to quit.")
+
+ ;; create choice keymap and disallow modifying buffer
(use-local-map (make-sparse-keymap))
(local-set-key "q" 'wttrin-exit)
- (local-set-key "g" 'wttrin)
- (setq buffer-read-only t)))))
+ (local-set-key "g" 'wttrin-restart)
+
+ (setq buffer-read-only t)))))
;;;###autoload
(defun wttrin (city)
"Display weather information for CITY."
(interactive
(list
- (completing-read "City Name: " wttrin-default-cities nil nil
+ (completing-read "City Name: " wttrin-default-cities nil nil
(when (= (length wttrin-default-cities) 1)
(car wttrin-default-cities)))))
(wttrin-query city))