Skip to content

Commit

Permalink
(twittering-image-type): don't use the external command 'file' becaus…
Browse files Browse the repository at this point in the history
…e Emacs can display only an image which is recongnized by 'image-type-from-data'.

(twittering-retrieve-image): don't look up 'twittering-image-data-table' here.
(twittering-make-display-spec-for-icon): call 'twittering-retrieve-image' only when 'gethash' returns nil.
  • Loading branch information
yata committed Feb 25, 2010
1 parent 69fd73d commit 60e32ad
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 65 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Expand Up @@ -21,6 +21,14 @@
`url-show-status' locally to inhibit showing a progress message.
(twittering-tinyurl-get): Likewise.

* twittering-mode.el (twittering-image-type): Don't use the
external command `file' because Emacs can display only an image
which is recongnized by `image-type-from-data'.
(twittering-retrieve-image): Don't look up
`twittering-image-data-table' here.
(twittering-make-display-spec-for-icon): Call
`twittering-retrieve-image' only when `gethash' returns nil.

2010-02-22 Satoshi Yatagawa <yata_github@y.hauN.org>

* twittering-mode.el (twittering-atom-xmltree-to-status-datum):
Expand Down
110 changes: 45 additions & 65 deletions twittering-mode.el
Expand Up @@ -363,28 +363,7 @@ and its contents (BUFFER)"
(case-fold-search t))
(if type-cache
(cdr type-cache)
(let ((image-type
(cond
((image-type-from-data (buffer-string)))
((executable-find "file")
(with-temp-buffer
(let ((res-buf (current-buffer)))
(save-excursion
(set-buffer buffer)
(call-process-region (point-min) (point-max)
(executable-find "file")
nil res-buf nil "-b" "-")))
(let ((file-output (buffer-string)))
(cond
((string-match "JPEG" file-output) 'jpeg)
((string-match "PNG" file-output) 'png)
((string-match "GIF" file-output) 'gif)
((string-match "bitmap" file-output) 'bitmap)
(t nil)))))
((string-match "\\.jpe?g\\(\\?[^/]+\\)?$" image-url) 'jpeg)
((string-match "\\.png\\(\\?[^/]+\\)?$" image-url) 'png)
((string-match "\\.gif\\(\\?[^/]+\\)?$" image-url) 'gif)
(t nil))))
(let ((image-type (image-type-from-data (buffer-string))))
(add-to-list 'twittering-image-type-cache `(,image-url . ,image-type))
image-type))))

Expand Down Expand Up @@ -2306,7 +2285,9 @@ the type of the image is not supported, nil is returned.
If the size of the image exceeds FIXED-LENGTH, the center of the
image are displayed."
(let ((image-data (twittering-retrieve-image image-url)))
(let ((image-data (or (gethash `(,image-url . ,twittering-convert-fix-size)
twittering-image-data-table)
(twittering-retrieve-image image-url))))
(and image-data (image-type-available-p (car image-data))
(let ((image-spec
`(image :type ,(car image-data)
Expand Down Expand Up @@ -2747,48 +2728,47 @@ variable `twittering-status-format'."
(error "%s has not been supported yet" type))))))

(defun twittering-retrieve-image (image-url)
(or (gethash `(,image-url . ,twittering-convert-fix-size)
twittering-image-data-table)
(with-temp-buffer
(set-buffer-multibyte nil)
(let ((coding-system-for-read 'binary)
(coding-system-for-write 'binary)
(url-show-status nil)
(require-final-newline nil))
(url-insert-file-contents image-url)
(let ((image-type (twittering-image-type image-url (current-buffer)))
(converted-image-size
`(,twittering-convert-fix-size
. ,twittering-convert-fix-size)))
(and (and twittering-convert-fix-size twittering-use-convert
(or (eq 'bitmap image-type)
(not (and (image-type-available-p image-type)
(let ((image-spec
`(image :type ,image-type
:data ,(buffer-string))))
(equal (image-size image-spec t)
converted-image-size))))))
(let ((exit-status
(call-process-region
(point-min) (point-max)
twittering-convert-program
t t nil
(if image-type (format "%s:-" image-type) "-")
"-resize"
(format "%dx%d" twittering-convert-fix-size
twittering-convert-fix-size)
"xpm:-")))
(setq image-type (and (integerp exit-status)
(= 0 exit-status)
'xpm))))
(if image-type
(let ((image-data `(,image-type . ,(buffer-string))))
(puthash `(,image-url . ,twittering-convert-fix-size)
image-data
twittering-image-data-table)
image-data)
nil))))
nil))
(with-temp-buffer
(set-buffer-multibyte nil)
(let ((coding-system-for-read 'binary)
(coding-system-for-write 'binary)
(url-show-status nil)
(require-final-newline nil))
(url-insert-file-contents image-url)
(let ((image-type (twittering-image-type image-url (current-buffer))))
(and twittering-use-convert
(or (not (image-type-available-p image-type))
(and (integerp twittering-convert-fix-size)
(not (let ((image-spec
`(image :type ,image-type
:data ,(buffer-string)))
(converted-image-size
`(,twittering-convert-fix-size
. ,twittering-convert-fix-size)))
(equal (image-size image-spec t)
converted-image-size)))))
(let ((exit-status
(call-process-region
(point-min) (point-max)
twittering-convert-program
t t nil
(if image-type (format "%s:-" image-type) "-")
(when (integerp twittering-convert-fix-size)
"-resize")
(when (integerp twittering-convert-fix-size)
(format "%dx%d" twittering-convert-fix-size
twittering-convert-fix-size))
"xpm:-")))
(setq image-type (and (integerp exit-status)
(= 0 exit-status)
'xpm))))
(if image-type
(let ((image-data `(,image-type . ,(buffer-string))))
(puthash `(,image-url . ,twittering-convert-fix-size)
image-data
twittering-image-data-table)
image-data)
nil)))))

(defun twittering-tinyurl-get (longurl)
"Tinyfy LONGURL."
Expand Down

0 comments on commit 60e32ad

Please sign in to comment.