Updated 2015-04-25 19:28:03 by pooryorick

NEM 3 August 2006: Here's a simple little text widget editor I knocked up. Its sole contribution is that it has some convenient bindings for entering symbols from predicate logic. I also added a binding for lambda too, on a whim.

 # logiceditor.tcl --
 #
 #       A simple text editor with convenient bindings for entering logic
 #       symbols.
 #
 # Copyright (c) 2006 Neil Madden ([email protected]).
 #
 # License: BSD-style.
 
 package require Tcl         8.4
 package require Tk          8.4
 package provide logiceditor 1.0
 
 namespace eval logiceditor {
    # List of special symbols
    #   Symbol name         UTF-8       Binding
    variable symbols {
        implication         \u21D2      i
        equivalence         \u21D4      q
        negation            \u00AC      n
        conjuction          \u2227      a
        disjunction         \u2228      o
        universal           \u2200      u
        existential         \u2203      e
        definition          \u2261      d
        entails             \u22A8      t
        proof               \u22A2      p
 
        lambda              \u03BB      l
    }
    variable modifier   Control
    proc setup {} {
        variable symbols
        variable modifier
        foreach {name unicode key} $symbols {
            bind LogicEditor <$modifier-$key> \
                "%W insert insert [subst $unicode]; break"
        }
    }
    setup
 
    proc create {path args} {
        set top [toplevel $path]
        wm title $top "Logic Editor"
        eval [linsert $args 0 text $top.editor -font {{Lucida Sans} 12} \
            -yscrollcommand [list $top.vsb set] \
            -xscrollcommand [list $top.hsb set] \
            -wrap none]
        bindtags $top.editor [linsert [bindtags $top.editor] 1 LogicEditor]
        scrollbar $top.vsb -orient vertical \
            -command [list $top.editor yview]
        scrollbar $top.hsb -orient horizontal \
            -command [list $top.editor xview]

        grid $top.editor -row 0 -column 0 -sticky nsew
        grid $top.vsb -row 0 -column 1 -sticky ns
        grid $top.hsb -row 1 -column 0 -sticky ew

        grid rowconfigure $top 0 -weight 1
        grid columnconfigure $top 0 -weight 1
        return $top
    }
 }
 logiceditor::create .t

NEM Thanks to the anonymous person who pointed out my use of {*} making this 8.5 only. I've corrected the above (no need for two versions).

NEM Changed equivalence binding to Control-q rather than Control-=.