From c59ead20f772c58b34f65e6ee8f7670165b478cc Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 6 Sep 2022 19:48:57 +0300 Subject: [PATCH] ENHANCED: redirect Prolog messages to Emacs message function --- README.org | 3 +-- sweep.el | 24 +++++++++++++++++++++++- sweep.pl | 19 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index 2808819..e9d9cea 100644 --- a/README.org +++ b/README.org @@ -6,7 +6,7 @@ #+startup: content indent #+export_file_name: sweep.texi #+texinfo_filename: sweep.info -#+texinfo_dir_category: Prolog +#+texinfo_dir_category: Emacs #+texinfo_dir_title: Sweep: (sweep) #+texinfo_dir_desc: SWI-Prolog Embedded in Emacs #+texinfo_header: @set MAINTAINERSITE @uref{https://eshelyaron.com,maintainer webpage} @@ -330,7 +330,6 @@ This enables the many commands that the =xref= interface provides, like [[info:emacs#Find Identifiers][Find Identifiers in the Emacs manual]] for an overview of the available commands. - * The Prolog top-level :PROPERTIES: :CUSTOM_ID: prolog-top-level diff --git a/sweep.el b/sweep.el index 9304d2b..1fa56f7 100644 --- a/sweep.el +++ b/sweep.el @@ -107,6 +107,28 @@ (require 'sweep-module)) (error "Sweep will not work until `sweep-module' is compiled!")))) + +(defvar sweep-messages-buffer nil) + +(defun sweep-setup-message-hook () + (with-current-buffer + (setq sweep-messages-buffer (get-buffer-create "*sweep-messages*")) + (compilation-minor-mode)) + (sweep-open-query "user" + "sweep" + "sweep_setup_message_hook" + nil) + (let ((sol (sweep-next-solution))) + (sweep-close-query) + sol)) + +(defun sweep-message (message) + (with-current-buffer sweep-messages-buffer + (save-excursion + (goto-char (point-max)) + (insert message) + (newline)))) + (defun sweep-start-prolog-server () (sweep-open-query "user" "prolog_server" @@ -122,9 +144,9 @@ (cons (expand-file-name "bin/swipl" (file-name-directory load-file-name)) (cons "-q" (cons "--no-signals" sweep-init-args)))) + (sweep-setup-message-hook) (sweep-start-prolog-server)) - (defvar sweep-predicate-completion-collection nil) (defvar-local sweep-buffer-module "user") diff --git a/sweep.pl b/sweep.pl index 823f6e5..7b97502 100644 --- a/sweep.pl +++ b/sweep.pl @@ -33,6 +33,7 @@ :- module(sweep, [ sweep_colourise_buffer/2, sweep_colourise_some_terms/2, + sweep_setup_message_hook/2, sweep_documentation/2, sweep_identifier_at_point/2, sweep_expand_file_name/2, @@ -583,3 +584,21 @@ sweep_path_module(Path0, Module) :- atom_string(Path, Path0), xref_module(Path, Module0), atom_string(Module0, Module). + + +sweep_setup_message_hook(_, _) :- + retractall(user:thread_message_hook(_, _, _)), + asserta(( + user:thread_message_hook(Term, Kind, Lines) :- + sweep_message_hook(Term, Kind, Lines) + )). + +sweep_message_hook(Term, Kind, _Lines) :- + should_handle_message_kind(Kind), + !, + message_to_string(Term, String), + sweep_funcall("sweep-message", String, _). + +should_handle_message_kind(error). +should_handle_message_kind(warning). +should_handle_message_kind(debug(_)). -- 2.39.2