emms-help
[Top][All Lists]
Advanced

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

[Emms-help] diff for emms-pbi.el Rev:1.6


From: Mario Domgörgen
Subject: [Emms-help] diff for emms-pbi.el Rev:1.6
Date: Sat, 06 Dec 2003 20:00:12 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3.50 (gnu/linux)

Hej dev-team!

Here's a new patch for pbi solving some problems with linenumbering,
killing and propertize (by removing them :)) and nameless other
things... :)

I bet there are some broken parts but i don't have more time to test it
as i go to a party tonight and don't want to hide that piece of code...

Mario

*** emms-pbi.el.~1.6.~  Wed Dec  3 14:31:11 2003
--- emms-pbi.el Sat Dec  6 19:56:44 2003
***************
*** 76,82 ****
    :group 'emms
    :prefix "emms-pbi-")
  
! (defcustom emms-pbi-playlist-entry-generate-function 'emms-pbi-generate-entry
    "*The function to call for generating a single item of the
  playlist. This will be called with a string argument FILENAME, and
  should return the text to be inserted in the playlist."
--- 76,82 ----
    :group 'emms
    :prefix "emms-pbi-")
  
! (defcustom emms-pbi-playlist-entry-generate-function 'identity
    "*The function to call for generating a single item of the
  playlist. This will be called with a string argument FILENAME, and
  should return the text to be inserted in the playlist."
***************
*** 158,163 ****
--- 158,165 ----
  the entire playlist-buffer, a good idea is to bind
  `emms-pbi-suspend-hooks' to t when you set `emms-playlist'.")
  
+ (defvar emms-current-overlay nil)
+ 
  ;; Entry points
  (defun emms-pbi (arg)
    "Turn on emms-playlist if prefix argument ARG is a positive integer,
***************
*** 165,173 ****
    (interactive "p")
    (if (and arg (> arg 0))
        (progn
!       (add-hook 'emms-player-stop-hook 'emms-pbi-remove-current-face)
!       (add-hook 'emms-player-start-hook 'emms-pbi-add-current-face)
! ;;    (add-hook 'emms-playlist-current-changed-hook 
'emms-pbi-update-current-face)
        (add-hook 'emms-playlist-changed-hook 'emms-pbi-rebuild-playlist-buffer)
        ;; build the playlist, if we're playing
        (when emms-player-playing-p
--- 167,173 ----
    (interactive "p")
    (if (and arg (> arg 0))
        (progn
!       (add-hook 'emms-player-start-hook 'emms-pbi-update-current-face)
        (add-hook 'emms-playlist-changed-hook 'emms-pbi-rebuild-playlist-buffer)
        ;; build the playlist, if we're playing
        (when emms-player-playing-p
***************
*** 191,211 ****
    ;; find the filename entry in the playlist
    (save-excursion
      (set-buffer (get-buffer emms-pbi-playlist-buffer-name))
!     (let ((linepoint (text-property-any (point-min) (point-max) 'file 
filename)))
        (when linepoint
        (goto-char linepoint)
        (let ((inhibit-read-only t))
          ;; update the text of it - by generating it again simply
          ;; first, find the index of the entry in the playlist.
          ;; and save the current properties
!         (let ((idx (get-text-property (point) 'playlist-index))
!               (props (text-properties-at (point))))
            (delete-region (point-at-bol) (point-at-eol))
!           (emms-pbi-insert-entry (emms-playlist-get-filename idx) idx)
!           ;; insert the properties again
!           (set-text-properties (point-at-bol) (point-at-eol) props)
            ;; and update them
!           (emms-pbi-add-properties-current-line filename idx)))))))
  
  
  (defun emms-pbi-rebuild-playlist-buffer ()
--- 191,210 ----
    ;; find the filename entry in the playlist
    (save-excursion
      (set-buffer (get-buffer emms-pbi-playlist-buffer-name))
!     (let ((linepoint (text-property-any (point-min) (point-max) 
!                                       'file filename)))
        (when linepoint
        (goto-char linepoint)
        (let ((inhibit-read-only t))
          ;; update the text of it - by generating it again simply
          ;; first, find the index of the entry in the playlist.
          ;; and save the current properties
!         (let ((idx (1- (count-lines (point-min) (line-end-position)))))
            (delete-region (point-at-bol) (point-at-eol))
!           (emms-pbi-insert-entry idx)
            ;; and update them
!           ;;That don't work FIXME
!           (emms-pbi-add-properties-current-line)))))))
  
  
  (defun emms-pbi-rebuild-playlist-buffer ()
***************
*** 232,269 ****
                              (funcall emms-pbi-async-alternative-text-function
                                       (emms-playlist-get-filename idx)))))
          ;; just insert the tag like normal
!         (emms-pbi-insert-entry (emms-playlist-get-filename idx) idx))
!       (emms-pbi-add-properties-current-line (emms-playlist-get-filename idx) 
idx)
        (insert "\n")
        (setq idx (1+ idx)))
        ;; Initialise the buffer variables
        ;; remove the last line
        (emms-pbi-update-current-face)
        (delete-backward-char 1)
        (setq buffer-read-only t)
        (emms-pbi-mode)
        (when (and (featurep 'emms-info) emms-pbi-load-info-async)
!       (emms-info-get-multiple 'emms-pbi-entry-info-updated (append 
emms-playlist nil)))
        ;; as the last thing we do, update the current-face.
        (when emms-player-playing-p
        (emms-pbi-update-current-face)))))
  
- (defun emms-pbi-current-linenumber-string ()
-   "Return the linenumber-string for the current line"
-   (let ((linenum (number-to-string (1+ (count-lines (point-min) (point)))))
-       (digits (length (number-to-string (length emms-playlist)))))
-     (while (< (length linenum) digits)
-       (setq linenum (concat " " linenum)))
-     linenum))
  
! (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)))
  
  (defun emms-pbi-generate-entry (entry)
    "Generate a playlist-entry"
    (if (not emms-pbi-linenumbers)
--- 231,299 ----
                              (funcall emms-pbi-async-alternative-text-function
                                       (emms-playlist-get-filename idx)))))
          ;; just insert the tag like normal
!         (emms-pbi-insert-entry idx))
!       (emms-pbi-add-properties-current-line)
        (insert "\n")
        (setq idx (1+ idx)))
        ;; Initialise the buffer variables
        ;; remove the last line
        (emms-pbi-update-current-face)
        (delete-backward-char 1)
+       (emms-numerotate-line)
        (setq buffer-read-only t)
        (emms-pbi-mode)
        (when (and (featurep 'emms-info) emms-pbi-load-info-async)
!       (emms-info-get-multiple 'emms-pbi-entry-info-updated 
!                               (append emms-playlist nil)))
        ;; as the last thing we do, update the current-face.
        (when emms-player-playing-p
        (emms-pbi-update-current-face)))))
  
  
! ;; The next two funcs should be made faster by letting 
! ;;them just work on point to point-max
! 
! (defun emms-numerotate-line ()
!     (interactive)
!     (when emms-pbi-linenumbers
!       (save-excursion
!       (let ((max (count-lines (point-min)(point-max)))
!             (inhibit-read-only t)
!             (line 1)
!             (formatstring (concat "%" 
!                                 (number-to-string
!                                  (length (number-to-string 
!                                          (length emms-playlist)))) 
!                                 "s. ")))
!       (goto-char (point-min))
!       (while (<= line max)
!         (insert (format formatstring (propertize
!                                       (number-to-string line)
!                                       'face 'emms-pbi-linenumber-face)))
!         (beginning-of-line 2)
!         (setq line (+ line 1)))))))
! 
! (defun emms-delete-linenumbers ()
!   (interactive)
!   (let ((inhibit-read-only t))
!     (when emms-pbi-linenumbers
!       (save-excursion
!       (delete-extract-rectangle (point-min)
!                                 (progn
!                                   (goto-char (point-max))
!                                   (re-search-backward "^[ ]*[0-9]+\\. " nil)
!                                   (match-end 0)))))))
! 
! (defun emms-pbi-insert-entry (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)))
! 
  
