Permalink
Browse files

Handling the case of not supported image type

* twittering-mode.el (twittering-make-display-spec-for-icon):
returns nil if the type of the image is not supported.
  • Loading branch information...
1 parent e939305 commit 7423c6f53aa30e3fa9560e0df25e7fd892d79fcf @hayamiz committed Jan 8, 2010
Showing with 26 additions and 19 deletions.
  1. +3 −0 ChangeLog
  2. +23 −19 twittering-mode.el
View
@@ -8,6 +8,9 @@
(twittering-status-not-blank-p): bug fix: return nil if a status
is ended by '@foo'.
+ * twittering-mode.el (twittering-make-display-spec-for-icon):
+ returns nil if the type of the image is not supported.
+
2010-01-09 Satoshi Yatagawa <yata_github@y.hauN.org>
* twittering-mode.el (twittering-status-to-status-datum): Change
View
@@ -1585,31 +1585,34 @@ If STATUS-DATUM is already in DATA-VAR, return nil. If not, return t."
))
(defun twittering-make-display-spec-for-icon (image-url)
- "Return the specification for `display' text property, which limits
-the size of an icon image IMAGE-URL up to FIXED-LENGTH.
+ "Return the specification for `display' text property, which
+limits the size of an icon image IMAGE-URL up to FIXED-LENGTH. If
+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))
(image-spec
`(image :type ,(car image-data)
:data ,(cdr image-data))))
- (if (and twittering-convert-fix-size (not twittering-use-convert))
- (let* ((size (if (cdr image-data)
- (image-size image-spec t)
- '(48 . 48)))
- (width (car size))
- (height (cdr size))
- (fixed-length twittering-convert-fix-size)
- (half-fixed-length (/ fixed-length 2))
- (slice-spec
- (if (or (< fixed-length width) (< fixed-length height))
- `(slice ,(max 0 (- (/ width 2) half-fixed-length))
- ,(max 0 (- (/ height 2) half-fixed-length))
- ,fixed-length ,fixed-length)
- `(slice 0 0 ,fixed-length ,fixed-length))))
- `(display (,image-spec ,slice-spec)))
- `(display ,image-spec))))
+ (if (not (image-type-available-p (car image-data)))
+ nil
+ (if (and twittering-convert-fix-size (not twittering-use-convert))
+ (let* ((size (if (cdr image-data)
+ (image-size image-spec t)
+ '(48 . 48)))
+ (width (car size))
+ (height (cdr size))
+ (fixed-length twittering-convert-fix-size)
+ (half-fixed-length (/ fixed-length 2))
+ (slice-spec
+ (if (or (< fixed-length width) (< fixed-length height))
+ `(slice ,(max 0 (- (/ width 2) half-fixed-length))
+ ,(max 0 (- (/ height 2) half-fixed-length))
+ ,fixed-length ,fixed-length)
+ `(slice 0 0 ,fixed-length ,fixed-length))))
+ `(display (,image-spec ,slice-spec)))
+ `(display ,image-spec)))))
(defun twittering-format-string (string prefix replacement-table)
"Format STRING according to PREFIX and REPLACEMENT-TABLE.
@@ -1690,7 +1693,8 @@ following symbols;
(when (and icon-string twittering-icon-mode)
(let ((display-spec
(twittering-make-display-spec-for-icon profile-image-url)))
- (set-text-properties 1 2 display-spec icon-string))
+ (when display-spec
+ (set-text-properties 1 2 display-spec icon-string)))
icon-string)
))
(make-string-with-url-property

0 comments on commit 7423c6f

Please sign in to comment.