diff options
| author | Stefan Monnier <monnier@iro.umontreal.ca> | 2023-09-15 12:56:23 -0400 |
|---|---|---|
| committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2023-09-15 12:57:50 -0400 |
| commit | 6fe3129a11f32078f5622e1321e9e5021eb0f5cc (patch) | |
| tree | be4ef5660a9a78110b656301f289b744e48f5b37 /greader-mac.el | |
| parent | dff6b60acb7456422f5e32e2c9a36fda8f077267 (diff) | |
Miscellanous simplifications and "tightening"scratch/greader
Many of the simplifications result from hoisting `setq`
out of ifs or avoiding `setq` altogether.
Among the tightening, don't treat hooks as mere "variables holding
a list of functions", since they're a bit more complex than that
(e.g. can contain a function rather than a list, can have both
global and buffer-local functions at the same time, ...).
* greader.el (greader--call-functions-after-get-of-sentence):
Use `run-hook-wrapped` and simplify.
(greader--call-before-finish-functions):
Use `run-hook-with-args-until-success`.
(greader-change-backend): Consolidate the `seq-local`s outside of
the ifs. Use (cadr (memq ...)) to find the "next" item instead of
going through index numbers.
(greader-read-asynchronous): Simplify the computation of `txt` and
`backend` by avoiding `setq`.
(greader-action): Assume `greader-backend-action` is non-nil.
Use `ignore` rather than `nil` if you want a backend that does
nothing :-)
(greader-set-language): Simplify by avoiding `setq`.
(greader-timer-flag-p, greader-sentence-needs-dehyphenation): η-reduce.
(greader-compile-mode): Don't trust the `member` test
since hooks aren't just "normal var holding a list".
* greader-speechd.el (greader-speechd-set-punctuation): Simplify.
Signal an error when `punct` is nil instead of returning
`greader-speechd-punctuation` without a preceding "-m".
* greader-mac.el: Add missing `Code:` header.
(greader-mac-set-voice): Simplify.
(greader-mac-forward-sentence): Use `move` arg of `re-search-forward`.
(greader-mac-get-sentence): Use `greader-mac-forward-sentence`
and eliminate dummy initialization of `sentence-start` that's
immediately overwritten by something else.
(greader--mac-get-voices): `beginning-of-buffer` is "interactive-only".
Diffstat (limited to 'greader-mac.el')
| -rw-r--r-- | greader-mac.el | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/greader-mac.el b/greader-mac.el index 067a19c..2577af3 100644 --- a/greader-mac.el +++ b/greader-mac.el @@ -1,6 +1,10 @@ ;;; greader.el --- gnamù reader, send buffer contents to a speech engine. -*- lexical-binding: t; -*- +;; FIXME: The above line is not right for this file :-( ;; Copyright (C) 2017-2023 Free Software Foundation, Inc. + +;;; Code: + (defgroup greader-mac nil "Back-end of mac for greader." @@ -37,27 +41,14 @@ nil means to use the system voice." (defun greader-mac-set-voice (voice) "Set specified VOICE for `say'. -When called interactively, this function reads a string from the minibuffer providing completion." +When called interactively, this function reads a string from the minibuffer +providing completion." (interactive - (list (read-string "voice: " nil nil (greader--mac-get-voices)))) - (let (result) - (if (called-interactively-p 'any) - (progn - (if (string-equal "system" voice) - (setq-local greader-mac-voice nil) - (setq-local greader-mac-voice voice))) - (when voice - (if (string-equal voice "system") - (progn - (setq result nil) - (setq-local greader-mac-voice nil)) - (setq result (concat "-v" voice)) - (setq-local greader-mac-voice voice))) - (unless voice - (if greader-mac-voice - (setq result (concat "-v" greader-mac-voice)) - (setq result nil))) - result))) + (list (read-string "Voice: " nil nil (greader--mac-get-voices)))) + (when voice + (setq-local greader-mac-voice + (if (string-equal "system" voice) nil voice))) + (when greader-mac-voice (concat "-v" greader-mac-voice))) ;;;###autoload (defun greader-mac (command &optional arg &rest _) @@ -87,25 +78,21 @@ COMMAND must be a string suitable for `make-process'." (put 'greader-mac 'greader-backend-name "greader-mac") (defun greader-mac-get-sentence () - (let ((sentence-start (make-marker))) - (setq sentence-start (point)) + (let ((sentence-start (point))) (save-excursion - (when (not (eobp)) - (if (not (re-search-forward greader-mac-end-of-sentence-regexp nil t)) - (end-of-buffer)) + (greader-mac-forward-sentence) (if (> (point) sentence-start) (string-trim (buffer-substring-no-properties sentence-start (point)) "[ \t\n\r]+") - nil))))) + nil)))) (defun greader-mac-forward-sentence () - (if (not (re-search-forward greader-mac-end-of-sentence-regexp nil t)) - (end-of-buffer))) + (re-search-forward greader-mac-end-of-sentence-regexp nil 'move)) (defun greader--mac-get-voices () "Return a list which contains all voices suitable for this backend." (with-temp-buffer (call-process "say" nil t nil "-v" "?") - (beginning-of-buffer) + (goto-char (point-min)) (let ((lines (list "system"))) (while (not (eobp)) (let ((mymarker (make-marker))) |
