* Re: [OT] Icon problem with org-google-weather
2011-06-06 0:27 [OT] Icon problem with org-google-weather Nick Dokos
@ 2011-06-06 7:38 ` Tassilo Horn
2011-06-06 13:51 ` Nick Dokos
2011-06-07 4:53 ` Nick Dokos
1 sibling, 1 reply; 7+ messages in thread
From: Tassilo Horn @ 2011-06-06 7:38 UTC (permalink / raw)
To: emacs-orgmode
Nick Dokos <nicholas.dokos@hp.com> writes:
> This is off-topic but it is driving me bananas. I do
>
> (setq date '(6 5 2011))
> (6 5 2011)
> (setq foo (let ((org-google-weather-cache-time 0))
> (org-google-weather)))
> (setq bar (org-google-weather))
> (equal foo bar)
> (insert foo)
> (insert bar)
>
> in the *scratch* buffer. The idea is that foo is freshly obtained from
> google every time: it never goes to cached data since the cache time
> is set to 0. bar, otoh, is obtained from cache. I've traced the code
> and that's indeed what happens. The two strings compare equal: (equal
> foo bar) returns t - just in case, I also displayed them in separate
> windows and did a compare-windows: they are the same that way too.
>
> Nevertheless, when I insert foo, the icon is shown, but when I insert
> bar, the icon is an empty box. What am I missing?
I have a similar problem. In one of my org files, I have
%%(org-google-weather "Montabaur" "de")
and since lately, I get only squares.
That said, while trying your example, `org-google-weather' always
returned nil. The reason is that I don't have
`org-google-weather-location' set explicitly to something different as
the default value. But that default is a form and it is never evaluated
AFAICS. So that seems to be another bug.
Ok, so when I change your testcase to this...
--8<---------------cut here---------------start------------->8---
(defun foobar ()
(interactive)
(let ((date '(6 6 2011)))
(setq bar (org-google-weather "Montabaur" "DE"))
(setq foo (let ((org-google-weather-cache-time 0))
(org-google-weather "Montabaur" "DE")))
(string= foo bar)
(insert foo)
(insert bar)))
--8<---------------cut here---------------end--------------->8---
I get an error at the foo value evaluation. The evaluation of bar seems
to work fine...
--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (error "Data not found")
signal(error ("Data not found"))
error("Data not found")
(if (search-forward "\n\n" nil t) nil (error "Data not found"))
(unless (search-forward "\n\n" nil t) (error "Data not found"))
(save-current-buffer (set-buffer (google-weather-retrieve-data-raw url org-google-weather-cache-time)) (unless (search-forward "\n\n" nil t) (error "Data not found")) (let ((data (buffer-substring (point) (point-max)))) (kill-buffer (current-buffer)) data))
(with-current-buffer (google-weather-retrieve-data-raw url org-google-weather-cache-time) (unless (search-forward "\n\n" nil t) (error "Data not found")) (let ((data (buffer-substring (point) (point-max)))) (kill-buffer (current-buffer)) data))
org-google-weather-get-icon("http://g0.gstatic.com/images/icons/onebox/weather_scatteredthunderstorms-40.gif")
(create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t)
(progn (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t))
(if (display-images-p) (progn (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t)))
(when (display-images-p) (create-image (org-google-weather-get-icon (cadr (assoc (quote icon) forecast))) nil t))
(let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr (assoc ... forecast))) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" (quote display) (append icon ...) (quote rear-nonsticky) (quote ...)) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))
(progn (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr ...)) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" ... ... ... ...) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol))))))
(if forecast (progn (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon ...) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if ... ... "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))))
(when forecast (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon (cadr ...)) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if (and icon org-google-weather-display-icon-p) (propertize "icon" ... ... ... ...) "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol))))))
(if problem-cause (message "%s: %s" location problem-cause) (when forecast (let ((condition (cadr (assoc (quote condition) forecast))) (low (cadr (assoc (quote low) forecast))) (high (cadr (assoc (quote high) forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image (org-google-weather-get-icon ...) nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, (if ... ... "")) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (104 \, high) (115 \, temp-symbol)))))))
(let* ((location (or location org-google-weather-location)) (data (ignore-errors (google-weather-get-data location language org-google-weather-cache-time))) (problem-cause (when data (google-weather-data->problem-cause data))) (forecast (when (and (null problem-cause) data) (google-weather-data->forecast-for-date data date)))) (if problem-cause (message "%s: %s" location problem-cause) (when forecast (let ((condition (cadr (assoc ... forecast))) (low (cadr (assoc ... forecast))) (high (cadr (assoc ... forecast))) (city (google-weather-data->city data)) (icon (when (display-images-p) (create-image ... nil t))) (temp-symbol (google-weather-data->temperature-symbol data))) (format-spec org-google-weather-format (\` ((105 \, ...) (99 \, condition) (76 \, location) (67 \, city) (108 \, low) (
104 \, high) (115 \, temp-symbol))))))))
org-google-weather("Montabaur" "DE")
(let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))
(setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE")))
(let ((date (quote (6 6 2011)))) (setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))) (setq bar (org-google-weather "Montabaur" "DE")) (string= foo bar) (insert foo) (insert bar))
eval((let ((date (quote (6 6 2011)))) (setq foo (let ((org-google-weather-cache-time 0)) (org-google-weather "Montabaur" "DE"))) (setq bar (org-google-weather "Montabaur" "DE")) (string= foo bar) (insert foo) (insert bar)) nil)
eval-last-sexp-1(nil)
eval-last-sexp(nil)
call-interactively(eval-last-sexp nil nil)
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [OT] Icon problem with org-google-weather
2011-06-06 0:27 [OT] Icon problem with org-google-weather Nick Dokos
2011-06-06 7:38 ` Tassilo Horn
@ 2011-06-07 4:53 ` Nick Dokos
1 sibling, 0 replies; 7+ messages in thread
From: Nick Dokos @ 2011-06-07 4:53 UTC (permalink / raw)
Cc: nicholas.dokos, emacs-orgmode
Nick Dokos <nicholas.dokos@hp.com> wrote:
> This is off-topic but it is driving me bananas. I do
>
> (setq date '(6 5 2011))
> (6 5 2011)
> (setq foo (let ((org-google-weather-cache-time 0))
> (org-google-weather)))
> (setq bar (org-google-weather))
> (equal foo bar)
> (insert foo)
> (insert bar)
>
> in the *scratch* buffer. The idea is that foo is freshly obtained from
> google every time: it never goes to cached data since the cache time is
> set to 0. bar, otoh, is obtained from cache. I've traced the code and
> that's indeed what happens. The two strings compare equal: (equal foo bar)
> returns t - just in case, I also displayed them in separate windows and
> did a compare-windows: they are the same that way too.
>
> Nevertheless, when I insert foo, the icon is shown, but when I insert
> bar, the icon is an empty box. What am I missing?
>
It turns out that they *are* different after all: you can't see it in
text form, but when the cached file is read, I think some of the bytes get
combined into multibyte characters. It finally became visible when
I did string-to-list on the image data. Here is the patch to url-cache.el
that I'm running with currently - it seems to resolve the problem:
--8<---------------cut here---------------start------------->8---
diff -u ~/src/emacs/emacs.repo/emacs/lisp/url/url-cache.el url-cache.el
--- /home/nick/src/emacs/emacs.repo/emacs/lisp/url/url-cache.el 2011-03-14 10:54:14.596645931 -0400
+++ url-cache.el 2011-06-07 00:30:35.082826000 -0400
@@ -191,6 +191,7 @@
;;;###autoload
(defun url-cache-extract (fnam)
"Extract FNAM from the local disk cache."
+ (set-buffer-multibyte nil)
(erase-buffer)
(insert-file-contents-literally fnam))
--8<---------------cut here---------------end--------------->8---
Can somebody who knows about these things give a thumbs-up or -down on
this change? If thumbs-down, how should it be fixed?
Thanks,
Nick
PS I must say this was no fun at all.
PPS I posted the original question and this result to the emacs list as well.
^ permalink raw reply [flat|nested] 7+ messages in thread