readline history not working

939 views Asked by At

Okay, so Chicken-scheme has this great readline egg that can be used to add history, tab completion, and other sane features to the csi command-line environment. However, I can't seem to get it to work correctly, that is it only works the first time I start csi up after creating a new history file.

I've checked the documentation for the egg and other similar eggs such as linenoise and parley, but neither of them offer tab-completion or any advice on how to address this shortcoming of readline.

Here's the code I'm working with:

(current-input-port (make-gnu-readline-port))
(gnu-history-install-file-manager
  (string-append (or (get-environment-variable "HOME") ".") "/.csi_history"))

NOTE

While writing this I think I may have figured out the problem or at least part of the problem. The problem, I think, lies in the fact that I'm installing a history file; as in it only works for the first installation?

However, my attempt to cook my own readline file-manager setup makes it so that gnu readline never writes to the history file, however, it will read from it.

(current-input-port (make-gnu-readline-port))
(let ((histfile (string-append (or (get-environment-variable "HOME") ".")
  "/.csi_history")))
  (and (file-exists? histfile) (gnu-readline-read-history histfile))
  (gnu-readline-append-history histfile))

Has anyone else encountered this problem?

2

There are 2 answers

0
Alexej Magura On BEST ANSWER

Turns out that in my ~/.zshrc file I had an alias for csi that called csi with rlwrap:

alias csi='rlwrap csi'

Calling rlwrap on csi was causing csi to use rlwrap's history instead of the built-in history provided by the readline egg.

0
Damien Mattei On

readline is deprecated in chicken scheme solution is to install linenoise

and put this in your .csirc:

(import linenoise)
(current-input-port (make-linenoise-port))

(set-history-length! 300)

(load-history-from-file ".linenoise-history")

(let loop ((expr (linenoise "> ")))
              (cond ((equal? expr "bye")
                             (save-history-to-file ".linenoise-history")
                             "Bye!")
                    (else
                        (display (eval (read (open-input-string expr))))
                        (newline)
                        (history-add expr)
                        (loop (linenoise "> ")))))