emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/greader 18f96fae7f 4/7: greader.el: fixed backends.


From: ELPA Syncer
Subject: [elpa] externals/greader 18f96fae7f 4/7: greader.el: fixed backends.
Date: Tue, 30 Apr 2024 03:58:19 -0400 (EDT)

branch: externals/greader
commit 18f96fae7f8d6e26c9893189018b93219625ed02
Author: Michelangelo Rodriguez <michelangelo.rodriguez@gmail.com>
Commit: Michelangelo Rodriguez <michelangelo.rodriguez@gmail.com>

    greader.el: fixed backends.
    
    Now back-ends are interely responsible for their punctuation levels,
    as it should have been from the beginning.
---
 greader-espeak.el  | 26 ++++++++++++++++++++------
 greader-speechd.el | 43 ++++++++++++++++++++++++++++++-------------
 greader.el         | 16 ++++------------
 3 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/greader-espeak.el b/greader-espeak.el
index d32431e1ff..e8f461073a 100644
--- a/greader-espeak.el
+++ b/greader-espeak.el
@@ -48,6 +48,13 @@ LANG must be recognized by espeak or espeak-ng."
     (progn
       (setq-local greader-espeak-language lang)
       (concat "-v " lang))))
+
+(defvar greader-espeak--punctuation-ring (make-ring 2))
+(ring-insert greader-espeak--punctuation-ring "yes")
+(ring-insert greader-espeak--punctuation-ring "no")
+(defvar greader-espeak--ring-item (if greader-espeak-punctuation "yes"
+                                   "no"))
+
 ;;;###autoload
 (defun greader-espeak (command &optional arg &rest _)
   "Back-end main function of greader-espeak.
@@ -65,12 +72,19 @@ COMMAND must be a string suitable for `make-process'."
        (greader-espeak-set-rate arg))))
     ('punctuation
      (pcase arg
-       ('yes
-       (setq-local greader-espeak-punctuation t)
-       "--punct")
-       ('no
-       (setq-local greader-espeak-punctuation nil)
-       nil)
+       ((or 'toggle 'yes 'no)
+       (setq greader-espeak--ring-item (ring-next
+                                        greader-espeak--punctuation-ring
+                                        greader-espeak--ring-item))
+       (pcase greader-espeak--ring-item
+         ("yes"
+          (setq-local greader-espeak-punctuation t)
+          (message "Punctuation enabled in current buffer.")
+          "--punct")
+         ("no"
+          (setq-local greader-espeak-punctuation nil)
+          (message "punctuation disabled in current buffer.")
+          nil)))
        ('nil
        (if greader-espeak-punctuation
            "--punct"
diff --git a/greader-speechd.el b/greader-speechd.el
index bac0f2f3ab..74c230b428 100644
--- a/greader-speechd.el
+++ b/greader-speechd.el
@@ -84,17 +84,34 @@ PUNCT must be a numeric value, 0 for no punctuation, 1 for 
some and 2
 or >2 for all punctuation."
   (setq-local greader-speechd-punctuation
               (pcase punct
-               ('t "all")
-               ('0 "none")
-               ('1 "some")
-               ((and (pred numberp) (pred (<= 2))) "all")
-               (_ (error "Unknown punctuation: %S" punct))))
+               ('t "all")
+               ('0 "none")
+               ('1 "some")
+               ((and (pred numberp) (pred (<= 2))) "all")
+               (_ (error "Unknown punctuation: %S" punct))))
   (concat "-m" greader-speechd-punctuation))
 
 (defun greader-speechd-stop ()
   "Stops speech-dispatcher client."
   (start-process "speechd-client" nil greader-speechd-executable "-S")
   (sleep-for 0.100))
+(defvar greader-speechd--punctuation-ring (make-ring 3))
+(ring-insert greader-speechd--punctuation-ring 0)
+(ring-insert greader-speechd--punctuation-ring 1)
+(ring-insert greader-speechd--punctuation-ring 2)
+
+(defvar greader-speechd--ring-item
+  (cond
+   ((equal greader-speechd-punctuation "none") 0)
+   ((equal greader-speechd-punctuation "some") 1)
+   ((= greader-speechd-punctuation "all") 2)))
+
+(defun greader-speechd--ring-next ()
+  "Return the next element in the `greader-speechd--punctuation-ring'
+based on `greader-speechd--ring-item'"
+  (setq greader-speechd--ring-item (ring-next greader-speechd--punctuation-ring
+            greader-speechd--ring-item)))
+
 ;;;###autoload
 (defun greader-speechd (command &optional arg &rest _)
   "greader speech-dispatcher back-end."
@@ -114,15 +131,15 @@ or >2 for all punctuation."
           greader-speechd-rate)))
     ('punctuation
      (cond
-      ((equal arg 'no)
-       (greader-speechd-set-punctuation 0)
-       nil)
-      ((equal arg 'yes)
-       (greader-speechd-set-punctuation 2))
+      ((equal arg 'toggle)
+       (prog1
+          (greader-speechd-set-punctuation (greader-speechd--ring-next))       
         
+        (message (concat "punctuation set to " greader-speechd-punctuation))))
       ((not arg)
-       (if (equal (greader-speechd-set-punctuation) "all")
-"-mall"
-        nil))))
+       (cond
+       ((equal greader-speechd--ring-item 0) "-mnone")
+       ((equal greader-speechd--ring-item 1) "-msome")
+       ((>= greader-speechd--ring-item 2) "-mall")))))
     ('stop
      (greader-speechd-stop))
     ('extra
diff --git a/greader.el b/greader.el
index 40c029fbd1..75d3f24b55 100644
--- a/greader.el
+++ b/greader.el
@@ -6,7 +6,7 @@
 ;; Author: Michelangelo Rodriguez <michelangelo.rodriguez@gmail.com>
 ;; Keywords: tools, accessibility
 
-;; Version: 0.9.19
+;; Version: 0.9.20
 
 ;; This program is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -745,17 +745,9 @@ the current backend"))))
 (defun greader-toggle-punctuation ()
   "Toggle punctuation locally for current buffer."
   (interactive)
-  (if (not (greader-call-backend 'punctuation))
-      (progn
-       (greader-tts-stop)
-       (greader-set-punctuation 'yes)
-       (message "punctuation enabled in current buffer")
-       (greader-read))
-    (progn
-      (greader-tts-stop)
-      (greader-set-punctuation 'no)
-      (message "punctuation disabled in current buffer")
-      (greader-read))))
+  (greader-stop)
+  (greader-call-backend 'punctuation 'toggle)
+  (greader-read))
 
 (defun greader-toggle-timer-flag ()
   "Not yet documented."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]