From bcd59aff790f40b8777e9929fff1e7fed6e4e06a Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Fri, 20 Jan 2023 20:45:14 +0200 Subject: [PATCH] ENHANCED: consult with library index for finding predicate defs * sweep.pl (sweep_predicate_location_/4): also check library_index/3. * sweeprolog-tests.el: add test for finding the source location of a predicate in the package clib. --- sweep.pl | 8 ++++++++ sweeprolog-tests.el | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/sweep.pl b/sweep.pl index 79c6ffc..7cfb80b 100644 --- a/sweep.pl +++ b/sweep.pl @@ -384,6 +384,14 @@ sweep_predicate_location_(M, H, Path, Line) :- xref_definition_line(How, Line), !, atom_string(Path0, Path). +sweep_predicate_location_(M, H, P, L) :- + '$autoload':library_index(H, M, P0), + absolute_file_name(P0, P1, [extensions([pl])]), + xref_source(P1, [comments(store)]), + xref_defined(P1, H, How), + xref_definition_line(How, L), + !, + atom_string(P1, P). sweep_predicate_location_(M, H, Path, Line) :- predicate_property(M:H, file(Path0)), predicate_property(M:H, line_count(Line)), diff --git a/sweeprolog-tests.el b/sweeprolog-tests.el index bb2c1a9..3076cb9 100644 --- a/sweeprolog-tests.el +++ b/sweeprolog-tests.el @@ -124,6 +124,10 @@ recursive(Var) :- *-> Bar is foo )"))))) +(ert-deftest predicate-location () + "Test `sweeprolog-predicate-location'." + (should (sweeprolog-predicate-location "memory_file:new_memory_file/1"))) + (ert-deftest term-search () "Test `sweeprolog-term-search'." (let ((temp (make-temp-file "sweeprolog-test" -- 2.39.2