Refactor some functions to prepare for a proper empc-playlist-mode.
This commit is contained in:
parent
4676a37073
commit
5f881d5a61
1 changed files with 25 additions and 12 deletions
37
empc.el
37
empc.el
|
|
@ -240,13 +240,14 @@ According to what is in the diff, several actions can be performed:
|
||||||
(unless (called-interactively-p)
|
(unless (called-interactively-p)
|
||||||
(dolist (frame (frame-list))
|
(dolist (frame (frame-list))
|
||||||
(with-selected-frame frame
|
(with-selected-frame frame
|
||||||
(when (get-buffer-window "*empc*")
|
(let ((bwindow (get-buffer-window "*empc*")))
|
||||||
(with-selected-window (get-buffer-window "*empc*")
|
(when bwindow
|
||||||
(goto-char (point-min))
|
(with-selected-window bwindow
|
||||||
(forward-line (plist-get empc-current-status :song))
|
(goto-char (point-min))
|
||||||
(when (and (not buffer) empc-may-pulse)
|
(forward-line (plist-get empc-current-status :song))
|
||||||
(pulse-momentary-highlight-one-line (point))))
|
(when (and (not buffer) empc-may-pulse)
|
||||||
(setq buffer (get-buffer-window "*empc*"))))))
|
(pulse-momentary-highlight-one-line (point))))
|
||||||
|
(setq buffer bwindow))))))
|
||||||
(unless buffer
|
(unless buffer
|
||||||
(with-current-buffer "*empc*"
|
(with-current-buffer "*empc*"
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
@ -371,7 +372,13 @@ Send the password or retrieve available commands."
|
||||||
(setq empc-queue (tq-create empc-process))
|
(setq empc-queue (tq-create empc-process))
|
||||||
(empc-initialize)))
|
(empc-initialize)))
|
||||||
|
|
||||||
(defun empc-close-connection ()
|
(defun empc-bury-buffers ()
|
||||||
|
"Bury all empc related buffers."
|
||||||
|
(interactive)
|
||||||
|
(while (member major-mode '(empc-playlist-mode))
|
||||||
|
(bury-buffer)))
|
||||||
|
|
||||||
|
(defun empc-quit ()
|
||||||
"Close connection between empc and mpd."
|
"Close connection between empc and mpd."
|
||||||
(interactive)
|
(interactive)
|
||||||
(when (and empc-process
|
(when (and empc-process
|
||||||
|
|
@ -393,6 +400,12 @@ Send the password or retrieve available commands."
|
||||||
empc-current-playlist-songs nil
|
empc-current-playlist-songs nil
|
||||||
empc-current-playlist nil))
|
empc-current-playlist nil))
|
||||||
|
|
||||||
|
(defun empc ()
|
||||||
|
"Emacs MPC (not really the most original name, but oh well…)."
|
||||||
|
(interactive)
|
||||||
|
(empc-ensure-connected)
|
||||||
|
(empc-switch-to-playlist))
|
||||||
|
|
||||||
(defun empc-maybe-enter-idle-state ()
|
(defun empc-maybe-enter-idle-state ()
|
||||||
"If not already in idle state and there is no other commands pending,
|
"If not already in idle state and there is no other commands pending,
|
||||||
enter idle state to accept notifications from the server."
|
enter idle state to accept notifications from the server."
|
||||||
|
|
@ -439,8 +452,9 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
|
|
||||||
(defun empc-playlist-mode ()
|
(defun empc-playlist-mode ()
|
||||||
"empc playlist mode."
|
"empc playlist mode."
|
||||||
|
(use-local-map empc-playlist-map)
|
||||||
(setq major-mode 'empc-playlist-mode)
|
(setq major-mode 'empc-playlist-mode)
|
||||||
(setq mode-name "empc-playlist")
|
(setq mode-name "Empc-Playlist")
|
||||||
(setq buffer-read-only t))
|
(setq buffer-read-only t))
|
||||||
|
|
||||||
(defun empc-switch-to-playlist ()
|
(defun empc-switch-to-playlist ()
|
||||||
|
|
@ -464,9 +478,8 @@ If the stream process is killed for whatever the reason, pause mpd if possible."
|
||||||
,(concat "Send " command " to the server.")
|
,(concat "Send " command " to the server.")
|
||||||
(interactive)
|
(interactive)
|
||||||
(empc-leave-idle-state)
|
(empc-leave-idle-state)
|
||||||
(if arg
|
(empc-send (concat ,command (when arg (concat " " (if (stringp arg) arg (number-to-string arg)))) "\n")
|
||||||
(empc-send (concat ,(concat command " ") arg "\n") ,closure)
|
,closure)))
|
||||||
(empc-send (concat ,command "\n") ,closure))))
|
|
||||||
|
|
||||||
(defmacro empc-define-toggle-command (command &optional state-name attr &rest body)
|
(defmacro empc-define-toggle-command (command &optional state-name attr &rest body)
|
||||||
"Define a command that toggle a state."
|
"Define a command that toggle a state."
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue