[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/scanner 2101ca0 08/17: handle undefined options and tes
From: |
Stefan Monnier |
Subject: |
[elpa] externals/scanner 2101ca0 08/17: handle undefined options and tesseract config directory gracefully |
Date: |
Mon, 14 Dec 2020 18:34:43 -0500 (EST) |
branch: externals/scanner
commit 2101ca0c18342319f2a7ad028dc37780b75a3a47
Author: Raffael Stocker <r.stocker@mnet-mail.de>
Commit: Raffael Stocker <r.stocker@mnet-mail.de>
handle undefined options and tesseract config directory gracefully
---
scanner.el | 48 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 38 insertions(+), 10 deletions(-)
diff --git a/scanner.el b/scanner.el
index 624d865..73a134a 100644
--- a/scanner.el
+++ b/scanner.el
@@ -143,23 +143,36 @@ widget's values and the elements of SET."
(mapconcat #'identity set ", ")))
widget)))
+(defcustom scanner-tessdata-dir
+ (or (getenv "TESSDATA_PREFIX")
+ "/usr/share/")
+ "Tesseract data directory prefix."
+ :type '(string))
+
+(defcustom scanner-tesseract-configdir
+ (if scanner-tessdata-dir
+ (concat (file-name-as-directory scanner-tessdata-dir)
"tessdata/configs/")
+ "/usr/share/tessdata/configs/")
+ "Config file directory for tesseract."
+ :type '(string))
+
(defun scanner--validate-languages (widget)
"Validate the language selection in customization WIDGET."
+ (cl-assert scanner-tesseract-program)
(scanner--widget-validate-subset
"Unknown language(s): %s; available are: %s" widget
- (cdr (process-lines scanner-tesseract-program
- "--list-langs"))))
+ (condition-case err
+ (cdr (process-lines scanner-tesseract-program
+ "--list-langs"
+ "--tessdata-dir"
+ scanner-tessdata-dir))
+ (error (error "No language definitions found %s" (cdr err))))))
(defcustom scanner-tesseract-languages
'("eng")
"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."
(scanner--widget-validate-subset
@@ -279,6 +292,7 @@ ignored, but something may not work as expected."))
Each entry of the list contains three elements: the SANE device
name, the device type, and the vendor and model names."
+ (cl-assert scanner-scanimage-program)
(let ((scanners (process-lines scanner-scanimage-program "-f" "%d|%t|%v
%m%n")))
;; attempt to filter out any spurious error output or other non-relevant
;; stuff
@@ -341,6 +355,7 @@ a device selection.
This function checks the SANE backend of the selected device
against the required options. The return value is a list of the
available options."
+ (cl-assert scanner-scanimage-program)
(let ((-compare-fn #'string=)
(switches-re (eval-when-compile
(regexp-opt
scanner--device-specific-switches t)))
@@ -414,8 +429,15 @@ them. Otherwise, return nil."
(defun scanner-select-languages (languages)
"Select LANGUAGES for optical character recognition."
(interactive
- (let ((langs (cdr (process-lines scanner-tesseract-program
-
"--list-langs"))))
+ (let ((langs (condition-case err
+ (progn
+ (cl-assert scanner-tesseract-program)
+ (cdr (process-lines
scanner-tesseract-program
+
"--list-langs"
+
"--tessdata-dir"
+
scanner-tessdata-dir)))
+ (error
+ (error "Could not query language list %s"
(cdr err))))))
(list (completing-read-multiple "Languages: " langs nil t))))
(setq scanner-tesseract-languages languages))
@@ -423,7 +445,10 @@ them. Otherwise, return nil."
(defun scanner-select-outputs (outputs)
"Select OUTPUTS for tesseract."
(interactive
- (let ((configs (directory-files scanner-tesseract-configdir nil "[^.]")))
+ (let ((configs (condition-case err
+ (directory-files
scanner-tesseract-configdir nil "[^.]")
+ (error
+ (error "Could not find output
configurations %s" (cdr err))))))
(list (completing-read-multiple "Outputs: " configs nil t))))
(setq scanner-tesseract-outputs outputs))
@@ -476,6 +501,8 @@ If ‘scanner-device-name’ is nil or this device is
unavailable,
attempt auto-detection. If more than one scanning device is
available, ask for a selection interactively."
(interactive "P\nFDocument file name: ")
+ (cl-assert scanner-scanimage-program)
+ (cl-assert scanner-tesseract-program)
(let ((doc-file (file-name-sans-extension filename))
(num-pages (prefix-numeric-value npages))
(fmt (plist-get scanner-image-format :doc))
@@ -566,6 +593,7 @@ If ‘scanner-device-name’ is nil or this device is
unavailable,
attempt auto-detection. If more than one scanning device is
available, ask for a selection interactively."
(interactive "P\nFImage file name: ")
+ (cl-assert scanner-scanimage-program)
(let ((derived-fmt (cdr (assoc (downcase (file-name-extension filename t))
'((".jpeg" .
"jpeg")
(".jpg" .
"jpeg")
- [elpa] externals/scanner updated (cbfd2bb -> b96d3d1), Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 1495d30 04/17: add time stamps when logging and log program arguments, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner f76603c 03/17: ask for confirmation before overwriting existing files, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner b683e19 05/17: correct handling of existing files, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner a43ce69 01/17: Update scanner.el, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 072222a 06/17: improve doc-string in scanner--confirm-filenames, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner e199957 07/17: add file-local variables for tab configuration, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 7d5cd5c 02/17: correct Readme.org markup (=...= instead of ~...~), Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 2101ca0 08/17: handle undefined options and tesseract config directory gracefully,
Stefan Monnier <=
- [elpa] externals/scanner 22ead30 15/17: correct handling of empty TESSDATA_PREFIX env variable, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 5c8f04b 09/17: add --tessdata-dir option to scanner--tesseract-args, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 52bb719 14/17: fix handling of tessdata directory, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner ff513b0 10/17: add image size selection function and order menu more logically, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 1439335 16/17: update documentation, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner f1a7256 12/17: make use of --tessdata-dir compatible with tesseract v4, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner 440a324 13/17: Revert "make use of --tessdata-dir compatible with tesseract v4", Stefan Monnier, 2020/12/14
- [elpa] externals/scanner b96d3d1 17/17: bump version number, Stefan Monnier, 2020/12/14
- [elpa] externals/scanner a09407e 11/17: query tesseract version and use new switches conditionally, Stefan Monnier, 2020/12/14