aboutsummaryrefslogtreecommitdiff
path: root/lisp/emms-show-all.el
blob: f37ef5e7c135e32c7dff00665e0e39f6c532534f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
;;; emms-show-all.el --- Detailed track information for Emms.

;; Copyright (C) 2016  Free Software Foundation, Inc.

;; Author: Yoni Rabkin <yrk@gnu.org>

;; This file is part of EMMS.

;; EMMS is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; EMMS is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with EMMS; if not, write to the Free Software Foundation,
;; Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

;;; 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.")

(defvar emms-show-all-track-alist nil
  "Declare so as to silence the compiler.")

(defvar 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'.")

(define-derived-mode emms-show-all-mode text-mode "Emms-Show-All"
  "Major mode for `emms-show-all'
  \\{emms-show-all-mode-map}")

(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)
  (quit-restore-window
   (selected-window)
   (when emms-show-all-kill-buffer-on-quit-p 'kill)))

(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)

;;; emms-playlist-mode.el ends here