logo       

Re: Emacs like line editing during perl input.: msg#00949

emacs.help

Subject: Re: Emacs like line editing during perl input.

those who know me have no need of my name <not-a-real-address@xxxxxxx> writes:

Sorry Those, but Nope ... you're not redirecting me. I posted here
for a purpose. I wanted the input of emacs perl sharpies.


>>I'd like to have somekind of line editing available during user
>>input to a perl script.
>>
>>By default it seems none is available. Any attempt to navigate or
>>edit an input line produces control chars. Only backspace works to
>>edit.
>
> that's all that is provided by your system's terminal driver. (probably
> there are some other functions too, but nowhere near what emacs provides.)
> most likely you want to special case terminal input to use Term::ReadLine.
>
>>I think Term::ReadLine is the tool for this but couldn't figure out
>>how to deploy it.

Not sure why you would post the synopsis since I had stated clearly
it was not parsable by me. I wasn't able to see how to translate
that example into something usable to make user input editable.


> | SYNOPSIS
> | use Term::ReadLine;
> | $term = new Term::ReadLine 'Simple Perl calc';
> | $prompt = "Enter your arithmetic expression: ";
> | $OUT = $term->OUT || STDOUT;
> | while ( defined ($_ = $term->readline($prompt)) ) {
> | $res = eval($_), "\n";
> | warn $@ if $@;
> | print $OUT $res, "\n" unless $@;
> | $term->addhistory($_) if /\S/;
> | }
> `----

For example: In the above script, the input lines are no more
editable than with perl -e 'while (<>){print}'

$ ksh93
$ set -o emacs
$ read
<enter line?

provides a fully emacs style line editor.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise