unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs like line editing during perl input.
@ 2002-12-30  2:01 Harry Putnam
  2002-12-30  8:20 ` those who know me have no need of my name
  2002-12-31 15:14 ` Kai Großjohann
  0 siblings, 2 replies; 14+ messages in thread
From: Harry Putnam @ 2002-12-30  2:01 UTC (permalink / raw)


I'm sneaking in a perl question that is only slightly related to
emacs.

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.

Test:
  perl -e 'while(<>){print}'

Try to edit an input line

How can I get behavior like is available in any of the true korn
shells (not pdksh).

ksh93 <RET>
read

Any input lines are editable with full vi like line editing.
if -o emacs is set then full emacs line editing is available.
How can I get similar line editing ability duing perl input?

I think Term::ReadLine is the tool for this but couldn't figure out
how to deploy it.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-30  2:01 Emacs like line editing during perl input Harry Putnam
@ 2002-12-30  8:20 ` those who know me have no need of my name
  2002-12-30 16:01   ` Harry Putnam
  2002-12-31 15:14 ` Kai Großjohann
  1 sibling, 1 reply; 14+ messages in thread
From: those who know me have no need of my name @ 2002-12-30  8:20 UTC (permalink / raw)


[fu-t set]

in gnu.emacs.help i read:

>I'm sneaking in a perl question that is only slightly related to
>emacs.

it'd be a lot better answered in comp.lang.perl.misc or .modules.

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

,----[ from ``perldoc Term::ReadLine'' ]
| NAME
|        Term::ReadLine - Perl interface to various "readline"
|        packages. If no real package is found, substitutes stubs
|        instead of basic functions.
| 
| 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/;
|          }
`----

-- 
bringing you boring signatures for 17 years

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-30  8:20 ` those who know me have no need of my name
@ 2002-12-30 16:01   ` Harry Putnam
  2002-12-30 16:15     ` those who know me have no need of my name
  0 siblings, 1 reply; 14+ messages in thread
From: Harry Putnam @ 2002-12-30 16:01 UTC (permalink / raw)


those who know me have no need of my name <not-a-real-address@usa.net> 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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-30 16:01   ` Harry Putnam
@ 2002-12-30 16:15     ` those who know me have no need of my name
  2002-12-31  1:17       ` Harry Putnam
  0 siblings, 1 reply; 14+ messages in thread
From: those who know me have no need of my name @ 2002-12-30 16:15 UTC (permalink / raw)


in gnu.emacs.help i read:
>those who know me have no need of my name <not-a-real-address@usa.net>
>writes:

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

too bad, they'd answer your entirely perl question.  (childish-mode: i know
how to do what you want to do, in fact it's plain as can be for anyone that
is willing to invest the effort in actually learning a little perl, but i'm
not going to tell you because you decided to ignore my hint, and besides
it's off-topic for this group.)

-- 
bringing you boring signatures for 17 years

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-30 16:15     ` those who know me have no need of my name
@ 2002-12-31  1:17       ` Harry Putnam
  2002-12-31  1:58         ` Bijan Soleymani
  0 siblings, 1 reply; 14+ messages in thread
From: Harry Putnam @ 2002-12-31  1:17 UTC (permalink / raw)


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

> in gnu.emacs.help i read:
>>those who know me have no need of my name <not-a-real-address@usa.net>
>>writes:
>
>>Sorry Those, but Nope ... you're not redirecting me.  I posted here
>>for a purpose.  I wanted the input of emacs perl sharpies.
>
> too bad, they'd answer your entirely perl question.  (childish-mode: i know
> how to do what you want to do, in fact it's plain as can be for anyone that
> is willing to invest the effort in actually learning a little perl, but i'm
> not going to tell you because you decided to ignore my hint, and besides
> it's off-topic for this group.)

You're a hard man Those.. But suprise, I've already posted about this
thrice on the perl beginner list.  I get no farther than suggestions
to use Term::ReadLine.

If it were really plain to see, I'd see it.  I've written semi
extensive perl scripts and know rudimentary perl.

I want emacs style editing so while it may be a bit of a stretch, it
is emacs related.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31  1:17       ` Harry Putnam
@ 2002-12-31  1:58         ` Bijan Soleymani
  2002-12-31  2:32           ` Harry Putnam
                             ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Bijan Soleymani @ 2002-12-31  1:58 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> those who know me have no need of my name <not-a-real-address@usa.net> writes:
