From: Eshel Yaron Date: Sun, 11 Sep 2022 15:43:24 +0000 (+0300) Subject: ADDED: sweep-load-buffer X-Git-Tag: v0.2.0~7 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=75ec7290beced5ec6d1c41d471ba2fb42c0fe81b;p=dict.git ADDED: sweep-load-buffer --- diff --git a/sweep.el b/sweep.el index 9dcc116..ac15758 100644 --- a/sweep.el +++ b/sweep.el @@ -867,6 +867,20 @@ module name, F is a functor name and N is its arity." (sweep-close-query) sol))))) +(defun sweep-load-buffer (&optional buffer) + (interactive) + (with-current-buffer (or buffer (current-buffer)) + (let* ((beg (point-min)) + (end (point-max)) + (contents (buffer-substring-no-properties beg end))) + (sweep-open-query "user" + "sweep" + "sweep_load_buffer" + (cons contents (buffer-file-name))) + (let ((sol (sweep-next-solution))) + (sweep-close-query) + sol)))) + ;;;###autoload (defun sweep-top-level (&optional buffer) "Run a Prolog top-level in BUFFER. diff --git a/sweep.pl b/sweep.pl index 3313d8c..0f8f06d 100644 --- a/sweep.pl +++ b/sweep.pl @@ -40,6 +40,7 @@ sweep_identifier_at_point/2, sweep_expand_file_name/2, sweep_path_module/2, + sweep_load_buffer/2, sweep_colourise_query/2, sweep_predicate_references/2, sweep_predicate_location/2, @@ -66,6 +67,8 @@ :- use_module(library(help)). :- use_module(library(prolog_server)). +:- meta_predicate with_buffer_stream(-, +, 0). + :- dynamic sweep_current_color/3, sweep_open/2, sweep_source_time/2, @@ -633,3 +636,24 @@ should_handle_message_kind(error, "error"). should_handle_message_kind(warning, "warning"). should_handle_message_kind(informational, "informational"). should_handle_message_kind(debug(Topic0), ["debug"|Topic]) :- atom_string(Topic0, Topic). + +sweep_load_buffer([String|Path0], Result) :- + atom_string(Path, Path0), + with_buffer_stream(Stream, + String, + sweep_load_buffer_(Stream, Path, Result)). + +sweep_load_buffer_(Stream, Path, []) :- + set_stream(Stream, file_name(Path)), + load_files(Path, [stream(Stream)]). + +with_buffer_stream(Stream, String, Goal) :- + setup_call_cleanup(( new_memory_file(H), + insert_memory_file(H, 0, String), + open_memory_file(H, read, Stream, [encoding(utf8)]), + set_stream(Stream, encoding(utf8)) + ), + Goal, + ( close(Stream), + free_memory_file(H) + )).