From 9f92cd40632a39e1b398531fd879e87dc26dd339 Mon Sep 17 00:00:00 2001 From: kuanyui Date: Sun, 6 Mar 2016 01:40:06 +0800 Subject: Refactoring to more universal functions --- wttrin.el | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'wttrin.el') diff --git a/wttrin.el b/wttrin.el index 460e991..c370a07 100644 --- a/wttrin.el +++ b/wttrin.el @@ -34,6 +34,16 @@ (lambda (status) (switch-to-buffer (current-buffer)))) (decode-coding-string (buffer-string) 'utf-8)))) +(defun wttrin-query (city-name) + "Query weather of CITY-NAME via wttrin, and display the result +in another buffer." + (let ((buf (get-buffer-create (format "*wttr.in - %s*" city-name)))) + (switch-to-buffer buf) + (insert (xterm-color-filter (wttrin-fetch-raw-string city-name))) + (goto-char (point-min)) + (re-search-forward "^$") + (delete-region (point-min) (1+ (point))) + (setq buffer-read-only t))) (defun wttrin (&optional force-ask) "Display weather information. @@ -42,14 +52,9 @@ Add C-u prefix to force to ask city name." (let* ((ask? (or current-prefix-arg force-ask)) (city-name (if ask? (read-from-minibuffer "City name: ") - (or wttring-default-city (read-from-minibuffer "City name: ")))) - (buf (get-buffer-create (format "*wttr.in - %s*" city-name)))) - (switch-to-buffer buf) - (insert (xterm-color-filter (wttrin-fetch-raw-string city-name))) - (goto-char (point-min)) - (re-search-forward "^$") - (delete-region (point-min) (1+ (point))) - (setq buffer-read-only t))) + (or wttring-default-city (read-from-minibuffer "City name: "))))) + (wttrin-query city-name))) + (provide 'wttrin) -- cgit v1.2.3