From 84acadce0e7916d1dd95a80aa69e57752ec80615 Mon Sep 17 00:00:00 2001 From: forcer Date: Wed, 7 Jun 2006 16:10:00 +0000 Subject: Mark the cache as dirty for each modification. darcs-hash:20060607161049-2189f-293b55878f4a073640a397e4b2aa563c3bf785d6.gz --- emms-cache.el | 7 ++++++- emms-info.el | 1 - emms-setup.el | 3 ++- emms.el | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/emms-cache.el b/emms-cache.el index be6c7ae..2366075 100644 --- a/emms-cache.el +++ b/emms-cache.el @@ -38,6 +38,7 @@ ;; (add-hook 'kill-emacs-hook 'emms-cache-save) ;; (setq emms-cache-get-function 'emms-cache-get) ;; (setq emms-cache-set-function 'emms-cache-set) +;; (setq emms-cache-modified-function 'emms-cache-dirty) ;;; Code: @@ -52,6 +53,10 @@ This is used to cache over emacs sessions.") (defvar emms-cache-dirty nil "True if the cache has been updated since init.") +(defun emms-cache-dirty (&rest ignored) + "Mark the cache as dirty." + (setq emms-cache-dirty t)) + (defun emms-cache-get (type path) "Return a cache element for PATH, or nil." (gethash path emms-cache-db)) @@ -59,7 +64,7 @@ This is used to cache over emacs sessions.") (defun emms-cache-set (type path track) "Set PATH to TRACK in the cache." (puthash path track emms-cache-db) - (setq emms-cache-dirty t)) + (emms-cache-dirty)) (defun emms-cache-save () "Save the track cache to a file." diff --git a/emms-info.el b/emms-info.el index 0edeb85..a1cdaa0 100644 --- a/emms-info.el +++ b/emms-info.el @@ -90,7 +90,6 @@ Return t when the track got changed." (run-hook-with-args 'emms-info-functions track) ;; not set by info functions (emms-track-set track 'info-mtime file-mtime) - (funcall emms-cache-set-function name track) (emms-track-updated track)) (when emms-info-asynchronously diff --git a/emms-setup.el b/emms-setup.el index e520662..b99e237 100644 --- a/emms-setup.el +++ b/emms-setup.el @@ -85,7 +85,8 @@ audio files, and a metadata cache." (add-hook 'after-init-hook 'emms-cache-restore) (add-hook 'kill-emacs-hook 'emms-cache-save) (setq emms-cache-get-function 'emms-cache-get) - (setq emms-cache-set-function 'emms-cache-set)) + (setq emms-cache-set-function 'emms-cache-set) + (setq emms-cache-modified-function 'emms-cache-dirty)) ;;;###autoload (defun emms-all () diff --git a/emms.el b/emms.el index 7af7176..1459b2b 100644 --- a/emms.el +++ b/emms.el @@ -224,6 +224,12 @@ This is called with a single argument, the track." :group 'emms :type 'function) +(defcustom emms-cache-modified-function nil + "A function to be called when a track is modified. +The modified track is passed as the argument to this function." + :group 'emms + :type 'function) + (defvar emms-player-playing-p nil "The currently playing EMMS player, or nil.") @@ -469,8 +475,10 @@ whenever possible." (funcall emms-cache-get-function type name)))) (when (not track) (setq track (emms-dictionary '*track*)) - (emms-track-set track 'type type) - (emms-track-set track 'name name) + ;; Prevent the cache from being called for these two sets + (let ((emms-cache-modified-function nil)) + (emms-track-set track 'type type) + (emms-track-set track 'name name)) (when emms-cache-set-function (funcall emms-cache-set-function type name track))) ;; run any hooks regardless of a cache hit, as the entry may be @@ -493,7 +501,9 @@ If there is no value, return DEFAULT (or nil, if not given)." (defun emms-track-set (track name value) "Set the value of NAME for TRACK to VALUE." - (emms-dictionary-set track name value)) + (emms-dictionary-set track name value) + (when emms-cache-modified-function + (funcall emms-cache-modified-function track))) (defun emms-track-description (track) "Return a description of TRACK. -- cgit v1.2.3