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

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

[elpa] externals/scanner fdfdb62 33/56: add tesseract outputs selection


From: Stefan Monnier
Subject: [elpa] externals/scanner fdfdb62 33/56: add tesseract outputs selection command
Date: Fri, 10 Apr 2020 13:56:04 -0400 (EDT)

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

    add tesseract outputs selection command
---
 scanner-test.el | 10 ++++++++++
 scanner.el      | 38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/scanner-test.el b/scanner-test.el
index 2b478a0..28093d5 100644
--- a/scanner-test.el
+++ b/scanner-test.el
@@ -213,6 +213,16 @@
     (ignore-errors
       (should (equal '("eng") (scanner-select-languages 42))))))
 
+(ert-deftest scanner-test-select-outputs ()
+  "Test the output selection command."
+  (let ((scanner-tesseract-outputs '("pdf")))
+    (should (equal '("txt") (scanner-select-outputs '("txt"))))
+    (should (equal '("pdf" "txt") (scanner-select-outputs '("pdf" "txt"))))
+    (should-error (scanner-select-outputs 42)
+                 :type 'wrong-type-argument)
+    (ignore-errors
+      (should (equal '("pdf") (scanner-select-outputs 42))))))
+
 (provide 'scanner-test)
 
 
diff --git a/scanner.el b/scanner.el
index c8e4eec..590e2d0 100644
--- a/scanner.el
+++ b/scanner.el
@@ -137,13 +137,32 @@ The value must be one of the keys in the paper sizes 
list."
   "List of languages passed to tesseract(1) for OCR."
   :type '(repeat :validate scanner--validate-languages string))
 
+(defcustom scanner-tesseract-configdir
+  "/usr/share/tessdata/configs/"
+  "Config file directory for tesseract."
+  :type '(string))
+
+(defun scanner--validate-outputs (widget)
+  "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
+      (widget-put widget
+                 :error
+                 (format "Unknown output(s): %s; available are: %s"
+                         (mapconcat #'identity val ", ")
+                         (mapconcat #'identity configs ", ")))
+      widget)))
+
+
 (defcustom scanner-tesseract-outputs
   '("pdf" "txt")
   "List of output formats to produce.
 The output formats correspond to the names of config files that
-come with tesseract(1).
-The config files may reside in ‘/usr/share/tessdata/configs’."
-  :type '(repeat string))
+come with tesseract(1).  The config files are assumed to reside
+in ‘scanner-tesseract-configdir’."
+  :type '(repeat :validate scanner--validate-outputs string))
 
 (defcustom scanner-tesseract-switches
   '()
@@ -182,6 +201,10 @@ If nil, attempt auto-detection."
       '(menu-item "Select languages" scanner-select-languages
                  :key-sequence nil
                  :help "Select languages for OCR."))
+    (define-key map [outputs]
+      '(menu-item "Select document outputs" scanner-select-outputs
+                 :key-sequence nil
+                 :help "Select document output formats."))
     (define-key map [papersize]
       '(menu-item "Select paper size" scanner-select-papersize
                  :key-sequence nil
@@ -380,6 +403,15 @@ availability of required options."
     (signal 'wrong-type-argument `(consp ,languages)))
   (setq scanner-tesseract-languages languages))
 
+(defun scanner-select-outputs (outputs)
+  "Select OUTPUTS for tesseract."
+  (interactive
+   (let ((configs (directory-files scanner-tesseract-configdir nil "[^.]")))
+     (list (completing-read-multiple "Outputs: " configs nil t))))
+  (unless (consp outputs)
+    (signal 'wrong-type-argument `(consp ,outputs)))
+  (setq scanner-tesseract-outputs outputs))
+
 (defun scanner-set-image-resolution (resolution)
   "Set the RESOLUTION for scanning images."
   (interactive "NImage scan resolution: ")



reply via email to

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