From: bg66 Date: Fri, 24 Nov 2006 05:09:01 +0000 (+0000) Subject: * mixi.el (mixi-directory): Rename from `mixi-cache-directory'. X-Git-Tag: cache-file-mergepoint~3 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7ccf327805b52cf30f97d5e0654d0abff4b6db7;p=elisp%2Fmixi.git * mixi.el (mixi-directory): Rename from `mixi-cache-directory'. (mixi-cache-regexp): New regexp. (mixi-save-cache): New function. (mixi-read-cache): Ditto. (mixi-load-cache): Ditto. --- diff --git a/ChangeLog b/ChangeLog index ede17ef..5138b05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2006-11-24 OHASHI Akira + * mixi.el (mixi-directory): Rename from `mixi-cache-directory'. + (mixi-cache-regexp): New regexp. + (mixi-save-cache): New function. + (mixi-read-cache): Ditto. + (mixi-load-cache): Ditto. + +2006-11-24 OHASHI Akira + * mixi.el (mixi-retrieve): New macro. (mixi-retrieve-1): Use it. (mixi-login): Ditto. diff --git a/mixi.el b/mixi.el index 23e774a..f90c783 100644 --- a/mixi.el +++ b/mixi.el @@ -116,6 +116,11 @@ :type 'string :group 'mixi) +(defcustom mixi-directory (expand-file-name "~/.mixi") + "*Where to look for mixi files." + :type 'directory + :group 'mixi) + (defcustom mixi-coding-system 'euc-jp "*Coding system for mixi." :type 'coding-system @@ -190,11 +195,6 @@ Increase this value when unexpected error frequently occurs." :type 'boolean :group 'mixi) -(defcustom mixi-cache-directory (expand-file-name "~/.mixi") - "*Where to look for cache files." - :type 'directory - :group 'mixi) - (defvar mixi-me nil) ;; Utilities. @@ -441,6 +441,77 @@ Increase this value when unexpected error frequently occurs." cache (puthash key value table)))) +(defconst mixi-cache-regexp "mixi-.*-cache") + +(defun mixi-save-cache () + (unless (file-directory-p mixi-directory) + (make-directory mixi-directory t)) + (let ((caches (apropos-internal mixi-cache-regexp 'boundp))) + (mapc (lambda (symbol) + (with-temp-file (expand-file-name (symbol-name symbol) + mixi-directory) + (let ((coding-system-for-write mixi-coding-system) + (cache (default-value symbol))) + (insert "#s(hash-table size " + (number-to-string (hash-table-count cache)) + " test equal data (\n") + (maphash + (lambda (key value) + (let (print-level print-length) + (insert (prin1-to-string key) " " + (prin1-to-string value) "\n"))) + cache)) + (insert "))"))) + caches))) + +;; stolen (and modified) from lsdb.el +(defun mixi-read-cache (&optional marker) + "Read one Lisp expression as text from MARKER, return as Lisp object." + (save-excursion + (goto-char marker) + (if (looking-at "^#s(") + (let ((end-marker + (progn + (forward-char 2);skip "#s" + (forward-sexp);move to the left paren + (point-marker)))) + (with-temp-buffer + (buffer-disable-undo) + (insert-buffer-substring (marker-buffer marker) + marker end-marker) + (goto-char (point-min)) + (delete-char 2) + (let ((object (read (current-buffer))) + hash-table data) + (if (eq 'hash-table (car object)) + (progn + (setq hash-table + (make-hash-table + :size (plist-get (cdr object) 'size) + :test 'equal) + data (plist-get (cdr object) 'data)) + (while data + (puthash (pop data) (pop data) hash-table)) + hash-table) + object)))) + (read marker)))) + +(defun mixi-load-cache () + (when (file-directory-p mixi-directory) + (let ((files (directory-files mixi-directory nil mixi-cache-regexp))) + (mapc (lambda (file) + (let ((buffer (find-file-noselect (expand-file-name + file mixi-directory)))) + (unwind-protect + (save-excursion + (set-buffer buffer) + (goto-char (point-min)) + (re-search-forward "^#s(") + (goto-char (match-beginning 0)) + (set (intern file) (mixi-read-cache (point-marker)))) + (kill-buffer buffer)))) + files)))) + ;; Object. (defconst mixi-object-prefix "mixi-")