branch: elpa/subed
commit 2477ff4b0dbf7d5d11dc2f0e15dafb3d7212b843
Author: Sacha Chua <[email protected]>
Commit: Sacha Chua <[email protected]>

    subed-wdiff: Ignore a regexp
    
    * subed/subed-common.el (subed-wdiff-subtitle-text-with-file):
    Add an optional parameter to ignore a regular expression
    when comparing.
---
 subed/subed-common.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/subed/subed-common.el b/subed/subed-common.el
index 87e2df8c22b..37a8e866624 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -2439,25 +2439,27 @@ prefix argument, include comments in TXT output."
 ;;;###autoload
 (defvar subed-wdiff-executable "wdiff" "Command for word-based diffs.")
 
-(defun subed-wdiff-subtitle-text-with-file (script-file)
+(defun subed-wdiff-subtitle-text-with-file (script-file &optional 
ignore-regexp)
        "Use wdiff to compare the captions with SCRIPT-FILE by word.
 The wdiff program must be installed.  Set
 `subed-wdiff-executable' if needed."
-       (interactive (list (read-file-name "Script: ")))
+       (interactive (list (read-file-name "Script: ")
+                     (when current-prefix-arg "[ ,\n]+")))
        (let ((subtitle-text (subed-subtitle-list-text (subed-subtitle-list)))
                                (subtitle-text-filename (make-temp-file 
"subed-wdiff-subtitles" nil ".txt"))
                                (one-line-script-filename (make-temp-file 
"subed-wdiff-script" nil ".txt"))
+        (ignore-regexp (or ignore-regexp "[ \n]+"))
                                result)
                (with-temp-file subtitle-text-filename
                        (insert (replace-regexp-in-string
-                                "[ \n]+" " "
+                                ignore-regexp" "
                                 subtitle-text)))
                (with-temp-file one-line-script-filename
                        (if (member (file-name-extension script-file) '("vtt" 
"srt" "tsv" "ass"))
                                        (insert (mapconcat (lambda (o) (concat 
(elt o 3) " ")) (subed-parse-file script-file)))
                                (insert-file-contents script-file))
                        (goto-char (point-min))
-                       (while (re-search-forward "[ \n]+" nil t)
+                       (while (re-search-forward ignore-regexp nil t)
                                (replace-match " ")))
                (setq result
                                        (shell-command-to-string (format "wdiff 
%s %s"

Reply via email to