X-Git-Url: http://git.kpe.io/?p=cl-readline.git;a=blobdiff_plain;f=readline.lisp;fp=readline.lisp;h=4e8af262c09fe969a4d58d71974a6809c3b6ae1f;hp=2685c4b374367145cb37c3ad5b923446d84e6604;hb=d9393c021044b97301b91b236473b65abab58951;hpb=49f16a2f58ec319d4d42e8a4af9dc3fadf05f6b7 diff --git a/readline.lisp b/readline.lisp index 2685c4b..4e8af26 100644 --- a/readline.lisp +++ b/readline.lisp @@ -36,16 +36,6 @@ (setq cl-complete nil) (libreadline::clear-completions)) - (defun use-custom-complete () - "Use custom-competions." - (libreadline::use-custom-complete) - nil) - - (defun use-filename-complete () - "Use default completion system. (filename)" - (libreadline::use-filename-complete) - nil) - (defun use-cl-complete () "Load symbols in package CL-USER as custom-completions." (unless cl-complete @@ -54,19 +44,34 @@ (do-symbols (sym (find-package :cl-user)) (add-completion (string-downcase (string sym))))) (use-custom-complete) - nil) + nil)) + +;;; Everything that affects the custom-completion collection goes +;;; above. + +(defun use-custom-complete () + "Use custom-competions." + (libreadline::use-custom-complete) + nil) + +(defun use-filename-complete () + "Use default completion system. (filename)" + (libreadline::use-filename-complete) + nil) - (defun add-history (string) - "Add STRING to history." - (with-cstring (c-string string) - (libreadline::add-history c-string)) - string) +(defun add-history (string) + "Add STRING to history." + (with-cstring (c-string string) + (libreadline::add-history c-string)) + string) - (defun readline (&key (prompt "") (history t)) - "Read a line from current TTY with line-editing." - (with-cstring (c-prompt prompt) - (let ((str (string-trim - *whitespace* - (convert-from-cstring (libreadline::readline c-prompt))))) - (when (and history (not (string= "" str))) - (add-history str)))))) +(defun readline (&key (prompt "") (history t)) + "Read a line from current TTY with line-editing." + (with-cstring (c-prompt prompt) + (let* ((char* (libreadline::readline c-prompt)) + (str (string-trim *whitespace* + (convert-from-foreign-string char*)))) + (free-foreign-object char*) + (when (and history (not (string= "" str))) + (add-history str)) + str)))