branch: elpa/subed commit f8793fb5ecebddec2f91abbba1b03fbd42285b1b Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
Move motion hooks from subed-config.el to subed-common.el --- subed/subed-common.el | 29 +++++++++++++++++++++++++++++ subed/subed-config.el | 26 -------------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/subed/subed-common.el b/subed/subed-common.el index 0e63686..0de7101 100644 --- a/subed/subed-common.el +++ b/subed/subed-common.el @@ -112,6 +112,35 @@ Before BODY is run, point is placed on the subtitle's ID." (concat string (make-string (- length (length string)) fillchar))) +;;; Hooks for point motion and subtitle motion + +(defvar-local subed--current-point -1) +(defvar-local subed--current-subtitle-id -1) +(defun subed--post-command-handler () + "Detect point motion and user entering text and signal hooks." + ;; Check for point motion first to avoid expensive calls to subed-subtitle-id + ;; as often as possible. + (let ((new-point (point))) + (when (and new-point subed--current-point + (not (= new-point subed--current-point))) + + ;; If point is synced to playback position, temporarily disable that so + ;; that manual moves aren't cancelled immediately by automated moves. + (subed-disable-sync-point-to-player-temporarily) + + ;; Store new point and fire signal. + (setq subed--current-point new-point) + (run-hooks 'subed-point-motion-hook) + + ;; Check if point moved across subtitle boundaries. + (let ((new-sub-id (subed-subtitle-id))) + (when (and new-sub-id subed--current-subtitle-id + (not (= new-sub-id subed--current-subtitle-id))) + ;; Store new ID and fire signal. + (setq subed--current-subtitle-id new-sub-id) + (run-hooks 'subed-subtitle-motion-hook)))))) + + ;;; Adjusting start/stop time individually (defun subed-adjust-subtitle-time-start (msecs &optional diff --git a/subed/subed-config.el b/subed/subed-config.el index 6660784..6daadd6 100644 --- a/subed/subed-config.el +++ b/subed/subed-config.el @@ -222,32 +222,6 @@ The functions are called with the subtitle's start time." (defvar-local subed-subtitle-motion-hook nil "Functions to call after current subtitle changed.") -(defvar-local subed--status-point 1 - "Keeps track of `(point)' to detect changes.") - -(defvar-local subed--status-subtitle-id 1 - "Keeps track of `(subed-subtitle-id)' to detect changes.") - -(defun subed--post-command-handler () - "Detect point motion and user entering text and signal hooks." - ;; Check for point motion first; skip checking for other changes if it didn't - (let ((new-point (point))) - (when (and new-point subed--status-point - (not (= new-point subed--status-point))) - - ;; If point is synced to playback position, temporarily prevent unexpected - ;; movement of the cursor. - (subed-disable-sync-point-to-player-temporarily) - - (setq subed--status-point new-point) - ;; Signal point motion - (run-hooks 'subed-point-motion-hook) - (let ((new-sub-id (subed-subtitle-id))) - (when (and new-sub-id subed--status-subtitle-id - (not (= subed--status-subtitle-id new-sub-id))) - (setq subed--status-subtitle-id new-sub-id) - ;; Signal motion between subtitles - (run-hooks 'subed-subtitle-motion-hook)))))) (provide 'subed-config) ;;; subed-config.el ends here