> 
> > in gnu.emacs.help i read:
> >>those who know me have no need of my name <not-a-real-address@usa.net>
> >>writes:
> >
> >>Sorry Those, but Nope ... you're not redirecting me.  I posted here
> >>for a purpose.  I wanted the input of emacs perl sharpies.
> >
> > too bad, they'd answer your entirely perl question.  (childish-mode: i know
> > how to do what you want to do, in fact it's plain as can be for anyone that
> > is willing to invest the effort in actually learning a little perl, but i'm
> > not going to tell you because you decided to ignore my hint, and besides
> > it's off-topic for this group.)
> 
> You're a hard man Those.. But suprise, I've already posted about this
> thrice on the perl beginner list.  I get no farther than suggestions
> to use Term::ReadLine.
> 
> If it were really plain to see, I'd see it.  I've written semi
> extensive perl scripts and know rudimentary perl.
> 
> I want emacs style editing so while it may be a bit of a stretch, it
> is emacs related.
I'm sorry but instructions on how to use term::readline have very
little to do with emacs. If you want emacs like editing you could
always rewrite your user interface in emacs lisp :) Then you would
get EMACS EDITING.

But seriously just download the source to a program that uses
Term:readline and figure it out. (vicq is a simple icq program written in 
perl that uses that library.)

Bijan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31  1:58         ` Bijan Soleymani
@ 2002-12-31  2:32           ` Harry Putnam
  2002-12-31  3:17           ` Harry Putnam
       [not found]           ` <mailman.737.1041305477.19936.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Harry Putnam @ 2002-12-31  2:32 UTC (permalink / raw)


Bijan Soleymani <bijan@psq.com> writes:

> I'm sorry but instructions on how to use term::readline have very
> little to do with emacs. If you want emacs like editing you could

He he.

I said going in this was a bit of stretch.

> always rewrite your user interface in emacs lisp :) Then you would
> get EMACS EDITING.

Yeah and how.  I could even use `qx' to call up an instance of emacs
for a single line... hehe.

> But seriously just download the source to a program that uses
> Term:readline and figure it out. (vicq is a simple icq program written in 
> perl that uses that library.)

Now this is a good tip.  Not sure why I didn't think of this.. I'll
try it out.

Now in my own defense.  I did do several detailed google.groups
searches with group as `comp*perl*' on Term::ReadLine and even using a
whole year as target.  I found not one example of a simple usage that
I could translate into my needs.

I've been digging around on this for a while now.  Off and on.

I've been reading/posting here since 1996 or so so I know for sure
there are some perl experts here who are also emacs users.
Maybe a little abusive on my part... but probably not worth a stoning.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31  1:58         ` Bijan Soleymani
  2002-12-31  2:32           ` Harry Putnam
@ 2002-12-31  3:17           ` Harry Putnam
       [not found]           ` <mailman.737.1041305477.19936.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 14+ messages in thread
From: Harry Putnam @ 2002-12-31  3:17 UTC (permalink / raw)


Bijan Soleymani <bijan@psq.com> writes:

> But seriously just download the source to a program that uses
> Term:readline and figure it out. (vicq is a simple icq program written in 
> perl that uses that library.)

emacs vICQ.pm
M-x occur [Rr]ead[Ll]ine <RET>
       <no matches>

M-x occur [Tt]erm <RET>
       <no matches>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
       [not found]           ` <mailman.737.1041305477.19936.help-gnu-emacs@gnu.org>
@ 2002-12-31  3:52             ` Bijan Soleymani
  2002-12-31  4:24               ` Harry Putnam
       [not found]               ` <mailman.738.1041308660.19936.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 14+ messages in thread
From: Bijan Soleymani @ 2002-12-31  3:52 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> Bijan Soleymani <bijan@psq.com> writes:
> 
> > But seriously just download the source to a program that uses
> > Term:readline and figure it out. (vicq is a simple icq program written in 
> > perl that uses that library.)
> 
> emacs vICQ.pm
> M-x occur [Rr]ead[Ll]ine <RET>
>        <no matches>
> 
> M-x occur [Tt]erm <RET>
>        <no matches>
I've installed the Debian package I'm looking at the file /usr/bin/vicq
and line 19 is:
use Term::Readline;
and m-x occur gives 23 matches.

Bijan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31  3:52             ` Bijan Soleymani
@ 2002-12-31  4:24               ` Harry Putnam
       [not found]               ` <mailman.738.1041308660.19936.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 14+ messages in thread
From: Harry Putnam @ 2002-12-31  4:24 UTC (permalink / raw)


Bijan Soleymani <bijan@psq.com> writes:

>> emacs vICQ.pm
>> M-x occur [Rr]ead[Ll]ine <RET>
>>        <no matches>
>> 
>> M-x occur [Tt]erm <RET>
>>        <no matches>
> I've installed the Debian package I'm looking at the file /usr/bin/vicq
> and line 19 is:
> use Term::Readline;
> and m-x occur gives 23 matches.

Oh.. thanks.  I was looking in the *.pm file.
Now I see them but still no closer to understanding how to use it to
make and input line editable.

Apparently this is just going to remain out of my grasp for some time
to come.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
       [not found]               ` <mailman.738.1041308660.19936.help-gnu-emacs@gnu.org>
