From e31d6f4c1a6a8ecefc23cd8825db922785dca567 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 10 Nov 2022 20:14:26 +0200 Subject: [PATCH] ADDED: new command sweeprolog-xref-project-source-files --- sweeprolog.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sweeprolog.el b/sweeprolog.el index 6d8b207..03db2c6 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -367,6 +367,7 @@ clause." (define-key map "P" #'sweeprolog-pack-install) (define-key map "R" #'sweeprolog-restart) (define-key map "T" #'sweeprolog-list-top-levels) + (define-key map "X" #'sweeprolog-xref-project-source-files) (define-key map "e" #'sweeprolog-view-messages) (define-key map "h" sweeprolog-help-prefix-map) (define-key map "l" #'sweeprolog-load-buffer) @@ -412,6 +413,10 @@ clause." [ "Describe Predicate" sweeprolog-describe-predicate t ] [ "Describe Prolog module" sweeprolog-describe-module t ] "--" + [ "Xref files in current project" + sweeprolog-xref-project-source-files + (project-current) ] + "--" [ "Reset sweep" sweeprolog-restart t ] [ "View sweep messages" sweeprolog-view-messages t ])) @@ -692,8 +697,30 @@ FLAG and VALUE are specified as strings and read as Prolog terms." "Return a list of prediacte completion candidates matchitng PREFIX." (sweeprolog--query-once "sweep" "sweep_predicates_collection" prefix)) +;;;###autoload +(defun sweeprolog-xref-project-source-files (&optional project) + "Update cross reference data for all Prolog files in PROJECT. + +If PROJECT is nil, update data for the current project. + +If called interactively with a prefix argument, prompt for +PROJECT." + (interactive (list (or (and current-prefix-arg + (let ((default-directory + (project-prompt-project-dir))) + (project-current))) + (or (project-current) + (user-error "No current project"))))) + (when-let ((proj (or project (project-current)))) + (mapc (lambda (path) + (sweeprolog--query-once "sweep" "sweep_xref_source" path)) + (seq-filter (lambda (path) + (string= "pl" (file-name-extension path))) + (project-files proj))))) + (defun sweeprolog-predicate-references (mfn) "Find source locations where the predicate MFN is called." + (sweeprolog-xref-project-source-files) (sweeprolog--query-once "sweep" "sweep_predicate_references" mfn)) (defun sweeprolog--mfn-to-functor-arity (mfn) -- 2.39.2