]> gitweb.factorcode.org Git - factor.git/commitdiff
improved factor plugin
authorSlava Pestov <slava@factorcode.org>
Mon, 20 Dec 2004 00:36:10 +0000 (00:36 +0000)
committerSlava Pestov <slava@factorcode.org>
Mon, 20 Dec 2004 00:36:10 +0000 (00:36 +0000)
TODO.FACTOR.txt
factor/DefaultVocabularyLookup.java
factor/ExternalFactor.java
factor/VocabularyLookup.java
factor/jedit/EditWordDialog.java
factor/jedit/FactorCompletion.java
factor/jedit/FactorPlugin.java
factor/jedit/FactorPlugin.props
factor/jedit/FactorSideKickParser.java
factor/jedit/WordListDialog.java
library/tools/jedit-wire.factor

index 1e54cf10d5d3bb00cd3d4e745aefac14c7a2f86c..dc8105334799c772b2ad9608a6c5f9076e2085b0 100644 (file)
 - handle odd base cases, with code after ifte\r
 - handle recursion with when, when* etc\r
 \r
-+ linearizer/generator:\r
++ compiler:\r
 \r
 - getenv/setenv: if literal arg, compile as a load/store\r
-\r
-+ compiler frontend:\r
-\r
 - assembler opcodes dispatch on operand types\r
 - save code in image\r
-- compile word twice; no more 'cannot compile' error!\r
 \r
 + oop:\r
 \r
@@ -36,7 +32,6 @@
 \r
 + listener/plugin:\r
 \r
-- use decl wrong\r
 - faster completion\r
 - sidekick: still parsing too much\r
 - errors don't always disappear\r
 - cat, reverse-cat primitives\r
 - first-class hashtables\r
 - rewrite accessors and mutators in Factor, with slot/set-slot primitive\r
-- replace -export-dynamic with sundry-xt\r
 - add a socket timeout\r
-- word, writes entire plist\r
 - do transfer-word in fixup\r
+- move dispatch getenv setenv to kernel-internals\r
 \r
 + misc:\r
 \r
@@ -65,7 +59,6 @@
 - perhaps /i should work with all numbers\r
 - unit test weirdness: 2 lines appears at end\r
 - jedit ==> jedit-word, jedit takes a file name\r
-- command line parsing cleanup\r
 - nicer way to combine two paths\r
 - ditch object paths\r
 - browser responder for word links in HTTPd; inspect responder for\r
index 3492910c792374279cfe36d576e8cb49fedf73a2..4e0a3d3f6b835eeaa5edba2ea713e42c355b5cb7 100644 (file)
@@ -207,8 +207,27 @@ public class DefaultVocabularyLookup implements VocabularyLookup
        } //}}}
 
        //{{{ getCompletions() method
-       public void getCompletions(String vocab, String word, Set completions,
-               boolean anywhere)
+       /**
+        * @param use A list of vocabularies.
+        * @param word A substring of the word name to complete
+        * @param anywhere If true, matches anywhere in the word name are
+        * returned; otherwise, only matches from beginning.
+        * @param completions Set to add completions to
+        */
+       public void getCompletions(Cons use, String word, boolean anywhere,
+               Set completions) throws Exception
+       {
+               while(use != null)
+               {
+                       String vocab = (String)use.car;
+                       getCompletions(vocab,word,anywhere,completions);
+                       use = use.next();
+               }
+       } //}}}
+
+       //{{{ getCompletions() method
+       public void getCompletions(String vocab, String word, boolean anywhere,
+               Set completions) throws Exception
        {
                Map v = (Map)vocabularies.get(vocab);
                if(v == null)
index d6f34771a16f65303ad087c3db233e0fffaf6cce..3c94bfffacaa70e69b0a608b1c094a87c91e4406 100644 (file)
@@ -178,6 +178,19 @@ public class ExternalFactor extends DefaultVocabularyLookup
                return vocabs;
        } //}}}
 
