1. readline
  2. Interface
  3. Examples
  4. Installation problems
    1. Mac OS X
      1. 10.8/10.9 (Snow Leopard/Mavericks)
      2. 10.6 (Snow Leopard)
      3. Pre-10.6
    2. Debian GNU/Linux and derivatives (such as Ubuntu)
  5. About this egg
    1. Author
    2. Version history
    3. License


Bindings for the GNU readline library.


[procedure] (use-legacy-bindings)

Exports symbols aliasing the v1.993 API to the current API.

Use this function only if you have legacy code that uses the older API.

Returns (void) on success; will cause an error on fail.


(current-input-port (make-readline-port))
[procedure] (readline prompt1 [prompt2])

Reads a line using the GNU readline() function and returns a string.

Both arguments must be strings; prompt2 is optional.

[procedure] (%signal-cleanup)

Sets the state of the underlying readline environment to a clean slate.

NOTE Calls free(); so using this more than once consecutively may cause problems, such as a segfault.

[procedure] (clear-history)

Clears the history buffer.

[procedure] (%read-history [file])

Reads contents of the provided file into the history buffer.

When called without file-name, reads from ~/.history. Returns 0 on success, or errno on fail.

[procedure] (%write-history [file])

Writes the history buffer to file or ~/.history when no file is provided.

Returns 0 on success; errno on fail.


Using this may clobber simultaneous sessions.

[procedure] (%append-history [file])

Appends history buffer from the current session to file.

Returns 0 on success; errno on fail.

[procedure] (history-newlines)

Returns the number of entries from the current session.

[procedure] (%truncate-history [file] [n])

Truncates provided history file to a maximum of n lines.

Returns 0 on win; errno on fail.

[procedure] (history-install-file-manager file [line-limit])

If you also want to make the command history span sessions, add the following:

(history-install-file-manager (string-append (or (get-environment-variable "HOME") ".") "/.csi_history"))

By default this will save 1000 lines of history between sessions (it will prune the history file to 1000 lines at startup). For a different history size, pass the desired number of lines as the (optional) second argument to history-install-file-manager. If #f or no second argument is passed in, no history-file-pruning will take place.

NOTE Do not use this in conjunction with rlwrap. The author did that and experience some very weird behavior from csi.

[procedure] (make-readline-port [prompt] [prompt])

Returns an input-port that uses the GNU readline facility. If PROMPT is not given, the value returned by (repl-prompt) is used for generating the current prompt (see the Chicken manual for more details about repl-prompt). PROMPT2 is used when there are still unclosed parenthesis; if not given, an appropriate default is generated.

[procedure] (set-bounce-ms ms)

Changes the time that the cursor spends bouncing on the matching parenthesis - the default 500ms. To turn bouncing off completely, set it to 0.

[procedure] (parse-and-bind string)

Passes string straight to the readline library for parsing (see the readline manual page for details).

This extension supports static linking.


% csi -quiet
#;1> (use readline)
#;2> (current-input-port (make-readline-port))

To get csi to use readline by default, and to keep a history, use the following (in your ~/.csirc file):

(use readline irregex)
(current-input-port (make-readline-port))
 (string-append (or (get-environment-variable "HOME") ".") "/.csi.history"))

Note: you must create the .csi.history file, readline will not create it:

% touch ~/.csi.history

To set readline to behave somewhat like vi:

(parse-and-bind "set editing-mode vi")

Installation problems

This extension requires GNU readline. You will receive errors if you don't have the C header files for your readline installation or if you use some versions of the BSD readline alternative, libedit.

Mac OS X

10.8/10.9 (Snow Leopard/Mavericks)

Using bash...

brew install readline
readline_version=$(brew list readline --versions)
readline_version=${readline_version##* }
export CSC_OPTIONS="-I/usr/local/Cellar/readline/$readline_version/include -L/usr/local/Cellar/readline/$readline_version/lib"
unset readline_version
brew reinstall chicken
chicken-install readline

10.6 (Snow Leopard)

10.6 ships with a much older version of readline than this egg expects. Fortunately, recent versions of readline in MacPorts work. readline @6.0.000_2+darwin is confirmed to work with 10.6.2. First install the readline package from MacPorts and then do this:

export CSC_OPTIONS="-I/opt/local/include -L/opt/local/lib"

...before the chicken-install. If this doesn't work, try an additional

export LIBRARY_PATH=/opt/local/lib


Mac OS X versions prior to 10.5 (Leopard) ship with an older readline, causing the following error when you install this egg:

/usr/bin/ld: Undefined symbols:

To fix this, install a copy of GNU readline in /usr/local/lib or, if you're using MacPorts, symlink it:

ln -s /opt/local/lib/libreadline.dylib /usr/local/lib

DO NOT modify the readline link in /usr/lib.

Debian GNU/Linux and derivatives (such as Ubuntu)

In the case of Debian, you should probably install the package libreadline-dev, which is not installed by default.

About this egg


Tony Garnock-Jones

Maintained by Alexej Magura

Version history

Fixed a bug with legacy support where the aliases pointed to uninterned symbols.
Fixed a bug with the unclosed-exp-prompt, where "<NEWLINE> did not count as an unclosed expression. Added more history functions and other cool stuff (see soon-to-appear changelog for details)
fixed buggy build bugs caused by repeated build "fixes" (Jim Ursetto)
fixed buggy fixes made by felix (thanks to ewfalor)
fixed buggy setup script (thanks to ewfalor)
Ported to Chicken 4
Fixed an old typo that could conceivably cause errors [elf]
Fixed build process for real this time (ensuring tests for lib availability actually do set, etc.) [elf]
Fixed build process [elf]
Added backtraces to control-c breaks [elf]
Fixed history so that multiple sessions dont clobber each other. [elf]
Added proper signal handling [elf]
Added support for static linking [felix]
Ignores duplicate history entries [Thanks to Toby Butzon]
Empty lines are not added to history [Thanks to Dan Muresan]
Added parenthesis bouncing, a new auto-complete [Heath Johns]
Export *completion-entry-function* to support autocomplete [Alejandro Forero Cuervo]
prompt argument to make-gnu-readline-port is optional [felix]
Replaced use of (end-of-file) with #!eof
Checks more possible libraries to link with at build time [Thanks to Peter Bex]
Adapted to new setup scheme.
More features, changed license to GPL, links with either libtermcap or libncurses.
Initial release


Copyright (c) 2002 Tony Garnock-Jones
Copyright (c) 2006 Heath Johns (paren bouncing and auto-completion code)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA