Factor plugin updates, other stuff

cvs
Slava Pestov 2005-04-01 17:42:14 +00:00
parent 32764e8029
commit 200caca9d5
9 changed files with 23 additions and 171 deletions

View File

@ -1,3 +1,4 @@
- extra chars in completion!
- set 'end' of artifacts/assets accurately - set 'end' of artifacts/assets accurately
- faster layout - faster layout
- faster repaint - faster repaint

View File

@ -1,89 +0,0 @@
/* :folding=explicit:collapseFolds=1: */
/*
* $Id$
*
* Copyright (C) 2004, 2005 Slava Pestov.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package factor.jedit;
import factor.*;
import java.util.*;
import javax.swing.ListCellRenderer;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*;
import sidekick.*;
public abstract class AbstractCompletion extends SideKickCompletion
{
protected View view;
protected JEditTextArea textArea;
protected FactorParsedData data;
//{{{ AbstractCompletion constructor
public AbstractCompletion(View view, FactorParsedData data)
{
this.view = view;
textArea = view.getTextArea();
this.data = data;
} //}}}
//{{{ getLongestPrefix() method
public String getLongestPrefix()
{
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)
{
if(keyChar == '\t' || keyChar == '\n')
{
insert(selectedIndex);
return false;
}
else if(keyChar == ' ')
{
insert(selectedIndex);
textArea.userInput(' ');
return false;
}
else
{
textArea.userInput(keyChar);
return true;
}
} //}}}
}

View File

@ -36,57 +36,15 @@ import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*; import org.gjt.sp.jedit.*;
import sidekick.*; import sidekick.*;
public class FactorVocabCompletion extends AbstractCompletion public class FactorVocabCompletion extends SideKickCompletion
{ {
private String vocab; protected FactorParsedData data;
//{{{ FactorVocabCompletion constructor //{{{ FactorVocabCompletion constructor
public FactorVocabCompletion(View view, String vocab, FactorParsedData data) public FactorVocabCompletion(View view, String vocab, FactorParsedData data)
{ {
super(view,data); super(view,vocab,Arrays.asList(FactorPlugin.getVocabCompletions(
String[] completions = FactorPlugin.getVocabCompletions( vocab,false)));
vocab,false); this.data = data;
this.items = Arrays.asList(completions);
this.vocab = vocab;
} //}}} } //}}}
public String getLongestPrefix()
{
return MiscUtilities.getLongestPrefix(items,false);
}
public void insert(int index)
{
String selected = ((String)get(index));
String insert = selected.substring(vocab.length());
Buffer buffer = textArea.getBuffer();
textArea.setSelectedText(insert);
}
public int getTokenLength()
{
return vocab.length();
}
public boolean handleKeystroke(int selectedIndex, char keyChar)
{
if(keyChar == '\t' || keyChar == '\n')
{
insert(selectedIndex);
return false;
}
else if(keyChar == ' ')
{
insert(selectedIndex);
textArea.userInput(' ');
return false;
}
else
{
textArea.userInput(keyChar);
return true;
}
}
} }

View File

@ -36,20 +36,16 @@ import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.jedit.*; import org.gjt.sp.jedit.*;
import sidekick.*; import sidekick.*;
public class FactorWordCompletion extends AbstractCompletion public class FactorWordCompletion extends SideKickCompletion
{ {
private String word; protected FactorParsedData data;
//{{{ FactorWordCompletion constructor //{{{ FactorWordCompletion constructor
public FactorWordCompletion(View view, String word, FactorParsedData data) public FactorWordCompletion(View view, String word, FactorParsedData data)
{ {
super(view,data); super(view,word,FactorPlugin.toWordArray(
FactorPlugin.getWordCompletions(word,false)));
FactorWord[] completions = FactorPlugin.toWordArray( this.data = data;
FactorPlugin.getWordCompletions(word,false));
this.items = Arrays.asList(completions);
this.word = word;
} //}}} } //}}}
/** /**
@ -58,14 +54,14 @@ public class FactorWordCompletion extends AbstractCompletion
*/ */
public boolean updateInPlace(EditPane editPane, int caret) public boolean updateInPlace(EditPane editPane, int caret)
{ {
String word = FactorSideKickParser.getCompletionWord(editPane,caret); text = FactorSideKickParser.getCompletionWord(editPane,caret);
List newItems = new ArrayList(); List newItems = new ArrayList();
Iterator iter = items.iterator(); Iterator iter = items.iterator();
while(iter.hasNext()) while(iter.hasNext())
{ {
FactorWord w = (FactorWord)iter.next(); FactorWord w = (FactorWord)iter.next();
if(w.name.startsWith(word)) if(w.name.startsWith(text))
newItems.add(w); newItems.add(w);
} }
@ -76,28 +72,11 @@ public class FactorWordCompletion extends AbstractCompletion
public void insert(int index) public void insert(int index)
{ {
super.insert(index);
FactorWord selected = ((FactorWord)get(index)); FactorWord selected = ((FactorWord)get(index));
String insert = selected.name.substring(word.length());
Buffer buffer = textArea.getBuffer();
try
{
buffer.beginCompoundEdit();
textArea.setSelectedText(insert);
if(!FactorPlugin.isUsed(view,selected.vocabulary)) if(!FactorPlugin.isUsed(view,selected.vocabulary))
FactorPlugin.insertUse(view,selected.vocabulary); FactorPlugin.insertUse(view,selected.vocabulary);
} }
finally
{
buffer.endCompoundEdit();
}
}
public int getTokenLength()
{
return word.length();
}
public ListCellRenderer getRenderer() public ListCellRenderer getRenderer()
{ {

View File

@ -58,6 +58,7 @@ BUILTIN: f 9 ; : f f swons ; parsing
! Do not execute parsing word ! Do not execute parsing word
: POSTPONE: ( -- ) scan-word swons ; parsing : POSTPONE: ( -- ) scan-word swons ; parsing
! Word definitions
: : : :
#! Begin a word definition. Word name follows. #! Begin a word definition. Word name follows.
CREATE [ define-compound ] [ ] "in-definition" on ; parsing CREATE [ define-compound ] [ ] "in-definition" on ; parsing

View File

@ -9,7 +9,8 @@ IN: words
USING: interpreter kernel lists stdio strings test ; USING: interpreter kernel lists stdio strings test ;
: annotate ( word quot -- ) #! Quotation: ( word def -- def ) : annotate ( word quot -- ) #! Quotation: ( word def -- def )
>r dup dup word-def r> call (define-compound) ; inline over >r >r dup word-def r> call r> swap (define-compound) ;
inline
: (watch) >r "==> " swap word-name cat2 \ print r> cons cons ; : (watch) >r "==> " swap word-name cat2 \ print r> cons cons ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2005 Slava Pestov. ! Copyright (C) 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: files IN: files
USING: alien kernel math namespaces ; USING: alien io-internals kernel math namespaces ;
: cd ( dir -- ) : cd ( dir -- )
"void" "libc" "chdir" [ "char*" ] alien-invoke ; "void" "libc" "chdir" [ "char*" ] alien-invoke ;

View File

@ -13,3 +13,6 @@ USING: errors kernel math ;
: open-write ( path -- fd ) : open-write ( path -- fd )
O_WRONLY O_CREAT bitor O_TRUNC bitor file-mode sys-open O_WRONLY O_CREAT bitor O_TRUNC bitor file-mode sys-open
dup io-error ; dup io-error ;
: read-step ( fd buffer -- )
;

View File

@ -1,3 +1 @@
#include "factor.h"
void primitive_arithmetic_type(void); void primitive_arithmetic_type(void);