[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mpv 33ca8987ed 03/50: work around spurious event messages
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mpv 33ca8987ed 03/50: work around spurious event messages |
Date: |
Tue, 28 Dec 2021 00:58:34 -0500 (EST) |
branch: elpa/mpv
commit 33ca8987ed267eadfe21977480839a38c88d3988
Author: Johann Klähn <kljohann@gmail.com>
Commit: Johann Klähn <kljohann@gmail.com>
work around spurious event messages
---
mpv-mode.el | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 62 insertions(+), 4 deletions(-)
diff --git a/mpv-mode.el b/mpv-mode.el
index 70a4134810..9e9276af88 100644
--- a/mpv-mode.el
+++ b/mpv-mode.el
@@ -27,6 +27,8 @@
(eval-when-compile (require 'names))
+(require 'tq)
+(require 'dash)
(require 'json)
(define-namespace mpv-mode-
@@ -42,9 +44,7 @@
(and -process (eq (process-status -process) 'run)))
(defun -start (&rest args)
- (when (-alive-p)
- (kill-process -process))
-
+ (-kill)
(let ((socket (make-temp-name
(expand-file-name "mpv-mode-" temporary-file-directory))))
(setq -process
@@ -56,7 +56,65 @@
(setq -queue (tq-create
(make-network-process :name "mpv-socket"
:family 'local
- :service socket)))))
+ :service socket)))
+ (set-process-filter
+ (tq-process -queue)
+ (lambda (_proc string)
+ (-tq-filter -queue string)))
+ t))
+
+(defun -kill ()
+ (when (-alive-p)
+ (kill-process -process))
+ (when -queue
+ (tq-close -queue))
+ (setq -process nil)
+ (setq -queue nil))
+
+(defun -enqueue (command fn &optional delay-command)
+ "Add COMMAND to the transaction queue.
+
+FN will be called with the corresponding answer.
+If DELAY-QUESTION is non-nil, delay sending this question until
+the process has finished replying to any previous questions.
+This produces more reliable results with some processes.
+
+Note that we do not use the regexp and closure arguments of
+`-tq-enque', see our custom implementation of `tq-process-buffer'
+below."
+ (tq-enqueue
+ -queue
+ (concat (json-encode `((command . ,command))) "\n")
+ "" nil fn delay-command))
+
+(defun -tq-filter (tq string)
+ (let ((buffer (tq-buffer tq)))
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (goto-char (point-max))
+ (insert string)
+ (-tq-process-buffer tq)))))
+
+(defun -tq-process-buffer (tq)
+ "Check TQ's buffer for a JSON response.
+
+Replacement for `tq-process-buffer' that ignores regular expressions
+\(answers are always passed to the first handler in the queue) and
+drops unsolicited event messages."
+ (goto-char (point-min))
+ (-when-let (answer (ignore-errors (json-read)))
+ (delete-region (point-min) (point))
+ ;; event messages have form {"event": ...}
+ ;; answers have form {"error": ..., "data": ...}
+ ;; FIXME: handle errors?
+ (unless (assoc 'event answer)
+ (unwind-protect
+ (condition-case nil
+ (funcall (tq-queue-head-fn tq)
+ (cdr (assoc 'data answer)))
+ (error nil))
+ (tq-queue-pop tq)))
+ (-tq-process-buffer tq)))
)
(provide 'mpv-mode)
- [nongnu] elpa/mpv 27b98410e5 45/50: Fix decreasing volume or speed by multiple steps, (continued)
- [nongnu] elpa/mpv 27b98410e5 45/50: Fix decreasing volume or speed by multiple steps, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 8da5b19f3d 07/50: cleanup, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 91b094c966 02/50: initial import, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv f0da905fd3 06/50: implement pausing and inserting playback position, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 6338f0d6b5 12/50: rename to mpv.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv e3fad297cd 18/50: add README.md, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv c6b3fa013c 36/50: Add mpv-run-command function to synchronously run commands, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 9dedf3b7c1 34/50: Monkey-patch org-timer-item instead of reimplementing, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 174cd4b68b 31/50: call expand-file-name on files passed to mpv-play, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 3849da1e45 01/50: root commit, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 33ca8987ed 03/50: work around spurious event messages,
ELPA Syncer <=
- [nongnu] elpa/mpv 6fe510798a 26/50: fix mpv-speed-set, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv fcdca618df 29/50: add badge for MELPA stable, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv d7bb3a7082 40/50: Add sleep and timeout to mpv-kill and mpv-play, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv bc89524528 15/50: use timer formatting from org-timer.el, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv b026ae5bb6 46/50: Merge pull request #19 from c1-g/volume, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 1e666079b8 05/50: skip junk at beginning of buffer, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 8c0933630b 08/50: add seek-to-position-at-point, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 03fe7a536a 24/50: add mpv-on-start-hook and mpv-on-exit-hook, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv 3021c55fa5 32/50: Merge pull request #1 from magnusstahre/expand-tilde, ELPA Syncer, 2021/12/28
- [nongnu] elpa/mpv f31cbdb94a 37/50: Add convenience functions to get and set properties, ELPA Syncer, 2021/12/28