From e7854c9b8b16ee118b5c7aca640f482a339d1cec Mon Sep 17 00:00:00 2001 From: forcer Date: Fri, 16 Sep 2005 00:33:00 +0000 Subject: Fix emms-playlist-new and make emms-playlist-clear use it. darcs-hash:20050916003331-2189f-e450098f69ebd1acf9605479ea9f760fd17d3caf.gz --- emms.el | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'emms.el') diff --git a/emms.el b/emms.el index 64881e6..bf0189c 100644 --- a/emms.el +++ b/emms.el @@ -410,30 +410,33 @@ Otherwise, return the type and the name with a colon in between." (setq emms-playlist-buffer (or (get-buffer buffer) (current-buffer)))) -(defun emms-playlist-new () - "Create a new playlist buffer." +(defun emms-playlist-new (&optional name) + "Create a new playlist buffer. +The buffer is named NAME, but made unique. NAME defaults to +`emms-playlist-buffer-name'. +If called interactively, the new buffer is also selected." (interactive) - (let ((buf (get-buffer emms-playlist-buffer-name))) - (when buf - (with-current-buffer buf - (rename-buffer (generate-new-buffer-name emms-playlist-buffer-name)))) - (emms-playlist-clear))) + (let ((buf (generate-new-buffer (or name + emms-playlist-buffer-name)))) + (with-current-buffer buf + (when (not (eq major-mode emms-playlist-default-major-mode)) + (funcall emms-playlist-default-major-mode)) + (setq emms-playlist-buffer-p t)) + (when (called-interactively-p) + (switch-to-buffer buf)) + buf)) (defun emms-playlist-clear () "Clear the current playlist. -If a buffer named `emms-playlist-buffer-name' exists, this is -used, and the contents removed." - (let ((buf (get-buffer-create emms-playlist-buffer-name))) - (with-current-buffer buf +If no playlist exists, a new one is generated." + (if (not emms-playlist-buffer) + (setq emms-playlist-buffer (emms-playlist-new)) + (with-current-buffer emms-playlist-buffer (let ((inhibit-read-only t)) (widen) (delete-region (point-min) (point-max))) - (when (not (eq major-mode emms-playlist-default-major-mode)) - (funcall emms-playlist-default-major-mode)) - (setq emms-playlist-buffer-p t) - (run-hooks 'emms-playlist-cleared-hook)) - (setq emms-playlist-buffer buf))) + (run-hooks 'emms-playlist-cleared-hook)))) (defmacro with-current-emms-playlist (&rest body) "Run BODY with the current buffer being the current playlist buffer." -- cgit v1.2.3