Here's a hack to get around the hacky creator names of the list objects 
(I also added "list", but I'm not sure if you want to use aliases.)

Is there no way to just get a list of all the creator names that are 
available when Pd loads up?

-Jonathan


--- On Sun, 4/3/11, yvan volochine <[email protected]> wrote:

> From: yvan volochine <[email protected]>
> Subject: Re: [PD] 3 new gui-plugins
> To: "Hans-Christoph Steiner" <[email protected]>
> Cc: [email protected]
> Date: Sunday, April 3, 2011, 6:53 PM
> On 04/03/2011 06:44 PM,
> Hans-Christoph Steiner wrote:
> >
> > On Apr 3, 2011, at 12:12 PM, yvan volochine wrote:
> >
> >> On 04/03/2011 05:57 PM, Hans-Christoph Steiner
> wrote:
> >>>
> >>> Wow, I love the tab autocompletion plugin!
> What would be amazing if we
> >>> had a bash-style completion files were the
> arguments were also
> >>> tab-completable, when relevant. Things like
> filenames, table/array
> >>> names, send/receive names, etc. This
> completion file could be included
> >>> in libraries. It really highlights how badly
> we need Enter/Return to
> >>> instantiate the object.
> >>>
> >>> Personally I prefer the default
> tcsh/bash-style where tab doesn't cycle
> >>> thru the options when you hit tab repeatly. I
> could see a bash/tcsh
> >>> style display of the options, like in a popup
> when you hit tab
> >>> repeatedly.
> >>
> >> hey thanks.
> >> I'm not really supposed to dedicate that ammount
> of time developping
> >> for pd but as I'm unemployed right now =)
> >> I'm afraid the bash style auto-completion is a bit
> above my head, but
> >> the idea is nice.
> >
> > Basically, the first is the trigger: hitting tab twice
> where the tab
> > does not add any more characters. So using your plugin
> as an example,
> > type M-O-Tab-Tab would then list 'mod' and 'moses' as
> options but not
> > change the 'mo' in the box. Those options could then
> be in a popup menu
> > to both see and select with the keyboard or mouse.
> 
> yeah that's what I wanted first: a ComboBox below the
> object box, but 
> then I had troubles with object box coordinates (did the
> user click or 
> is the object still moving with the cursor, etc...) and I
> started adding 
> some "if" and all kind of stuff inside mouse motion
> procedures and that 
> became nasty.
> this (and the fact that I wanted it now =) made me rewrite
> the plugin 
> with the "cycling-through-completions-with-tab" behavior
> (which I still 
> find very cool for speedy-patching)
> 
> cheers,
> _y
> 
> > Adding the argument completion would probably be a lot
> more work, but I
> > haven't really thought about it. But just having
> object name completion
> > is huge!
> >
> > .hc
> >
> >>> One thing that needs to happen to make the
> auto-complete plugin more
> >>> deployable is to have all its procs in its own
> namespace. Otherwise
> >>> there can easily be name conflicts with other
> things named 'init',
> >>> 'trigger', etc.
> >>
> >> done
> >>
> >>> (FYI: sending to pd-announce also sends to
> pd-list)
> >>
> >> okay
> >>
> >> cheers,
> >> _y
> >
> >
> >
> >
> >
> ----------------------------------------------------------------------------
> >
> >
> > You can't steal a gift. Bird gave the world his music,
> and if you can
> > hear it, you can have it. - Dizzy Gillespie
> >
> >
> >
> 
> 
> _______________________________________________
> [email protected]
> mailing list
> UNSUBSCRIBE and account-management -> 
> http://lists.puredata.info/listinfo/pd-list
>
# META NAME auto-complete plugin
# META DESCRIPTION Does auto-completion for objects
# META AUTHOR <Yvan Volochine> [email protected]
# META VERSION 0.2

package require Tcl 8.4

namespace eval ::completion:: {}

###########################################################
# overwritten procedures
rename ::pd_bindings::sendkey ::pd_bindings::sendkey_old
rename pdtk_text_set pdtk_text_set_old
rename pdtk_text_editing pdtk_text_editing_old

###########################################################
# GLOBALS

# this is where you can put extra objects/abstractions that you want to
# work with auto-completion. BEWARE, you should have *only one* object/abstraction
# name per line!
#set ::user_objects_list "~/pd/list_of_my_objects.txt"
set ::user_objects_list ""

set ::new_object false
set ::current_canvas ""
set ::lock_motion false
set ::motionx 0
set ::motiony 0
set ::current_text ""
set ::first_text ""
set ::erase_text ""
set ::i 0
set ::cycle false
set ::completions {}
# all pd internals (hopefully)
set foob [join {list {list append}}]
set ::all_externals {random loadbang namecanvas serial cputime realtime canvas declare template curve plot drawnumber vradio declare mtof ftom rmstodb powtodb dbtopow dbtorms max~ min~ delwrite~ delread~ vd~ inlet~ outlet~ block samplerate~ inlet midiin sysexin notein ctlin pgmin bendin touchin polytouchin midiclkin midirealtimein midiout noteout ctlout pgmout bendout touchout polytouchout makenote stripnote poly bag hradio print text cos~ osc~ vcf~ noise~ hslider hip~ lop~ bp~ biquad~ samphold~ rpole~ rzero~ rzero_rev~ cpole~ czero~ czero_rev~ dac~ adc~ sig~ line~ vline~ snapshot~ vsnapshot~ env~ threshold~ bang~ fft~ ifft~ rfft~ rifft~ framp~ qlist textfile openpanel savepanel key keyup keyname int float symbol bang send receive sel route pack unpack trigger spigot moses until makefilename swap change value bng pow max min mod div sin cos tan atan atan2 sqrt log exp abs wrap clip toggle soundfiler readsf writesf tabwrite~ tabplay~ tabread~ tabread4~ tabosc4~ tabsend tabreceive tabread tabread4 tabwrite send~ receive~ catch~ throw~ get set getsize setsize append sublist netsend netreceive nbx vslider clip~ rsqrt~ sqrt~ wrap~ mtof~ ftom~ dbtorms~ rmstodb~ dbtopow~ powtodb~ pow~ exp~ log~ abs~ text vu delay metro line timer pipe list}

# add list classes separately because of space in the creator name
foreach list_op { append prepend split trim length } {
    lappend ::all_externals "list $list_op"
}


proc ::completion::init {} {
    # bind Tab for autocompletion
    bind all <Tab> {::completion::trigger}
    ::completion::list_user_externals
    ::completion::list_user_objects $::user_objects_list
    # sort objects list for a quicker search later
    set ::all_externals [lsort $::all_externals]
}

proc ::completion::trigger {} {
    if {$::new_object} {
        # remove whitespaces
        set ::current_text [string map {" " ""} $::current_text]
        ::completion::find_external
    }
}

proc ::completion::list_user_externals {} {
    foreach pathdir [concat $::sys_searchpath $::sys_staticpath] {
        set dir [file normalize $pathdir]
        if { ! [file isdirectory $dir]} {continue}
        foreach filename [glob -directory $dir -nocomplain -types {f} -- \
                              *.pd_linux] {
            set basename [file tail $filename]
            set name [file rootname $basename]
            lappend ::all_externals $name
        }
    }
}

proc ::completion::list_user_objects {afile} {
    set filename [file join $afile]
    if {
        $afile ne ""
        && [file exists $filename]
        && [file readable $filename]
    } {
        set fl [open $filename r]
        while {[gets $fl line] >= 0} {
            if {[string index $line 0] ne "#"} {
                lappend ::all_externals $line
            }
        }
        close $fl
    }
}

proc ::completion::find_external {} {
    set length [llength $::completions]
    set text $::current_text
    
    if {$text ne "" && $::cycle == false} {
        set ::completions [lsearch -all -inline -glob $::all_externals $text*]
        # to retrieve typed text after cycling through all possible completions
        set ::first_text $::current_text
        set ::cycle true
        set length [llength $::completions]
        set ::i 0
    }

    if {$::cycle && $length > 0} {
        if {$::i == $length} {
            # return to what user first typed
            set new_text $::first_text
            set ::i -1
        } {
            set new_text [lindex $::completions $::i]
        }
        if {$::i == 0} { set ::erase_text $text }
        ::completion::erase_previoustext
        ::completion::write_text $new_text
        set ::i [expr $::i + 1]
    }
}

# simulate backspace keys
proc ::completion::erase_previoustext {} {
    set mytoplevel [winfo toplevel $::current_canvas]
    set i [string length $::erase_text]
    while {$i > 0} {
        pdsend "$mytoplevel key 1 8 0"
        pdsend "$mytoplevel key 0 8 0"
        set i [expr {$i - 1}]
    }
}

# write text into the object box
proc ::completion::write_text {text} {
    set mytoplevel [winfo toplevel $::current_canvas]
    for {set i 0} {$i < [string length $text]} {incr i 1} {
        set cha [string index $text $i]
        scan $cha %c keynum
        pdsend "pd key 1 $keynum 0"
    }
    # to be able to erase it later
    set ::erase_text $text
}

###########################################################
# overwritten

# I overwrite this just to be able to reset the cycle in auto-completion
proc ::pd_bindings::sendkey {window state key iso shift} {
    switch -- $key {
        "BackSpace" { set iso ""; set key 8 }
        "Tab"       { set iso ""; set key 9 }
        "Return"    { set iso ""; set key 10 }
        "Escape"    { set iso ""; set key 27 }
        "Space"     { set iso ""; set key 32 }
        "Delete"    { set iso ""; set key 127 }
        "KP_Delete" { set iso ""; set key 127 }
    }
    if {$iso ne ""} {
        scan $iso %c key
    }
    if {! [winfo exists $window]} {return}
    set mytoplevel [winfo toplevel $window]
    if {[winfo class $mytoplevel] eq "PatchWindow"} {
        pdsend "$mytoplevel key $state $key $shift"
        # auto-completion
        # something was typed in so reset $::cycle
        if {$key != 9} {set ::cycle false}
    }
}

# change the text in an existing text box
proc pdtk_text_set {tkcanvas tag text} {
    $tkcanvas itemconfig $tag -text $text
    # auto-completion: store typed text
    set ::current_text $text
    set ::current_canvas $tkcanvas
}

proc pdtk_text_editing {mytoplevel tag editing} {
    set tkcanvas [tkcanvas_name $mytoplevel]
    if {$editing == 0} {
        selection clear $tkcanvas
        # auto-completion
        set ::completions {}
        set ::new_object false
        set ::lock_motion false
        set ::cycle false
    } {
        set ::editingtext($mytoplevel) $editing
        # auto-completion
        set ::new_object $editing
    }
    $tkcanvas focus $tag
}

###########################################################
# main

::completion::init

pdtk_post "loaded: autocompletion-plugin 0.2\n"
_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to