Re: Readline completion example?

Jean Louis <[email protected]> Sat, 11 Nov 2017 19:04:16 +0300
Newsgroups gmane.lisp.clisp.general
Message-ID <[email protected]>
On Wed, Feb 22, 2017 at 01:39:53PM -0500, Sam Steingold wrote:
> You can start your quest by replacing sys::completion with, say,
> 
> (defun sys::completion (string start end)
>   (list "foo" "foo1" "foo2"))
> 
> Now, whenever you hit TAB, you get "foo" inserted and "foo1" and "foo2"
> suggested (or something like that).
> 
> The current behavior is described here:
> http://clisp.org/impnotes/clisp.html#completion

Hello Sam,

I am trying to do the above, but I am not getting
it. The link also does not say much any more about
how to get completion words in CLISP, and I need
it for prompts and inputs.

(defun completion-trim-double-colon (string)
  (string (string-trim '(#\: #\Space) string)))

(defun completion-get-item-id (string)
  "Returns the ID from \"string :: ID\""
  (let* ((pos (search "::" string :from-end t))
         (id (read-from-string (completion-trim-double-colon (substring string pos)))))
    id))

(defun completion-construct-completions (list-of-cons)
  (let ((completions '()))
    (dolist (cons list-of-cons completions)
      (push (format nil "~A :: ~A" (cadr cons) (car cons)) completions))))

(defun completions (list-of-cons)
  ;;  (setf CUSTOM:*SUPPRESS-CHECK-REDEFINITION* t)
  ;; work in progress
  (setf (symbol-function 'sys::completion)
          #'(lambda (string start end)
              (completion-construct-completions list-of-cons))))
;;  (setf CUSTOM:*SUPPRESS-CHECK-REDEFINITION* nil))

(completion-construct-completions '((1 "Hello") (2 "Alright") (3 "Something")))

(setf CUSTOM:*SUPPRESS-CHECK-REDEFINITION* t)

(defun sys::completion (string start end)
  (list "Something :: 3" "Alright :: 2" "Hello :: 1"))

The last one above would work if the words begin
with the same letters, but it does not give me
result with multiple letters.

If you have any pointer how to construct
completion list for CLISP natively, without
systems, let me know.

Jean

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list