# Console help system

**URL:** <https://swi-prolog.discourse.group/t/console-help-system/5815>\
**Category:** General\
**Created:** [October 3, 2022, 3:04am UTC](https://swi-prolog.discourse.group/t/console-help-system/5815 "2022-10-03T03:04:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 3, 2022, 3:04am UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/1 "2022-10-03T03:04:31Z")

</div>

Is there a way to add custom code to the regular console help system that can be used in the top-level? For example, adding the docs from a pack.

so I would like to do from the top level something like:

```prolog
?- help(my_pack_predicate). 

```

or some other predicate that I have documented with pldoc.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 3, 2022, 9:47am UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/2 "2022-10-03T09:47:18Z")

</div>

Most of the functionality is there. The help/1 on the terminal works by fetching the HTML documentation and using a Prolog library for rendering this as text. PlDoc produces HTML from the structured comments.

Would require some plumbing. Any volunteers?

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 3, 2022, 8:09pm UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/3 "2022-10-03T20:09:42Z")

</div>

I’ll work on it, an tips on what files to look into?

My idea is to enhance the help/1 predicate to build the html on the fly if the sought predicate is not found in the main documentation. Let me know if this seems reasonable.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 4, 2022, 9:54pm UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/4 "2022-10-04T21:54:50Z")

</div>

Jan has improved and merged a patch I sent, it is in the master branch. You are able to call:

- `help(my_currently_loaded_predicate)` or
- `help(my_currently_loaded_module)`

and it will show the documentation for the predicate or for the documented predicates in the module.

There is still todo the enhancement to show the module documentation. As Jan likes to say: Enjoy!

---

<div class="post-metadata">

**Author:** ![oskardrums](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/oskardrums/32/3594_2.png) [@oskardrums](https://swi-prolog.discourse.group/u/oskardrums)\
**Post date:** [October 11, 2022, 3:08pm UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/5 "2022-10-11T15:08:37Z")

</div>

This is a really nice improvement, much appreciated!

I experience an issue where the PlDoc-based documentation is repeated multiple times when the source file has been loaded and then xref’ed with option `comments(store)`:

```prolog
?- ['sweep.pl'].
true.

?- help(sweep_accept_top_level_client).
/Users/eshelyaron/checkouts/sweep/sweep.pl

 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from
    buffer Buffer.
true.

?- xref_source('sweep.pl', [comments(store)]).
true.

?- help(sweep_accept_top_level_client).

 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from
    buffer Buffer.
 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from
    buffer Buffer.
 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from
    buffer Buffer.
 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from
    buffer Buffer.
true.

```

Any ideas where this might be coming from?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 11, 2022, 3:32pm UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/6 "2022-10-11T15:32:23Z")

</div>

> [@oskardrums](#):
>
> Any ideas where this might be coming from?

Possibly because the help system doesn’t look at the xref stored comments, but at the normal comments. If these are not there it reloads the file. Using the cross-referencer may be a better choice. PR welcome.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [October 11, 2022, 8:28pm UTC](https://swi-prolog.discourse.group/t/console-help-system/5815/7 "2022-10-11T20:28:40Z")

</div>

The problem happens because xref\_source/2 adds a duplicate comment entry in the sweep module (you can see them with `listing(sweep:'$pldoc'/4)` ). If you pass the absolute path the problem is avoided:

```prolog
3 ?- absolute_file_name('sweep.pl',F),xref_source(F, [comments(store)]).
F = '/tmp/swipl-devel/packages/sweep/sweep.pl'.
4 ?- help(sweep_accept_top_level_client).
% the pager shows it only once
/tmp/swipl-devel/packages/sweep/sweep.pl

 sweep_accept_top_level_client(+Buffer, -Result) is det
    Signal the top-level server thread to accept a new TCP connection from buffer Buffer.

true.

```

Perhaps xref\_source/2 should always use the absolute file name?
