bongo-devel
[Top][All Lists]
Advanced

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

Re: [bongo-devel] Header line flashing away


From: Daniel Brockman
Subject: Re: [bongo-devel] Header line flashing away
Date: Tue, 27 Mar 2007 20:08:20 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (gnu/linux)

Daniel,

> Another TODO list item:
>
>     Prevent the header line from flashing away and back
>     when going from one track to the next.

Thank you for working on this!

I think my friend who reported this and whom it has annoyed
quite a bit would be glad to see it fixed.  I put him on CC.

> The attached solution looks OK to me. Could it cause problems?

I believe it could cause a slight problem since it assumes
that `bongo-update-header-line-string' is only called in a
few controlled situations.  This assumption seems bad.

For example, after applying your patch, if you stop playback
and then call the aforementioned function, the header line
will appear (displaying an empty string).

On the other hand, it is a clever and compact solution.

Here is my less clever and much less compact proposal:

diff -rN -u old-bongo/bongo.el new-bongo/bongo.el
--- old-bongo/bongo.el  2007-03-27 20:02:33.000000000 +0200
+++ new-bongo/bongo.el  2007-03-27 20:02:33.000000000 +0200
@@ -189,6 +189,24 @@
                                (error "No track at point"))))
        ,@body)))
 
+(defvar bongo-defer-status-indicator-updates nil
+  "If non-nil, defer all Bongo status indicator updates.
+Updates are stored in `bongo-deferred-status-indicator-updates'.")
+
+(defvar bongo-deferred-status-indicator-updates nil
+  "List of deferred Bongo status indicator updates.
+Entries are of the form (FUNCTION . ARGUMENTS).")
+
+(defmacro with-deferred-bongo-status-indicator-updates (&rest body)
+  "Execute BODY without updating any Bongo status indicators.
+Afterwards, perform all status indicator updates all at once."
+  (declare (indent 0) (debug t))
+  `(progn (let ((bongo-defer-status-indicator-updates t))
+            ,@body)
+          (dolist (entry bongo-deferred-status-indicator-updates)
+            (apply (car entry) (cdr entry)))
+          (setq bongo-deferred-status-indicator-updates nil)))
+
 (defmacro bongo-ignore-movement-errors (&rest body)
   "Execute BODY; if a Bongo movement error occurs, return nil.
 Otherwise, return the value of the last form in BODY."
@@ -848,20 +866,32 @@
 If Bongo is not playing anything, set the header line string to nil.
 Accept DUMMY arguments to ease hook usage."
   (when (bongo-buffer-p)
-    (when (null header-line-format)
-      (setq header-line-format '("")))
-    (if bongo-header-line-mode
-        (add-to-list 'header-line-format
-          'bongo-header-line-string t)
-      (setq header-line-format
-            (remq 'bongo-header-line-string header-line-format)))
-    (setq bongo-header-line-string
-          (when (bongo-playing-p)
-            (bongo-format-string bongo-header-line-format)))
-    (when (or (equal header-line-format '(""))
-              (and (equal header-line-format '("" bongo-header-line-string))
-                   (null bongo-header-line-string)))
-      (setq header-line-format nil))))
+    (let ((new-header-line-format header-line-format)
+          (new-bongo-header-line-string bongo-header-line-string))
+      (when (null new-header-line-format)
+        (setq new-header-line-format '("")))
+      (if bongo-header-line-mode
+          (add-to-list 'new-header-line-format
+            'bongo-header-line-string t)
+        (setq new-header-line-format
+              (remq 'bongo-header-line-string new-header-line-format)))
+      (setq new-bongo-header-line-string
+            (when (bongo-playing-p)
+              (bongo-format-string bongo-header-line-format)))
+      (when (or (equal new-header-line-format '(""))
+                (and (equal new-header-line-format
+                            '("" bongo-header-line-string))
+                     (null new-bongo-header-line-string)))
+        (setq new-header-line-format nil))
+      (if (not bongo-defer-status-indicator-updates)
+          (setq header-line-format new-header-line-format
+                bongo-header-line-string new-bongo-header-line-string)
+        (add-to-list 'bongo-deferred-status-indicator-updates
+          (list 'set 'header-line-format
+                new-header-line-format))
+        (add-to-list 'bongo-deferred-status-indicator-updates
+          (list 'set 'bongo-header-line-string
+                new-bongo-header-line-string))))))
 
 (defun bongo-header-line-mode (argument &optional called-interactively-p)
   "Toggle display of Bongo mode line indicator on or off.
@@ -1531,8 +1561,12 @@
   the resulting string in `bongo-mode-line-indicator-string'.
 Accept DUMMY arguments to ease hook usage."
   (when (bongo-buffer-p)
-    (setq bongo-mode-line-indicator-string
-          (bongo-format-string bongo-mode-line-indicator-format))))
+    (let ((new-value (bongo-format-string
+                      bongo-mode-line-indicator-format)))
+      (if (not bongo-defer-status-indicator-updates)
+          (setq bongo-mode-line-indicator-string new-value)
+        (add-to-list 'bongo-deferred-status-indicator-updates
+          (list 'set 'bongo-mode-line-indicator-string new-value))))))
 
 (defun bongo-mode-line-indicator-mode
   (argument &optional called-interactively-p)
@@ -5715,21 +5742,22 @@
   (interactive "d")
   (unless (bongo-playlist-buffer-p)
     (error "Not a Bongo playlist buffer"))
-  (with-point-at-bongo-track point
-    (when bongo-player
-      (bongo-player-stop bongo-player))
-    (bongo-set-current-track-position)
-    (let ((player (if (bongo-action-track-line-p)
-                      (bongo-start-action-player (bongo-line-action))
-                    (bongo-play-file
-                     (bongo-line-file-name)
-                     (bongo-line-get-property 'bongo-backend)))))
-      (bongo-player-put player 'infoset (bongo-line-infoset))
-      (setq bongo-player player)
-      (bongo-line-set-property 'bongo-player player)
-      (bongo-set-current-track-marker bongo-playing-track-marker)
-      (run-hooks 'bongo-player-started-hook)
-      (bongo-redisplay-line))))
+  (with-deferred-bongo-status-indicator-updates
+    (with-point-at-bongo-track point
+     (when bongo-player
+       (bongo-player-stop bongo-player))
+     (bongo-set-current-track-position)
+     (let ((player (if (bongo-action-track-line-p)
+                       (bongo-start-action-player (bongo-line-action))
+                     (bongo-play-file
+                      (bongo-line-file-name)
+                      (bongo-line-get-property 'bongo-backend)))))
+       (bongo-player-put player 'infoset (bongo-line-infoset))
+       (setq bongo-player player)
+       (bongo-line-set-property 'bongo-player player)
+       (bongo-set-current-track-marker bongo-playing-track-marker)
+       (run-hooks 'bongo-player-started-hook)
+       (bongo-redisplay-line)))))
 
 (defun bongo-play-lines (&optional n)
   "Start playing the next N tracks or sections.
@@ -5868,9 +5896,10 @@
         (bongo-progressive-playback-mode))
     (if (< (prefix-numeric-value n) 0)
         (bongo-play-previous (- (prefix-numeric-value n)))
-      (bongo-stop)
-      (bongo-next n)
-      (bongo-start))))
+      (with-deferred-bongo-status-indicator-updates
+        (bongo-stop)
+        (bongo-next n)
+        (bongo-start)))))
 
 (defun bongo-play-next-or-stop (&optional n)
   "Maybe start playing the next track in the nearest playlist buffer.
@@ -5940,9 +5969,10 @@
         (bongo-regressive-playback-mode))
     (if (< (prefix-numeric-value n) 0)
         (bongo-play-next (- (prefix-numeric-value n)))
-      (bongo-stop)
-      (bongo-previous n)
-      (bongo-start))))
+      (with-deferred-bongo-status-indicator-updates
+        (bongo-stop)
+        (bongo-previous n)
+        (bongo-start)))))
 
 (defun bongo-play-previous-or-stop (&optional n)
   "Maybe start playing the previous track in the playlist buffer.
Do you think that's okay?

-- 
Daniel Brockman <address@hidden>

reply via email to

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