From 7e45986db1b541e9e3c34394d856ee3780ad51bd Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 5 Jun 2006 16:33:00 +0000 Subject: info-cache-dirty/coding * mark the info cache as dirty when it's modified, so we don't have to write it out all the time * save the cache as mule-utf-8 - comments? i'm not sure if this is correct darcs-hash:20060605163339-4e3e3-35731daf2d74d73bb6f776ad29de3f4cbe5d3529.gz --- emms-info.el | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/emms-info.el b/emms-info.el index 22f2685..ab48b45 100644 --- a/emms-info.el +++ b/emms-info.el @@ -91,6 +91,9 @@ This is used to cache file info over emacs sessions.") (defvar emms-info-cache-file "~/.emms-cache" "A file used to store cached file info information over sessions") +(defvar emms-info-cache-dirty nil + "True if the cache has been updated since init.") + (defun emms-info-initialize-track (track) "Initialize TRACK with emms-info information. This is a suitable value for `emms-track-initialize-functions'." @@ -127,9 +130,10 @@ Return t when the track got changed." (emms-track-set track 'info-mtime file-mtime) (emms-track-updated track) - (if (or (not cached-track) + (when (or (not cached-track) updated) - (puthash name track emms-info-cache)) + (puthash name track emms-info-cache) + (setq emms-info-cache-dirty t)) (when emms-info-asynchronously (setq emms-info-asynchronous-tracks (1- emms-info-asynchronous-tracks)) @@ -139,18 +143,24 @@ Return t when the track got changed." (defun emms-info-cache-save () "Save the info cache to a file." - (set-buffer (get-buffer-create " emms-info-cache ")) - (erase-buffer) - (maphash (lambda (k v) - (insert (format - "(puthash %S '%S emms-info-cache)\n" k v))) - emms-info-cache) - (write-region (point-min) (point-max) emms-info-cache-file) - (kill-buffer (current-buffer))) + (when emms-info-cache-dirty + (message "Saving emms info cache...") + (set-buffer (get-buffer-create " emms-info-cache ")) + (erase-buffer) + (maphash (lambda (k v) + (insert (format + "(puthash %S '%S emms-info-cache)\n" k v))) + emms-info-cache) + (set-buffer-file-coding-system 'mule-utf-8) + (write-region (point-min) (point-max) emms-info-cache-file) + (kill-buffer (current-buffer)) + (message "Saving emms info cache...done") + (setq emms-info-cache-dirty nil))) (defun emms-info-cache-restore () "Restore the info cache from a file." - (load emms-info-cache-file t nil t)) + (load emms-info-cache-file t nil t) + (setq emms-info-cache-dirty nil)) (defun emms-info-track-file-mtime (track) "Return the mtime of the file of TRACK, if any. -- cgit v1.2.3