emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/sweeprolog fc6c2964d9 105/166: ADDED: (sweep-file-at-point


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog fc6c2964d9 105/166: ADDED: (sweep-file-at-point): new function
Date: Fri, 30 Sep 2022 04:59:30 -0400 (EDT)

branch: elpa/sweeprolog
commit fc6c2964d9c47a99864a28d206dde3b55cd530d4
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ADDED: (sweep-file-at-point): new function
---
 sweep.el | 25 ++++++++++++++++++++++++-
 sweep.pl | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/sweep.el b/sweep.el
index 866130f84a..16aa103c50 100644
--- a/sweep.el
+++ b/sweep.el
@@ -1190,13 +1190,36 @@ Interactively, a prefix arg means to prompt for BUFFER."
   (and (looking-at-p (rx bol graph))
        (not (nth 8 (syntax-ppss)))))
 
-(defun sweep-identifier-at-point (&optional point)
+(defun sweep-file-at-point (&optional point)
   (let* ((p (or point (point)))
          (beg (save-mark-and-excursion
                 (goto-char p)
                 (unless (sweep-at-beginning-of-top-term-p)
                   (sweep-beginning-of-top-term))
+                (max (1- (point)) (point-min))))
+         (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_file_at_point"
+                      (list contents
+                            (buffer-file-name)
+                            (- p beg)))
+    (let ((sol (sweep-next-solution)))
+      (sweep-close-query)
+      (when (sweep-true-p sol)
+        (cdr sol)))))
+
+(defun sweep-identifier-at-point (&optional point)
+  (let* ((p (or point (point)))
+         (beg (save-mark-and-excursion
+                (goto-char p)
+                (unless (sweep-at-beginning-of-top-term-p)
+                  (sweep-beginning-of-top-term))
+                (max (1- (point)) (point-min))))
          (end (save-mark-and-excursion
                 (goto-char p)
                 (sweep-end-of-top-term)
diff --git a/sweep.pl b/sweep.pl
index 75138a17db..d5d451fef2 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -37,6 +37,7 @@
             sweep_current_prolog_flags/2,
             sweep_set_prolog_flag/2,
             sweep_documentation/2,
+            sweep_file_at_point/2,
             sweep_identifier_at_point/2,
             sweep_expand_file_name/2,
             sweep_path_module/2,
@@ -130,6 +131,37 @@ sweep_colourise_buffer_(Path0, Contents, []) :-
     erase(Ref1).
 
 
+sweep_file_at_point([Contents,Path0,Point], Result) :-
+    atom_string(Path, Path0),
+    with_buffer_stream(Stream,
+                       Contents,
+                       sweep_file_at_point_(Stream, Path, Point, Result)).
+
+:- dynamic sweep_current_file_at_point/1.
+
+sweep_file_at_point_(Stream, Path, Point, File) :-
+    set_stream(Stream, file_name(Path)),
+    retractall(sweep_current_file_at_point(_)),
+    prolog_colourise_term(Stream, Path,
+                          sweep_handle_file_at_point(Point),
+                          []),
+    sweep_current_file_at_point(File0),
+    atom_string(File0, File).
+
+sweep_handle_file_at_point(Point, file_no_depend(File), Beg, Len) :-
+    Beg =< Point,
+    Point =< Beg + Len,
+    !,
+    asserta(sweep_current_file_at_point(File)).
+sweep_handle_file_at_point(Point, file(File), Beg, Len) :-
+    Beg =< Point,
+    Point =< Beg + Len,
+    !,
+    asserta(sweep_current_file_at_point(File)).
+sweep_handle_file_at_point(_, _, _, _).
+
+
+
 sweep_identifier_at_point([Contents0, Path, Point], Identifier) :-
     setup_call_cleanup(( new_memory_file(H),
                          insert_memory_file(H, 0, Contents0),



reply via email to

[Prev in Thread] Current Thread [Next in Thread]