diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 7d0fcc4873..8191667d9a 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -28,7 +28,6 @@ - listener: if too many things popped off the stack, complain - gracefully handle non-working cfactor -- don't show listener on certain commands - NPE in ErrorHighlight - some way to not have previous definitions from a source file clutter the namespace @@ -64,7 +63,6 @@ objects - worddef props - prettyprint: when unparse called due to recursion, write a link -- prettyprinter should output {{ ... }} syntax for hashtables - FORGET: and forget + httpd: diff --git a/factor/ExternalFactor.java b/factor/ExternalFactor.java index b053554164..21641c32db 100644 --- a/factor/ExternalFactor.java +++ b/factor/ExternalFactor.java @@ -172,7 +172,7 @@ public class ExternalFactor extends DefaultVocabularyLookup } //}}} //{{{ getCompletions() method - public void getCompletions(String vocab, String word, List completions, + public void getCompletions(String vocab, String word, Set completions, boolean anywhere) { super.getCompletions(vocab,word,completions,anywhere); @@ -193,8 +193,10 @@ public class ExternalFactor extends DefaultVocabularyLookup while(moreCompletions != null) { Cons completion = (Cons)moreCompletions.car; - completions.add(searchVocabulary(completion.next(), - (String)completion.car)); + FactorWord w = searchVocabulary(completion.next(), + (String)completion.car); + if(w != null) + completions.add(w); moreCompletions = moreCompletions.next(); } } diff --git a/factor/jedit/EditWordDialog.java b/factor/jedit/EditWordDialog.java index cf9e29fea7..265999fd54 100644 --- a/factor/jedit/EditWordDialog.java +++ b/factor/jedit/EditWordDialog.java @@ -117,13 +117,11 @@ public class EditWordDialog extends WordListDialog //{{{ updateList() method private void updateList() { - List completions = FactorPlugin.getCompletions( - field.getText(),true); - FactorWord[] completionArray - = (FactorWord[])completions.toArray( - new FactorWord[completions.size()]); - list.setListData(completionArray); - if(completionArray.length != 0) + FactorWord[] completions = FactorPlugin.toWordArray( + FactorPlugin.getCompletions( + field.getText(),true)); + list.setListData(completions); + if(completions.length != 0) { list.setSelectedIndex(0); list.ensureIndexIsVisible(0); diff --git a/factor/jedit/FactorCompletion.java b/factor/jedit/FactorCompletion.java index ae14cb8345..3ee9e50b5f 100644 --- a/factor/jedit/FactorCompletion.java +++ b/factor/jedit/FactorCompletion.java @@ -44,12 +44,12 @@ public class FactorCompletion extends SideKickCompletion private FactorParsedData data; //{{{ FactorCompletion constructor - public FactorCompletion(View view, List items, + public FactorCompletion(View view, FactorWord[] items, String word, FactorParsedData data) { this.view = view; textArea = view.getTextArea(); - this.items = items; + this.items = Arrays.asList(items); this.word = word; this.data = data; } //}}} diff --git a/factor/jedit/FactorPlugin.java b/factor/jedit/FactorPlugin.java index a25565d03d..d20d220497 100644 --- a/factor/jedit/FactorPlugin.java +++ b/factor/jedit/FactorPlugin.java @@ -200,6 +200,16 @@ public class FactorPlugin extends EditPlugin evalInWire(word + " " + op); } //}}} + //{{{ toWordArray() method + public static FactorWord[] toWordArray(Set completions) + { + FactorWord[] w = (FactorWord[])completions.toArray(new FactorWord[ + completions.size()]); + Arrays.sort(w,new MiscUtilities.StringICaseCompare()); + + return w; + } //}}} + //{{{ getCompletions() method /** * Returns all words in all vocabularies. @@ -207,7 +217,7 @@ public class FactorPlugin extends EditPlugin * @param anywhere If true, matches anywhere in the word name are * returned; otherwise, only matches from beginning. */ - public static List getCompletions(String word, boolean anywhere) + public static Set getCompletions(String word, boolean anywhere) { try { @@ -225,11 +235,11 @@ public class FactorPlugin extends EditPlugin * @param anywhere If true, matches anywhere in the word name are * returned; otherwise, only matches from beginning. */ - public static List getCompletions(Cons use, String word, boolean anywhere) + public static Set getCompletions(Cons use, String word, boolean anywhere) { try { - List completions = new ArrayList(); + Set completions = new HashSet(); while(use != null) { @@ -238,10 +248,7 @@ public class FactorPlugin extends EditPlugin vocab,word,completions,anywhere); use = use.next(); } - - Collections.sort(completions, - new MiscUtilities.StringICaseCompare()); - + return completions; } catch(Exception e) diff --git a/factor/jedit/FactorSideKickParser.java b/factor/jedit/FactorSideKickParser.java index b0dd9f0dfc..603b447663 100644 --- a/factor/jedit/FactorSideKickParser.java +++ b/factor/jedit/FactorSideKickParser.java @@ -274,10 +274,11 @@ public class FactorSideKickParser extends SideKickParser if(word.length() == 0) return null; - List completions = FactorPlugin.getCompletions( - data.use,word,false); + FactorWord[] completions = FactorPlugin.toWordArray( + FactorPlugin.getCompletions( + data.use,word,false)); - if(completions.size() == 0) + if(completions.length == 0) return null; else { diff --git a/library/syntax/prettyprint.factor b/library/syntax/prettyprint.factor index a16e198f19..0298dffd25 100644 --- a/library/syntax/prettyprint.factor +++ b/library/syntax/prettyprint.factor @@ -34,7 +34,6 @@ USE: logic USE: lists USE: math USE: namespaces -USE: prettyprint USE: stack USE: stdio USE: strings @@ -42,6 +41,7 @@ USE: presentation USE: unparser USE: vectors USE: words +USE: hashtables : tab-size #! Change this to suit your tastes. @@ -82,10 +82,10 @@ DEFER: prettyprint* ] unless ; : prettyprint-[ ( indent -- indent ) - "[" write "]" write ; + prettyprint> \ ] prettyprint-word ; : prettyprint-list ( indent list -- indent ) #! Pretty-print a list, without [ and ]. @@ -104,10 +104,10 @@ DEFER: prettyprint* swap prettyprint-[ swap prettyprint-list prettyprint-] ; : prettyprint-{ ( indent -- indent ) - "{" write "}" write ; + prettyprint> \ } prettyprint-word ; : prettyprint-vector ( indent list -- indent ) #! Pretty-print a vector, without { and }. @@ -115,11 +115,24 @@ DEFER: prettyprint* : prettyprint-{} ( indent vector -- indent ) dup vector-length 0 = [ - drop "{ }" write + drop prettyprint-{ prettyprint-} ] [ swap prettyprint-{ swap prettyprint-vector prettyprint-} ] ifte ; +: prettyprint-{{ ( indent -- indent ) + \ {{ prettyprint-word \ }} prettyprint-word ; + +: prettyprint-{{}} ( indent hashtable -- indent ) + hash>alist dup length 0 = [ + drop prettyprint-{{ prettyprint-}} + ] [ + swap prettyprint-{{ swap prettyprint-list prettyprint-}} + ] ifte ; + : trim-newline ( str -- str ) dup ends-with-newline? dup [ nip ] [ drop ] ifte ; @@ -168,11 +181,12 @@ DEFER: prettyprint* unparse write ] [ [ - [ f = ] [ prettyprint-object ] - [ cons? ] [ prettyprint-[] ] - [ vector? ] [ prettyprint-{} ] - [ word? ] [ prettyprint-word ] - [ drop t ] [ prettyprint-object ] + [ f = ] [ prettyprint-object ] + [ cons? ] [ prettyprint-[] ] + [ hashtable? ] [ prettyprint-{{}} ] + [ vector? ] [ prettyprint-{} ] + [ word? ] [ prettyprint-word ] + [ drop t ] [ prettyprint-object ] ] cond ] ifte ; diff --git a/library/test/errors.factor b/library/test/errors.factor index 3f999d88c1..7c3a6904a5 100644 --- a/library/test/errors.factor +++ b/library/test/errors.factor @@ -4,6 +4,7 @@ USE: kernel USE: namespaces USE: stack USE: test +USE: lists [ f ] [ [ ] [ ] catch ] unit-test @@ -14,3 +15,6 @@ USE: test global [ "error" get ] bind "Hello" = ] unit-test + +[ ] [ [ ] print-error ] unit-test +[ ] [ [ 2 car ] print-error ] unit-test diff --git a/library/tools/debugger.factor b/library/tools/debugger.factor index 1ce352252c..3a3934c811 100644 --- a/library/tools/debugger.factor +++ b/library/tools/debugger.factor @@ -76,4 +76,4 @@ USE: unparser : print-error ( quot -- ) #! Execute a quotation, and if it throws an error, print it #! and return to the caller. - [ [ default-error-handler drop ] when* ] catch ; + [ [ default-error-handler ] when* ] catch ;