diff options
author | Yoni Rabkin <yrk@gnu.org> | 2016-03-01 12:36:04 -0500 |
---|---|---|
committer | Yoni Rabkin <yrk@gnu.org> | 2016-03-01 12:36:04 -0500 |
commit | 59bb98c5c63b305259e677103badb001eec98896 (patch) | |
tree | 429a377888cafe57b37e65d55933e2b84f86fefd | |
parent | 8ba0a5eb1991544ef91ea90772b614f9ab7d953c (diff) |
* lisp/emms-show-all.el: first implementation
-rw-r--r-- | lisp/emms-show-all.el | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/lisp/emms-show-all.el b/lisp/emms-show-all.el index 3ff7978..38856d8 100644 --- a/lisp/emms-show-all.el +++ b/lisp/emms-show-all.el @@ -22,13 +22,102 @@ ;;; Commentary: ;;; -;;; +;;; Shows all of the available information Emms can provide on the +;;; currently playing track. Based on an idea suggested on the +;;; emms-help mailing list by Ivan Truskov. ;;; Code: +(require 'emms) (require 'emms-tag-editor) +(defvar emms-show-all-buffer-name "Emms Track Information" + "Name of buffer used by `emms-show-all'.") + +(defvar emms-show-all-kill-buffer-on-quit-p nil + "If t, kill the show-all buffer when quitting.") + + +(define-derived-mode emms-show-all-mode text-mode "Emms-Show-All" + "Major mode for `emms-show-all' + \\{emms-show-all-mode-map}") + +(defconst emms-show-all-mode-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map text-mode-map) + (define-key map (kbd "q") 'emms-show-all-mode-bury-buffer) + (define-key map (kbd "E") 'emms-show-all-edit-track) + map) + "Keymap for `emms-show-all-mode'.") + + +(defun emms-show-all-edit-track () + "Edit the track being shown." + (interactive) + (let ((track emms-show-all-track-alist)) + (emms-show-all-mode-bury-buffer) + (emms-tag-editor-edit-track track))) + +(defun emms-show-all-mode-bury-buffer () + "Bury, and optionally kill the show buffer." + (interactive) + (bury-buffer emms-show-all-buffer-name) + (delete-window) + (when emms-show-all-kill-buffer-on-quit-p + (kill-buffer emms-show-all-buffer-name))) + +(defun emms-show-all-setup-buffer () + "Prepare the display buffer." + (let ((buffer (get-buffer-create emms-show-all-buffer-name))) + (with-current-buffer buffer + (when (not (local-variable-p 'emms-show-all-track-alist)) + (make-local-variable 'emms-show-all-track-alist)) + (setq buffer-read-only t) + (when (not (equal major-mode 'emms-show-all-mode)) + (emms-show-all-mode)) + (let ((inhibit-read-only t)) + (erase-buffer))) + buffer)) + +(defun emms-show-all-format (track) + "Format information for TRACK." + (let ((s "")) + (dolist (e (mapcar #'(lambda (tag) + (cons + (format "%s" (car tag)) + (or (emms-track-get track (car tag)) ""))) + emms-tag-editor-tags)) + (setq s (concat s (format "%-17s: %s\n" (car e) (cdr e))))) + s)) + +(defun emms-show-all-insert (track) + "Insert information for TRACK in current buffer." + (let ((type (emms-track-type track))) + (cond ((eq 'file type) + (insert (emms-show-all-format track))) + ((eq 'url type) + (insert + (emms-format-url-track-name (emms-track-name track)))) + (t (concat (symbol-name type) + ": " (emms-track-name track)))))) + +(defun emms-show-all-track (track) + "Display information for TRACK." + (let ((buffer (emms-show-all-setup-buffer))) + (with-current-buffer buffer + (let ((inhibit-read-only t)) + (setq emms-show-all-track-alist track) + (emms-show-all-insert track)) + (pop-to-buffer (current-buffer))))) + +(defun emms-show-all () + "Describe the current EMMS track in detail." + (interactive) + (if emms-player-playing-p + (emms-show-all-track + (emms-playlist-current-selected-track)) + (message "nothing playing right now"))) (provide 'emms-show-all) |