Tcl拡張 – edit 1.00

Pocket

edit
a text widget with highlighting support for Tcl/Tk

NAME

edit (version 1.02 – 2010-01-21)
download: edit.zip
screenshot: demo1, demo2

REQUIREMENT

hashtrie 1.0
unicodeblock 1.1

SYNOPSIS

package require Tk
package require hashtrie 1.0
package require  unicodeblock 1.1
package require edit  ? 1.0 ?
edit pathName  ? options ?
edit::addHighlightWord pathName word class
edit::deleteHighlightWord pathName word
edit::generateHighlightRule sourcefile rulefile
edit::addHighlightRgx pathName pattern tagname
edit::deleteHighlightRgx pathName pattern
edit::defineBrackets pathName brackets
edit::defineTextTag filename
edit::applyTextTags pathName tags
edit::linemapPopup X Y menu
edit::getAllMarkedIndex pathName startIndex endIndex
edit::getMarkedLine pathName index direction
pathName highlight startIndex endIndex
pathName copy
pathName cut
pathName paste
pathName append
pathName configure option value  ? ... ?
pathName refresh

DESCRIPTION

The edit package provides the edit widget which support syntax highlighting, line-number display and some extra commands. This package based on ctext.

COMMANDS

edit pathName ? options ?

HIGHLIGHTING

edit::addHighlightWord pathName word class

Add a highlighting word word to the widget pathName. class class will be applied to word. class is a list that contains 2 or 3 elements. First element is type(word, noblank, nobreak, pair, char, string). Second element is tagname that apply to word. If type is pair, We must specify 3rd element pair which corresponding to word.

edit::addHighlightWord .t proc [list word syntax1]
edit::addHighlightWord .t < [list pair tags >]

edit::deleteHighlightWord pathName word

Delete the highlight word word from the widget pathName.

edit::generateHighlightRule sourcefile rulefile

Compile a highlight-rule sourcefile and save to rulefile.
sourcefile‘s format(TSV)(UTF-8 encoded):

#	nobreak	comment
$	noblank	syntax2
< pair	tags	>
after	word	syntax1
append	word	syntax1
array	word	syntax1
lindex	word	syntax1
proc	word	syntax1

see also /demo/tcl.txt.

#Generate highlight rules from text file
edit::generateHighlightRule tcl.txt tcl.dat
.t configure -highlight 1 -highlightrule tcl.dat

edit::addHighlightRgx pathName pattern tagname

Add a highlighting pattern pattern to the widget pathName. tagname tagname will be applied to pattern.

set url_rgx {https?://[-_.!~*'()a-zA-Z0-9;?:@&=+$,%#]+}
edit::addHighlightRgx .t $url_rgx url

edit::deleteHighlightRgx pathName pattern

Delete the highlight pattern pattern from the widget pathName.

edit::defineBrackets pathName brackets

edit widget can highlight corresponding brackets. This procedure defines corresponding brackets.

edit::defineBrackets .t "[]<>{}()"

edit::defineTextTag filename

Define some text-tags that included in text-file filename. This proc will returns a dict.
file’s format : tagname {tag-option : value;} (css-like style)

comment {
	-foreground: #0000ff;
}
brackets {
	-foreground:#ff0000;
	-background:#fbf1ea;
}
url {
	-foreground:#34A7EB;
	-underline :1;
}

You can only define four tag-options, -foreground -background -underline -overstrike -font.
see also /demo/tag.txt

edit::applyTextTags pathName tags

Apply text-tags(dict) to the widget pathName. These tags are made by edit::defineTextTag.

set tagfile [file join [file dirname [info script]] tag.txt]
set tags [edit::defineTextTag $tagfile]
edit::applyTextTags $txt $tags

edit::linemapPopup X Y menu

Show popup-menu for linemap. See also /demo/demo4.tcl and screen shot.

edit::getAllMarkedIndex pathName startIndex endIndex

Returns a list of marked-indices.

edit::getMarkedLine pathName index direction(forwards/backwards)

Return a index of next/previous marked line.

WIDGET COMMANDS

pathName highlight startIndex endIndex

Highlight the text between startIndex and endIndex.

pathName refresh

Refresh all highlight.

pathName configure option value ? … ?

Set the options for the edit widget.

WIDGET OPTIONS

NAME VALUE
-linemap 1 or 0 Creates or deletes a line number list on the left of the widget.
-linemapfg color Changes the foreground of the linemap.
-linemapbg color Changes the background of the linemap.
-linemapwidth width Changes the width of the linemap.
-linemapmenu path of menu Changes the menu for linemap. see also edit::linemapPopup.
-linemap_markable 1 or 0 Takes a boolean value which specifies whether or not lines in the linemap are markable with the mouse.
-linemap_select_fg color Changes the foreground of the selected line-number.
-linemap_separator 1 or 0 Creates or deletes a linemap’s separator.
-linemap_separator_bg color Changes the background of the linemap’s separator.
-highlight 1 or 0 Takes a boolean value which defines whether or not to highlight text which is inserted or deleted.
-highlightrule filename Changes the rule-file for highlight. See also edit::generateHighlightRule.
-highlightbrackets 1 or 0 Hilight bracket or not.
-brackets brackets Set brackets for highlighting.
-nocase 1 or 0 If -nocase is 1, then the patterns that defined by edit::addHighlightRgx are compared in a case-insensitive manner.
-autoindent 1 or 0 On or off auto-indent.
-rmargin 1 or 0 line wrap at specified width (units of characters) or not.

SHORTCUT KEYS

Control-MouseWheel font zoom
Control-Up/Down scroll(keep current caret position)

EXAMPLE

see also demos.

HISTORY

2010/01/21 v1.02 Fix some bugs

カテゴリー: Tcl タグ:

コメントを残す

メールアドレスが公開されることはありません。