2008-10-01

Let emms to remember the last directory

It causes a little trouble to me each time to find the target directory in directory when using the fantastic Emacs Multimedia System(emms), because I have to start to locate the target directory from the default directory which is specified in `emms-source-file-default-directory'(BTW, I bound the key `' to `emms-play-find').

So I'm wondering why not to make emms remember the last target directory? Then it's easy to switch other directories around the current targeted one(I tend to listen to albums with the same genre). So after digging into emms's source code, I changed the definition of `emms-play-find' a little(in fact that function is defined via a macro called `define-emms-source'):


;;;###autoload (autoload 'emms-play-find "emms-source-file" nil t)
;;;###autoload (autoload 'emms-add-find "emms-source-file" nil t)
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
(interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
emms-source-file-default-directory
emms-source-file-default-directory
t))
(regex (read-from-minibuffer "Find files matching: ")))
(setq emms-source-file-default-directory directory-name)
(list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))
(emms-playlist-insert-track
(emms-track 'file file))))
(emms-source-file-directory-tree dir regex)))


And that's it. After reloading emms, use `emms-play-find' to find a target directory, it simply remembers that directory which ease the next operation for me.

And here is the patch file:


--- /tmp/emms-3.0/emms-source-file.el 2007-06-30 00:16:24.000000000 +0800
+++ elisp/emms/emms-source-file.el 2008-10-01 14:14:40.000000000 +0800
@@ -150,12 +150,13 @@
(define-emms-source find (dir regex)
"An EMMS source that will find files in DIR or
`emms-source-file-default-directory' that match REGEX."
- (interactive (list
- (emms-read-directory-name "Find in directory: "
- emms-source-file-default-directory
- emms-source-file-default-directory
- t)
- (read-from-minibuffer "Find files matching: ")))
+ (interactive (let ((directory-name (emms-read-directory-name "Find in directory: "
+ emms-source-file-default-directory
+ emms-source-file-default-directory
+ t))
+ (regex (read-from-minibuffer "Find files matching: ")))
+ (setq emms-source-file-default-directory directory-name)
+ (list directory-name regex)))
(mapc (lambda (file)
(unless (let ((case-fold-search nil))
(string-match emms-source-file-exclude-regexp file))

1 条评论:

Luo Yang 说...

你们这些玩emacs的真nb……