diff options
| author | kuanyui <azazabc123@gmail.com> | 2016-03-06 01:54:45 +0800 |
|---|---|---|
| committer | kuanyui <azazabc123@gmail.com> | 2016-03-06 01:54:45 +0800 |
| commit | ae1377c2176e2c64d800f412674bd8a8006cc4ff (patch) | |
| tree | a2734d34ee68fdec84ec36202829f433462aafde /wttrin.el | |
| parent | 9f92cd40632a39e1b398531fd879e87dc26dd339 (diff) | |
Error handling
Diffstat (limited to 'wttrin.el')
| -rw-r--r-- | wttrin.el | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -21,7 +21,7 @@ :group 'comm) (defcustom wttring-default-city "Taipei" - "Specify a query condition to get the weather information." + "Specify a defauly city to get the weather information." :group 'wttrin :type 'string) @@ -37,13 +37,16 @@ (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))) + (let ((raw-string (wttrin-fetch-raw-string city-name))) + (if (string-match "ERROR" raw-string) + (message "Cannot get weather data. Maybe you inputed a wrong city name?") + (let ((buffer (get-buffer-create (format "*wttr.in - %s*" city-name)))) + (switch-to-buffer buffer) + (insert (xterm-color-filter raw-string)) + (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. |
