Re: Readline completion example?

Jean Louis <[email protected]> Thu, 16 Nov 2017 01:16:40 +0300
Newsgroups gmane.lisp.clisp.general
Message-ID <[email protected]>
On Wed, Nov 15, 2017 at 03:57:23PM -0500, Sam Steingold wrote:
> > * Jean Louis <[email protected]> [2017-11-15 09:20:07 +0300]:
> >
> > On Tue, Nov 14, 2017 at 04:27:08PM -0500, Sam Steingold wrote:
> >> 
> >> > * Jean Louis <[email protected]> [2017-11-14 10:31:51 +0300]:
> >> >
> >> > (defun prompt-read (prompt &optional default)
> >> 
> >> Please try hg tip facilities described in
> >> https://clisp.sourceforge.io/beta/impnotes/terminal.html#readline-extend
> >
> > That is great, thank you,
> 
> You are welcome.
> 
> > can be good for the start.
> 
> I think you will have to develop it yourself now.
> 
> > I see it is to complete the single words nicely,
> > yet if there are words with spaces it is not
> > working as expected and it is not completing.
> 
> This is because of readline limitations:
> 
> --8<---------------cut here---------------start------------->8---
> (let ((custom:*completion* (lambda (s b e) (print (list s b e)) nil))) (read-line))
> foo b <TAB>
> ("foo b" 4 5) 
> --8<---------------cut here---------------end--------------->8---
> 
> as you see, when you type "foo b" and hit TAB, readline asks you to
> complete the string "b"=(subseq "foo b" 4 5), not "foo b" as you expect.
> You are free to ignore the start and end arguments in your completion
> function, of course, but this is a fairly special-purpose circumstance.
> 
> Feel free to copy and modify clisp/src/complete.lisp:make-completion.

I am trying something into this direction, but I
am not getting it.

You said there are some limitations, is it then
possible to make completion of list of words
containing spaces? Or not?




(defun ext:make-completion (list)
  "Return a function suitable for `CUSTOM::*COMPLETION*'."
  (lambda (string start end)
    (let ((return-list
           ;; REMOVE-IF may return its list argument,
           ;; and SORT modifies its argument,
           ;; so we have to use DELETE-IF+COPY-LIST
           ;; to ensure that we do not modify the list argument.
           (delete-if-not (lambda (s)
                            (let ((s (string s)))
                              (equalp 0 (search string s))))
                          ;; (string/= s string
                          ;;           :start1 0 :end1 (min (length s) (- end start))
                                    ;; :start2 0 :end2 end)))
                      (copy-list list))))
      return-list)))

------------------------------------------------------------------------------
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