From e6a87bffca9d44ec180f7a17f6891de8f4bfccec Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 19 Apr 2026 07:15:29 -0500 Subject: refactor(transcription): extract running-transcriptions and format-entry Two cleanups round out the transcription-config refactor: - cj/--running-transcriptions: the 'status = running' filter used by cleanup and count helpers is now one function. Existing counter tests cover both callers. - cj/--format-transcription-entry: the 13-line dolist body inside cj/transcriptions-buffer becomes a testable pure function. 6 tests cover status-face mapping, basename-only rendering, duration format, trailing newline. --- modules/transcription-config.el | 45 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'modules') diff --git a/modules/transcription-config.el b/modules/transcription-config.el index 1c864b95..91d33a8e 100644 --- a/modules/transcription-config.el +++ b/modules/transcription-config.el @@ -246,19 +246,19 @@ associated output files." (run-at-time 600 nil #'cj/--cleanup-completed-transcriptions) (force-mode-line-update t))) +(defun cj/--running-transcriptions () + "Return the subset of `cj/transcriptions-list' whose status is `running'." + (seq-filter (lambda (entry) (eq (nth 3 entry) 'running)) + cj/transcriptions-list)) + (defun cj/--cleanup-completed-transcriptions () "Remove completed/errored transcriptions from tracking list." - (setq cj/transcriptions-list - (seq-filter (lambda (entry) - (eq (nth 3 entry) 'running)) - cj/transcriptions-list)) + (setq cj/transcriptions-list (cj/--running-transcriptions)) (force-mode-line-update t)) (defun cj/--count-active-transcriptions () "Return count of running transcriptions." - (length (seq-filter (lambda (entry) - (eq (nth 3 entry) 'running)) - cj/transcriptions-list))) + (length (cj/--running-transcriptions))) ;; ----------------------------- Modeline Integration -------------------------- @@ -304,6 +304,23 @@ Uses backend specified by `cj/transcribe-backend'." (user-error "No file at point")) (cj/transcribe-audio file))) +(defun cj/--format-transcription-entry (entry) + "Return a display string for a transcription ENTRY. +ENTRY is (PROCESS AUDIO-FILE START-TIME STATUS). Status drives the face; +duration is computed from START-TIME." + (let* ((audio-file (nth 1 entry)) + (start-time (nth 2 entry)) + (status (nth 3 entry)) + (duration (cj/--transcription-duration start-time)) + (status-face (pcase status + ('running 'warning) + ('complete 'success) + ('error 'error)))) + (concat (propertize (format "%-10s" status) 'face status-face) + " " + (file-name-nondirectory audio-file) + (format " (%s)\n" duration)))) + ;;;###autoload (defun cj/transcriptions-buffer () "Show buffer with active transcriptions." @@ -318,19 +335,7 @@ Uses backend specified by `cj/transcribe-backend'." (if (null cj/transcriptions-list) (insert "No active transcriptions.\n") (dolist (entry cj/transcriptions-list) - (let* ((process (nth 0 entry)) - (audio-file (nth 1 entry)) - (start-time (nth 2 entry)) - (status (nth 3 entry)) - (duration (cj/--transcription-duration start-time)) - (status-face (pcase status - ('running 'warning) - ('complete 'success) - ('error 'error)))) - (insert (propertize (format "%-10s" status) 'face status-face) - " " - (file-name-nondirectory audio-file) - (format " (%s)\n" duration)))))) + (insert (cj/--format-transcription-entry entry))))) (goto-char (point-min)) (special-mode)) (display-buffer buffer))) -- cgit v1.2.3