From f6694b874ce8cfa5651eceffbdbd0076bda44b7e Mon Sep 17 00:00:00 2001 From: forcer Date: Wed, 7 Jun 2006 13:42:00 +0000 Subject: Cleaned up the cached code in emms.el a bit darcs-hash:20060607134238-2189f-208cd31323c69521084137e367d689cead44a6df.gz --- emms-cache.el | 11 +++++++++-- emms.el | 28 ++++++++++++++++++---------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/emms-cache.el b/emms-cache.el index dcda390..80cf820 100644 --- a/emms-cache.el +++ b/emms-cache.el @@ -32,6 +32,13 @@ ;; This code is activated by (emms-standard) and above. +;; To activate it by hand, use: + +;; (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) + ;;; Code: (define-hash-table-test 'string-hash 'string= 'sxhash) @@ -45,11 +52,11 @@ 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-get (path) +(defun emms-cache-get (type path) "Return a cache element for PATH, or nil." (gethash path emms-cache-db)) -(defun emms-cache-set (path track) +(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)) diff --git a/emms.el b/emms.el index 1070b23..ca04788 100644 --- a/emms.el +++ b/emms.el @@ -212,6 +212,18 @@ seconds the player did seek." :group 'emms :type 'hook) +(defcustom emms-cache-get-function nil + "A function to retrieve a track entry from the cache. +This is called with two arguments, the type and the name." + :group 'emms + :type 'function) + +(defvar emms-cache-set-function nil + "A function to add/set a track entry from the cache. +This is called with a single argument, the track." + :group 'emms + :type 'function) + (defvar emms-player-playing-p nil "The currently playing EMMS player, or nil.") @@ -223,11 +235,6 @@ seconds the player did seek." This can be used if the source depends on the current buffer not being the playlist buffer.") -(defvar emms-cache-get-function (lambda (path)) - "A function to retrieve a track entry from the cache.") -(defvar emms-cache-set-function (lambda (path track)) - "A function to add/set a track entry from the cache.") - ;;; User Interface @@ -458,13 +465,14 @@ whenever possible." (defun emms-track (type name) "Create an EMMS track with type TYPE and name NAME." - (let (track) - ;; we assume that name is unique across types, so type is not used - ;; if we find name in the cache - (unless (setq track (funcall emms-cache-get-function name)) + (let ((track (when emms-cache-get-function + (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)) + (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 ;; old (run-hook-with-args 'emms-track-initialize-functions track) -- cgit v1.2.3