faster completion
parent
0a8e84cd5b
commit
bbc7c97aa4
|
@ -252,13 +252,16 @@ public class ExternalFactor extends DefaultVocabularyLookup
|
|||
/* We can't send words across the socket at this point in
|
||||
human history, because of USE: issues. so we send name/vocab
|
||||
pairs. */
|
||||
Cons moreCompletions = (Cons)parseObject(eval(
|
||||
|
||||
String result = eval(
|
||||
FactorReader.unparseObject(word)
|
||||
+ " "
|
||||
+ FactorReader.unparseObject(Boolean.valueOf(anywhere))
|
||||
+ " "
|
||||
+ FactorReader.unparseObject(use)
|
||||
+ " completions .")).car;
|
||||
+ " completions .");
|
||||
|
||||
Cons moreCompletions = (Cons)parseObject(result).car;
|
||||
|
||||
while(moreCompletions != null)
|
||||
{
|
||||
|
|
|
@ -43,12 +43,10 @@ public abstract class AbstractCompletion extends SideKickCompletion
|
|||
protected FactorParsedData data;
|
||||
|
||||
//{{{ AbstractCompletion constructor
|
||||
public AbstractCompletion(View view, Object[] items,
|
||||
FactorParsedData data)
|
||||
public AbstractCompletion(View view, FactorParsedData data)
|
||||
{
|
||||
this.view = view;
|
||||
textArea = view.getTextArea();
|
||||
this.items = Arrays.asList(items);
|
||||
this.data = data;
|
||||
} //}}}
|
||||
|
||||
|
@ -58,6 +56,16 @@ public abstract class AbstractCompletion extends SideKickCompletion
|
|||
return MiscUtilities.getLongestPrefix(items,false);
|
||||
} //}}}
|
||||
|
||||
//{{{ updateInPlace() method
|
||||
/**
|
||||
* @return If this returns false, then we create a new completion
|
||||
* object after user input.
|
||||
*/
|
||||
public boolean updateInPlace(EditPane editPane, int caret)
|
||||
{
|
||||
return false;
|
||||
} //}}}
|
||||
|
||||
//{{{ handleKeystroke() method
|
||||
public boolean handleKeystroke(int selectedIndex, char keyChar)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
plugin.factor.jedit.FactorPlugin.activate=startup
|
||||
|
||||
plugin.factor.jedit.FactorPlugin.name=Factor
|
||||
plugin.factor.jedit.FactorPlugin.version=0.73
|
||||
plugin.factor.jedit.FactorPlugin.version=0.74
|
||||
plugin.factor.jedit.FactorPlugin.author=Slava Pestov
|
||||
plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html
|
||||
|
||||
|
@ -57,11 +57,11 @@ factor-restart.label=Restart Factor
|
|||
sidekick.parser.factor.label=Factor
|
||||
mode.factor.sidekick.parser=factor
|
||||
|
||||
factor.completion.in=<font color="#a0a0a0">IN: {0}</font>\
|
||||
factor.completion.def={0} <b>{1}</b>
|
||||
factor.completion.in=IN: {0}\
|
||||
factor.completion.def={0} {1}
|
||||
factor.completion.stack={0} ( {1})
|
||||
factor.completion.method=<html>M: <b>{0} {1}</b>
|
||||
factor.completion.constructor=<html>C: <b>{0}</b>
|
||||
factor.completion.method=M: {0} {1}
|
||||
factor.completion.constructor=C: {0}
|
||||
|
||||
# Dialog boxes
|
||||
factor.status.inserted-use=Using {0}
|
||||
|
|
|
@ -214,7 +214,7 @@ public class FactorSideKickParser extends SideKickParser
|
|||
} //}}}
|
||||
|
||||
//{{{ isWhitespace() method
|
||||
private boolean isWhitespace(char ch)
|
||||
private static boolean isWhitespace(char ch)
|
||||
{
|
||||
return (ReadTable.DEFAULT_READTABLE.getCharacterType(ch)
|
||||
== ReadTable.WHITESPACE);
|
||||
|
@ -233,6 +233,28 @@ public class FactorSideKickParser extends SideKickParser
|
|||
return false;
|
||||
} //}}}
|
||||
|
||||
//{{{ getCompletionWord() method
|
||||
public static String getCompletionWord(EditPane editPane, int caret)
|
||||
{
|
||||
Buffer buffer = editPane.getBuffer();
|
||||
int caretLine = buffer.getLineOfOffset(caret);
|
||||
int lineStart = buffer.getLineStartOffset(caretLine);
|
||||
String text = buffer.getText(lineStart,caret - lineStart);
|
||||
|
||||
int wordStart = 0;
|
||||
for(int i = text.length() - 1; i >= 0; i--)
|
||||
{
|
||||
char ch = text.charAt(i);
|
||||
if(isWhitespace(ch))
|
||||
{
|
||||
wordStart = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return text.substring(wordStart);
|
||||
} //}}}
|
||||
|
||||
//{{{ complete() method
|
||||
/**
|
||||
* Returns completions suitable for insertion at the specified position.
|
||||
|
@ -255,74 +277,17 @@ public class FactorSideKickParser extends SideKickParser
|
|||
if(ruleset == null)
|
||||
return null;
|
||||
|
||||
Buffer buffer = editPane.getBuffer();
|
||||
|
||||
// first, we get the word before the caret
|
||||
int caretLine = buffer.getLineOfOffset(caret);
|
||||
int lineStart = buffer.getLineStartOffset(caretLine);
|
||||
String text = buffer.getText(lineStart,caret - lineStart);
|
||||
|
||||
/* Don't complete in the middle of a word */
|
||||
/* int lineEnd = buffer.getLineEndOffset(caretLine) - 1;
|
||||
if(caret != lineEnd)
|
||||
{
|
||||
String end = buffer.getText(caret,lineEnd - caret);
|
||||
if(!isWhitespace(end.charAt(0)))
|
||||
return null;
|
||||
} */
|
||||
|
||||
int wordStart = 0;
|
||||
for(int i = text.length() - 1; i >= 0; i--)
|
||||
{
|
||||
char ch = text.charAt(i);
|
||||
if(isWhitespace(ch))
|
||||
{
|
||||
wordStart = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String word = text.substring(wordStart);
|
||||
String word = getCompletionWord(editPane,caret);
|
||||
|
||||
/* Don't complete empty string */
|
||||
if(word.length() == 0)
|
||||
return null;
|
||||
|
||||
View view = editPane.getView();
|
||||
|
||||
if(ruleset.equals("factor::USING"))
|
||||
return vocabComplete(editPane,data,word,caret);
|
||||
return new FactorVocabCompletion(view,word,data);
|
||||
else
|
||||
return wordComplete(editPane,data,word,caret);
|
||||
} //}}}
|
||||
|
||||
//{{{ vocabComplete() method
|
||||
private SideKickCompletion vocabComplete(EditPane editPane,
|
||||
FactorParsedData data, String vocab, int caret)
|
||||
{
|
||||
String[] completions = FactorPlugin.getVocabCompletions(
|
||||
vocab,false);
|
||||
|
||||
if(completions.length == 0)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
return new FactorVocabCompletion(editPane.getView(),
|
||||
completions,vocab,data);
|
||||
}
|
||||
} //}}}
|
||||
|
||||
//{{{ wordComplete() method
|
||||
private SideKickCompletion wordComplete(EditPane editPane,
|
||||
FactorParsedData data, String word, int caret)
|
||||
{
|
||||
FactorWord[] completions = FactorPlugin.toWordArray(
|
||||
FactorPlugin.getWordCompletions(word,false));
|
||||
|
||||
if(completions.length == 0)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
return new FactorWordCompletion(editPane.getView(),
|
||||
completions,word,data);
|
||||
}
|
||||
return new FactorWordCompletion(view,word,data);
|
||||
} //}}}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,12 @@ public class FactorVocabCompletion extends AbstractCompletion
|
|||
private String vocab;
|
||||
|
||||
//{{{ FactorVocabCompletion constructor
|
||||
public FactorVocabCompletion(View view, String[] items,
|
||||
String vocab, FactorParsedData data)
|
||||
public FactorVocabCompletion(View view, String vocab, FactorParsedData data)
|
||||
{
|
||||
super(view,items,data);
|
||||
super(view,data);
|
||||
String[] completions = FactorPlugin.getVocabCompletions(
|
||||
vocab,false);
|
||||
this.items = Arrays.asList(completions);
|
||||
this.vocab = vocab;
|
||||
} //}}}
|
||||
|
||||
|
@ -87,9 +89,4 @@ public class FactorVocabCompletion extends AbstractCompletion
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public ListCellRenderer getRenderer()
|
||||
{
|
||||
return new DefaultListCellRenderer();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,13 +41,39 @@ public class FactorWordCompletion extends AbstractCompletion
|
|||
private String word;
|
||||
|
||||
//{{{ FactorWordCompletion constructor
|
||||
public FactorWordCompletion(View view, FactorWord[] items,
|
||||
String word, FactorParsedData data)
|
||||
public FactorWordCompletion(View view, String word, FactorParsedData data)
|
||||
{
|
||||
super(view,items,data);
|
||||
super(view,data);
|
||||
|
||||
FactorWord[] completions = FactorPlugin.toWordArray(
|
||||
FactorPlugin.getWordCompletions(word,false));
|
||||
|
||||
this.items = Arrays.asList(completions);
|
||||
this.word = word;
|
||||
} //}}}
|
||||
|
||||
/**
|
||||
* @return If this returns false, then we create a new completion
|
||||
* object after user input.
|
||||
*/
|
||||
public boolean updateInPlace(EditPane editPane, int caret)
|
||||
{
|
||||
String word = FactorSideKickParser.getCompletionWord(editPane,caret);
|
||||
|
||||
List newItems = new ArrayList();
|
||||
Iterator iter = items.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
FactorWord w = (FactorWord)iter.next();
|
||||
if(w.name.startsWith(word))
|
||||
newItems.add(w);
|
||||
}
|
||||
|
||||
items = newItems;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void insert(int index)
|
||||
{
|
||||
FactorWord selected = ((FactorWord)get(index));
|
||||
|
@ -58,7 +84,6 @@ public class FactorWordCompletion extends AbstractCompletion
|
|||
try
|
||||
{
|
||||
buffer.beginCompoundEdit();
|
||||
|
||||
textArea.setSelectedText(insert);
|
||||
if(!FactorPlugin.isUsed(view,selected.vocabulary))
|
||||
FactorPlugin.insertUse(view,selected.vocabulary);
|
||||
|
|
|
@ -39,33 +39,24 @@ public class FactorWordRenderer extends DefaultListCellRenderer
|
|||
//{{{ getWordHTMLString() method
|
||||
public static String getWordHTMLString(FactorWord word, boolean showIn)
|
||||
{
|
||||
String defStr = jEdit.getProperty(
|
||||
"factor.completion.def",
|
||||
new String[] {
|
||||
MiscUtilities.charsToEntities(word.getDefiner().name),
|
||||
MiscUtilities.charsToEntities(word.name)
|
||||
});
|
||||
String str = jEdit.getProperty("factor.completion.def",
|
||||
new String[] { word.getDefiner().name,word.name });
|
||||
|
||||
String in;
|
||||
if(showIn)
|
||||
{
|
||||
in = jEdit.getProperty("factor.completion.in",
|
||||
str = jEdit.getProperty("factor.completion.in",
|
||||
new Object[] {
|
||||
MiscUtilities.charsToEntities(word.vocabulary)
|
||||
});
|
||||
}) + str;
|
||||
}
|
||||
else
|
||||
in = "";
|
||||
|
||||
String html = "<html>" + in + defStr;
|
||||
|
||||
if(word.stackEffect != null)
|
||||
{
|
||||
html = jEdit.getProperty("factor.completion.stack",
|
||||
new String[] { html, word.stackEffect });
|
||||
str = jEdit.getProperty("factor.completion.stack",
|
||||
new String[] { str, word.stackEffect });
|
||||
}
|
||||
|
||||
return html;
|
||||
return str;
|
||||
} //}}}
|
||||
|
||||
private FactorSideKickParser parser;
|
||||
|
|
Loading…
Reference in New Issue