: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.")
(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)))
sweep_predicate_location/2,
sweep_predicates_collection/2,
sweep_modules_collection/2,
+ sweep_packs_collection/2,
+ sweep_pack_install/2,
sweep_module_path/2
]).
:- 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,
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)]).