branch: elpa/subed commit f2f11ca123076415305ecd8e5fff68b51070e9bf Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
subed-mpv-find-video: Gracefully handle new file If the subtitle file we're editing doesn't exist yet, but the video file does, we must add the subtitles after the first save. --- subed/subed-mpv.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/subed/subed-mpv.el b/subed/subed-mpv.el index 8eff234..632c844 100644 --- a/subed/subed-mpv.el +++ b/subed/subed-mpv.el @@ -348,7 +348,16 @@ Video files are expected to have any of the extensions listed in (subed-debug "Opening video file: %s" filepath) (subed-mpv--client-connect subed-mpv--retry-delays) (subed-mpv--client-send `(loadfile ,filepath replace)) - (subed-mpv--client-send `(sub-add ,(buffer-file-name) select)) + (if (file-exists-p (buffer-file-name)) + (subed-mpv--client-send `(sub-add ,(buffer-file-name) select)) + ;; mpv won't add the subtitles if the file doesn't exist yet, so we add + ;; it via after-save-hook. We don't want to add the subtitles on every + ;; save, so we remove and undefine ourselves after the first save. + (defun subed-mpv--sub-add-after-save () + (subed-mpv--client-send `(sub-add ,(buffer-file-name) select)) + (remove-hook 'after-save-hook #'subed-mpv--sub-add-after-save :local) + (fmakunbound 'subed-mpv--sub-add-after-save)) + (add-hook 'after-save-hook #'subed-mpv--sub-add-after-save :append :local)) (subed-mpv--client-send `(observe_property 1 time-pos)) (subed-mpv-playback-speed subed-playback-speed-while-not-typing))))