branch: externals/emms commit e3824b81b11ac71b9bb0993a3a3d3647b923a377 Author: Yoni Rabkin <y...@gnu.org> Commit: Yoni Rabkin <y...@gnu.org>
* emms-tag-editor.el: replace strings in filename when renaming `emms-tag-editor-rename-alist' will control how strings are replaced in a file which is being renamed. --- doc/emms.texinfo | 8 +++++++- emms-tag-editor.el | 48 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/doc/emms.texinfo b/doc/emms.texinfo index 1730de33d6..09795fa830 100644 --- a/doc/emms.texinfo +++ b/doc/emms.texinfo @@ -3381,7 +3381,6 @@ variable. @end defvr @heading Renaming Files - The tag editor is also capable to rename the file of the track at point or all files of the marked tracks according to the value this variable. @@ -3399,6 +3398,13 @@ The default value is "%a - %l - %n - %t", so that files are named after renaming. @end defopt +@defopt emms-tag-editor-file-rename-alist +For each pair in this alist, the first string will replaced by the +second. This can be used to replace filename elements, spaces, or +other unwanted strings or characters automatically whenever renaming a +file. +@end defopt + To perform the renaming put point on the track you want to rename or mark some tracks. Then hit @kbd{R} which calls this function: diff --git a/emms-tag-editor.el b/emms-tag-editor.el index 401bca7274..a294948646 100644 --- a/emms-tag-editor.el +++ b/emms-tag-editor.el @@ -343,6 +343,16 @@ program for writing tags to the specified track or tracks." "Major mode to edit track tags. \\{emms-tag-editor-mode-map}") +(defvar emms-tag-editor-file-rename-alist + '(("/" "⁄") ;; avoid characters reserved for filenames + ;; (" " "_") ;; example of another substitution + ) + "Alist with replacement pairs for filename renaming. + +For each pair the first element is the string to be replaced, and the +second element is the replacement string.") + + (defun emms-tag-editor-set-all (tag value) "Set TAG to VALUE in all tracks. If transient-mark-mode is turned on, you can apply the command to @@ -487,21 +497,21 @@ C-u M-x emms-tag-editor-guess-tag-filename RET (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map "\C-h" - (lambda () - (interactive) - (with-output-to-temp-buffer "*Help*" - (princ - "A pattern is a string like \"%a-%t-%y\" which stand for + (lambda () + (interactive) + (with-output-to-temp-buffer "*Help*" + (princ + "A pattern is a string like \"%a-%t-%y\" which stand for the file name is constructed by artist, title, year with seperator '-'. see `emms-tag-editor-compile-pattern' for detail about pattern syntax. Available tags are: ") - (mapc (lambda (tag) - (princ (format "\t%s - %S\n" (cdr tag) (car tag)))) - emms-tag-editor-tags) - (with-current-buffer standard-output - (help-mode))))) + (mapc (lambda (tag) + (princ (format "\t%s - %S\n" (cdr tag) (car tag)))) + emms-tag-editor-tags) + (with-current-buffer standard-output + (help-mode))))) map)) current-prefix-arg)) (setq pattern (emms-tag-editor-compile-pattern pattern)) @@ -775,6 +785,18 @@ tracks according to the value of (emms-tag-editor-rename-marked-tracks) (emms-tag-editor-rename-track (emms-tag-editor-track-at)))) +(defun emms-tag-editor-filename-replace-strings (str) + "Replace substrings of STR and then return STR. + +Replacement is done according to `emms-tag-editor-file-rename-alist'." + (mapc + (lambda (pair) + (let ((from (car pair)) + (to (cadr pair))) + (setq str (string-replace from to str)))) + emms-tag-editor-file-rename-alist) + str) + (defun emms-tag-editor-rename-track (track &optional dont-apply) "Rename TRACK's file according `emms-tag-editor-rename-format's value. @@ -795,8 +817,10 @@ Then it's the callers job to apply them afterwards with (mapcar (lambda (tag) (list (string-to-char (cdr tag)) - (or (emms-track-get track (car tag)) - ""))) + (let ((filename-element (emms-track-get track (car tag)))) + (if filename-element + (emms-tag-editor-filename-replace-strings filename-element) + "")))) emms-tag-editor-tags)))) "." suffix))) (emms-track-set track 'newname new-file)