feature request ...readline extention inside newlisp.c

Started by newdep, November 21, 2008, 03:55:23 AM

Previous topic - Next topic

newdep

Hi Lutz,



Customized readline macro's can be created for "specific" programs

inside the ~/.inputrc file by use of $if <name>



If newlisp would have defined ->  char * rl_readline_name <-

***

 This variable is set to a unique name by each application using

 Readline.  The value allows conditional parsing of the inputrc file

 (see Conditional Init Constructs.).

***





People can create readline macro's inside their ~/.inputrc specificly

for newlisp only! So they wont work outside the newlisp shell i.e.

inside bash..



$if newlisp

# Quote the current or previous word

"C-nq": "eb(ef)"

$endif









like this in newlisp.c ->

(checked and works)



#ifdef READLINE
        if(isTTY)
                {
                rl_readline_name = "newlisp";
                errnoSave = errno;
                if((cmd = readline(prompt())) == NULL) exit(0);
                errno = errnoSave; /* reset errno, set by readline() */
                if(strlen(cmd) > 0) add_history(cmd);
                executeCommandLine(cmd, OUT_CONSOLE, &cmdStream);
                free(cmd);
                continue;
                }  

        if(IOchannel != stdin || forcePromptMode)
                varPrintf(OUT_CONSOLE, prompt());
#endif
-- (define? (Cornflakes))

newdep

#1
And something which is on my wish list for some time,

being a tty user.. that is called name completion..



As with readline yuo can complete yuor typing by pressing (double TAB)



http://docs.freebsd.org/info/readline/readline.info.Completion_Functions.html">//http://docs.freebsd.org/info/readline/readline.info.Completion_Functions.html



It should not be a lot of code to make "newlisp SYMBOL" completion possible

in newlisp i guess?



What do you think Lutz? Is it an option to build in into the

newlisp-console when reladine is compiled with it?



Norman.







PS: regaring this option, Im investigating if its possible to make this

work with 100% newlisp code...
-- (define? (Cornflakes))

Lutz

#2
I can include 'rl_readline_name="newlisp"' in the code. The question is, if there is a way to put a list of all names to complete into .inputrc, so I don't have to burden the code with a completion_matches() function.



Also I could not get your quoting examle to work after compiling with 'rl_readline_name'. What am I supposed to type for "C-nq": "eb(ef)"? Ctrl-NQ will delete the whole line.

newdep

#3
the environment default points to /etc/inputrc  



you can do a "export INPUTRC=~/.inputrc" if youre using Bash

or leave it empty "export INPUTRC"..

because bash needs to re-read the inputrc.. I just put it inside

/etc/inputrc that easier and works directly..





There could be a trick with a readline-macro to "grab" from a file

and link that to the completion perhpas..ill have a look...
-- (define? (Cornflakes))

newdep

#4
btw...



If you have put the macro inside the inputrc..



start newlisp and press CTRL-n then plain "q" after i.e. typing hello...

it will make it (hello)..



if the rl_readline_name is inside your newlisp code your need to

put inside the inputrc the statement of $if newlisp.....
-- (define? (Cornflakes))

newdep

#5
doing readline completion still could be done in 100% newlisp code

together wth the inputrc file.. im heading towards a solutions.. hold on ;-)
-- (define? (Cornflakes))

newdep

#6
Its not possible to interact from the outside with readline macro's

with the internal buffer of readline. The only Trick is putting all the

symbols inside a directory and then handle it as filenames, but no option..



So also with a readline keyboard macro i cant get there.. There must be

something from inside newlisp that points to a buffer/file.. From that point

on you could execute newlisp-commands to parse that file and append

it to the current cursor position...
-- (define? (Cornflakes))

newdep

#7
Perhpas the completion should not be part of newlisp binary if it

takes too much resources/code.



Im now working with 'read-key to make this working under linux

together with command-event as an alternative..this implies that

readline doesnt work anymore..which is a backdraw...



(on second thought... too much work, need to rewrite actualy a complete

line handler in newlisp...)
-- (define? (Cornflakes))

newdep

#8
when using BASH there is a configurable way to use completion!

see the manpage of bash... This could be done 100% in newlisp scripting

actualy.. but im not sure yet it is copied into newlisp command shell

when running ontop of bash...
-- (define? (Cornflakes))

Lutz

#9
Its done!



Took very little code, because I could use the existing primitive[] array which has all the names of built-in primitives.


newLISP v.9.9.95 on OSX IPv4 UTF-8, execute 'newlisp -h' for more info.

> (print
print    println  
> (print


look for 9.9.95 on Monday



ps: when nothing is entered, or only the opening parenthesis and hitting Tab and yes, it will show all 341 built-in functions, nicely formatted in a multicolumn list

newdep

#10
...marvelous solution!!!



Thanks!
-- (define? (Cornflakes))

itistoday

#11
Thanks! This is really neat! :-)
Get your Objective newLISP groove on.