+ ;; not in use
  (defun emms-pbi-generate-entry (entry)
    "Generate a playlist-entry"
    (if (not emms-pbi-linenumbers)
***************
*** 280,348 ****
  ;; Updating the currently playing face
  (defun emms-pbi-update-current-face ()
    "Updates the file line with the current-face"
-   (when (get-buffer emms-pbi-playlist-buffer-name)
-     (emms-pbi-remove-current-face)
-     (emms-pbi-add-current-face)))
- 
- ;; Handling faces & properties
- (defun emms-pbi-add-properties-current-line (&optional filename idx)
-   "Adds the correct faces and other properties to the current line"
-   ;; Default face, filename and playlist index
-   (let ((filename (or filename (get-text-property (point-at-bol) 'file)))
-       (idx (or idx (get-text-property (point-at-bol) 'playlist-index))))
-     (add-text-properties (point-at-bol) (point-at-eol)
-                        `(face emms-pbi-song-face
-                               file ,filename
-                               playlist-index ,idx))
-     (when emms-pbi-linenumbers
-       (let* ((line (buffer-substring (point-at-bol) (point-at-eol)))
-            (pos (string-match "^[ ]*[0-9]+\\. " line)))
-       (when pos
-         ;; set the face of the linenumbers as well.
-         (put-text-property (+ (point-at-bol) pos)
-                            (+ (point-at-bol) pos (length (match-string 0 
line)))
-                            'face 'emms-pbi-linenumber-face))))
-     (run-hooks 'emms-pbi-current-line-face-changed-hook)))
- 
- ;; Updating the currently playing face
- (defun emms-pbi-update-current-face ()
-   "Updates the file line with the current-face"
-   (emms-pbi-remove-current-face)
-   (emms-pbi-add-current-face))
- 
- (defun emms-pbi-add-current-face ()
-   "Add `emms-pbi-current-face' to the appropriate line in the
- playlist-buffer."
    (save-excursion
      (set-buffer (get-buffer-create emms-pbi-playlist-buffer-name))
      (let ((inhibit-read-only t))
        (goto-line (1+ emms-playlist-current))
!       (put-text-property (point-at-bol) (point-at-eol) 'face 
'emms-pbi-current-face)
!       (run-hooks 'emms-pbi-current-line-face-changed-hook))))
! 
! (defun emms-pbi-remove-current-face ()
!   "Remove `emms-pbi-current-face' from the appropriate line in the
! playlist-buffer."
!   (save-excursion
!     (set-buffer (get-buffer emms-pbi-playlist-buffer-name))
!     (let ((np (text-property-any (point-min) (point-max) 'face 
'emms-pbi-current-face))
!         (inhibit-read-only t))
!       (when np
!       (goto-char np)
!       (let ((filename (get-text-property (point) 'file))
!             (index (get-text-property (point) 'playlist-index)))
!         (remove-text-properties (point-at-bol) (point-at-eol) '(face))
!         (emms-pbi-add-properties-current-line filename index))))))
! 
  (defun emms-pbi-play-current-line ()
    "Play the current line"
    (interactive)  
!   (let ((new-idx (get-text-property (point-at-bol) 'playlist-index)))
      ;; check boundaries
      (when (and new-idx (> new-idx -1) (< new-idx (length emms-playlist)))
        (emms-stop)
-       ;; stop-hooks don't get called when it's issued by me
-       (emms-pbi-remove-current-face)
        (emms-playlist-set-current new-idx)
        (emms-play))))
  
--- 310,340 ----
  ;; Updating the currently playing face
  (defun emms-pbi-update-current-face ()
    "Updates the file line with the current-face"
    (save-excursion
      (set-buffer (get-buffer-create emms-pbi-playlist-buffer-name))
      (let ((inhibit-read-only t))
        (goto-line (1+ emms-playlist-current))
!       (if (overlayp emms-current-overlay)
!         (move-overlay emms-current-overlay (line-beginning-position) 
(line-end-position))
!       (setq emms-current-overlay 
!             (make-overlay (line-beginning-position) (line-end-position)))
!       (overlay-put emms-current-overlay 'face 'emms-pbi-current-face)))))
!                       
! ;;Handling faces & properties
! (defun emms-pbi-add-properties-current-line ()
!   "Adds the correct faces and other properties to the current line"
!   ;; Default face, filename and playlist index
!   (add-text-properties (point-at-bol) (point-at-eol)
!                      `(face emms-pbi-song-face))                            
!   (run-hooks 'emms-pbi-current-line-face-changed-hook))
!            
  (defun emms-pbi-play-current-line ()
    "Play the current line"
    (interactive)  
!   (let ((new-idx (1- (count-lines (point-min) (line-end-position)))))
      ;; check boundaries
      (when (and new-idx (> new-idx -1) (< new-idx (length emms-playlist)))
        (emms-stop)
        (emms-playlist-set-current new-idx)
        (emms-play))))
  
***************
*** 410,440 ****
                                            (kill-buffer 
emms-pbi-playlist-buffer-name)))
    )
  
- (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.
--- 402,407 ----
***************
*** 442,471 ****
  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
--- 409,438 ----
  Send the filename to the `kill-ring'. Make sure hooks that regenerate
  the entire playlist aren't run."
    (interactive)
!   (let ((idx (1- (count-lines (point-min) (line-end-position))))
        (inhibit-read-only t))
!     (save-excursion
!       (when emms-pbi-linenumbers (emms-delete-linenumbers))
!       (kill-new (aref emms-playlist idx))
!       (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
!       (when emms-pbi-linenumbers (emms-numerotate-line))
!       (forward-line -1))))
!       
  
  (defun emms-pbi-yank ()
    "Yank a filename from `kill-ring' into the playlist."
    (interactive)
    (let ((filename (current-kill 0))
        (curplaylist emms-playlist)
!       (idx (1- (count-lines (point-min) (line-end-position)))))
      (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
***************
*** 475,488 ****
          (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)))))
  
  (defun emms-pbi-recenter ()
    "Center on current playing track"
--- 442,455 ----
          (insert "\n")
          (forward-line -1)
          (goto-char (point-at-bol))
!         (emms-pbi-insert-entry 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
!       )))
  
  (defun emms-pbi-recenter ()
    "Center on current playing track"

-- 
Windoze not found: (C)heer, (P)arty or (D)ance?





reply via email to

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