1 ;;; eh-emms.el --- Tumashu's emacs configuation -*- lexical-binding: t; -*-
4 ;; Copyright (c) 2011-2019, Feng Shu
6 ;; Author: Feng Shu <tumashu@163.com>
7 ;; URL: https://github.com/tumashu/emacs-helper
10 ;; This file is not part of GNU Emacs.
14 ;; This program is free software; you can redistribute it and/or
15 ;; modify it under the terms of the GNU General Public License
16 ;; as published by the Free Software Foundation; either version 3
17 ;; of the License, or (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
32 ;; 这个文件是tumashu个人专用的emacs配置文件,emacs中文用户可以参考。
39 (require 'emms-info-exiftool
)
40 (require 'emms-info-native
)
41 (require 'emms-browser
)
44 (emms-default-players)
47 (global-set-key (kbd "<f12>") 'emms-smart-browse
)
48 (global-set-key (kbd "<f11>") 'emms-next
)
49 (global-set-key (kbd "<f10>") 'emms-pause
)
52 (define-key emms-playlist-mode-map
(kbd "=") 'emms-volume-raise
)
53 (define-key emms-browser-mode-map
(kbd "=") 'emms-volume-raise
)
55 (setq emms-directory
(concat user-emacs-directory
"emms"))
57 (setq emms-source-file-default-directory
58 (or emms-source-file-default-directory
59 (concat (file-name-as-directory emms-directory
) "music")))
61 (when (file-writable-p "~")
62 (unless (file-directory-p emms-directory
)
64 (file-name-as-directory emms-directory
) t
))
66 (unless (file-directory-p emms-source-file-default-directory
)
68 (file-name-as-directory
69 emms-source-file-default-directory
)
72 ;; 设定EMMS主模式为 Playlist 模式
73 (setq emms-playlist-default-major-mode
'emms-playlist-mode
)
76 (setq emms-player-next-function
'emms-next-noerror
)
79 (add-to-list 'emms-track-initialize-functions
80 'emms-info-initialize-track
)
83 (setq emms-info-asynchronously nil
)
86 (setq emms-repeat-playlist t
)
88 ;; 排序方法: 艺术家 -> 专辑 -> 序号
89 (setq emms-playlist-sort-function
90 'emms-playlist-sort-by-natural-order
)
92 ;; 在 minibuffer 中显示播放信息 (emms-show)
93 (setq emms-show-format
"正在播放:%s")
94 (add-hook 'emms-player-started-hook
#'emms-show
)
96 ;; 不在 mode-line 中显示播放信息
97 (require 'emms-mode-line
)
98 (emms-mode-line-mode -
1)
101 (setq emms-track-description-function
102 #'eh-emms-track-simple-description
)
104 (defun eh-emms-track-simple-description (track)
105 (let* ((type (emms-track-type track
))
106 (string (cond ((eq 'file type
)
107 (emms-track-name track
))
109 (emms-format-url-track-name (emms-track-name track
)))
110 (t (concat (symbol-name type
)
111 ": " (emms-track-name track
))))))
113 (insert (concat " ♪ " string
))
114 (eh-emms-wash-buffer)
118 (defvar eh-emms-wash-config nil
)
120 (defun eh-emms-wash-buffer ()
121 (dolist (x eh-emms-wash-config
)
122 (goto-char (point-min))
123 (while (re-search-forward
126 (regexp-quote (nth 0 x
)))
128 (replace-match (propertize (nth 1 x
) 'face
(text-properties-at (point))) nil t
))))
130 (defun eh-emms-wash-config ()
132 (let ((str1 (read-string "请输入需清洗的字符串:"))
133 (str2 (read-string "请输入清洗成的字符串:"))
134 (regexp-p (y-or-n-p "是否将待清洗的字符串作为 regexp 处理? ")))
135 (when (> (length str1
) 0)
136 (push (list str1 str2 regexp-p
) eh-emms-wash-config
))
137 (customize-save-variable
139 (delete-dups eh-emms-wash-config
))
140 (with-current-emms-playlist
141 (eh-emms-wash-buffer))))
144 (require 'emms-lyrics
)
148 ;; 1. emms-info-exiftool 使用 perl 程序 exiftool, 速度比较慢但兼容性很好。
149 ;; 2. emms-info-native 是用 elisp 实现的,安装比较省事,速度还可以。
151 ;; (setq emms-info-functions '(emms-info-exiftool))
152 (setq emms-info-functions
'(eh-emms-info-native))
154 (defun eh-emms-info-native (track)
155 (let ((file (emms-track-name track
)))
157 (emms-info-native track
)
158 (error (message "EMMS: 无法从 %S 中读取音乐信息." file
)))))
161 (setq emms-last-played-format-alist
162 '(((emms-last-played-seconds-today) .
"%H:%M")
164 ((emms-last-played-seconds-month) .
"%d")
165 ((emms-last-played-seconds-year) .
"%m-%d")
168 ;; 设置 EMMS 浏览器, 默认显示方式为: 显示所有
169 (emms-browser-set-filter (assoc "EVERYTHING" emms-browser-filters
))
172 (emms-browser-make-filter "EVERYTHING" 'ignore
)
175 (emms-browser-make-filter
177 (emms-browser-filter-only-type 'file
))
180 (emms-browser-make-filter
182 (emms-browser-filter-only-recent 7))
184 ;; filter: 最近一个月都没有播放的
185 (emms-browser-make-filter
186 "LAST-MONTH-NOT-PLAYED"
188 (not (funcall (emms-browser-filter-only-recent 30) track
))))
190 ;; 设置 emms browser 和 playlist 中音乐的显示格式
192 (defun eh-emms-browser-format-line (orig_func bdata
&optional target
)
193 (let* ((type (emms-browser-bdata-type bdata
))
194 (level (emms-browser-bdata-level bdata
))
195 (indent (emms-browser-make-indent level
))
196 (str (funcall orig_func bdata target
)))
197 ;; 删除原来函数添加的 " ", 不然 playlist 对齐不好处理。
198 (when (and (eq type
'info-title
)
199 (not (string= indent
"")))
200 (setq str
(string-remove-prefix " " str
)))
203 (advice-add 'emms-browser-format-line
:around
#'eh-emms-browser-format-line
)
205 (defvar emms-browser-info-year-format
"%i+ %n")
206 (defvar emms-browser-info-genre-format
"%i+ %n")
207 (defvar emms-browser-info-performer-format
"%i+ %n")
208 (defvar emms-browser-info-composer-format
"%i+ %n")
209 (defvar emms-browser-info-artist-format
"%i* %n")
210 (defvar emms-browser-info-album-format
"%i- %n")
211 (defvar emms-browser-info-title-format
"%i♪ %n")
212 (defvar emms-browser-playlist-info-year-format
"%i%n")
213 (defvar emms-browser-playlist-info-genre-format
"%i%n")
214 (defvar emms-browser-playlist-info-performer-format
"%i%n")
215 (defvar emms-browser-playlist-info-composer-format
"%i%n")
216 (defvar emms-browser-playlist-info-artist-format
"%i%n")
217 (defvar emms-browser-playlist-info-album-format
"%i%n")
218 (defvar emms-browser-playlist-info-title-format
" ♪ %n")
220 (defun eh-emms-browser-wash-playlist (&optional _
)
221 "简化 playlist, emms-browser 默认生成的 playlist 有缩进,看起来太花。"
222 (with-current-emms-playlist
223 (eh-emms-wash-buffer)
224 (goto-char (point-max))))
226 (add-hook 'emms-browser-tracks-added-hook
#'eh-emms-browser-wash-playlist
)
228 ;; 使用类似 org-mode 的快捷键
229 (define-key emms-browser-mode-map
(kbd "<tab>") 'emms-browser-toggle-subitems-recursively
)
230 (define-key emms-browser-mode-map
(kbd "<backtab>") 'emms-browser-toggle-subitems-recursively
)
231 (define-key emms-browser-mode-map
(kbd "C-c C-c") 'emms-browser-add-tracks-and-play
)
234 (require 'emms-history
)
235 (require 'emms-tag-editor
)
237 (add-hook 'after-init-hook
#'emms-history-load
)
239 (setq emms-tag-editor-pipe-config
240 '(("处理MP3中文标签乱码 (mid3iconv -e gbk <file>)"
242 :arguments
("-e" "gbk" name
))
243 ("Test1 (echo -a <name> -c <name>)"
245 :arguments
(("-a" name
) ("-b" name1
) ("-c" name
)))
246 ("Test2 (echo <artist>-<title>)"
250 (list (format "%s-%s"
251 (emms-track-get track
'info-artist
)
252 (emms-track-get track
'info-title
)))))))
258 ;; coding: utf-8-unix
261 ;;; eh-emms.el ends here