branch: elpa/subed
commit 74251457ef5ccead6ac6e15f8bf5ec9321ef87cc
Author: Sacha Chua <[email protected]>
Commit: Sacha Chua <[email protected]>
New command subed-fill-subtitles
* subed/subed-common.el (subed-fill-subtitles): New command.
* subed/subed-config.el (subed-subtitle-fill-length): New option.
---
subed/subed-common.el | 65 +++++++++++++++++++++++++++------------------------
subed/subed-config.el | 5 ++++
2 files changed, 40 insertions(+), 30 deletions(-)
diff --git a/subed/subed-common.el b/subed/subed-common.el
index d901303ce4..b034f5010c 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -860,40 +860,45 @@ scheduled call is canceled and another call is scheduled
in
(concat string (make-string (- length (length string)) fillchar)))
;;;###autoload
-(defun subed-fill-subtitles (beg end)
- "Wrap the current subtitle at `fill-column'.
-In `subed-mode' buffers, this calls `subed-split-subtitle'
-ignoring the MPV playback position.
-In other buffers, this just adds newlines."
+(defun subed-fill-subtitles (&optional beg end)
+ "Wrap the current subtitle at `subed-subtitle-fill-length'.
+In `subed-mode' buffers, this calls `subed-split-subtitle' ignoring the
+MPV playback position. In other buffers, this just adds newlines. If
+`subed-subtitle-fill-length' is nil, use `fill-column'."
(interactive (if (region-active-p)
(list (region-beginning)
(region-end))
(list (point-min) (point-max))))
- (if (derived-mode-p 'subed-mode)
- (let ((subed-mpv-playback-position nil))
- (subed-for-each-subtitle beg end nil
- (subed-jump-to-subtitle-text)
- (move-to-column (current-fill-column))
- (while (> (current-column) (current-fill-column))
- (let ((linebeg (line-beginning-position)))
- (move-to-column (current-fill-column))
- (fill-move-to-break-point linebeg)
- (subed-split-subtitle)
- (subed-jump-to-subtitle-text)
- (move-to-column (current-fill-column))))))
- (goto-char beg)
- (let (linebeg)
- (while (< (point) end)
- (setq linebeg (point))
- (move-to-column (current-fill-column))
- (if (and (< (point) end)
- (< linebeg end)
- (not (looking-at " *$")))
- (progn
- (fill-move-to-break-point linebeg)
- (insert "\n")
- (delete-horizontal-space))
- (forward-char 1))))))
+ (setq beg (or beg (point-min)))
+ (setq end (or end (point-max)))
+ (let ((fill-to (or subed-subtitle-fill-length fill-column)))
+ (if (derived-mode-p 'subed-mode)
+ (let ((subed-mpv-playback-position nil))
+ (save-restriction
+ (narrow-to-region beg end)
+ (subed-for-each-subtitle beg end nil
+ (subed-jump-to-subtitle-text)
+ (move-to-column fill-to)
+ (let ((linebeg (line-beginning-position)))
+ (while (and (< (point) (point-max))
+ (< linebeg (point-max))
+ (not (looking-at " *$")))
+ (fill-move-to-break-point linebeg)
+ (subed-split-subtitle)
+ (move-to-column fill-to))))))
+ (goto-char beg)
+ (let (linebeg)
+ (while (< (point) end)
+ (setq linebeg (point))
+ (move-to-column fill-to)
+ (if (and (< (point) end)
+ (< linebeg end)
+ (not (looking-at " *$")))
+ (progn
+ (fill-move-to-break-point linebeg)
+ (insert "\n")
+ (delete-horizontal-space))
+ (forward-char 1)))))))
;;; Hooks for point motion and subtitle motion
diff --git a/subed/subed-config.el b/subed/subed-config.el
index c6b80e67c7..9c4410731d 100644
--- a/subed/subed-config.el
+++ b/subed/subed-config.el
@@ -154,6 +154,11 @@ If set to zero or smaller, playback is paused."
:type 'integer
:group 'subed)
+(defcustom subed-subtitle-fill-length 50
+ "Number of characters to wrap subtitles at when using
`subed-fill-subtitles'."
+ :type 'integer
+ :group 'subed)
+
(defcustom subed-default-subtitle-length 1000
"How long to make inserted subtitles in milliseconds."
:type 'float