+       //{{{ makeWord() method
+       /**
+        * Make a word from an info list returned by Factor.
+        */
+       public synchronized FactorWord makeWord(Cons info)
+       {
+               FactorWord w = new FactorWord(
+                       (String)info.car,
+                       (String)info.next().car);
+               w.stackEffect = (String)info.next().next().car;
+               return w;
+       } //}}}
+
        //{{{ searchVocabulary() method
        /**
         * Search through the given vocabulary list for the given word.
@@ -197,16 +210,11 @@ public class ExternalFactor extends DefaultVocabularyLookup
                        Cons result = parseObject(eval(FactorReader.unparseObject(name)
                                + " "
                                + FactorReader.unparseObject(vocabulary)
-                               + " jedit-lookup ."));
+                               + " search jedit-lookup ."));
                        if(result.car == null)
                                return null;
 
-                       result = (Cons)result.car;
-                       w = new FactorWord(
-                               (String)result.car,
-                               (String)result.next().car);
-                       w.stackEffect = (String)result.next().next().car;
-                       return w;
+                       return makeWord((Cons)result.car);
                }
                catch(Exception e)
                {
@@ -216,40 +224,32 @@ public class ExternalFactor extends DefaultVocabularyLookup
        } //}}}
 
        //{{{ getCompletions() method
-       public synchronized void getCompletions(String vocab, String word, Set completions,
-               boolean anywhere)
+       public synchronized void getCompletions(Cons use, String word,
+               boolean anywhere, Set completions) throws Exception
        {
-               super.getCompletions(vocab,word,completions,anywhere);
+               super.getCompletions(use,word,anywhere,completions);
 
                if(closed)
                        return;
 
-               try
-               {
-                       /* 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(
-                               FactorReader.unparseObject(word)
-                               + " "
-                               + FactorReader.unparseObject(vocab)
-                               + " "
-                               + (anywhere ? "vocab-apropos" : "vocab-completions")
-                               + " [ dup word-name swap word-vocabulary 2list ] map .")).car;
-
-                       while(moreCompletions != null)
-                       {
-                               Cons completion = (Cons)moreCompletions.car;
-                               FactorWord w = searchVocabulary(completion.next(),
-                                       (String)completion.car);
-                               if(w != null)
-                                       completions.add(w);
-                               moreCompletions = moreCompletions.next();
-                       }
-               }
-               catch(Exception e)
+               /* 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(
+                       FactorReader.unparseObject(word)
+                       + " "
+                       + FactorReader.unparseObject(Boolean.valueOf(anywhere))
+                       + " "
+                       + FactorReader.unparseObject(use)
+                       + " completions .")).car;
+
+               while(moreCompletions != null)
                {
-                       Log.log(Log.ERROR,this,e);
+                       Cons completion = (Cons)moreCompletions.car;
+                       FactorWord w = makeWord(completion);
+                       if(w != null)
+                               completions.add(w);
+                       moreCompletions = moreCompletions.next();
                }
        } //}}}
 
index 60ec6ada3651dd510f655d756a8517e085c70674..31b4f85c9b1a6b9efcb19db758369bdf40807298 100644 (file)
@@ -42,15 +42,25 @@ public interface VocabularyLookup
 
        public void forget(FactorWord word);
 
+       /**
+        * @param use A list of vocabularies.
+        * @param word A substring of the word name to complete
+        * @param anywhere If true, matches anywhere in the word name are
+        * returned; otherwise, only matches from beginning.
+        * @param completions Set to add completions to
+        */
+       public void getCompletions(Cons use, String word, boolean anywhere,
+               Set completions) throws Exception;
+
        /**
         * @param vocab The vocabulary name
         * @param word A substring of the word name to complete
-        * @param completions List to add completions to
         * @param anywhere If true, word name will be matched anywhere, otherwise, just at
         * the beginning of the name.
+        * @param completions Set to add completions to
         */
-       public void getCompletions(String vocab, String word, Set completions,
-               boolean anywhere) throws Exception;
+       public void getCompletions(String vocab, String word, boolean anywhere,
+               Set completions) throws Exception;
 
        public Cons getVocabularies() throws Exception;
 }
index 265999fd546d14cfb769b75aa6ef387f4406e021..cae245698b9f48fb6562b0253ac184821f54a4b5 100644 (file)
@@ -126,6 +126,8 @@ public class EditWordDialog extends WordListDialog
                        list.setSelectedIndex(0);
                        list.ensureIndexIsVisible(0);
                }
+
+               updatePreview();
        } //}}}
        
        //{{{ UpdateTimer class
