X-Git-Url: http://christophe.rhodes.io/gitweb/?p=squeeze-el.git;a=blobdiff_plain;f=squeeze.el;h=977813b28fc24c118fc0dafd600d7c7901250723;hp=1e34449f76861986fee4ab9ca0ca31686188cb59;hb=35375c87ec7345b3005cb5e70a86ea03e9414695;hpb=c25024a3a63e4e6bf71f882d2e8697c831dd3a91 diff --git a/squeeze.el b/squeeze.el index 1e34449..977813b 100644 --- a/squeeze.el +++ b/squeeze.el @@ -39,15 +39,25 @@ (defvar squeeze-control-inhibit-display nil) -(defun squeeze-update-state (string) - (let (done-something) - (dolist (line (split-string string "\n")) - (when (squeeze-update-state-from-line line) - (setq done-something t))) - (when done-something - (unless squeeze-control-inhibit-display - (squeeze-control-display-players)))) - string) +(lexical-let ((buffer (get-buffer-create " *squeeze-update-state*"))) + (defun squeeze-update-state (string) + ;; FIXME: we could make this a lot more elegant by using the + ;; buffer abstraction more + (if (cl-position ?\n string) + (let (done-something) + (with-current-buffer buffer + (insert string) + (setq string (buffer-string)) + (erase-buffer)) + (dolist (line (split-string string "\n")) + (when (squeeze-update-state-from-line line) + (setq done-something t))) + (when done-something + (unless squeeze-control-inhibit-display + (squeeze-control-display-players)))) + (with-current-buffer buffer + (insert string))) + string)) (defconst squeeze-player-line-regexp "^\\(\\(?:[0-9a-f]\\{2\\}%3A\\)\\{5\\}[0-9a-f]\\{2\\}\\) ") @@ -334,7 +344,7 @@ (save-match-data (let (result) (loop - (if (string-match "\\([a-z]+\\)%3A\\([^ \n]+\\)" string start) + (if (string-match "\\([a-z_]+\\)%3A\\([^ \n]+\\)" string start) (let ((mend (match-end 0))) (when (> mend end) (return)) @@ -353,20 +363,30 @@ (when startpos (squeeze-string-plistify string startpos (length string))))) +(defun squeeze-parse-count (string) + (save-match-data + (let ((countpos (string-match "count%3A\\([0-9]*\\)\\>" string))) + (if countpos + (string-to-number + (substring string (match-beginning 1) (match-end 1))) + (let ((kind + (progn (string-match "^\\([a-z]*\\) " string) + (substring string (match-beginning 1) (match-end 1))))) + (message "no count found in %s line" kind) + nil))))) + (defun squeeze-parse-players-line (string) - (let ((countpos (string-match " count%3A\\([0-9]\\) " string)) - (startpos (match-end 0))) - (unless countpos - (message "no count found in players line")) - (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) - (match-end 0))) - (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result) - (setq startpos endpos)) - (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result) - result))) + (let ((count (squeeze-parse-count string)) + (startpos (string-match "playerindex" string)) + result endpos) + (dotimes (i (1- count)) + (setq endpos (progn (string-match " connected%3A[0-1] " string startpos) + (match-end 0))) + (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result) + (setq startpos endpos)) + (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result) + result)) + (defun squeeze-complete-command-at-point () (save-excursion @@ -404,7 +424,7 @@ "serverstatus" "status" "displaystatus" "readdirectory" ;; Notifications - + ;; Alarm commands and queries "alarm" "alarms"