@ 2002-12-31  5:45                 ` Bijan Soleymani
  0 siblings, 0 replies; 14+ messages in thread
From: Bijan Soleymani @ 2002-12-31  5:45 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> Bijan Soleymani <bijan@psq.com> writes:
> 
> >> emacs vICQ.pm
> >> M-x occur [Rr]ead[Ll]ine <RET>
> >>        <no matches>
> >> 
> >> M-x occur [Tt]erm <RET>
> >>        <no matches>
> > I've installed the Debian package I'm looking at the file /usr/bin/vicq
> > and line 19 is:
> > use Term::Readline;
> > and m-x occur gives 23 matches.
> 
> Oh.. thanks.  I was looking in the *.pm file.
> Now I see them but still no closer to understanding how to use it to
> make and input line editable.
> 
> Apparently this is just going to remain out of my grasp for some time
> to come.

I just checked and the Debian package for libterm-readline comes with
some examples. This is in:
/usr/share/doc/libterm-readline-gnu-perl/examples

You might also want to check the Readline manual itself as it seems as
the readline capability of perl simply calls the functions in the
Readline library (which is written in C).

If you do check out the Readline manual be careful there are two
manuals. One is a user manual that comes with the binary package. The
one you want is the other manual that comes with the dev package.

Bijan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-30  2:01 Emacs like line editing during perl input Harry Putnam
  2002-12-30  8:20 ` those who know me have no need of my name
@ 2002-12-31 15:14 ` Kai Großjohann
  2002-12-31 15:30   ` Harry Putnam
  1 sibling, 1 reply; 14+ messages in thread
From: Kai Großjohann @ 2002-12-31 15:14 UTC (permalink / raw)


Harry Putnam <hgp@sbcglobal.net> writes:

> I'd like to have somekind of line editing available during user
> input to a perl script.

Here is an example program using Term::ReadLine that worked for me.

#!/usr/sw/perl/default/bin/perl -w
use Term::ReadLine;
my $t = Term::ReadLine->new('Do nothing');
my $inp = '';	# input from user
print "Type quit to quit.\n";
do {
    $inp = $t->readline("> ");
} while ( $inp ne 'quit' );
exit 0;

Don't forget to change the first line.  It's really as easy as
calling $x->readline($prompt) to read a line after creating the
Term::ReadLine object $x.

-- 
Ambibibentists unite!

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31 15:14 ` Kai Großjohann
@ 2002-12-31 15:30   ` Harry Putnam
  2002-12-31 17:29     ` those who know me have no need of my name
  0 siblings, 1 reply; 14+ messages in thread
From: Harry Putnam @ 2002-12-31 15:30 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 423 bytes --]

kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

> #!/usr/sw/perl/default/bin/perl -w
> use Term::ReadLine;
> my $t = Term::ReadLine->new('Do nothing');
> my $inp = '';	# input from user
> print "Type quit to quit.\n";

Ha... heres somethuing I can follow.  Thanks Kai.
Seems to automatically have emacs like line editing.

And indulging myself in childish mode too..
Hey `Those Who Know Me'  ... Na na na naaa na

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Emacs like line editing during perl input.
  2002-12-31 15:30   ` Harry Putnam
@ 2002-12-31 17:29     ` those who know me have no need of my name
  0 siblings, 0 replies; 14+ messages in thread
From: those who know me have no need of my name @ 2002-12-31 17:29 UTC (permalink / raw)


in gnu.emacs.help i read:
>kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

>> #!/usr/sw/perl/default/bin/perl -w
>> use Term::ReadLine;
>> my $t = Term::ReadLine->new('Do nothing');

[then use the object]

>Ha... heres somethuing I can follow.  Thanks Kai.
>Seems to automatically have emacs like line editing.
>
>And indulging myself in childish mode too..
>Hey `Those Who Know Me'  ... Na na na naaa na

i told you it was trivial perl programming.

-- 
bringing you boring signatures for 17 years

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2002-12-31 17:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-30  2:01 Emacs like line editing during perl input Harry Putnam
2002-12-30  8:20 ` those who know me have no need of my name
2002-12-30 16:01   ` Harry Putnam
2002-12-30 16:15     ` those who know me have no need of my name
2002-12-31  1:17       ` Harry Putnam
2002-12-31  1:58         ` Bijan Soleymani
2002-12-31  2:32           ` Harry Putnam
2002-12-31  3:17           ` Harry Putnam
     [not found]           ` <mailman.737.1041305477.19936.help-gnu-emacs@gnu.org>
2002-12-31  3:52             ` Bijan Soleymani
2002-12-31  4:24               ` Harry Putnam
     [not found]               ` <mailman.738.1041308660.19936.help-gnu-emacs@gnu.org>
2002-12-31  5:45                 ` Bijan Soleymani
2002-12-31 15:14 ` Kai Großjohann
2002-12-31 15:30   ` Harry Putnam
2002-12-31 17:29     ` those who know me have no need of my name

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).