summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkuanyui <azazabc123@gmail.com>2016-03-06 01:40:06 +0800
committerkuanyui <azazabc123@gmail.com>2016-03-06 01:40:06 +0800
commit9f92cd40632a39e1b398531fd879e87dc26dd339 (patch)
tree00593b7340b75aa5c1aec7c7103a362d61edb6e2
parent30e8abcbd629969bbd20e7159a62c0fcb6f8e11b (diff)
Refactoring to more universal functions
-rw-r--r--wttrin.el21
1 files changed, 13 insertions, 8 deletions
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)