From fc6c2964d9c47a99864a28d206dde3b55cd530d4 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sun, 11 Sep 2022 22:31:15 +0300 Subject: [PATCH] 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 866130f..16aa103 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 75138a1..d5d451f 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), -- 2.39.2