feature request ...readline extention inside newlisp.c

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

feature request ...readline extention inside newlisp.c

Post by 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)

Code: Select all

#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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

name completion

Post by newdep »

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/r ... tions.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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Its done!

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

Code: Select all

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
Last edited by Lutz on Fri Nov 21, 2008 7:02 pm, edited 2 times in total.

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

...marvelous solution!!!

Thanks!
-- (define? (Cornflakes))

itistoday
Posts: 429
Joined: Sun Dec 02, 2007 5:10 pm
Contact:

Post by itistoday »

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

Locked