emacs-nano-tts-minor-mode

A text-to-speech accessibility tool which reads aloud the active region.
git clone https://kaka.farm/~git/emacs-nano-tts-minor-mode
Log | Files | Refs | LICENSE

commit 9c72d4120163fc02e313340b1e57bec33dcc7c84
parent a4838075569f68aa8ce26f67702be0bd96cd8976
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Mon, 15 Jul 2024 08:22:24 +0300

Replace if with cond and one armed if with when.

Diffstat:
Mnano-tts.el | 73+++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 37 insertions(+), 36 deletions(-)

diff --git a/nano-tts.el b/nano-tts.el @@ -74,33 +74,34 @@ process. If the process is not running, make nano-tts forget about the last process." (interactive) - (if nano-tts--tts-process - ;; If there is already a TTS process. - (let ((tts-process-status (process-status nano-tts--tts-process))) - (pcase tts-process-status - ;; And if the process is running. - ('run - ;; Send the existing process the text. - (process-send-string nano-tts--tts-process - (nano-tts--get-region-as-string-to-speak))) - ;; If the TTS process is not running. - (_ - ;; Kill the TTS process before making nano-tts forget about - ;; it. - (nano-tts-kill)))) - - ;; If there is no running TTS process. - (progn - ;; Start the TTS process so that later we can send text to it. - (setq nano-tts--tts-process - (make-process - :name "espeak" - :command (list "espeak" - "-s" (number-to-string nano-tts-words-per-minute)))) - - ;; Send text to it. - (process-send-string nano-tts--tts-process - (nano-tts--get-region-as-string-to-speak))))) + (cond + (nano-tts--tts-process + ;; If there is already a TTS process. + (let ((tts-process-status (process-status nano-tts--tts-process))) + (pcase tts-process-status + ;; And if the process is running. + ('run + ;; Send the existing process the text. + (process-send-string nano-tts--tts-process + (nano-tts--get-region-as-string-to-speak))) + ;; If the TTS process is not running. + (_ + ;; Kill the TTS process before making nano-tts forget about + ;; it. + (nano-tts-kill))))) + + ;; If there is no running TTS process. + (t + ;; Start the TTS process so that later we can send text to it. + (setq nano-tts--tts-process + (make-process + :name "espeak" + :command (list "espeak" + "-s" (number-to-string nano-tts-words-per-minute)))) + + ;; Send text to it. + (process-send-string nano-tts--tts-process + (nano-tts--get-region-as-string-to-speak))))) (defun nano-tts-kill () @@ -111,15 +112,15 @@ kill the process." (interactive) ;; If there is a TTS process object. - (if nano-tts--tts-process - (let ((old-tts-process nano-tts--tts-process)) - ;; Make nano-tts aware that it is dead. - (setq nano-tts--tts-process - nil) - ;; Kill the TTS process. - (kill-process old-tts-process) - (message (format "Kill nano-tts process: %S" - old-tts-process))))) + (when nano-tts--tts-process + (let ((old-tts-process nano-tts--tts-process)) + ;; Make nano-tts aware that it is dead. + (setq nano-tts--tts-process + nil) + ;; Kill the TTS process. + (kill-process old-tts-process) + (message (format "Kill nano-tts process: %S" + old-tts-process))))) ;;;###autoload