aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-cache.el46
-rw-r--r--emms-setup.el6
-rw-r--r--emms.el3
3 files changed, 46 insertions, 9 deletions
diff --git a/emms-cache.el b/emms-cache.el
index 60b3b24..dba9fcf 100644
--- a/emms-cache.el
+++ b/emms-cache.el
@@ -49,12 +49,52 @@
"A mapping of paths to file info.
This is used to cache over emacs sessions.")
-(defvar emms-cache-file "~/.emms-cache"
- "A file used to store cached file info information over sessions")
-
(defvar emms-cache-dirty nil
"True if the cache has been updated since init.")
+(defcustom emms-cache-file "~/.emms-cache"
+ "A file used to store cached file information over sessions."
+ :group 'emms
+ :type 'file)
+
+(defun emms-cache (arg)
+ "Turn on Emms caching if ARG is positive, off otherwise."
+ (interactive "p")
+ (if (and arg (> arg 0))
+ (progn
+ (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-modified-function 'emms-cache-dirty))
+ (remove-hook 'after-init-hook 'emms-cache-restore)
+ (remove-hook 'kill-emacs-hook 'emms-cache-save)
+ (setq emms-cache-get-function nil)
+ (setq emms-cache-set-function nil)
+ (setq emms-cache-modified-function nil)))
+
+;;;###autoload
+(defun emms-cache-enable ()
+ "Enable caching of Emms track data."
+ (interactive)
+ (emms-cache 1)
+ (message "Emms cache enabled"))
+
+;;;###autoload
+(defun emms-cache-disable ()
+ "Disable caching of Emms track data."
+ (interactive)
+ (emms-cache -1)
+ (message "Emms cache disabled"))
+
+;;;###autoload
+(defun emms-cache-toggle ()
+ "Toggle caching of Emms track data."
+ (interactive)
+ (if emms-cache-get-function
+ (emms-cache-disable)
+ (emms-cache-enable)))
+
(defun emms-cache-dirty (&rest ignored)
"Mark the cache as dirty."
(setq emms-cache-dirty t))
diff --git a/emms-setup.el b/emms-setup.el
index b3f8313..dc55b36 100644
--- a/emms-setup.el
+++ b/emms-setup.el
@@ -84,11 +84,7 @@ audio files, and a metadata cache."
(add-to-list 'emms-info-functions 'emms-info-mp3info)
(add-to-list 'emms-info-functions 'emms-info-ogginfo)
(setq emms-track-description-function 'emms-info-track-description)
- (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-modified-function 'emms-cache-dirty))
+ (emms-cache 1))
;;;###autoload
(defun emms-all ()
diff --git a/emms.el b/emms.el
index f818343..e2f2fa3 100644
--- a/emms.el
+++ b/emms.el
@@ -222,7 +222,8 @@ This is called with two arguments, the type and the name."
(defcustom 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."
+This is called with three arguments: the type of the track, the
+name of the track, and the track itself."
:group 'emms
:type 'function)