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

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

[nongnu] elpa/subed 5e9518da77 18/22: Work around direct call of subed-m


From: ELPA Syncer
Subject: [nongnu] elpa/subed 5e9518da77 18/22: Work around direct call of subed-mode by guessing format
Date: Tue, 1 Feb 2022 14:06:12 -0500 (EST)

branch: elpa/subed
commit 5e9518da77a3c79a5f84fded676025a706b34d8d
Author: Sacha Chua <sacha@sachachua.com>
Commit: Sacha Chua <sacha@sachachua.com>

    Work around direct call of subed-mode by guessing format
    
    * README.org (Important change in v1.0.0): Document v1.0.0 breaking
    change.
    * subed/subed.el: Bump version to 1.0.0.
    (subed-mode): Add subed-guess-format function.
    (subed-guess-format): New function works around direct calls of
    subed-mode.
---
 README.org     | 17 +++++++++++++++++
 subed/subed.el | 16 +++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/README.org b/README.org
index 0035ad4c93..5dc51c4016 100644
--- a/README.org
+++ b/README.org
@@ -10,6 +10,23 @@ corresponding video with [[https://mpv.io/][mpv]].  At the 
moment, the only supp
 SubRip ( ~.srt~), WebVTT ( ~.vtt~ ), and Advanced SubStation Alpha ( ~.ass~, 
experimental ).
 
 [[file:https://raw.githubusercontent.com/rndusr/subed/master/screenshot.jpg]]
+** Important change in v1.0.0
+
+~subed~ now uses ~subed-srt-mode~, ~subed-vtt-mode~, and
+~subed-ass-mode~ instead of directly using ~subed-mode~. These modes
+should be automatically associated with the ~.vtt~, ~.srt~, and ~.ass~
+extensions. If the generic ~subed-mode~ is loaded instead of the 
format-specific mode,
+you may get an error such as:
+
+#+begin_example
+Error in post-command-hook (subed--post-command-handler): 
(cl-no-applicable-method subed--subtitle-id)
+#+end_example
+
+If you set ~auto-mode-alist~ manually in your config, please make sure
+you associate extensions the appropriate format-specific mode instead
+of ~subed-mode~. The specific backend functions (ex:
+~subed-srt--jump-to-subtitle-id~) are also deprecated in favor of
+using generic functions such as ~subed-jump-to-subtitle-id~.
 
 ** Features
    - Quickly jump to next (~M-n~) and previous (~M-p~) subtitle text.
diff --git a/subed/subed.el b/subed/subed.el
index 59187e897e..34f830a775 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -1,6 +1,6 @@
 ;;; subed.el --- A major mode for editing subtitles  -*- lexical-binding: t; 
-*-
 
-;; Version: 0.1.0
+;; Version: 1.0.0
 ;; Keywords: convenience, files, hypermedia, multimedia
 ;; URL: https://github.com/rndusr/subed
 ;; Package-Requires: ((emacs "25.1"))
@@ -124,6 +124,7 @@ Adjust - Increase or decrease start or stop time of a 
subtitle
 Key bindings:
 \\{subed-mode-map}"
   :group 'subed
+  (add-hook 'subed-mode-hook #'subed-guess-format :local)
   (add-hook 'post-command-hook #'subed--post-command-handler :append :local)
   (add-hook 'before-save-hook #'subed-prepare-to-save :append :local)
   (add-hook 'after-save-hook #'subed-mpv-reload-subtitles :append :local)
@@ -135,5 +136,18 @@ Key bindings:
   (when subed-auto-find-video
     (add-hook 'subed-mode-hook #'subed-auto-find-video-maybe :append :local)))
 
+(defun subed-guess-format ()
+  "Set this buffer's format to a more specific subed mode format.
+This is a workaround for the transition to using format-specific
+modes such as `subed-srt-mode' while `auto-mode-alist' might
+still refer to `subed-mode'. It will also switch to the
+format-specific mode if `subed-mode' is called directly."
+  (when (and (eq major-mode 'subed-mode)
+             (buffer-file-name))
+    (pcase (file-name-extension (buffer-file-name))
+      ("vtt" (subed-vtt-mode))
+      ("srt" (subed-srt-mode))
+      ("ass" (subed-ass-mode)))))
+
 (provide 'subed)
 ;;; subed.el ends here



reply via email to

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