branch: elpa/subed
commit a66d2206ee93259e939c78acbcc8b8cc28f9780a
Author: Sacha Chua <[email protected]>
Commit: Sacha Chua <[email protected]>
New command subed-wpm calculates words per minute
* subed/subed-common.el (subed-wpm): New command.
---
subed/subed-common.el | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/subed/subed-common.el b/subed/subed-common.el
index aa8c150fb2..017e3af542 100644
--- a/subed/subed-common.el
+++ b/subed/subed-common.el
@@ -1980,6 +1980,30 @@ if PRINT-MESSAGE is non-nil, display a message."
'after-string
(propertize (format " %.1f CPS" cps) 'face 'shadow 'display '(height
0.9)))))))
+(defun subed-wpm (&optional subtitles)
+ "Display words per minute.
+Use SUBTITILES if specified."
+ (interactive)
+ (setq subtitles (or subtitles (subed-subtitle-list)))
+ (let (word-count
+ (minutes
+ (/ (apply '+ (mapcar (lambda (o) (- (elt o 2) (elt o 1))) subtitles))
+ 60000.0)))
+ (with-temp-buffer
+ (insert
+ (mapconcat (lambda (o)
+ (replace-regexp-in-string "</?[^>]+>" "" (elt o 3)))
+ subtitles
+ " "))
+ (setq word-count (count-words (point-min) (point-max))))
+ (if (called-interactively-p 'any)
+ (message
+ "%d wpm (%d words / %.1f minutes)"
+ (/ (* 1.0 word-count) minutes)
+ word-count
+ minutes)
+ (/ (* 1.0 word-count) minutes))))
+
;;; Trimming overlaps
(defun subed--identify-overlaps ()