Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

embed vi editor in tk application

196 views
Skip to first unread message

amitm...@gmail.com

unread,
Jun 3, 2008, 1:53:06 PM6/3/08
to
How can embed the vi editor in tk application?
Any tk widget available for this?
Currently i am using scrolledtext widget to show and edit the file.
I am used to with vi and want to embed the same in this application.
Can somebody please help me out.

thanks
Amit M Joshi

Bryan Oakley

unread,
Jun 3, 2008, 2:28:59 PM6/3/08
to

The problem is, vi expects a terminal with curses support and Tk has no
widget that meets that criteria. It's not impossible, though. If you
can use the expect extension, it includes demo code that emulates a
terminal in which vi can run and which you can embed in a program (last
I checked anyway, which admittedly was a few years ago).

With a lot of work you might be able to make it happen in pure Tcl/Tk
but I don't think anyone has ever needed it badly enough to do it.
Probably an easier task would be to create a set of vi-like bindings to
the text widget.

Uwe Klein

unread,
Jun 3, 2008, 2:53:53 PM6/3/08
to
Bryan Oakley wrote:
> amitm...@gmail.com wrote:
>
>> How can embed the vi editor in tk application?
>> Any tk widget available for this?
>> Currently i am using scrolledtext widget to show and edit the file.
>> I am used to with vi and want to embed the same in this application.
>> Can somebody please help me out.
>>
>> thanks
>> Amit M Joshi
>
>
> The problem is, vi expects a terminal with curses support and Tk has no
...........................
> the text widget.
>
>
>
>
>
OK, try this:

# create a frame configure to embed another app
frame .f -container true
pack .f -expand 1 -fill both

# expr used to a dezimal window ID
# as winfo returns a string with the hexnumber
set wID [ expr [ winfo id .f ] ]

# the content you want to work on
set file /etc/hosts

# exec xterm with the "-into" option and have
# it run vi with your file in background:
exec xterm -into $wID -e vi $file &

# exercise left: how to notice vi has ended.

uwe

George Peter Staplin

unread,
Jun 3, 2008, 3:49:05 PM6/3/08
to


As the author of the -into patch to xterm (years ago), I think I should
point out that the example isn't ideal, because it won't resize with the
parent. However it's possible to make it do so by selecting the
SubstructureRedirectMask so that everytime the xterm resizes, you get a
ConfigureRequest. That's originally how I used xterm as a widget.

The original project I wrote that used the embedded xterm is no longer
maintained. I do however have some more recent code that demonstrates
the sequence with ntk in a prototype:
http://code.google.com/p/megapkg/source/browse/trunk/tclsrc/xterm_proto.tcl

Note: I decided I may need the ability to render offscreen with the
XComposite, and XDamage extensions (at the least), so that it would work
with NexTk and overlapped windows.

I'm willing to write an xterm widget that embeds xterm as a Tk widget,
but I don't always have a lot of time and/or motivation. I'll see if I
can piece some code together this week though.

The Whim desktop could use a Whimterm or something like that.


George

Darren New

unread,
Jun 3, 2008, 4:51:38 PM6/3/08
to
Bryan Oakley wrote:
> With a lot of work you might be able to make it happen in pure Tcl/Tk
> but I don't think anyone has ever needed it badly enough to do it.

http://gpl.internetconnection.net/vi/

You wouldn't think anyone would need vi-in-javascript badly enough to do
it either. :-) If there's a javascript interpreter in Tcl, you might be
able to get there from here, depending on how great your need is.

--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."

Uwe Klein

unread,
Jun 3, 2008, 5:41:20 PM6/3/08
to
George Peter Staplin wrote:

> As the author of the -into patch to xterm (years ago), I think I should
> point out that the example isn't ideal, because it won't resize with the
> parent. However it's possible to make it do so by selecting the
> SubstructureRedirectMask so that everytime the xterm resizes, you get a
> ConfigureRequest. That's originally how I used xterm as a widget.

Facinating.

uwe ;-)
and thanks for this information.
I just pieced this together with some diddling ( I knew about
-container and -into ) but had only used container stuff via
blt.

rf

unread,
Jun 4, 2008, 10:41:34 AM6/4/08
to

Tk's text widget is appropriate for any text manipulation. Melissa
Schrumpf offers vi-command implementations in pure tcl as part of her
code-editor on http://www.geocities.com/m_schrumpf/tcl/index.html
roland frank

Melissa Schrumpf

unread,
Jun 19, 2008, 8:18:06 PM6/19/08
to
rf wrote:

> Tk's text widget is appropriate for any text manipulation. Melissa
> Schrumpf offers vi-command implementations in pure tcl as part of her
> code-editor on http://www.geocities.com/m_schrumpf/tcl/index.html

It's a pretty sad commentary when other people can find your website
more easily than you can find it yourself.

--
MKS

0 new messages