emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/mpv 8c0933630b 08/50: add seek-to-position-at-point


From: ELPA Syncer
Subject: [nongnu] elpa/mpv 8c0933630b 08/50: add seek-to-position-at-point
Date: Tue, 28 Dec 2021 00:58:34 -0500 (EST)

branch: elpa/mpv
commit 8c0933630bd52532169d6e6b34143d0697101d6c
Author: Johann Klähn <kljohann@gmail.com>
Commit: Johann Klähn <kljohann@gmail.com>

    add seek-to-position-at-point
---
 mpv-mode.el | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/mpv-mode.el b/mpv-mode.el
index 5cfba03ce8..0a7b78cb21 100644
--- a/mpv-mode.el
+++ b/mpv-mode.el
@@ -39,9 +39,13 @@
   "Name or path to the mpv executable."
   :type 'file)
 
-(defcustom position-format "%H:%M:%S"
-  "Format used for inserting playback position."
-  :type 'string)
+(defvar -position-format "%H:%M:%S"
+  "Format used for inserting playback position.")
+(defvar -position-regexp
+  (rx (group (repeat 2 num)) ":"
+      (group (repeat 2 num)) ":"
+      (group (repeat 2 num))))
+(defvar -position-skipchars ":[:digit:]")
 
 (defvar -process nil)
 (defvar -queue nil)
@@ -142,8 +146,19 @@ drops unsolicited event messages."
                 (let* ((secs (truncate time))
                        (usecs (round (* 1000 (- time secs)))))
                   (with-current-buffer buffer
-                    (insert (format-time-string position-format
+                    (insert (format-time-string -position-format
                                                 `(0 ,secs ,usecs 0) t))))))))
+
+(defun seek-to-position-at-point ()
+  "Jump to playback position as inserted by 
`mpv-mode-insert-playback-position'."
+  (interactive)
+  (save-excursion
+    (skip-chars-backward -position-skipchars (point-at-bol))
+    (when (looking-at -position-regexp)
+      (let ((hours (string-to-number (match-string 1)))
+            (mins (string-to-number (match-string 2)))
+            (secs (string-to-number (match-string 3))))
+        (-enqueue `("seek" ,(+ (* 3600 hours) (* 60 mins) secs) "absolute") 
#'ignore)))))
 )
 
 (provide 'mpv-mode)



reply via email to

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