Browse Source

Support for single-buffer mode

jao 1 year ago
3 changed files with 49 additions and 9 deletions
  1. +4
  2. +38
  3. +7

+ 4
- 0 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'."
(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)
"* 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'."
(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."
(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)))
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql albums)))
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql directories)))
(navigel-method mpdel navigel-entity-tablist-mode ((_e libmpdel-directory))
(navigel-method mpdel navigel-entity-id ((dir libmpdel-directory))
(let ((name (libmpdel--directory-name dir)))
(if (member name '("." ".."))
(libmpdel--directory-path dir)
(navigel-method mpdel navigel-entity-tablist-mode ((_e (eql stored-playlists)))
@ -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
:key #'car-safe))
(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
:key #'car-safe))
(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 <>
;; 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")
(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