[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog d974b0fe0a 071/166: ADDED: prepare xref backend
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sweeprolog d974b0fe0a 071/166: ADDED: prepare xref backend |
Date: |
Fri, 30 Sep 2022 04:59:27 -0400 (EDT) |
branch: elpa/sweeprolog
commit d974b0fe0a6ba4f2ac033ba870d165d7b23aef45
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
ADDED: prepare xref backend
---
sweep.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
sweep.pl | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 102 insertions(+)
diff --git a/sweep.el b/sweep.el
index 69fdac0eb2..9603c17fdf 100644
--- a/sweep.el
+++ b/sweep.el
@@ -987,6 +987,52 @@ Interactively, a prefix arg means to prompt for BUFFER."
(string-to-syntax "w")))))
start end)))
+
+(defun sweep-identifier-at-point (&optional point)
+ (let* ((p (or point (point)))
+ (beg (save-mark-and-excursion
+ (goto-char p)
+ (sweep-beginning-of-top-term)
+ (point)))
+ (end (save-mark-and-excursion
+ (goto-char p)
+ (sweep-end-of-top-term)
+ (point)))
+ (contents (buffer-substring-no-properties beg end)))
+ (sweep-open-query "user"
+ "sweep"
+ "sweep_identifier_at_point"
+ (list contents
+ (buffer-file-name)
+ (- p beg)))
+ (let ((sol (sweep-next-solution)))
+ (sweep-close-query)
+ (when (sweep-true-p sol)
+ (cdr sol)))))
+
+;;;###autoload
+(defun sweep--xref-backend ()
+ "Hook for `xref-backend-functions'."
+ 'sweep)
+
+
+(cl-defmethod xref-backend-identifier-at-point ((_backend (eql 'sweep)))
+ (sweep-identifier-at-point))
+
+(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql
'sweep)))
+ (sweep-identifier-completion-table))
+
+(cl-defmethod xref-backend-identifier-completion-ignore-case ((_backend (eql
'sweep)))
+ "Case is always significant for Prolog identifiers, so return nil."
+ nil)
+
+(cl-defmethod xref-backend-definitions ((_backend (eql 'sweep)) symbol))
+
+(cl-defmethod xref-backend-references ((_backend (eql 'sweep)) symbol))
+
+(cl-defmethod xref-backend-apropos ((_backend (eql 'sweep)) pattern))
+
+
;;;###autoload
(define-derived-mode sweep-mode prog-mode "sweep"
"Major mode for reading and editing Prolog code."
@@ -1007,6 +1053,7 @@ Interactively, a prefix arg means to prompt for BUFFER."
(font-lock-fontify-region-function .
sweep-colourise-some-terms)))
(sweep-colourise-buffer)
(sweep--set-buffer-module)
+ (add-hook 'xref-backend-functions #'sweep--xref-backend nil t)
(add-hook 'completion-at-point-functions
#'sweep-completion-at-point-function nil t))
;;;; Testing:
diff --git a/sweep.pl b/sweep.pl
index a9836c6633..61583c6284 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -34,6 +34,7 @@
[ sweep_colourise_buffer/2,
sweep_colourise_some_terms/2,
sweep_documentation/2,
+ sweep_identifier_at_point/2,
sweep_expand_file_name/2,
sweep_path_module/2,
sweep_predicate_location/2,
@@ -103,6 +104,60 @@ sweep_colourise_buffer_(Path0, Contents, []) :-
erase(Ref0),
erase(Ref1).
+
+sweep_identifier_at_point([Contents0, Path, Point], Identifier) :-
+ setup_call_cleanup(( new_memory_file(H),
+ insert_memory_file(H, 0, Contents0),
+ open_memory_file(H, read, Contents, [encoding(utf8)])
+ ),
+ sweep_identifier_at_point_(Path, Point, Contents,
Identifier),
+ ( close(Contents),
+ free_memory_file(H)
+ )).
+
+:- dynamic sweep_current_identifier_at_point/1.
+
+
+sweep_identifier_at_point_(Path0, Point, Contents, Identifier) :-
+ atom_string(Path, Path0),
+ ( xref_module(Path, M)
+ -> true
+ ; M = user
+ ),
+ set_stream(Contents, encoding(utf8)),
+ set_stream(Contents, file_name(Path)),
+ seek(Contents, 0, bof, _),
+ retractall(sweep_current_identifier_at_point(_)),
+ prolog_colourise_term(Contents, Path,
+ sweep_handle_identifier_at_point(Path, M, Point),
+ []),
+ sweep_current_identifier_at_point(Identifier0),
+ term_string(Identifier0, Identifier).
+
+
+sweep_handle_identifier_at_point(Path, M, Point, Col, Beg, Len) :-
+ Beg =< Point,
+ Point =< Beg + Len,
+ !,
+ sweep_handle_identifier_at_point_(Path, M, Col).
+sweep_handle_identifier_at_point(_, _, _, _, _, _).
+
+sweep_handle_identifier_at_point_(Path, M0, goal_term(_Kind, Goal)) :-
+ !,
+ pi_head(PI0, Goal),
+ ( PI0 = M:PI
+ -> true
+ ; xref_defined(Path, Goal, imported(Other)), xref_module(Other, M)
+ -> PI = PI0
+ ; predicate_property(M0:Goal, imported_from(M))
+ -> PI = PI0
+ ; '$autoload':library_index(Goal, M, _)
+ -> PI = PI0
+ ; M = M0, PI = PI0
+ ),
+ asserta(sweep_current_identifier_at_point(M:PI)).
+sweep_handle_identifier_at_point_(_, _, _).
+
sweep_colourise_some_terms([String,Path,Offset], Colors) :-
setup_call_cleanup(( new_memory_file(H),
insert_memory_file(H, 0, String),
- [nongnu] elpa/sweeprolog 5455c53eaf 031/166: ENHANCED: Add optional "reverse" argument flag to sweep-open-query, (continued)
- [nongnu] elpa/sweeprolog 5455c53eaf 031/166: ENHANCED: Add optional "reverse" argument flag to sweep-open-query, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog ff13d97396 034/166: DOC: Add CUSTOM_ID properties to README.org headings where needed, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5fa0e16ee3 037/166: DOC: Document sweep_funcall/2, 3 in the manual, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 66ac977deb 045/166: Make use of the new SWI-Prolog embedded GMP handling..., ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 8f1275f113 044/166: Remove the swipl-devel git submodule, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 5dcdec144d 052/166: PORT: use swipl --dump-runtime-variables to locate SWI-Prolog.h, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog b24f66da61 051/166: Add licensing information, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 43e5cdaf91 054/166: ADDED: global keymap sweep-prefix-map, not bound by default, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 239e205add 059/166: ADDED: sweep-mode, a major mode for editing Prolog code, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog d226bbb70c 063/166: ENHANCED: set per buffer module name in sweep-mode, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog d974b0fe0a 071/166: ADDED: prepare xref backend,
ELPA Syncer <=
- [nongnu] elpa/sweeprolog 27c441ab49 068/166: PORT: don't rely on defvar-keymap available only since Emacs 29, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 0b054bac88 072/166: ENHANCED: better detection of the identifier at point, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog c59ead20f7 075/166: ENHANCED: redirect Prolog messages to Emacs message function, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 031c07ac93 076/166: DOC: document the Prolog messages buffer, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 8ac0e7afb9 065/166: ENHANCED: also complete predicate names from xref, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 85ca3a5dc2 067/166: FIXED: bind SourceId in xref based completions, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog 21a4475306 112/166: Makefile: Allow specifying the path to emacs, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog ec01154a41 102/166: PORT: sweep.el: require Emacs version 28 for RTLD_GLOBAL, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog e991b1a92c 097/166: ENHANCED: (sweep-load-buffer): use read-buffer to choose a buffer, ELPA Syncer, 2022/09/30
- [nongnu] elpa/sweeprolog c69c6bad3c 084/166: FIXED: correctly identify the predicate defined at start of clause, ELPA Syncer, 2022/09/30