index 3ee9e50b5f4a3ea020b6fa2257288eb0262d77e9..654b77dcf1c854f01c702e9718d72db664a81eba 100644 (file)
@@ -61,14 +61,23 @@ public class FactorCompletion extends SideKickCompletion
 
        public void insert(int index)
        {
-               Macros.Recorder recorder = view.getMacroRecorder();
+               FactorWord selected = ((FactorWord)get(index));
+               String insert = selected.name.substring(word.length());
 
-               String insert = ((FactorWord)get(index)).name.substring(
-                       word.length());
+               Buffer buffer = textArea.getBuffer();
 
-               if(recorder != null)
-                       recorder.recordInput(insert,false);
-               textArea.setSelectedText(insert);
+               try
+               {
+                       buffer.beginCompoundEdit();
+                       
+                       textArea.setSelectedText(insert);
+                       if(!FactorPlugin.isUsed(view,selected.vocabulary))
+                               FactorPlugin.insertUse(view,selected.vocabulary);
+               }
+               finally
+               {
+                       buffer.endCompoundEdit();
+               }
        }
 
        public int getTokenLength()
@@ -81,13 +90,7 @@ public class FactorCompletion extends SideKickCompletion
                if(keyChar == '\t' || keyChar == '\n')
                        insert(selectedIndex);
                else
-               {
-                       Macros.Recorder recorder = view.getMacroRecorder();
-
-                       if(recorder != null)
-                               recorder.recordInput(1,keyChar,false);
                        textArea.userInput(keyChar);
-               }
 
                boolean ws = (ReadTable.DEFAULT_READTABLE
                        .getCharacterType(keyChar)
index e556b70560ad1fcc2c2d5b5bf9cb965fba17cbfa..7b5b6ddb8bc1ddbe22e3c4770619f8b92816c58d 100644 (file)
@@ -73,6 +73,13 @@ public class FactorPlugin extends EditPlugin
        public void stop()
        {
                stopExternalInstance();
+
+               Buffer buffer = jEdit.getFirstBuffer();
+               while(buffer != null)
+               {
+                       buffer.setProperty(FactorSideKickParser.PARSED_PROPERTY,null);
+                       buffer = buffer.getNext();
+               }
        } //}}}
        
        //{{{ getExternalInstance() method
@@ -165,9 +172,9 @@ public class FactorPlugin extends EditPlugin
        } //}}}
 
        //{{{ evalInWire() method
-       public static void evalInWire(String cmd) throws IOException
+       public static String evalInWire(String cmd) throws IOException
        {
-               getExternalInstance().eval(cmd);
+               return getExternalInstance().eval(cmd);
        } //}}}
 
        //{{{ lookupWord() method
@@ -275,37 +282,15 @@ public class FactorPlugin extends EditPlugin
         * returned; otherwise, only matches from beginning.
         */
        public static Set getCompletions(String word, boolean anywhere)
-       {
-               try
-               {
-                       return getCompletions(getExternalInstance().getVocabularies(),word,
-                               anywhere);
-               }
-               catch(Exception e)
-               {
-                       throw new RuntimeException(e);
-               }
-       } //}}}
-       
-       //{{{ getCompletions() method
-       /**
-        * @param anywhere If true, matches anywhere in the word name are
-        * returned; otherwise, only matches from beginning.
-        */
-       public static Set getCompletions(Cons use, String word, boolean anywhere)
        {
                try
                {
                        Set completions = new HashSet();
-       
-                       while(use != null)
-                       {
-                               String vocab = (String)use.car;
-                               getExternalInstance().getCompletions(
-                                       vocab,word,completions,anywhere);
-                               use = use.next();
-                       }
-
+                       getExternalInstance().getCompletions(
+                               getExternalInstance().getVocabularies(),
+                               word,
+                               anywhere,
+                               completions);
                        return completions;
                }
                catch(Exception e)
@@ -375,7 +360,7 @@ public class FactorPlugin extends EditPlugin
        } //}}}
        
        //{{{ isUsed() method
-       private static boolean isUsed(View view, String vocab)
+       public static boolean isUsed(View view, String vocab)
        {
                SideKickParsedData data = SideKickParsedData
                        .getParsedData(view);
index 2a35e840233bd5ee37197187bbbaab5ab505fda0..7d36660d79002b37dab76458912eeec7038d710a 100644 (file)
@@ -2,7 +2,7 @@
 plugin.factor.jedit.FactorPlugin.activate=startup
 
 plugin.factor.jedit.FactorPlugin.name=Factor
-plugin.factor.jedit.FactorPlugin.version=0.70
+plugin.factor.jedit.FactorPlugin.version=0.71
 plugin.factor.jedit.FactorPlugin.author=Slava Pestov
 plugin.factor.jedit.FactorPlugin.docs=/doc/jedit/index.html
 
index fe7e19a1d3abe1265b956597083af4ba07e7f7e0..cda9819c61fda5bf28d7b55b92456c098ba16c2a 100644 (file)
@@ -290,8 +290,7 @@ public class FactorSideKickParser extends SideKickParser
                        return null;
 
                FactorWord[] completions = FactorPlugin.toWordArray(
-                       FactorPlugin.getCompletions(
-                       data.use,word,false));
+                       FactorPlugin.getCompletions(word,false));
 
                if(completions.length == 0)
                        return null;
