# Readline history length

**URL:** <https://swi-prolog.discourse.group/t/readline-history-length/6898>\
**Category:** Help!\
**Created:** [October 19, 2023, 3:45am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898 "2023-10-19T03:45:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 19, 2023, 3:45am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/1 "2023-10-19T03:45:14Z")

</div>

Hello,

I would like to increase the length of the swi prolog top-level history but I can’t find how to do it.  
I’m on linux, so I suppose that swi prolog is using the readline library to store the history.

I managed to find the history files in `~/.config/swi-prolog/dir-history` as documented [here](https://www.swi-prolog.org/pldoc/doc/_SWI_/library/prolog_history.pl).  
But none of the history files I have exceed 101 lines which makes me thing that the length of my history is 100 but I can’t find anywhere how to configure this ?

Readline manual says that when not configured the history length is unlimited.

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [October 19, 2023, 5:10am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/2 "2023-10-19T05:10:20Z")

</div>

The [readline(3) documentation](https://www.man7.org/linux/man-pages/man3/readline.3.html) says how to set the initialization file (`INPUTRC` or `~/.inputrc` or `/etc/inputrc`), and there’s a `history-size` setting.

Not answering your question, but if you run SWI-Prolog in an emacs terminal window (`*shell*`), you get almost unlimited history and scrollback.

---

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 19, 2023, 5:31am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/3 "2023-10-19T05:31:49Z")

</div>

So the weird thing is that the readline manual states that when not set, the history size is not limited:

```prolog
       history-size (unset)
              Set the maximum number of history entries saved in the
              history list. If set to zero, any existing history
              entries are deleted and no new entries are saved. If set
              to a value less than zero, the number of history entries
              is not limited. By default, the number of history entries
              is not limited. If an attempt is made to set history-size
              to a non-numeric value, the maximum number of history
              entries will be set to 500.

```

Since I don’t have a `~/.inputrc` file, I believe readline only reads `/etc/inputrc`, which on my system (fedora) does not set the history-size setting.

It would be nice know why my history is limited to 100 by default…  
I suppose I’ll have to spend some time configuring readline now.

> [@peter.ludemann](#):
>
> Not answering your question, but if you run [SWI-Prolog](https://www.swi-prolog.org/pldoc/doc_for?object=manual) in an emacs terminal window (`*shell*`), you get almost unlimited history and scrollback.

I’m more on the Vim camp myself 🙂 Which also provide unlimited scrollback.  
But the problem is that I often restart vim which I know is not the habit of people using emacs ^^  
By the way, is emacs shell able to capture the history of swi prolog queries ? like how readline does ?

> **/etc/inputrc**
>
> ```prolog
> # do not bell on tab-completion
> #set bell-style none
> 
> set meta-flag on
> set input-meta on
> set convert-meta off
> set output-meta on
> 
> # Completed names which are symbolic links to
> # directories have a slash appended.
> set mark-symlinked-directories on
> 
> $if mode=emacs
> 
> # for linux console and RH/Debian xterm
> "\e[1~": beginning-of-line
> "\e[4~": end-of-line
> # commented out keymappings for pgup/pgdown to reach begin/end of history
> #"\e[5~": beginning-of-history
> #"\e[6~": end-of-history
> "\e[5~": history-search-backward
> "\e[6~": history-search-forward
> "\e[3~": delete-char
> "\e[2~": overwrite-mode
> "\e[5C": forward-word
> "\e[5D": backward-word
> "\e[1;5C": forward-word
> "\e[1;5D": backward-word
> 
> # for rxvt
> "\e[8~": end-of-line
> "\eOc": forward-word
> "\eOd": backward-word
> 
> # for non RH/Debian xterm, can't hurt for RH/DEbian xterm
> "\eOH": beginning-of-line
> "\eOF": end-of-line
> 
> # for freebsd console
> "\e[H": beginning-of-line
> "\e[F": end-of-line
> $endif
> 
> ```

---

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 19, 2023, 5:40am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/4 "2023-10-19T05:40:50Z")

</div>

I just tried copying `/etc/inputrc` into `~/.inputrc` and added `set history-size 10000` but it does not work.  
I’m still limited to 100 entries in my history file…

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [October 19, 2023, 6:14am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/5 "2023-10-19T06:14:08Z")

</div>

> [@kwon-young](#):
>
> is emacs shell able to capture the history of swi prolog queries

Yes.  
It keeps a history of all commands, including Prolog inputs (so, it somewhat overlaps the bash shell’s history).

- Esc-P bound to `comint-previous-input`
- Esc-R bound to `comint-history-isearch-backward-regexp`

Some of the history is saved across sessions, but I’m not sure exactly what.

---

<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 19, 2023, 7:08am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/6 "2023-10-19T07:08:57Z")

</div>

FWIW, in the Sweep top-level (also in Emacs), you have top-level specific history (not mangled with the shell’s history) and you can control how and when history is persisted (see [Top-level History (Sweep: SWI-Prolog Embedded in Emacs)](https://eshelyaron.com/man/sweep/Top_002dlevel-History.html)). It is also a `comint-mode` derivative, just like `shell-mode`, so all the usual `comint` commands work (such as `M-p` and `M-n` for cycling through history). But unlike `shell-mode`, it has a bunch of Prolog-specific goodies 🙂

---

<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 19, 2023, 7:21am UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/7 "2023-10-19T07:21:49Z")

</div>

No 🙂 using Emacs, history on non-Windows is provided by GNU readline or BSD editline, using the latter as default. History management is explicit in Prolog itself and controlled by the flag `history`. So, I think this should help in  
`~/.config/swi-prolog/init.pl`:

```
:- set_prolog_flag(history, 1000).

```

I use 50, which sets the prompt to 100 and scrolling back it seems it restores the 50 entries as 50…100. 1…50 would have been cleaner …

---

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 19, 2023, 3:29pm UTC](https://swi-prolog.discourse.group/t/readline-history-length/6898/8 "2023-10-19T15:29:22Z")

</div>

> [@jan](#):
>
> History management is explicit in Prolog itself and controlled by the flag `history`. So, I think this should help in  
> `~/.config/swi-prolog/init.pl`:
> 
> `:- set_prolog_flag(history, 1000).`

I followed this but I still only get 100 entries in my `~/.config/swi-prolog/dir-history/HISTORY_FILE`.  
It seems to max out at 100 no matter what ?
