aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--emms-i18n.el32
-rw-r--r--emms-mp3tag.el8
-rw-r--r--emms-playlist-mode.el25
-rw-r--r--emms-score.el15
-rw-r--r--emms-setup.el2
-rw-r--r--emms.el42
6 files changed, 101 insertions, 23 deletions
diff --git a/emms-i18n.el b/emms-i18n.el
index 26ccbb4..52e315a 100644
--- a/emms-i18n.el
+++ b/emms-i18n.el
@@ -80,7 +80,7 @@
(or (cdr emms-default-coding-system)
(cdr default-process-coding-system))))))
-(defun emms-call-process-to-string (program &rest args)
+(defun emms-call-process-simple (&rest args)
"This function run program and return the program result. If the CAR
part of `emms-default-coding-system' is non-nil, the program result will
be decode use the CAR part of emms-default-coding-system. Otherwise,
@@ -90,18 +90,24 @@ result. If the emms-coding-dectect-functions failed, use
coding system is nil or in `emms-nerver-used-coding-system', decode
the result using `emms-coding-system-for-read'.
-The result arguments ARGS is a list of string which pass to `call-process'."
- (with-temp-buffer
- (let ((default-process-coding-system (copy-tree default-process-coding-system))
- (process-coding-system-alist nil) exit)
+The rest arguments ARGS is as the same as `call-process', except the
+BUFFER should always have value t. Otherwise the coding detection will
+not perform."
+ (let ((default-process-coding-system (copy-tree default-process-coding-system))
+ (process-coding-system-alist nil) exit pos)
+ (when (eq (nth 2 args) 't)
(setcar default-process-coding-system (car emms-default-coding-system))
- (setq exit (apply 'call-process (append (list program nil t nil) args)))
- (when (and (zerop exit) (null (car emms-default-coding-system)))
- (decode-coding-region (point-min) (point-max) (emms-detect-buffer-coding-system)))
- (and (zerop exit) (buffer-string)))))
+ (setq pos (point)))
+ (setq exit (apply 'call-process args))
+ (when (and (eq (nth 2 args) 't)
+ (null (car emms-default-coding-system)))
+ (save-restriction
+ (narrow-to-region pos (point))
+ (decode-coding-region (point-min) (point-max) (emms-detect-buffer-coding-system))))
+ exit))
;; Is this function useful?
-(defun emms-call-process (program &rest args)
+(defun emms-call-process (&rest args)
"Run the program like `call-process'. If
the cdr part `emms-default-coding-system' is non-nil, the string in
ARGS will be encode by the CDR part of `emms-default-coding-system',
@@ -110,8 +116,8 @@ otherwise, it is pass all parameter to `call-process'."
(if (cdr emms-default-coding-system)
(let ((default-process-coding-system emms-default-coding-system)
(process-coding-system-alist nil))
- (apply 'call-process (append (list program nil t nil) args)))
- (apply 'call-process (append (list program nil t nil) args)))))
+ (apply 'call-process args))
+ (apply 'call-process args))))
(defvar emms-nerver-used-coding-system
'(raw-text undecided)
@@ -139,7 +145,7 @@ this list, use `emms-default-coding-system' instead.")
(defun emms-detect-buffer-coding-system (&optional buf)
"Before call this function, make sure the buffer is literal"
- (let ((size (buffer-size))
+ (let ((size (- (point-max) (point-min)))
(func (append emms-coding-dectect-functions 'emms-detect-coding-function))
coding)
(save-excursion
diff --git a/emms-mp3tag.el b/emms-mp3tag.el
index 1e8be5f..8580393 100644
--- a/emms-mp3tag.el
+++ b/emms-mp3tag.el
@@ -187,6 +187,10 @@ See also `emms-mp3tag-tag-file' and `emms-mp3tag-tag-ogg'.
(and track
(insert (emms-mp3tag-format-track track))))
+(defsubst emms-mp3tag-display-log-buffer-maybe ()
+ (if (> (buffer-size (get-buffer emms-mp3tag-log-buffer)) 0)
+ (display-buffer emms-mp3tag-log-buffer)))
+
(defun emms-mp3tag-insert-tracks (tracks)
(save-excursion
(emms-mp3tag-erase-buffer emms-mp3tag-log-buffer)
@@ -218,10 +222,6 @@ See also `emms-mp3tag-tag-file' and `emms-mp3tag-tag-ogg'.
(emms-mp3tag-edit-marked-tracks)
(emms-mp3tag-edit-track (emms-mp3tag-track-at))))
-(defsubst emms-mp3tag-display-log-buffer-maybe ()
- (if (> (buffer-size (get-buffer emms-mp3tag-log-buffer)) 0)
- (display-buffer emms-mp3tag-log-buffer)))
-
(defvar emms-mp3tag-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [tab] 'emms-mp3tag-next-field)
diff --git a/emms-playlist-mode.el b/emms-playlist-mode.el
index 54bb739..0562fee 100644
--- a/emms-playlist-mode.el
+++ b/emms-playlist-mode.el
@@ -125,6 +125,8 @@ This is true for every invocation of `emms-playlist-mode-go'."
(define-key map (kbd "M-y") 'emms-playlist-mode-yank-pop)
(define-key map (kbd "M-<") 'emms-playlist-mode-first)
(define-key map (kbd "M->") 'emms-playlist-mode-last)
+ (define-key map (kbd "M-n") 'emms-playlist-mode-next)
+ (define-key map (kbd "M-p") 'emms-playlist-mode-previous)
(define-key map (kbd "a") 'emms-playlist-mode-add-contents)
(define-key map (kbd "b") 'emms-playlist-set-playlist-buffer)
(define-key map (kbd "d") 'emms-playlist-mode-kill-entire-track)
@@ -495,6 +497,29 @@ WINDOW-WIDTH should be a positive integer."
(emms-playlist-mode-go)
(setq emms-playlist-mode-popup-enabled t))
+(defun emms-playlist-mode-next (arg)
+ "Navigate between playlists."
+ (interactive "p")
+ (let ((playlists (remove-if-not 'buffer-live-p
+ (emms-playlist-buffer-list)))
+ bufs idx)
+ (if playlists
+ ;; if not in playlist mode, switch to emms-playlist-buffer
+ (if (not (member (current-buffer) playlists))
+ (switch-to-buffer (if (and emms-playlist-buffer
+ (buffer-live-p emms-playlist-buffer))
+ emms-playlist-buffer
+ (car playlists)))
+ (setq bufs (member (current-buffer) playlists))
+ (setq idx
+ (+ (- (length playlists) (length bufs))
+ (if (> arg 0) 1 -1)))
+ (switch-to-buffer (nth (mod idx (length playlists)) playlists)))
+ (message "No playlist found!"))))
+(defun emms-playlist-mode-previous (arg)
+ (interactive "p")
+ (emms-playlist-mode-next (- arg)))
+
(defun emms-playlist-mode-startup ()
"Instigate emms-playlist-mode on the current buffer."
;; when there is neither a current emms track or a playing one...
diff --git a/emms-score.el b/emms-score.el
index f9e520e..e8d066f 100644
--- a/emms-score.el
+++ b/emms-score.el
@@ -242,12 +242,15 @@ See also `emms-next-noerror'."
(defun emms-score-load-hash ()
"Load score hash from `emms-score-file'."
(interactive)
- (mapc (lambda (elt)
- (puthash (car elt) (cdr elt) emms-score-hash))
- (read
- (with-temp-buffer
- (insert-file-contents emms-score-file)
- (buffer-string)))))
+ (if (file-exists-p emms-score-file)
+ (mapc (lambda (elt)
+ (puthash (car elt) (cdr elt) emms-score-hash))
+ (read
+ (with-temp-buffer
+ (insert-file-contents emms-score-file)
+ (buffer-string))))
+ ;; when file not exists, make empty but valid score file
+ (emms-score-save-hash)))
(defun emms-score-get-plist (filename)
(gethash filename emms-score-hash))
diff --git a/emms-setup.el b/emms-setup.el
index 599e479..854d6f3 100644
--- a/emms-setup.el
+++ b/emms-setup.el
@@ -125,6 +125,8 @@ on the edge."
(require 'emms-score)
(require 'emms-last-played)
(require 'emms-bookmarks)
+ (require 'emms-history)
+ (require 'emms-mark)
;; setup
(add-hook 'emms-player-started-hook 'emms-last-played-update-current))
diff --git a/emms.el b/emms.el
index 8ed1de9..89c57ba 100644
--- a/emms.el
+++ b/emms.el
@@ -110,6 +110,11 @@ songs, increase this number."
:type 'function
:group 'emms)
+(defcustom emms-playlist-uniq-function 'emms-playlist-simple-uniq
+ "*The function to use for make track uniq in the playlist."
+ :type 'function
+ :group 'emms)
+
(defcustom emms-sort-lessp-function 'emms-sort-track-name-less-p
"*Function for comparing two EMMS tracks.
The function should return non-nil if and only if the first track
@@ -416,6 +421,14 @@ This uses `emms-playlist-sort-function'."
(save-excursion
(funcall emms-playlist-sort-function))))
+(defun emms-uniq ()
+ "Uniq the current playlist.
+This uses `emms-playlist-uniq-function'."
+ (interactive)
+ (with-current-emms-playlist
+ (save-excursion
+ (funcall emms-playlist-uniq-function))))
+
(defun emms-toggle-repeat-playlist ()
"Toggle whether emms repeats the playlist after it is done.
See `emms-repeat-playlist'."
@@ -1091,6 +1104,35 @@ ignore this."
(emms-playlist-select pos)
(emms-playlist-first)))))
+(defun emms-uniq-list (list stringfy)
+ "Compare stringfied element of list, and remove duplicate elements."
+ (let ((hash (make-hash-table :test 'equal))
+ str)
+ (remove-if (lambda (elm)
+ (setq str (funcall stringfy elm))
+ (if (gethash str hash) t
+ (puthash str t hash) nil)) list)))
+
+(defun emms-playlist-simple-uniq ()
+ "Remove duplicate tracks"
+ (emms-playlist-ensure-playlist-buffer)
+ (widen)
+ (let ((inhibit-read-only t)
+ (current (emms-playlist-selected-track))
+ (tracks (emms-playlist-tracks-in-region (point-min)
+ (point-max))))
+ (delete-region (point-min) (point-max))
+ (run-hooks 'emms-playlist-cleared-hook)
+ (mapc 'emms-playlist-insert-track
+ (nreverse
+ (emms-uniq-list tracks 'emms-track-name)))
+ (let ((pos (text-property-any (point-min)
+ (point-max)
+ 'emms-track current)))
+ (if pos
+ (emms-playlist-select pos)
+ (emms-playlist-first)))))
+
;;; Helper functions
(defun emms-property-region (pos prop)
"Return a pair of the beginning and end of the property PROP at POS.