35
36:- module(pldoc_register,
37 [ process_stored_comments/0
38 ]). 39:- use_module(doc_process). 40:- use_module(library(pldoc)). 41:- use_module(library(debug)). 42:- set_prolog_flag(generate_debug_info, false). 43
44pldoc_module(pldoc_modes). 45pldoc_module(pldoc_process).
46pldoc_module(pldoc_wiki).
47pldoc_module(pldoc).
48pldoc_module(lists).
49pldoc_module(apply).
50pldoc_module(pairs).
51
52 55
56:- multifile
57 prolog:comment_hook/3,
58 user:message_hook/3. 59
60:- dynamic
61 mydoc/3. 62
(_, _, _, _) :-
64 current_prolog_flag(pldoc_collecting, false),
65 !.
66do_comment_hook(Comments, TermPos, File, _) :-
67 pldoc_loading,
68 !,
69 assert(mydoc(Comments, TermPos, File)).
70do_comment_hook(Comments, TermPos, File, _Term) :-
71 \+ current_prolog_flag(xref, true),
72 prolog_load_context(module, Module),
73 pldoc_module(Module),
74 !,
75 assert(mydoc(Comments, TermPos, File)).
76do_comment_hook(Comments, TermPos, File, _) :-
77 ( \+ current_prolog_flag(xref, true)
78 -> true
79 ; current_prolog_flag(xref_store_comments, true)
80 ),
81 process_comments(Comments, TermPos, File).
94prolog:(Comments, TermPos, Term) :-
95 source_location(File, _TermLine),
96 setup_call_cleanup(
97 '$push_input_context'(pldoc), 98 do_comment_hook(Comments, TermPos, File, Term),
99 '$pop_input_context').
100
:-
102 forall(retract(mydoc(Comments, TermPos, File)),
103 delayed_process(Comments, TermPos, File)).
104
105delayed_process(Comments, TermPos, File) :-
106 module_property(Module, file(File)),
107 setup_call_cleanup(
108 '$set_source_module'(Old, Module),
109 process_comments(Comments, TermPos, File),
110 '$set_source_module'(_, Old)).
111
112user:message_hook(load_file(done(0, _F, _A, _M, _T, _H)), _, _) :-
113 ( mydoc(_, _, _),
114 \+ pldoc_loading
115 -> debug(pldoc, 'Processing delayed comments', []),
116 process_stored_comments
117 ),
118 fail