Boxes.el: Check that boxes v2.1.0 is available before using -q "(all)" (#114)

v2.1.0 is required to run boxes-command-on-region interactively due to requiring support for "-q (all)". The other
commands work on all versions.
This commit is contained in:
Mike Woolley 2022-12-13 20:47:13 +00:00 committed by GitHub
parent d62637e6fa
commit 380e7814ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,6 +77,9 @@
:type '(alist :key-type symbol :value-type string)
:group 'boxes)
(defconst boxes-minimum-version "2.1.0"
"Minimum required version of `boxes' to support querying the available box types.")
(defvar boxes-history nil
"Boxes types history.")
@ -87,12 +90,15 @@
"List of types available to the current boxes implementation, nil if not set yet.")
(defun boxes-types ()
"Return the list of types available to the current boxes implementation."
(or boxes-types-list
(setq boxes-types-list
(let ((types (process-lines boxes-command "-q" "(all)")))
(mapcar (lambda(type) (replace-regexp-in-string " *\(alias\) *$" "" type))
types)))))
"Return the list of types available to the current boxes implementation.
Signal error if a supported version of `boxes' is not available."
(condition-case nil
(or boxes-types-list
(setq boxes-types-list
(let ((types (process-lines boxes-command "-q" "(all)")))
(mapcar (lambda(type) (replace-regexp-in-string " *\(alias\) *$" "" type))
types))))
(error (error "Please install Boxes %s or later" boxes-minimum-version))))
(defun boxes-default-type (mode)
"Get the default box type for the given buffer major MODE."
@ -113,12 +119,20 @@
;;;###autoload
(defun boxes-command-on-region (start end type &optional remove)
"Create or Remove boxes from a region.
To create a box select a region, hit \\[boxes-command-on-region] & enter a box type.
Box type selection uses tab completion on the supported types.
To remove a box simply prefix a 1 to the call, eg
M-1 \\[boxes-command-on-region] will remove a box from a region.
When calling from Lisp, supply the region START & END and the box TYPE to
create a box. Specifying a non-nil value for REMOVE, removes the box."
To create a box select a region, hit \\[boxes-command-on-region]
& enter a box type. Box type selection uses tab completion on
the supported types.
To remove a box simply prefix a 1 to the call, eg M-1
\\[boxes-command-on-region] will remove a box from a region.
Note that interactive use requires `boxes' >= 2.1.0 to support
querying the supported types.
When calling from Lisp, supply the region START & END and the box
TYPE to create a box. Specifying a non-nil value for REMOVE,
removes the box."
(interactive (let ((string
(completing-read (format "Box type (%s): " boxes-default-type)
(boxes-types) nil t nil 'boxes-history boxes-default-type)))