From: Eshel Yaron Date: Sat, 27 Aug 2022 19:56:03 +0000 (+0300) Subject: ADDED: sweep-pack-install for interactively installing packs X-Git-Tag: v0.2.0~76 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ea04f467b9c498cfd313c93b9d572c25535101a6;p=sweep.git ADDED: sweep-pack-install for interactively installing packs --- diff --git a/sweep.el b/sweep.el index 012bd05..437d1ef 100644 --- a/sweep.el +++ b/sweep.el @@ -31,6 +31,12 @@ :type 'string :group 'sweep) +(defcustom sweep-read-pack-prompt "Pack: " + "Prompt used for reading a Prolog pack name from the minibuffer." + :package-version '((sweep . "0.1.0")) + :type 'string + :group 'sweep) + (defvar sweep-install-buffer-name "*Install sweep*" "Name of the buffer used for compiling sweep-module.") @@ -155,6 +161,46 @@ module name, F is a functor name and N is its arity." (interactive (list (sweep-read-module-name))) (find-file (sweep-module-path mod))) + +(defun sweep-packs-collection () + (sweep-open-query "user" "sweep" "sweep_packs_collection" "") + (let ((sol (sweep-next-solution))) + (sweep-close-query) + (when (or (eq (car sol) '!) + (eq (car sol) t)) + (cdr sol)))) + +(defun sweep-read-pack-name () + "Read a Prolog pack name from the minibuffer, with completion." + (let* ((col (sweep-packs-collection)) + (completion-extra-properties + (list :annotation-function + (lambda (key) + (message key) + (let* ((val (cdr (assoc-string key col))) + (des (car val)) + (ver (cadr val))) + (concat (make-string (max 0 (- 32 (length key))) ? ) + (if des + (concat ver (make-string (max 0 (- 16 (length ver))) ? ) des) + ver))))))) + (completing-read sweep-read-pack-prompt col))) + +(defun sweep-true-p (sol) + (or (eq (car sol) '!) + (eq (car sol) t))) + +;;;###autoload +(defun sweep-pack-install (pack) + "Install or upgrade Prolog package PACK." + (interactive (list (sweep-read-pack-name))) + (sweep-open-query "user" "sweep" "sweep_pack_install" pack) + (let ((sol (sweep-next-solution))) + (sweep-close-query) + (if (sweep-true-p sol) + (message "Package install successful.") + (user-error "Pacakge installation failed")))) + ;;;; Testing: ;; (add-to-list 'load-path (file-name-directory (buffer-file-name))) diff --git a/sweep.pl b/sweep.pl index 3a2991b..6f9ef2a 100644 --- a/sweep.pl +++ b/sweep.pl @@ -4,6 +4,8 @@ sweep_predicate_location/2, sweep_predicates_collection/2, sweep_modules_collection/2, + sweep_packs_collection/2, + sweep_pack_install/2, sweep_module_path/2 ]). @@ -17,6 +19,7 @@ :- use_module(library(pldoc/doc_man)). :- use_module(library(pldoc/man_index)). :- use_module(library(lynx/html_text)). +:- use_module(library(prolog_pack)). :- dynamic sweep_current_color/3, sweep_open/2, @@ -214,3 +217,16 @@ sweep_predicate_description_(M, F, N, [D]) :- sweep_predicate_description_(_M, F, N, [D]) :- man_object_property(F/N, summary(D0)), !, atom_string(D0, D). sweep_predicate_description_(_, _, _, []). + +sweep_packs_collection(SearchString, Packs) :- + prolog_pack:query_pack_server(search(SearchString), true(Packs0), []), + maplist(sweep_pack_info, Packs0, Packs). + +sweep_pack_info(pack(Name0, _, Desc0, Version0, URLS0), [Name, Desc, Version, URLS]) :- + atom_string(Name0, Name), + atom_string(Desc0, Desc), + atom_string(Version0, Version), + maplist(atom_string, URLS0, URLS). + +sweep_pack_install(PackName, []) :- + atom_string(Pack, PackName), pack_install(Pack, [silent(true), upgrade(true), interactive(false)]).