From: Eshel Yaron Date: Wed, 7 Sep 2022 19:50:03 +0000 (+0300) Subject: ADDED: sweep-set-prolog-flag for setting Prolog flags X-Git-Tag: v0.2.0~21 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=8dc9359dcaf721f266b40f0fb8fd344007a6ebbf;p=dict.git ADDED: sweep-set-prolog-flag for setting Prolog flags --- diff --git a/sweep.el b/sweep.el index e6790d5..0778c7f 100644 --- a/sweep.el +++ b/sweep.el @@ -6,7 +6,7 @@ ;; Maintainer: Eshel Yaron ;; Keywords: prolog languages extensions ;; URL: https://git.sr.ht/~eshel/sweep -;; Package-Version: 0.1.1 +;; Package-Version: 0.1.2 ;; Package-Requires: ((emacs "27")) ;; This file is NOT part of GNU Emacs. @@ -47,6 +47,12 @@ is used to find a the swipl executable." :type 'string :group 'sweep) +(defcustom sweep-read-flag-prompt "Flag: " + "Prompt used for reading a Prolog flag name from the minibuffer." + :package-version '((sweep . "0.1.2")) + :type 'string + :group 'sweep) + (defcustom sweep-read-module-prompt "Module: " "Prompt used for reading a Prolog module name from the minibuffer." :package-version '((sweep . "0.1.0")) @@ -172,6 +178,39 @@ is used to find a the swipl executable." (set-window-point win (point)) win))) +(defun sweep-current-prolog-flags (&optional prefix) + (sweep-open-query "user" "sweep" "sweep_current_prolog_flags" (or prefix "")) + (let ((sol (sweep-next-solution))) + (sweep-close-query) + (when (sweep-true-p sol) + (cdr sol)))) + +(defun sweep-read-prolog-flag () + "Read a Prolog flag from the minibuffer, with completion." + (let* ((col (sweep-current-prolog-flags)) + (completion-extra-properties + (list :annotation-function + (lambda (key) + (let* ((val (cdr (assoc-string key col)))) + (if val + (concat (make-string + (max (- 32 (length key)) 1) ? ) + val) + nil)))))) + (completing-read sweep-read-flag-prompt col))) + +(defun sweep-set-prolog-flag (flag value) + (interactive (let ((f (sweep-read-prolog-flag))) + (list f (read-string (concat "Set " f " to: "))))) + (sweep-open-query "user" + "sweep" + "sweep_set_prolog_flag" + (cons flag value)) + (let ((sol (sweep-next-solution))) + (sweep-close-query) + (when (sweep-true-p sol) + (cdr sol)))) + (defun sweep-setup-message-hook () (with-current-buffer (get-buffer-create sweep-messages-buffer-name) (setq-local window-point-insertion-type t) diff --git a/sweep.pl b/sweep.pl index 8afce75..bdbebf9 100644 --- a/sweep.pl +++ b/sweep.pl @@ -34,6 +34,8 @@ [ sweep_colourise_buffer/2, sweep_colourise_some_terms/2, sweep_setup_message_hook/2, + sweep_current_prolog_flags/2, + sweep_set_prolog_flag/2, sweep_documentation/2, sweep_identifier_at_point/2, sweep_expand_file_name/2, @@ -85,6 +87,20 @@ prolog:xref_open_source(Source, Stream) :- prolog:xref_close_source(Source, Stream) :- sweep_open(Source, Stream). + +sweep_current_prolog_flags(Sub, Flags) :- + findall([Flag|Value], + (current_prolog_flag(Flag0, Value0), + atom_string(Flag0, Flag), + once(sub_string(Flag, _, _, _, Sub)), + term_string(Value0, Value)), + Flags). + +sweep_set_prolog_flag([Flag0|Value0], []) :- + atom_string(Flag, Flag0), + term_string(Value, Value0), + set_prolog_flag(Flag, Value). + sweep_colourise_buffer([String|Path], Colors) :- setup_call_cleanup(( new_memory_file(H), insert_memory_file(H, 0, String),