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) :type '(alist :key-type symbol :value-type string)
:group 'boxes) :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 (defvar boxes-history nil
"Boxes types history.") "Boxes types history.")
@ -87,12 +90,15 @@
"List of types available to the current boxes implementation, nil if not set yet.") "List of types available to the current boxes implementation, nil if not set yet.")
(defun boxes-types () (defun boxes-types ()
"Return the list of types available to the current boxes implementation." "Return the list of types available to the current boxes implementation.
(or boxes-types-list Signal error if a supported version of `boxes' is not available."
(setq boxes-types-list (condition-case nil
(let ((types (process-lines boxes-command "-q" "(all)"))) (or boxes-types-list
(mapcar (lambda(type) (replace-regexp-in-string " *\(alias\) *$" "" type)) (setq boxes-types-list
types))))) (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) (defun boxes-default-type (mode)
"Get the default box type for the given buffer major MODE." "Get the default box type for the given buffer major MODE."
@ -113,12 +119,20 @@
;;;###autoload ;;;###autoload
(defun boxes-command-on-region (start end type &optional remove) (defun boxes-command-on-region (start end type &optional remove)
"Create or Remove boxes from a region. "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 create a box select a region, hit \\[boxes-command-on-region]
To remove a box simply prefix a 1 to the call, eg & enter a box type. Box type selection uses tab completion on
M-1 \\[boxes-command-on-region] will remove a box from a region. 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." 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 (interactive (let ((string
(completing-read (format "Box type (%s): " boxes-default-type) (completing-read (format "Box type (%s): " boxes-default-type)
(boxes-types) nil t nil 'boxes-history boxes-default-type))) (boxes-types) nil t nil 'boxes-history boxes-default-type)))