From 99fc2242d8700551aa3396ae90e8c5676549ea5f Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 27 Aug 2022 12:52:11 +0300 Subject: [PATCH] Document sweep-find-predicate --- README.org | 11 +++++++++-- sweep.el | 15 ++++++++++++--- sweep.pl | 51 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/README.org b/README.org index 8156cd5..56ee5d3 100644 --- a/README.org +++ b/README.org @@ -14,8 +14,6 @@ #+texinfo_header: @set MAINTAINEREMAIL @email{me@eshelyaron.com} #+texinfo_header: @set MAINTAINERCONTACT @uref{mailto:me@eshelyaron.com,contact the maintainer} -# The "kbd" macro turns KBD into @kbd{KBD}. Additionally, it -# encloses case-sensitive special keys (SPC, RET...) within @key{...}. #+macro: kbd (eval (let ((case-fold-search nil) (regexp (regexp-opt '("SPC" "RET" "LFD" "TAB" "BS" "ESC" "DELETE" "SHIFT" "Ctrl" "Meta" "Alt" "Cmd" "Super" "UP" "LEFT" "RIGHT" "DOWN") 'words))) (format "@@texinfo:@kbd{@@%s@@texinfo:}@@" (replace-regexp-in-string regexp "@@texinfo:@key{@@\\&@@texinfo:}@@" $1 t)))) This manual describes the Emacs package =sweep=, which provides an @@ -31,19 +29,23 @@ embedded SWI-Prolog runtime inside of Emacs. #+begin_src sh git clone --recursive https://git.sr.ht/~eshel/sweep #+end_src + 2. Optionally, build the C module =sweep-module=: #+begin_src sh cd sweep make #+end_src + 3. Add =sweep= to Emacs' =load-path=: #+begin_src emacs-lisp (add-to-list 'load-path "/path/to/sweep") #+end_src + 4. Load =sweep= into Emacs: #+begin_src emacs-lisp (require 'sweep) #+end_src + If =sweep-module= is not already built, =sweep= will suggest to build it when loaded. Note that this may take a couple of minutes as the SWI-Prolog runtime may need to be built as well. @@ -85,6 +87,11 @@ Prolog module. =sweep= integrates with Emacs' standard completion API to annotate candidate modules in the completion UI with their =PLDoc= description when available. +#+FINDEX: sweep-find-predicate +Along with {{{kbd(M-x sweep-find-module)}}}, =sweep= provides the +command {{{kbd(M-x sweep-find-predicate)}}} jumping to the definition a +loaded or auto-loadable Prolog predicate. + * Indices :PROPERTIES: :END: diff --git a/sweep.el b/sweep.el index 88f6c99..88dfe1b 100644 --- a/sweep.el +++ b/sweep.el @@ -62,8 +62,10 @@ (sweep-open-query "user" "sweep" "sweep_predicates_collection" nil) (let ((sol (sweep-next-solution))) (sweep-close-query) - (when (eq '! (car sol)) - (cdr sol)))) + (let ((car (car sol))) + (when (or (eq car '!) + (eq car t)) + (cdr sol))))) (defun sweep-predicate-location (mfn) (sweep-open-query "user" "sweep" "sweep_predicate_location" mfn) @@ -76,7 +78,14 @@ (defun sweep-read-predicate () "Read a Prolog predicate (M:F/N) from the minibuffer, with completion." - (let* ((col (sweep-predicates-collection))) + (let* ((col (sweep-predicates-collection)) + (completion-extra-properties + (list :annotation-function + (lambda (key) + (let* ((val (cdr (assoc-string key col)))) + (if val + (concat (make-string (- 64 (length key)) ? ) (car val)) + nil)))))) (completing-read "Predicate: " col))) (defun sweep-find-predicate (mfn) diff --git a/sweep.pl b/sweep.pl index 57f20cf..ee9bb66 100644 --- a/sweep.pl +++ b/sweep.pl @@ -1,9 +1,11 @@ -:- module(sweep, [ sweep_colors/2, - sweep_documentation/2, - sweep_predicate_location/2, - sweep_predicates_collection/2, - sweep_modules_collection/2, - sweep_module_path/2]). +:- module(sweep, + [ sweep_colors/2, + sweep_documentation/2, + sweep_predicate_location/2, + sweep_predicates_collection/2, + sweep_modules_collection/2, + sweep_module_path/2 + ]). :- use_module(library(pldoc)). :- use_module(library(listing)). @@ -176,7 +178,7 @@ sweep_modules_collection([], Modules) :- maplist(sweep_module_description, Modules1, Modules). sweep_module_description([M0|P], [M|[P|D]]) :- - pldoc_process:doc_comment(M0:module(D0), _, _, _), + doc_comment(M0:module(D0), _, _, _), atom_string(M0, M), atom_string(D0, D). sweep_module_description([M0|P], [M|[P]]) :- atom_string(M0, M). @@ -188,18 +190,33 @@ sweep_predicate_location(MFN, [Path|Line]) :- predicate_property(M:H, file(Path0)), atom_string(Path0, Path). sweep_predicates_collection([], Preds) :- - findall(Pred, - ( current_predicate(M0:P0/N), - pi_head(P0/N, H), - \+ (predicate_property(M0:H, imported_from(M)), M \= M0), - format(string(Pred), '~w:~w/~w', [M0, P0, N]) + findall(M:F/N, + ( current_predicate(M:F/N), + pi_head(F/N, H), + \+ (predicate_property(M:H, imported_from(M1)), M \= M1) ), Preds0, Tail), - findall(Pred, - ( '$autoload':library_index(F, M0, _), - pi_head(P0/N, F), - format(string(Pred), '~w:~w/~w', [M0, P0, N]) + findall(M:F/N, + ( '$autoload':library_index(H, M, _), + pi_head(F/N, H) ), Tail), - list_to_set(Preds0, Preds). + list_to_set(Preds0, Preds1), + maplist(sweep_predicate_description, Preds1, Preds). + +sweep_predicate_description(M:F/N, [S|T]) :- + sweep_predicate_description_(M, F, N, T), format(string(S), '~w:~w/~w', [M, F, N]). + +sweep_predicate_description_(M, F, N, [D]) :- + doc_comment(M:F/N, _, D0, _), !, atom_string(D0, D). +% sweep_predicate_description_(_M, F, N, [D]) :- +% pldoc_man:load_man_object(F/N, _, _, Dom), +% with_output_to(string(DomS), html_text(Dom, [])), +% sub_string(DomS, EOL, _, _, '\n'), +% sub_string(DomS, EOL, _, 0, Rest), +% ( sub_string(Rest, EOS, _, _, '. ') +% -> sub_string(Rest, 0, EOS, _, D) +% ; D=Rest +% ). +sweep_predicate_description_(_, _, _, []). -- 2.39.2