Browse Source

Support for single-buffer mode

single-buffer
jao 1 year ago
parent
commit
5b5aec7cc1
3 changed files with 49 additions and 9 deletions
  1. +4
    -0
      README.org
  2. +38
    -8
      mpdel-browser.el
  3. +7
    -1
      mpdel.el

+ 4
- 0
README.org View File

@ -186,6 +186,10 @@ or rearrange how children buffers show their contents with
~mpdel-browser-list-clean-up-function~. Please see the customization
group ~mpdel-browser~ for more details.
If you would like to use MPDel in single-buffer mode when traversing
your music collection entries, call ~mpdel-enable-single-buffer~ in your
init file.
*** Communication with MPD
If you have only one MPD server, you can tell libmpdel how to


+ 38
- 8
mpdel-browser.el View File

@ -132,7 +132,7 @@ orderings."
(defun mpdel-browser--buffer-name (entity)
"Return the name of a browser buffer displaying ENTITY."
(format "* %s *"
(format (if (navigel-single-buffer-app-p 'mpdel) "%s" "* %s *")
(cond ((stringp entity) entity)
((libmpdel-directory-p entity)
(file-name-nondirectory (or (libmpdel--directory-path entity) "")))
@ -200,7 +200,10 @@ This listing is constructed using `mpdel-browser-top-level-entries'."
'browser)
(navigel-method mpdel navigel-buffer-name ((_e (eql browser)))
(format "* MPDel - %s:%d *" libmpdel-hostname libmpdel-port))
(format (if (navigel-single-buffer-app-p 'mpdel)
"%s:%d"
"* MPDel - %s:%d *")
libmpdel-hostname libmpdel-port))
(navigel-method mpdel navigel-entity-buffer ((_e (eql browser)))
(navigel-buffer-name 'browser))
@ -228,7 +231,10 @@ This listing is constructed using `mpdel-browser-top-level-entries'."
;;;###autoload
(defun mpdel-browser-open ()
"Open the top level MPDel browser buffer."
"Open the top level MPDel browser buffer.
If MPDel is configured in single-window mode, popup to an
existing browser buffer, if any, instead of creating it."
(interactive)
(mpdel-core-open 'browser))
@ -241,12 +247,21 @@ This listing is constructed using `mpdel-browser-top-level-entries'."
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql browser)))
(mpdel-browser-mode))
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql albums)))
(mpdel-browser-mode))
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql directories)))
(mpdel-browser-mode))
(navigel-method mpdel navigel-entity-tablist-mode ((_e libmpdel-directory))
(mpdel-browser-mode))
(navigel-method mpdel navigel-entity-id ((dir libmpdel-directory))
(let ((name (libmpdel--directory-name dir)))
(if (member name '("." ".."))
(libmpdel--directory-path dir)
name)))
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql stored-playlists)))
(mpdel-browser-mode))
@ -262,12 +277,27 @@ This listing is constructed using `mpdel-browser-top-level-entries'."
(string= ".." name)
(string= "Music directory" name))))
(cl-defmethod navigel-parent-to-open (entity &context (major-mode mpdel-browser-mode))
(defun mpdel-browser--find-parent-directory ()
"Find the parent directory of current buffer, or 'browser if none."
(or (car (cl-find-if #'mpdel-browser--entry-is-parent-directory-p
tabulated-list-entries
:key #'car-safe))
'browser))
(cl-defmethod navigel-parent-to-open ((album libmpdel-album))
"Find the parent of the given ALBUM."
(if (string-empty-p (or (libmpdel-artist-name album) ""))
(list 'albums album)
(list (libmpdel--album-artist album) album)))
(cl-defmethod navigel-parent-to-open (_e &context (major-mode mpdel-browser-mode))
"Find parent of ENTITY when in a buffer with MAJOR-MODE `mpdel-browser-mode'."
(cons (car (cl-find-if #'mpdel-browser--entry-is-parent-directory-p
tabulated-list-entries
:key #'car-safe))
entity))
(list (mpdel-browser--find-parent-directory)))
(cl-defmethod navigel-parent-to-open
(_e &context (major-mode mpdel-playlist-current-playlist-mode))
"Find parent of ENTITY when in a buffer with MAJOR-MODE `mpdel-playlist-current-playlist-mode'."
(list (mpdel-browser--find-parent-directory)))
(define-key mpdel-core-map (kbd ":") #'mpdel-browser-open)


+ 7
- 1
mpdel.el View File

@ -1,6 +1,6 @@
;;; mpdel.el --- Play and control your MPD music -*- lexical-binding: t; -*-
;; Copyright (C) 2018-2019 Damien Cassou
;; Copyright (C) 2018-2020 Damien Cassou
;; Author: Damien Cassou <damien@cassou.me>
;; Keywords: multimedia
@ -31,6 +31,7 @@
;;; Code:
(require 'navigel)
(require 'mpdel-song)
(require 'mpdel-playlist)
(require 'mpdel-tablist)
@ -64,6 +65,11 @@
:require 'mpdel
:lighter " MPDel")
;;;###autoload
(defun mpdel-enable-single-buffer ()
"Configure mpdel to reuse a single buffer when navigating or browsing."
(navigel-register-single-buffer-app 'mpdel))
(provide 'mpdel)
;;; mpdel.el ends here


Loading…
Cancel
Save