emms-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emms-help] Temporary patch for yanking and killing - emms-playlist.el


From: Ulrik Jensen
Subject: [Emms-help] Temporary patch for yanking and killing - emms-playlist.el
Date: Sun, 30 Nov 2003 18:48:51 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

Hey

This patch *doesn't* include kanaldraches changes - but from a quick
glimpse, they don't overlap, so it should be possible to merge them
together without a problem.

Also includes some bugfixes/changes.

Here goes:

cvs server: Diffing .
Index: emms-playlist.el
===================================================================
RCS file: /cvsroot/emms/emms/emms-playlist.el,v
retrieving revision 1.2
diff -r1.2 emms-playlist.el
145a146,154
> ;; Variables
> (defvar emms-pbi-suspend-hooks nil
>   "When this variable is t, the hooks updating the playlist stop
> reacting.
> 
> If you do something with `emms-playlist', and don't want to regenerate
> the entire playlist-buffer, a good idea is to bind
> `emms-pbi-suspend-hooks' to t when you set `emms-playlist'.")
> 
154c163
<       (add-hook 'emms-playlist-changed-hook 'emms-pbi-build-playlist-buffer)
---
>       (add-hook 'emms-playlist-changed-hook 'emms-pbi-rebuild-playlist-buffer)
158,159c167
<         (switch-to-buffer emms-pbi-playlist-buffer-name)
<           ))
---
>         (switch-to-buffer emms-pbi-playlist-buffer-name)))
161c169
<     (remove-hook 'emms-playlist-changed-hook 
'emms-pbi-build-playlist-buffer)))
---
>     (remove-hook 'emms-playlist-changed-hook 
> 'emms-pbi-rebuild-playlist-buffer)))
186,188c194
<           (insert (emms-pbi-shorten-entry-to-max-length
<                    (funcall emms-pbi-playlist-entry-generate-function
<                             (emms-playlist-get idx))))
---
>           (emms-pbi-insert-entry (emms-playlist-get-filename idx) idx)
193a200,205
> 
> (defun emms-pbi-rebuild-playlist-buffer ()
>   "This function rebuilds the playlist-buffer if necessary."
>   (unless emms-pbi-suspend-hooks
>     (emms-pbi-build-playlist-buffer)))
> 
213,215c225
<         (insert (emms-pbi-shorten-entry-to-max-length
<                  (funcall emms-pbi-playlist-entry-generate-function
<                           (emms-playlist-get idx)))))
---
>         (emms-pbi-insert-entry (emms-playlist-get-filename idx) idx))
235a246,253
> (defun emms-pbi-insert-entry (filename idx)
>   "Insert an entry in the playlist"
>   (let ((inhibit-read-only t))
>     (insert (emms-pbi-shorten-entry-to-max-length
>            (funcall emms-pbi-playlist-entry-generate-function
>                     (emms-playlist-get idx))))
>     (emms-pbi-add-properties-current-line filename idx)))
> 
252,253c270,272
<   (emms-pbi-remove-current-face)
<   (emms-pbi-add-current-face))
---
>   (when (get-buffer emms-pbi-playlist-buffer-name)
>     (emms-pbi-remove-current-face)
>     (emms-pbi-add-current-face)))
278,280c297,298
<   (when (get-buffer emms-pbi-playlist-buffer-name)
<     (emms-pbi-remove-current-face)
<     (emms-pbi-add-current-face)))
---
>   (emms-pbi-remove-current-face)
>   (emms-pbi-add-current-face))
357a376,449
> (defun emms-pbi-check-linenumbers (beg end)
>   "Check and if necessary correct the linenumbers of the lines from
> \(including\) the line with the point BEG on it, to \(also including\) the
> line with the point END on it."
>   (when emms-pbi-linenumbers
>     ;; do some stuff here
>     (save-excursion
>       (goto-char beg)
>       (let ((curline (1+ (count-lines (point-min) (point-at-eol)))))
>       (while (< (point-at-eol) end)
>         ;; check this line
>         (let ((line (buffer-substring (point-at-bol) (point-at-eol))))
>           (when (string-match "^[ ]*\\([0-9]+\\)\\. " line)
>             (let ((linenum (match-string 1 line)))
>               ;; if this is correct - do nothing..
>               (unless (= (string-to-number linenum) curline)
>                 (replace-match (string-to-number linenum) t t line 1)
>                 ;; insert this again
>                 (delete-region (point-at-bol) (point-at-eol))
>                 (insert line)
>                 (emms-pbi-add-properties-current-line)))))
>         ;; proceed
>         (setq curline (1+ curline))
>         (forward-line 1))))))
> 
> ;; Killing and yanking
> (defun emms-pbi-kill-line ()
>   "Kill the current line from the playlist.
> 
> Send the filename to the `kill-ring'. Make sure hooks that regenerate
> the entire playlist aren't run."
>   (interactive)
>   (let ((filename (get-text-property (point-at-bol) 'file))
>       (idx (get-text-property (point-at-bol) 'playlist-index))
>       (inhibit-read-only t))
>     (when filename
>       (save-excursion
>       (kill-new filename)
>       (delete-region (point-at-bol) (point-at-eol))
>       (forward-line 1)      
>       ;; remove the new line
>       (delete-backward-char 1)
>       ;; now, delete the entry from the playlist. - making sure that
>       ;; the entire list isn't regenerated
>       (let ((emms-pbi-suspend-hooks t))
>         (emms-playlist-set (vconcat (subseq emms-playlist 0 idx) (subseq 
> emms-playlist (1+ idx)))))
>       ;; update the linenumbers so everything is still correct
>       (forward-line -1)
>       (emms-pbi-check-linenumbers (point-at-bol) (point-max))))))
> 
> (defun emms-pbi-yank ()
>   "Yank a filename from `kill-ring' into the playlist."
>   (interactive)
>   (let ((filename (current-kill 0))
>       (curplaylist emms-playlist)
>       (idx (get-text-property (point-at-bol) 'playlist-index)))
>     (when (and (file-exists-p filename) (emms-player-for filename))
>       ;; only insert files that actually exist, and can be played.
>       ;; insert it into the buffer
>       (save-excursion
>       (let ((inhibit-read-only t))
>         (goto-char (point-at-bol))
>         (insert "\n")
>         (forward-line -1)
>         (goto-char (point-at-bol))
>         (emms-pbi-insert-entry filename idx)))
>       ;; insert it into the playlist
>       (let ((emms-pbi-suspend-hooks t))
>       (emms-playlist-set (vconcat (subseq emms-playlist 0 idx)
>                                   (list filename)
>                                   (subseq emms-playlist idx))))
>       ;; update the linenumbers so everything is still correct
>       (emms-pbi-check-linenumbers (point-at-bol) (point-at-eol)))))
> 
363a456,457
>   (define-key emms-pbi-mode-map (kbd "C-k")       'emms-pbi-kill-line)
>   (define-key emms-pbi-mode-map (kbd "C-y")       'emms-pbi-yank)

-- 
Ulrik Jensen -- address@hidden -- http://www.terryp.tk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]