;; Maintainer: Eshel Yaron <me(at)eshelyaron(dot)com>
;; 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.
: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"))
(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)
[ 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,
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),