;; Copyright (c) 2003 Nikodemus Siivola ;; ;; Permission is hereby granted, free of charge, to any person obtaining ;; a copy of this software and associated documentation files (the ;; "Software"), to deal in the Software without restriction, including ;; without limitation the rights to use, copy, modify, merge, publish, ;; distribute, sublicense, and/or sell copies of the Software, and to ;; permit persons to whom the Software is furnished to do so, subject to ;; the following conditions: ;; ;; The above copyright notice and this permission notice shall be included ;; in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (in-package readline) (defvar *whitespace* (list #\Space #\Tab)) (let (cl-complete) (defun add-completion (string) "Add STRING as a custom-completion." (setq cl-complete nil) (with-cstring (c-str string) (= 1 (libreadline::add-completion c-str)))) (defun clear-completions () "Clear all custom-completions." (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 (setq cl-complete t) (clear-completions) (do-symbols (sym (find-package :cl-user)) (add-completion (string-downcase (string sym))))) (use-custom-complete) nil) (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))))))