From e874d110f8a5d15a559fe372a12121547d84c4ac Mon Sep 17 00:00:00 2001 From: Michael Olson Date: Tue, 30 May 2006 04:01:00 +0000 Subject: emms-streams: Implement kill and yank. darcs-hash:20060530040114-1bfb2-dee2441306ea4d38715338c0cec9d74996238e8c.gz --- emms-streams.el | 104 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 78 insertions(+), 26 deletions(-) diff --git a/emms-streams.el b/emms-streams.el index 8676d64..fca5e4a 100644 --- a/emms-streams.el +++ b/emms-streams.el @@ -52,7 +52,11 @@ Can be either \"add\" or \"play\". The default is \"add\"." "Face for stream names." :group 'emms-stream) -(defface emms-stream-url-face '((t (:foreground "LightSteelBlue"))) +(defface emms-stream-url-face + '((((class color) (background dark)) + (:foreground "LightSteelBlue")) + (((class color) (background light)) + (:foreground "Blue"))) "Face for stream URLs." :group 'emms-stream) @@ -131,24 +135,25 @@ needed info.") (defvar emms-stream-mode-map (let ((map (make-keymap))) (suppress-keymap map) - (define-key map [(control ?a)] 'beginning-of-line) - (define-key map [(control ?e)] 'end-of-line) - (define-key map [(control ?k)] 'emms-stream-kill-bookmark) - (define-key map [(control ?y)] 'emms-stream-yank-bookmark) - (define-key map [(control ?n)] 'emms-stream-next-line) - (define-key map [(control ?p)] 'emms-stream-previous-line) - (define-key map [?Q] 'emms-stream-quit) - (define-key map [?a] 'emms-stream-add-bookmark) - (define-key map [?d] 'emms-stream-delete-bookmark) - (define-key map [?e] 'emms-stream-edit-bookmark) - (define-key map [?h] 'describe-mode) - (define-key map [?n] 'emms-stream-next-line) - (define-key map [?p] 'emms-stream-previous-line) - (define-key map [?q] 'emms-stream-quit) - (define-key map [?s] 'emms-stream-save-bookmarks-file) - (define-key map [?t] 'emms-stream-toggle-default-action) -;; (define-key map [?u] 'emms-stream-move-bookmark-up) - (define-key map [?i] 'emms-stream-info-bookmark) + (define-key map (kbd "C-a") 'beginning-of-line) + (define-key map (kbd "C-e") 'end-of-line) + (define-key map (kbd "C-k") 'emms-stream-kill-bookmark) + (define-key map (kbd "C-y") 'emms-stream-yank-bookmark) + (define-key map (kbd "C-n") 'emms-stream-next-line) + (define-key map (kbd "C-p") 'emms-stream-previous-line) + (define-key map (kbd "M-y") 'emms-stream-yank-pop) + (define-key map (kbd "Q") 'emms-stream-quit) + (define-key map (kbd "a") 'emms-stream-add-bookmark) + (define-key map (kbd "d") 'emms-stream-delete-bookmark) + (define-key map (kbd "e") 'emms-stream-edit-bookmark) + (define-key map (kbd "h") 'describe-mode) + (define-key map (kbd "n") 'emms-stream-next-line) + (define-key map (kbd "p") 'emms-stream-previous-line) + (define-key map (kbd "q") 'emms-stream-quit) + (define-key map (kbd "s") 'emms-stream-save-bookmarks-file) + (define-key map (kbd "t") 'emms-stream-toggle-default-action) +;; (define-key map (kbd "u") 'emms-stream-move-bookmark-up) + (define-key map (kbd "i") 'emms-stream-info-bookmark) (define-key map (kbd "") 'emms-stream-previous-line) (define-key map (kbd "") 'emms-stream-next-line) (define-key map (kbd "") 'beginning-of-line) @@ -182,6 +187,7 @@ needed info.") (emms-stream-display) (toggle-read-only 1) (run-hooks 'emms-stream-hook) + (set-buffer-modified-p nil) (message "EMMS Stream Menu")) (defun emms-stream-popup-revert () @@ -393,6 +399,57 @@ Don't forget to save your modifications !" (emms-stream-info-message url)) (message "Streaming media info not available."))) +(defun emms-stream-look-behind () + "Return non-nil if the position behind the point is an emms-stream." + (and (not (bobp)) + (get-text-property (1- (point)) 'emms-stream))) + +(defun emms-stream-back-to-stream () + "If we are not on a stream, move backwards to the nearest one." + (unless (get-text-property (point) 'emms-stream) + (unless (emms-stream-look-behind) + (goto-char (or (previous-single-property-change (point) 'emms-stream) + (point-min)))) + (goto-char (or (previous-single-property-change (point) 'emms-stream) + (point-min))))) + +;; Killing and yanking +(defun emms-stream-kill-bookmark () + "Kill the current bookmark." + (interactive) + (emms-stream-back-to-stream) + (let ((inhibit-read-only t)) + (kill-line 2))) + +(defun emms-stream-yank-bookmark () + "Yank bookmark into the streams buffer." + (interactive) + (emms-stream-back-to-stream) + (let ((inhibit-read-only t)) + (save-restriction + (narrow-to-region (point) (point)) + (yank) + (remove-text-properties (point-min) (point-max) + '(emms-stream nil face nil)) + (goto-char (point-min)) + (while (and (< (point) (point-max)) + (looking-at "^\\(.+\\)\n \\(.+\\)\n")) + (add-text-properties (match-beginning 1) (match-end 1) + '(face emms-stream-name-face)) + (add-text-properties (match-beginning 1) (match-end 1) + (list 'emms-stream + (list (match-string 1) (match-string 2)))) + (goto-char (match-beginning 2)) + (add-text-properties (point-at-bol) (match-end 2) + '(face emms-stream-url-face)) + (goto-char (match-end 0)))))) + +(defun emms-stream-yank-pop () + "Cycle through the kill-ring." + (interactive) + (let ((inhibit-read-only t)) + (yank-pop nil))) + ;; Navigation (defun emms-stream-next-line () (interactive) @@ -405,14 +462,9 @@ Don't forget to save your modifications !" (defun emms-stream-previous-line () (interactive) - (unless (get-text-property (point) 'emms-stream) - (goto-char (or (previous-single-property-change (point) 'emms-stream) + (emms-stream-back-to-stream) + (goto-char (or (previous-single-property-change (point) 'emms-stream) (point-min))) - (goto-char (or (previous-single-property-change (point) 'emms-stream) - (point-min)))) - (when (get-text-property (point) 'emms-stream) - (goto-char (or (previous-single-property-change (point) 'emms-stream) - (point-min)))) (goto-char (or (previous-single-property-change (point) 'emms-stream) (point-min))) (forward-line 0)) -- cgit v1.2.3