jtextcmds.tcl

Introduction

The jtextcmds.tcl library is distributed as part of the jstools package. It provides user­level command procedures (in the sense of jcommand.tcl) for working with text widgets that are likely to be useful across applications. It depends on the jtext.tcl library, and supports (but does not require) the jtexttags.tcl library. Currently, it provides Cut, Copy, and Paste commands. In the future I hope for it to provide Undo and Redo commands and text formatting commands as well.

This document describes jtextcmds.tcl version 4.1/4.4.

Usage

Accessing the Library

In order to use the jtextcmds.tcl library, it (and any other libraries it depends on) must be in your Tcl auto_path, described in tclvars(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.

Credits and Copyright

Author

Jay Sekora
js@aq.org
http://www.aq.org/~js/

Copyright

The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.

Overview

Procedures

j:cmd:text_cut - delete selected text and save it in a cut buffer
j:cmd:text_copy - save selected text in a cut buffer without deleting it
j:cmd:text_paste - paste previously cut or copied text into text widget

See Also

jtext.tcl
jtexttags.tcl

j:cmd:text_cut

Usage

j:cmd:text_cut w args


Arguments

w is the text widget to cut text from
Any additional args are ignored

Description


This procedure deletes any selected text from the text widget w and stores it in a global variable so it can later be pasted. If w is a rich­text widget (i.e., it's using the jtexttags.tcl library for tag maintenance), then the tags associated with the selected text are also saved, so they can be restored when the text is later pasted.

The cut text (and tags, if applicable) will be saved to disk if possible (specifically, if the files ~/.tk/cut_text and ~/.tk/cut_richtext can be written to) so that cut text can be pasted into an application running as a separate process. (This also means that cut text is preserved across invocations of jedit; i.e., you can cut some text, quit jedit, start it again, and paste the text cut in the previous session.)

j:cmd:text_copy

Usage

j:cmd:text_copy w args

Arguments

w is the text widget to cut text from
Any additional args are ignored

Description

This procedure copies any selected text in text widget w into a global variable so it can later be pasted. If w is a rich­text widget (i.e., it's using the jtexttags.tcl library for tag maintenance), then the tags associated with the selected text are also saved, so they can be restored when the text is later pasted.

The copied text (and tags, if applicable) will be saved to disk if possible (specifically, if the files ~/.tk/cut_text and ~/.tk/cut_richtext can be written to) so that copied text can be pasted into an application running as a separate process.

j:cmd:text_paste

Usage

j:cmd:text_paste w args

Arguments

w is the text widget to paste text into
Any additional args are ignored

Description

This procedure inserts previously cut or copied text into text widget w. If J_PREFS(typeover) is true, than the existing selection in w, if any, will first be deleted if the insert point is in or adjacent to the selection. If w is a rich­text widget (i.e., it's using the jtexttags.tcl library for tag maintenance), then the tags associated with the selected text will also be restored.

The pasted text (and tags, if applicable) will be read to disk if possible (specifically, if the files ~/.tk/cut_text and ~/.tk/cut_richtext exist and are readable) so that text cut or copied in a separate application can be pasted. Otherwise, application­specific global variables are used.

Bugs and Misfeatures

* Cutting or copying rich text can be hideously slow, since the text is examined for tags character­by­character. Now that Tk4.1 provides the text dump command, this could be speeded up considerably.