Permalink
Browse files

Introduce the limit of number of icons being stored persistently.

* twittering-mode.el: Introduce the limit of number of
icons being stored persistently.
(twittering-icon-storage-file): add docstring about
`twittering-icon-storage-limit'.
(twittering-icon-storage-recent-icons): new variable to which
properties of recently rendered icons are stored.
(twittering-icon-storage-limit): new variable.
(twittering-update-icon-storage-recent-icons): new function.
(twittering-get-display-spec-for-icon): invoke
`twittering-update-icon-storage-recent-icons' whenever this
function is invoked.
(twittering-save-icon-properties): write properties of icons
within the limit specified by `twittering-icon-storage-limit'. In
addition, this function records properties in the new format.
(twittering-load-icon-properties): support the new format for
storing properties of icons.
  • Loading branch information...
1 parent 0e65299 commit 12e3b90ed95d128117f1a1c754367bd67aec3f85 @cvmat cvmat committed Feb 19, 2011
Showing with 120 additions and 33 deletions.
  1. +17 −0 ChangeLog
  2. +7 −4 NEWS
  3. +3 −0 NEWS.ja
  4. +93 −29 twittering-mode.el
View
@@ -14,6 +14,23 @@
(twittering-add-timeline-history): use
`twittering-add-to-history'.
+ * twittering-mode.el: Introduce the limit of number of
+ icons being stored persistently.
+ (twittering-icon-storage-file): add docstring about
+ `twittering-icon-storage-limit'.
+ (twittering-icon-storage-recent-icons): new variable to which
+ properties of recently rendered icons are stored.
+ (twittering-icon-storage-limit): new variable.
+ (twittering-update-icon-storage-recent-icons): new function.
+ (twittering-get-display-spec-for-icon): invoke
+ `twittering-update-icon-storage-recent-icons' whenever this
+ function is invoked.
+ (twittering-save-icon-properties): write properties of icons
+ within the limit specified by `twittering-icon-storage-limit'. In
+ addition, this function records properties in the new format.
+ (twittering-load-icon-properties): support the new format for
+ storing properties of icons.
+
2011-02-15 Tadashi MATSUO <tad@mymail.twin.jp>
* twittering-mode.el: Confirm validity of a format string before
View
11 NEWS
@@ -135,10 +135,13 @@
on a tweet, you can block its author.
* Support for persistent icon storage.
By "(setq twittering-use-icon-storage t)", you can save retrieved
- and resized icon images into a persistent storage. On next and later
- invocation, twittering-mode can display icons faster because the
- storage reduces time required to retrieve and resize images. In
- default, this function is disabled.
+ and resized icon images into a persistent storage, which is disabled
+ in default. On next and later invocation, twittering-mode can
+ display icons faster because the storage reduces time required to
+ retrieve and resize images.
+ In default, recently rendered 500 icons are stored at most. You can
+ change the limit by the variable `twittering-icon-storage-limit'. To
+ store all icons, configure the variable as nil.
The default storage file is `~/.twittering-mode-icons.gz'. You can
change it by changing `twittering-icon-storage-file'. Note that icon
images in the storage generated on a certain version of Emacs may be
View
@@ -142,6 +142,9 @@
この機能はデフォルトでは無効です。次回以降は専用ファイルに格納された
画像が優先的に使われますのでアイコン取得・サイズ変更にかかる時間が省
けます。
+ デフォルトでは直近に描画されたアイコンを最大500個まで保存します。保
+ 存されるアイコンの個数は変数`twittering-icon-storage-limit'で変更で
+ きます。この変数をnilに設定すると全てのアイコンが保存されます。
アイコンを保存するファイルはデフォルトでは
`~/.twittering-mode-icons.gz'ですが`twittering-icon-storage-file'と
いう変数で変更できます。あるバージョンのEmacsで生成したアイコン保存
View
@@ -4686,13 +4686,26 @@ NOTE: This API is rate limited.")
(defvar twittering-icon-storage-file
(expand-file-name "~/.twittering-mode-icons.gz")
- "*The file to which icon images are stored.")
+ "*The file to which icon images are stored.
+`twittering-icon-storage-limit' determines the number icons stored in the
+file.
+The file is loaded with `with-auto-compression-mode'.")
(defvar twittering-use-icon-storage nil
"*Whether to use the persistent icon storage.
If this variable is non-nil, icon images are stored to the file specified
by `twittering-icon-storage-file'.")
+(defvar twittering-icon-storage-recent-icons nil
+ "List of recently rendered icons.")
+
+(defvar twittering-icon-storage-limit 500
+ "*How many icons are stored in the persistent storage.
+If `twittering-use-icon-storage' is nil, this variable is ignored.
+If a positive integer N, `twittering-save-icon-properties' saves N icons that
+have been recently rendered.
+If nil, the function saves all icons.")
+
(defconst twittering-error-icon-data-pair
'(xpm . "/* XPM */
static char * yellow3_xpm[] = {
@@ -4718,11 +4731,25 @@ static char * yellow3_xpm[] = {
")
"Image used when the valid icon cannot be retrieved.")
+(defun twittering-update-icon-storage-recent-icons (size image-url spec)
+ (unless (null twittering-icon-storage-limit)
+ (let ((dummy-icon-properties (twittering-make-display-spec-for-icon
+ twittering-error-icon-data-pair)))
+ (unless (equal spec dummy-icon-properties)
+ (let ((history-delete-duplicates t))
+ (twittering-add-to-history 'twittering-icon-storage-recent-icons
+ (list size image-url)
+ twittering-icon-storage-limit))))))
+
(defun twittering-get-display-spec-for-icon (image-url)
(let ((hash
(gethash twittering-convert-fix-size twittering-icon-prop-hash)))
(when hash
- (gethash image-url hash))))
+ (let ((spec (gethash image-url hash))
+ (size twittering-convert-fix-size))
+ (when spec
+ (twittering-update-icon-storage-recent-icons size image-url spec)
+ spec)))))
(defun twittering-convert-image-data (image-data dest-type &optional src-type)
"Convert IMAGE-DATA into XPM format and return it. If it fails to convert,
@@ -4858,30 +4885,45 @@ image are displayed."
(defun twittering-save-icon-properties (&optional filename)
(let ((filename (or filename twittering-icon-storage-file))
- (dummy-icon-properties (twittering-make-display-spec-for-icon
- twittering-error-icon-data-pair)))
+ (stored-data
+ (cond
+ ((null twittering-icon-storage-limit)
+ (let ((result nil)
+ (dummy-icon-properties (twittering-make-display-spec-for-icon
+ twittering-error-icon-data-pair)))
+ (maphash
+ (lambda (size hash)
+ (maphash (lambda (url properties)
+ (unless (equal properties dummy-icon-properties)
+ (setq result (cons (cons size url) result))))
+ hash))
+ twittering-icon-prop-hash)
+ result))
+ (t
+ (reverse twittering-icon-storage-recent-icons)))))
(when (require 'jka-compr nil t)
(with-auto-compression-mode
(with-temp-file filename
- (insert "(")
- (maphash
- (lambda (size hash)
- (insert (format "(%d . (" size))
- (maphash (lambda (url properties)
- (unless (equal properties dummy-icon-properties)
- (insert "(")
- (prin1 url (current-buffer))
- (insert " . ")
- (prin1 properties (current-buffer))
- (insert ")")))
- hash)
- (insert "))"))
- twittering-icon-prop-hash)
- (insert ")"))))))
+ (insert "( 2 ")
+ (prin1 (cons 'emacs-version emacs-version) (current-buffer))
+ (insert "(icon-list ")
+ (mapc (lambda (entry)
+ (let* ((size (elt entry 0))
+ (url (elt entry 1))
+ (properties
+ (gethash url
+ (gethash size twittering-icon-prop-hash))))
+ (insert (format "(%d " size))
+ (prin1 url (current-buffer))
+ (insert " ")
+ (prin1 properties (current-buffer))
+ (insert ")\n")))
+ stored-data)
+ (insert "))"))))))
(defun twittering-load-icon-properties (&optional filename)
(let* ((filename (or filename twittering-icon-storage-file))
- (alist
+ (data
(with-temp-buffer
(condition-case err
(cond
@@ -4894,15 +4936,37 @@ image are displayed."
(error
(message "Failed to load icon images. %s" (cdr err))
nil)))))
- (mapc (lambda (entry)
- (let ((size (car entry))
- (prop-alist (cdr entry)))
- (mapc (lambda (entry)
- (let ((url (car entry))
- (properties (cdr entry)))
- (twittering-register-image-spec url properties size)))
- prop-alist)))
- alist)))
+ (cond
+ ((equal 2 (car data))
+ (let ((version (cdr (assq 'emacs-version data))))
+ (cond
+ ((or (equal version emacs-version)
+ (y-or-n-p
+ (format "%s is generated by Emacs %s! Use it?"
+ filename version)))
+ (mapc (lambda (entry)
+ (let ((size (elt entry 0))
+ (url (elt entry 1))
+ (properties (elt entry 2)))
+ (twittering-update-icon-storage-recent-icons size url
+ properties)
+ (twittering-register-image-spec url properties size)))
+ (cdr (assq 'icon-list data))))
+ (t
+ (message "Stopped loading icons")))))
+ (t
+ (mapc (lambda (entry)
+ (let ((size (car entry))
+ (prop-alist (cdr entry)))
+ (mapc (lambda (entry)
+ (let ((url (car entry))
+ (properties (cdr entry)))
+ (twittering-update-icon-storage-recent-icons
+ size url properties)
+ (twittering-register-image-spec url properties
+ size)))
+ prop-alist)))
+ data)))))
;;;;
;;;; Mode-line

0 comments on commit 12e3b90

Please sign in to comment.