File: axe.tcl

package info (click to toggle)
axe 6.1.2-16.2
  • links: PTS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,592 kB
  • ctags: 2,245
  • sloc: ansic: 20,644; sed: 361; tcl: 72; makefile: 46; sh: 14
file content (92 lines) | stat: -rw-r--r-- 1,966 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
proc with-selection {func {args {}}} {
    set selection [get-selection]
    set start [lindex $selection 0]
    set end   [lindex $selection 1]
    set lines [lindex $selection 2]

    if {$start == $end} {return}

    set-position $start
    for {set line 0} {$line < $lines} {incr line} {
	action beginning-of-line
	eval $func $args
	action next-line
    }
    action beginning-of-line
    set-selection $start [get-position]
}

proc prefix {{text {> }}} {
    with-selection action insert-string $text
}

proc stripn {{n 1}} {
    action multiply $n
    action delete-next-character
}

proc strip {{n 1}} {
    with-selection stripn $n
}

proc join-lines {{n 1} {insert " "}} {
    for {set line 0} {$line < $n} {incr line} {
	action end-of-line
	action delete-next-character
	action insert-string $insert
    }
}

proc format-all {} {
    set caret [get-position]
    action beginning-of-file
    for {set lastpos -1; set curpos 0} \
            {$curpos != $lastpos} \
                {set lastpos $curpos; set curpos [get-position]} { 
	action forward-paragraph
	action form-paragraph
	action next-line
    }
    set-position $caret
    action redraw-display
}

proc upper {{conversion toupper}} {
    set selected [get-selection]
    set start [lindex $selected 0]
    set finish [lindex $selected 1]
    set selection [lindex $selected 3]
    
    action delete-selection
    action insert-string [string $conversion $selection]
    set-selection $start $finish
}

proc lower {} {
    upper tolower
}

# - # - # - # - # - # - # - Backwards Compatability - # - # - # - # - # - # - #

proc loopSel {func {args {}}} {
    eval with-selection $func $args
}

proc getSelection {} {
    get-selection
}

proc setSelection {from to} {
    set-selection $from $to
}

proc getPos {} {
    get-position
}

proc setPos {pos} {
    set-position $pos
}

# Compatability versions of join and format have not been
# implemented as they mask Tcl commands of the same name.