:create-mal-env
:get-env
:find-env
- :set-env))
+ :set-env
+ :mal-env-bindings))
(in-package :env)
(:use :common-lisp)
(:import-from :uiop
:getenv)
+ (:import-from :cl-readline
+ :readline)
(:export :main))
(in-package :mal)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
:printer)
(:import-from :utils
:getenv)
+ (:import-from :cl-readline
+ :readline)
(:export :main))
(in-package :mal)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
:env
:reader
:printer)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of *repl-env*
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(loop do (let ((line (mal-readline "user> ")))
(if line (mal-writeline (rep line)) (return)))))
:reader
:printer
:genhash)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(loop do (let ((line (mal-readline "user> ")))
(if line (mal-writeline (rep line)) (return)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(loop do (let ((line (mal-readline "user> ")))
(if line (mal-writeline (rep line)) (return)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(loop do (let ((line (mal-readline "user> ")))
(if line (mal-writeline (rep line)) (return)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(let ((args (if argv-provided-p
argv
(cdr (utils:raw-command-line-arguments)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(let ((args (if argv-provided-p
argv
(cdr (utils:raw-command-line-arguments)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(let ((args (if argv-provided-p
argv
(cdr (utils:raw-command-line-arguments)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
+
(let ((args (if argv-provided-p
argv
(cdr (utils:raw-command-line-arguments)))))
:reader
:printer
:core)
+ (:import-from :cl-readline
+ :readline
+ :register-function)
(:import-from :genhash
:hashref
:hashmap)
(:import-from :utils
:listify
- :getenv)
+ :getenv
+ :common-prefix)
(:export :main))
(in-package :mal)
(defvar *use-readline-p* nil)
+(defun complete-toplevel-symbols (input &rest ignored)
+ (declare (ignorable ignored))
+
+ (let (candidates)
+ (loop for key being the hash-keys of (env:mal-env-bindings *repl-env*)
+ when (let ((pos (search input key))) (and pos (zerop pos)))
+ do (push key candidates))
+
+ (if (= 1 (length candidates))
+ (cons (car candidates) candidates)
+ (cons (apply #'utils:common-prefix candidates) candidates))))
+
(defun raw-input (prompt)
(format *standard-output* prompt)
(force-output *standard-output*)
(defun mal-readline (prompt)
(if *use-readline-p*
- (rl:readline :prompt prompt
- :add-history t
- :novelty-check (lambda (old new)
- (not (string= old new))))
+ (rl:readline :prompt prompt :add-history t :novelty-check #'string/=)
(raw-input prompt)))
(defun mal-writeline (string)
*standard-output* (ext:make-stream :output :buffered t)
*error-output* (ext:make-stream :error :buffered t))
+ ;; CCL fails with a error while registering completion function
+ ;; See also https://github.com/mrkkrp/cl-readline/issues/5
+ #-ccl (rl:register-function :complete #'complete-toplevel-symbols)
+
(let ((args (if argv-provided-p
argv
(cdr (utils:raw-command-line-arguments)))))
:getenv
:read-file-string
:raw-command-line-arguments
- :listify))
+ :listify
+ :common-prefix))
(in-package :utils)
(defun listify (sequence)
"Convert a sequence to a list"
(map 'list #'identity sequence))
+
+(defun common-prefix (&rest strings)
+ (if (not strings)
+ ""
+ (let* ((char-lists (mapcar (lambda (string) (coerce string 'list)) strings))
+ (char-tuples (apply #'mapcar #'list char-lists))
+ (count 0))
+ (loop for char-tuple in char-tuples
+ while (every (lambda (char) (equal char (car char-tuple))) char-tuple)
+ do (incf count))
+
+ (subseq (car strings) 0 count))))