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

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

[elpa] externals/scanner e9b14b5 39/56: clean up a few rather cosmetic i


From: Stefan Monnier
Subject: [elpa] externals/scanner e9b14b5 39/56: clean up a few rather cosmetic issues
Date: Fri, 10 Apr 2020 13:56:05 -0400 (EDT)

branch: externals/scanner
commit e9b14b5e013cf8a24759b538f08517f0d2570d9d
Author: Raffael Stocker <address@hidden>
Commit: Raffael Stocker <address@hidden>

    clean up a few rather cosmetic issues
---
 Readme.org |  1 +
 scanner.el | 94 ++++++++++++++++++++++++++++++--------------------------------
 2 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/Readme.org b/Readme.org
index dd6ee28..ccc469f 100644
--- a/Readme.org
+++ b/Readme.org
@@ -39,3 +39,4 @@
 * Bugs
 
   - This package doesn't support document feeders yet.
+  - This package doesn't support authentication.
diff --git a/scanner.el b/scanner.el
index 01eadc3..5cda3c9 100644
--- a/scanner.el
+++ b/scanner.el
@@ -130,8 +130,7 @@ The value must be one of the keys in the paper sizes list."
   (let ((val (widget-value widget))
        (langs (cdr (process-lines scanner-tesseract-program
                                   "--list-langs"))))
-    (if (cl-subsetp val langs :test #'string=)
-       nil
+    (unless (cl-subsetp val langs :test #'string=)
       (widget-put widget
                  :error
                  (format "Unknown language(s): %s; available are: %s"
@@ -153,8 +152,7 @@ The value must be one of the keys in the paper sizes list."
   "Validate the output selection in customization WIDGET."
   (let ((val (widget-value widget))
        (configs (directory-files scanner-tesseract-configdir nil "[^.]")))
-    (if (cl-subsetp val configs :test #'string=)
-       nil
+    (unless (cl-subsetp val configs :test #'string=)
       (widget-put widget
                  :error
                  (format "Unknown output(s): %s; available are: %s"
@@ -290,8 +288,8 @@ results are cached in ‘scanner--available-switches’ and
       (goto-char (point-min))
       (while (re-search-forward scanner--device-option-re nil t)
        (push (match-string 1) opts)))
-    (setq scanner--available-switches opts)
-    (setq scanner--missing-switches
+    (setq scanner--available-switches opts
+         scanner--missing-switches
          (-difference scanner--device-specific-switches opts))
     (list scanner--available-switches scanner--missing-switches)))
 
@@ -479,18 +477,32 @@ available, ask for a selection interactively."
        (fmt (plist-get scanner-image-format :doc))
        (file-list '())
        (fl-file nil))
-    (cl-labels ((cleanup
+    (cl-labels ((scanimage
                 ()
-                (and file-list (dolist (file file-list)
-                                 (delete-file file)))
-                (and fl-file (delete-file fl-file)))
-               (finish
+                (let* ((img-file (make-temp-file "scanner" nil (concat "." 
fmt)))
+                       (scanimage-args (scanner--scanimage-args img-file
+                                                                :doc fmt)))
+                  (push img-file file-list)
+                  (make-process :name "Scanner (scanimage)"
+                                :command `(,scanner-scanimage-program
+                                           ,@scanimage-args)
+                                :sentinel #'scan-or-process)))
+               (scan-or-process
                 (process event)
-                (unwind-protect
+                (condition-case err
                     (let ((ev (string-trim event)))
                       (unless (string= "finished" ev)
-                        (error "%s: %s" process ev)))
-                  (cleanup)))
+                        (error "%s: %s" process ev))
+                      (cond ((consp npages) (if (y-or-n-p "Scan another page? 
")
+                                                (scanimage)
+                                              (tesseract)))
+                            ((> num-pages 1)
+                             (cl-decf num-pages)
+                             (run-at-time scanner-scan-delay nil #'scanimage))
+                            (t (tesseract))))
+                  (error
+                   (cleanup)
+                   (signal (car err) (cdr err)))))
                (tesseract
                 ()
                 (unless scanner-reverse-pages
@@ -504,32 +516,18 @@ available, ask for a selection interactively."
                                 :command `(,scanner-tesseract-program
                                            ,@tesseract-args)
                                 :sentinel #'finish)))
-               (scan-or-finish
+               (finish
                 (process event)
-                (condition-case err
+                (unwind-protect
                     (let ((ev (string-trim event)))
                       (unless (string= "finished" ev)
-                        (error "%s: %s" process ev))
-                      (cond ((consp npages) (if (y-or-n-p "Scan another page? 
")
-                                                (scanimage)
-                                              (tesseract)))
-                            ((> num-pages 1)
-                             (cl-decf num-pages)
-                             (run-at-time scanner-scan-delay nil #'scanimage))
-                            (t (tesseract))))
-                  (error
-                   (cleanup)
-                   (signal (car err) (cdr err)))))
-               (scanimage
+                        (error "%s: %s" process ev)))
+                  (cleanup)))
+               (cleanup
                 ()
-                (let* ((img-file (make-temp-file "scanner" nil (concat "." 
fmt)))
-                       (scanimage-args (scanner--scanimage-args img-file
-                                                                :doc fmt)))
-                  (push img-file file-list)
-                  (make-process :name "Scanner (scanimage)"
-                                :command `(,scanner-scanimage-program
-                                           ,@scanimage-args)
-                                :sentinel #'scan-or-finish))))
+                (and file-list (dolist (file file-list)
+                                 (delete-file file)))
+                (and fl-file (delete-file fl-file))))
       (scanimage))))
 
 ;;;###autoload
@@ -555,17 +553,7 @@ available, ask for a selection interactively."
                      (concat "." fmt)))
         (num-scans (prefix-numeric-value nscans))
         (page-count 1))
-    (cl-labels ((scan-or-finish
-                (process event)
-                (let ((ev (string-trim event)))
-                  (unless (string= "finished" ev)
-                    (error "%s: %s" process ev))
-                  (cond ((consp nscans) (when (y-or-n-p "Scan another page? ")
-                                          (scanimage t)))
-                        ((> num-scans 1)
-                         (cl-decf num-scans)
-                         (run-at-time scanner-scan-delay nil #'scanimage t)))))
-               (scanimage
+    (cl-labels ((scanimage
                 (multi-scan)
                 (let* ((img-file (if multi-scan
                                      (prog1
@@ -579,7 +567,17 @@ available, ask for a selection interactively."
                   (make-process :name "Scanner (scanimage)"
                                 :command `(,scanner-scanimage-program
                                            ,@scanimage-args)
-                                :sentinel #'scan-or-finish))))
+                                :sentinel #'scan-or-finish)))
+               (scan-or-finish
+                (process event)
+                (let ((ev (string-trim event)))
+                  (unless (string= "finished" ev)
+                    (error "%s: %s" process ev))
+                  (cond ((consp nscans) (when (y-or-n-p "Scan another page? ")
+                                          (scanimage t)))
+                        ((> num-scans 1)
+                         (cl-decf num-scans)
+                         (run-at-time scanner-scan-delay nil #'scanimage 
t))))))
       (scanimage (or (> num-scans 1) (consp nscans))))))
 
 (provide 'scanner)



reply via email to

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