Read_line_to_codes and bash blink_matching_paren

In bash, in the ~/.inputrc file, setting blink_matching_paren on will cause the cursor to briefly jump to a matching open-parenthesis when you type the closing parenthesis.

SWI-Prolog will show this behaviour when you use read_line_to_codes(user_input,X).

However, the cursor doesn’t always jump back to the right position in SWI. I don’t know why that is, but in any case, I would rather turn that behaviour off. In Bash, I can turn it off in ~/.inputrc but SWI doesn’t seem to read that setting. The behaviour remains in SWI-Prolog programs.

Does anybody know how to turn this off in Prolog?

First of all, SWI-Prolog can bind to GNU readline or BSD editline, preferring the latter. You can figure out which is in use using

?- current_prolog_flag(readline, Lib).

By default editline tries to read ~/.editrc. By default paren matching is bound for the parenthesis as well as the quotes. I guess you can rebind these keys. You find the code, which is mostly in Prolog, in library(editline). It also defines a hook el_setup/1 that allows for additional configuration.

Then of course there is the question what is so annoying that you want to disable this? Are you reading non-Prolog syntax with different quoting and parenthesis rules?

Bedankt! the tips will help.

In the meantime, I think I’ve figured out what is causing my issue. In the the following code,

write('> '), read_line_to_codes(user_input,X).

The cursor is offset by two characters. That will cause the cursor blink to return to the wrong position (two characters short). I’m not sure how to correct that.



Because the line editor expects the cursor to be at the first column. You should not write the prompt, but instead using

?- prompt(_, '> '), read_line_to_codes(user_input,X).

Do not forget to restore the prompt if you d not want to change it permanently.