Christophe Weblog Wiki Code Publications Music
decode utf-8 as well as unhex in comint network stream output
[squeeze-el.git] / squeeze.el
index c4a229ad0249a345a0691b2e4914c03e504e36b9..86fd2e982ffd14c0039cf312b288cd66cad6cb02 100644 (file)
     (define-key map (kbd "TAB") 'completion-at-point)
     map))
 
+(defun squeeze-unhex-and-decode-utf8-string (string)
+  (decode-coding-string (url-unhex-string string) 'utf-8))
+
 (define-derived-mode squeeze-mode comint-mode "Squeeze"
   "Major mode for interacting with the Squeezebox Server CLI.\\<squeeze-mode-map>"
   (add-to-list 'completion-at-point-functions 'squeeze-complete-command-at-point)
-  (add-hook 'comint-preoutput-filter-functions 'url-unhex-string nil t)
+  (add-hook 'comint-preoutput-filter-functions 'squeeze-unhex-and-decode-utf8-string nil t)
   (add-hook 'comint-preoutput-filter-functions 'squeeze-update-state nil t))
 
 (defvar squeeze-control-mode-map
 (defun squeeze-control-listen ()
   (squeeze-send-string "listen 1"))
 
+(defun squeeze-accept-process-output ()
+  (while (accept-process-output (get-buffer-process "*squeeze*") 0.1 nil t)))
+
 (defun squeeze-control-refresh ()
   (interactive)
   (let ((squeeze-control-inhibit-display t))
     (squeeze-control-query-players)
-    (accept-process-output (get-buffer-process "*squeeze*"))
+    (squeeze-accept-process-output)
     (squeeze-control-query-syncgroups)
-    (accept-process-output (get-buffer-process "*squeeze*"))
     (dolist (player squeeze-players)
       (squeeze-control-query-power (squeeze-player-playerid player))
-      (accept-process-output (get-buffer-process "*squeeze*"))
-      (squeeze-control-query-mixer-volume (squeeze-player-playerid player))
-      (accept-process-output (get-buffer-process "*squeeze*"))))
+      (squeeze-control-query-mixer-volume (squeeze-player-playerid player))))
+  (squeeze-accept-process-output)
   (squeeze-control-display-players))
 
 (defvar squeeze-control-mixer-map
         (startpos (match-end 0)))
     (unless countpos
       (message "no count found in players line"))
-    (let ((count (parse-integer string (match-beginning 1) (match-end 1)))
+    (let ((count (string-to-number (substring string (match-beginning 1) (match-end 1))))
           result endpos)
       (dotimes (i (1- count))
         (setq endpos (progn (string-match " connected%3A[0-1] " string startpos)