diff options
author | Yoni Rabkin <yoni@rabkins.net> | 2020-01-15 16:07:02 -0500 |
---|---|---|
committer | Yoni Rabkin <yoni@rabkins.net> | 2020-01-15 16:07:02 -0500 |
commit | 3cf79f88bcb5204ca74d0e576780f535d96f5bf2 (patch) | |
tree | 306b83cff855557413cb1ff59bc390ba5edd3263 | |
parent | eedd61d9639de043933293b662a148d57d2f8a2f (diff) |
* lisp/emms-source-file.el: guess the directory
Try to guess the directory if the adding a file is called over a 'file
type track-at-point.
-rw-r--r-- | lisp/emms-source-file.el | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lisp/emms-source-file.el b/lisp/emms-source-file.el index d2ac164..2be6538 100644 --- a/lisp/emms-source-file.el +++ b/lisp/emms-source-file.el @@ -88,12 +88,28 @@ in code." :type 'string :group 'emms-source-file) +(defcustom emms-source-file-directory-hint-p t + "*When non-nil, guess the directory based on a track at point." + :type 'boolean + :group 'emms-source-file) + ;; The `read-directory-name' function is not available in Emacs 21. (defalias 'emms-read-directory-name (if (fboundp 'read-directory-name) #'read-directory-name #'read-file-name)) +(defun emms-source-file-directory-hint () + (if (and emms-source-file-directory-hint-p + emms-playlist-buffer-p + (emms-playlist-track-at)) + (let ((name (emms-track-get (emms-playlist-track-at) 'name)) + (type (emms-track-get (emms-playlist-track-at) 'type))) + (when (eq type 'file) + (file-name-directory name))) + emms-source-file-default-directory)) + + ;;; Sources ;;;###autoload (autoload 'emms-play-file "emms-source-file" nil t) @@ -102,7 +118,7 @@ in code." "An EMMS source for a single file - either FILE, or queried from the user." (interactive (list (read-file-name "Play file: " - emms-source-file-default-directory + (emms-source-file-directory-hint) emms-source-file-default-directory t))) (if (file-directory-p file) @@ -117,7 +133,7 @@ user." from the user." (interactive (list (emms-read-directory-name "Play directory: " - emms-source-file-default-directory + (emms-source-file-directory-hint) emms-source-file-default-directory t))) (mapc (lambda (file) @@ -135,7 +151,7 @@ from the user." value of `emms-source-file-default-directory'." (interactive (list (emms-read-directory-name "Play directory tree: " - emms-source-file-default-directory + (emms-source-file-directory-hint) emms-source-file-default-directory t))) (let ((files (emms-source-file-directory-tree (expand-file-name dir) |