index 4b2f0f8967997cd3a3482036b63b61eb0b548ef3..7846378ce29ccb60f0dd03c7a4ec9bb31f8a55b2 100644 (file)
@@ -31,16 +31,19 @@ package factor.jedit;
 
 import factor.*;
 import javax.swing.border.*;
+import javax.swing.event.*;
 import javax.swing.*;
 import java.awt.event.*;
 import java.awt.*;
 import org.gjt.sp.jedit.gui.EnhancedDialog;
 import org.gjt.sp.jedit.*;
+import org.gjt.sp.util.Log;
 
 public abstract class WordListDialog extends EnhancedDialog
 {
        protected View view;
        protected JList list;
+       protected JTextArea preview;
        protected JButton ok, cancel;
 
        //{{{ WordListDialog constructor
@@ -55,13 +58,47 @@ public abstract class WordListDialog extends EnhancedDialog
                content.setBorder(new EmptyBorder(12,12,12,12));
                setContentPane(content);
 
-               content.add(BorderLayout.CENTER,new JScrollPane(
-                       list = new JList()));
+               JScrollPane listScroll = new JScrollPane(
+                       list = new JList());
                list.setCellRenderer(new FactorWordRenderer(parser,true));
+               list.addListSelectionListener(new ListHandler());
+
+               JScrollPane previewScroll = new JScrollPane(
+                       preview = new JTextArea(12,60));
+               preview.setEditable(false);
+
+               listScroll.setPreferredSize(previewScroll.getPreferredSize());
+
+               JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
+                       listScroll,previewScroll);
+               split.setDividerLocation(0.5);
+               split.setResizeWeight(0.5);
+               content.add(BorderLayout.CENTER,split);
 
                content.add(BorderLayout.SOUTH,createButtonPanel());
        } //}}}
 
+       //{{{ updatePreview() method
+       protected void updatePreview()
+       {
+               FactorWord word = (FactorWord)list.getSelectedValue();
+               if(word == null)
+               {
+                       preview.setText("");
+                       return;
+               }
+
+               try
+               {
+                       preview.setText(FactorPlugin.evalInWire(
+                               FactorPlugin.factorWord(word) + " see").trim());
+               }
+               catch(Exception e)
+               {
+                       Log.log(Log.ERROR,this,e);
+               }
+       } //}}}
+
        //{{{ createButtonPanel() method
        private Box createButtonPanel()
        {
@@ -91,4 +128,13 @@ public abstract class WordListDialog extends EnhancedDialog
                                cancel();
                }
        } //}}}
+
+       //{{{ ListHandler class
+       class ListHandler implements ListSelectionListener
+       {
+               public void valueChanged(ListSelectionEvent evt)
+               {
+                       updatePreview();
+               }
+       } //}}}
 }
index 87db36e0ef09fb527d6f3e558efd7f1835e7d40d..f75c1ff8dcb01f6a5276486daecdd62acd7f71eb 100644 (file)
@@ -95,10 +95,10 @@ C: jedit-stream ( stream -- stream )
     #! Execute this in the inferior Factor.
     stdio [ <jedit-stream> ] change  print-banner ;
 
-: jedit-lookup ( word vocabs -- )
+: jedit-lookup ( word -- list )
     #! A utility word called by the Factor plugin to get some
     #! required word info.
-    search dup [
+    dup [
         [
             "vocabulary"
             "name"
@@ -107,3 +107,16 @@ C: jedit-stream ( stream -- stream )
             dupd word-property
         ] map nip
     ] when ;
+
+: completions ( str anywhere vocabs -- list )
+    #! Make a list of completions. Each element of the list is
+    #! a name/vocabulary pair.
+    [
+        [
+            >r 2dup r> swap [
+                vocab-apropos
+            ] [
+                vocab-completions
+            ] ifte [ jedit-lookup , ] each
+        ] each
+    ] make-list ;