]> git.eshelyaron.com Git - sweep.git/commitdiff
ADDED: (sweep-file-at-point): new function
authorEshel Yaron <me@eshelyaron.com>
Sun, 11 Sep 2022 19:31:15 +0000 (22:31 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 11 Sep 2022 19:41:35 +0000 (22:41 +0300)
sweep.el
sweep.pl

index 866130f84a3a16757f37d9ff750e414fa77da485..16aa103c50c1faf9cafb4a83640cf74cd086fe31 100644 (file)
--- 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)
index 75138a17db1aa00101d4d427ee72840e2cb296ba..d5d451fef20b10277680c53dff22412b821eeed5 100644 (file)
--- 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),