From: Eshel Yaron Date: Sun, 16 Oct 2022 18:34:21 +0000 (+0300) Subject: Extracted locating libswipl and sweep-module to sweep_link.pl X-Git-Tag: V8.5.18-sweep-0.7.0~2 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=21ab1519fbafa6c2456c6920f7a4312f705ce50b;p=sweep.git Extracted locating libswipl and sweep-module to sweep_link.pl --- diff --git a/.elpaignore b/.elpaignore new file mode 100644 index 0000000..039e1d9 --- /dev/null +++ b/.elpaignore @@ -0,0 +1 @@ +sweep_link.pl \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c5f15b9..4183534 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,8 @@ if(EMACS_INCLUDE_DIR) swipl_plugin( sweep-module C_SOURCES sweep.c - C_INCLUDE_DIR ${EMACS_INCLUDE_DIR}) + C_INCLUDE_DIR ${EMACS_INCLUDE_DIR} + PL_LIBS sweep_link.pl) pkg_doc( sweep diff --git a/sweep.pl b/sweep.pl index 4258444..9d429f9 100644 --- a/sweep.pl +++ b/sweep.pl @@ -796,16 +796,21 @@ sweep_imenu_index(Path, Index) :- ), Index). +:- if(exists_source(library(sweep_link))). +:- use_module(library(sweep_link), [write_sweep_module_location/0]). +:- else. write_sweep_module_location :- + format('V ~w~n', 1), absolute_file_name(foreign('sweep-module'), Path, [file_type(executable), access(read)]), ( current_prolog_flag(executable_format, elf) -> current_prolog_flag(libswipl, Libpath), - writeln(Libpath) + format('L ~w~n', Libpath) ; true ), - writeln(Path). + format('M ~w~n', Path). +:- endif. sweep_top_level_server(_, Port) :- tcp_socket(ServerSocket), diff --git a/sweep_link.pl b/sweep_link.pl new file mode 100644 index 0000000..6b97789 --- /dev/null +++ b/sweep_link.pl @@ -0,0 +1,53 @@ +/* + Author: Eshel Yaron + E-mail: eshel@swi-prolog.org + Copyright (c) 2022, SWI-Prolog Solutions b.v. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +:- module(sweep_link, + [ write_sweep_module_location/0 + ]). + +/** Information for dynamically linking to GNU Emacs +*/ + +sweep_link_version(1). + +write_sweep_module_location :- + sweep_link_version(V), + format('V ~w~n', V), + absolute_file_name(foreign('sweep-module'), + Path, + [file_type(executable), access(read)]), + ( current_prolog_flag(executable_format, elf) + -> current_prolog_flag(libswipl, Libpath), + format('L ~w~n', Libpath) + ; true + ), + format('M ~w~n', Path). diff --git a/sweeprolog.el b/sweeprolog.el index 76b8106..c37a7ca 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -223,10 +223,20 @@ clause." (declare-function sweeprolog-close-query "sweep-module") (declare-function sweeprolog-cleanup "sweep-module") +(defun sweeprolog--load-module (line) + (save-match-data + (when (string-match (rx bos + (or "L" "M") + (one-or-more whitespace) + (group-n 1 (one-or-more not-newline)) + eos) + line) + (load (match-string 1 line))))) + (defun sweeprolog--ensure-module () "Locate and load `sweep-module', unless already loaded." (unless (featurep 'sweep-module) - (if-let ((paths (save-match-data + (if-let ((lines (save-match-data (split-string (with-output-to-string (with-current-buffer standard-output @@ -239,7 +249,7 @@ clause." "sweep.pl" (file-name-directory load-file-name))))) "\n" t)))) - (mapc #'load paths) + (mapc #'sweeprolog--load-module lines) (error (concat "Failed to locate `sweep-module'. " "Make sure SWI-Prolog is installed " "and up to date"))))) @@ -599,8 +609,10 @@ module name, F is a functor name and N is its arity." (sweeprolog-open-query "user" "sweep" "sweep_path_module" (buffer-file-name)) (let ((sol (sweeprolog-next-solution))) (sweeprolog-close-query) - (when (sweeprolog-true-p sol) - (setq sweeprolog-buffer-module (cdr sol))))) + (setq sweeprolog-buffer-module + (if (sweeprolog-true-p sol) + (cdr sol) + "user")))) ;;;###autoload (defun sweeprolog-find-module (mod) @@ -1554,6 +1566,7 @@ module name, F is a functor name and N is its arity." (when sweeprolog--diagnostics-report-fn (funcall sweeprolog--diagnostics-report-fn sweeprolog--diagnostics) (setq sweeprolog--diagnostics-report-fn nil)) + (sweeprolog--set-buffer-module) sol)))) (defun sweeprolog-colourise-some-terms (beg0 end0 &optional _verbose)