- plugin should not exit jEdit on fatal errors\r
- IN: format base: work with all types of numbers\r
- wordpreview: don't show for string literals and comments\r
-- NPE in activate()/deactivate()\r
-- NPE in ErrorHighlight\r
- 64 bit support\r
- alist -vs- assoc terminology\r
- clean up listener's action popups\r
- jedit ==> jedit-word, jedit takes a file name\r
- introduce ifte* and ?str-head/?str-tail where appropriate\r
-- cwd, cd, pwd, dir., pwd. words\r
- namespace clone drops static var bindings\r
-- f usages. --> don't print all words\r
\r
+ bignums:\r
\r
\r
+ listener/plugin:\r
\r
+- NPE in activate()/deactivate()\r
+- NPE in ErrorHighlight\r
- don't use jEdit's word finding API\r
- some way to not have previous definitions from a source file\r
clutter the namespace\r
\r
+ misc:\r
\r
+- write-icon kind of messy; " " should be output by the listener\r
+- f usages. --> don't print all words\r
+- pipe support\r
- telnetd: init-history\r
- str-reverse primitive\r
- some way to run httpd from command line\r
- wiki responder:\r
- port to native\r
- text styles\r
-- if user clicks stop in browser, doesn't stop sending?\r
- log with date\r
basic authentication, using httpdAuth function from a config file\r
- file responder; last-modified field\r
FactorPlugin.insertUseDialog(view,word);
</CODE>
</ACTION>
+ <ACTION NAME="factor-extract-word">
+ <CODE>
+ FactorPlugin.extractWord(view);
+ </CODE>
+ </ACTION>
</ACTIONS>
} //}}}
//{{{ exec() method
- public static int exec(String[] args) throws Exception
+ public static int exec(String[] args, String dir) throws Exception
{
int exitCode = -1;
try
{
- Process process = Runtime.getRuntime().exec(args);
+ Process process = Runtime.getRuntime().exec(args,
+ null,new File(dir));
process.getInputStream().close();
process.getOutputStream().close();
process.getErrorStream().close();
*/
public FactorWord nextWord(boolean define) throws Exception
{
+ // remember the position before the word name
+ int line = scanner.getLineNumber();
+ int col = scanner.getColumnNumber();
+
Object next = nextNonEOL(true,false);
if(next instanceof Number)
{
}
else if(next instanceof String)
{
- // remember the position before the word name
- int line = scanner.getLineNumber();
- int col = scanner.getColumnNumber();
-
FactorWord w = intern((String)next,define);
if(define && w != null)
{
buffer.insert(lastUseOffset,decl);
showStatus(view,"inserted-use",decl);
} //}}}
+
+ //{{{ extractWord() method
+ public static void extractWord(View view)
+ {
+ JEditTextArea textArea = view.getTextArea();
+ Buffer buffer = textArea.getBuffer();
+ String selection = textArea.getSelectedText();
+ if(selection == null)
+ selection = "";
+
+ SideKickParsedData data = SideKickParsedData
+ .getParsedData(view);
+ if(!(data instanceof FactorParsedData))
+ {
+ view.getToolkit().beep();
+ return;
+ }
+
+ Asset asset = data.getAssetAtPosition(
+ textArea.getCaretPosition());
+
+ if(asset == null)
+ {
+ GUIUtilities.error(view,"factor.extract-word-where",null);
+ return;
+ }
+
+ String newWord = GUIUtilities.input(view,
+ "factor.extract-word",null);
+ if(newWord == null)
+ return;
+
+ int start = asset.start.getOffset();
+
+ String indent = MiscUtilities.createWhiteSpace(
+ buffer.getIndentSize(),
+ (buffer.getBooleanProperty("noTabs") ? 0
+ : buffer.getTabSize()));
+
+ String newDef = ": " + newWord + "\n" + indent
+ + selection.trim() + " ;\n\n" ;
+
+ buffer.insert(start,newDef);
+ textArea.setSelectedText(newWord);
+ } //}}}
}
factor-edit-dialog \
factor-see \
factor-usages \
+ - \
+ factor-extract-word
factor.label=Factor Listener
factor-run-file.label=Run current file
factor-edit.label=Edit word at caret
factor-edit-dialog.label=Edit word...
factor-usages.label=Word usages at caret
+factor-extract-word.label=Extract word...
factor.title=Factor
factor.edit-word.title=Edit Word Definition
factor.edit-word.caption=Word name:
+
+factor.extract-word.title=Extract Word
+factor.extract-word.message=Enter name of new word:
+
+factor.extract-word-where.title=Cannot Extract Here
+factor.extract-word-where.message=This command can only be used inside a word definition.
IN: files
DEFER: stat
DEFER: (directory)
+DEFER: cwd
+DEFER: cd
IN: io-internals
DEFER: port?
allot-count
set-allot-count
dump
+ cwd
+ cd
] [
swap succ tuck primitive,
] each drop ;
] ifte
] each drop ;
+: pwd cwd print ;
+: dir. cwd directory. ;
+
[
[ "html" | "text/html" ]
[ "txt" | "text/plain" ]
"/library/math/simpson.factor" run-resource ! math
!!! Development tools.
+"/library/platform/jvm/processes.factor" run-resource ! processes
"/library/extend-stream.factor" run-resource ! streams
"/library/stdio-binary.factor" run-resource ! stdio
"/library/vocabulary-style.factor" run-resource ! style
USE: logic
USE: stack
USE: strings
+USE: namespaces
: <file> ( path -- file )
dup "java.io.File" is not [
: file-length ( file -- size )
<file> [ ] "java.io.File" "length" jinvoke ;
+
+: cwd ( -- dir )
+ global [ "cwd" get ] bind ;
+
+: cd ( dir --)
+ global [ "cwd" set ] bind ;
+
+global [ "user.dir" system-property "cwd" set ] bind
interpreter
[ ] "factor.FactorInterpreter" "topLevel" jinvoke ;
-: exec ( args -- exitCode )
- [ [ "java.lang.String" ] ] "factor.FactorLib" "exec"
- jinvoke-static ;
-
: exit* ( code -- )
[ "int" ] "java.lang.System" "exit" jinvoke-static ;
: version "factor.FactorInterpreter" "VERSION" jvar-static-get ;
: jvm-runtime ( -- java.lang.Runtime )
- #! Return the java.lang.Runtime object for the JVM
- f "java.lang.Runtime" "getRuntime" jinvoke-static ;
+ #! Return the java.lang.Runtime object for the JVM
+ f "java.lang.Runtime" "getRuntime" jinvoke-static ;
: free-memory ( -- int )
#! Return the free memory in the JVM.
: file-actions ( -- list )
[
- [ "" | "Push" ]
- [ "run-file" | "Run file" ]
- [ "directory." | "List directory" ]
+ [ "" | "Push" ]
+ [ "run-file" | "Run file" ]
+ [ "directory." | "List directory" ]
+ [ "cd" | "Change directory" ]
] ;
: <file-actions-menu> ( path -- alist )
--- /dev/null
+! :folding=indent:collapseFolds=1:
+
+! $Id$
+!
+! Copyright (C) 2004 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.
+
+IN: processes
+USE: files
+USE: kernel
+USE: streams
+USE: stack
+
+: exec ( args -- exitCode )
+ cwd
+ [
+ [ "java.lang.String" ] "java.lang.String"
+ ] "factor.FactorLib" "exec"
+ jinvoke-static ;
+
+: (pipe) ( args -- process )
+ f cwd <file> jvm-runtime
+ [
+ [ "java.lang.String" ]
+ [ "java.lang.String" ]
+ "java.io.File"
+ ] "java.lang.Runtime" "exec" jinvoke ;
+
+: close-stderr ( process -- )
+ [ ] "java.lang.Process" "getErrorStream" jinvoke close ;
+
+: pipe ( args -- stream )
+ #! Start a process, and return a stream for communicating
+ #! with it.
+ (pipe) dup close-stderr
+ dup [ ] "java.lang.Process" "getInputStream" jinvoke
+ swap [ ] "java.lang.Process" "getOutputStream" jinvoke
+ <byte-stream> ;
USE: stack
USE: strings
+: close ( stream -- )
+ [
+ [ "java.io.InputStream" is ] [
+ [ ] "java.io.InputStream" "close" jinvoke
+ ]
+ [ "java.io.OutputStream" is ] [
+ [ ] "java.io.OutputStream" "close" jinvoke
+ ]
+ [ "java.io.Reader" is ] [
+ [ ] "java.io.Reader" "close" jinvoke
+ ]
+ [ "java.io.Writer" is ] [
+ [ ] "java.io.Writer" "close" jinvoke
+ ]
+ ] cond ;
+
: fcopy ( from to -- )
#! Copy the contents of the byte-stream 'from' to the
#! byte-stream 'to'.
"out" get [ ] "java.io.OutputStream" "flush" jinvoke ;
: <byte-stream>/fclose ( -- )
- "in" get [ [ ] "java.io.InputStream" "close" jinvoke ] when*
- "out" get [ [ ] "java.io.OutputStream" "close" jinvoke ] when* ;
+ "in" get [ close ] when*
+ "out" get [ close ] when* ;
: <bin> ( in -- in )
[ "java.io.InputStream" ] "java.io.BufferedInputStream" jnew ;
"out" get [ ] "java.io.Writer" "flush" jinvoke ;
: <char-stream>/fclose ( -- )
- "in" get [ [ ] "java.io.Reader" "close" jinvoke ] when*
- "out" get [ [ ] "java.io.Writer" "close" jinvoke ] when* ;
+ "in" get [ close ] when*
+ "out" get [ close ] when* ;
: <char-stream> ( in out -- stream )
#! Creates a new stream for reading from the
: <sreader> ( string -- reader )
[ "java.lang.String" ] "java.io.StringReader" jnew ;
-: close ( stream -- )
- dup "java.io.Reader" is [
- [ ] "java.io.Reader" "close" jinvoke
- ] [
- [ ] "java.io.Writer" "close" jinvoke
- ] ifte ;
-
: <server> ( port -- stream )
#! Starts listening on localhost:port. Returns a stream that
#! you can close with fclose, and accept connections from
init-error-handler
init-random
- "stdio" get <ansi-stream> "stdio" set
! Some flags are *on* by default, unless user specifies
! -no-<flag> CLI switch
t "user-init" set
t "interactive" set
+ t "ansi" set
! The first CLI arg is the image name.
cli-args uncons parse-command-line "image" set
-
+
run-user-init
+ "ansi" get [ "stdio" get <ansi-stream> "stdio" set ] when
"interactive" get [ init-interpreter ] when
0 exit* ;
[ allot-count | " word -- n " ]
[ set-allot-count | " n word -- n " ]
[ dump | " obj -- " ]
+ [ cwd | " -- dir " ]
+ [ cd | " dir -- " ]
] [
unswons "stack-effect" swap set-word-property
] each
: write-icon ( resource -- )
#! Write an icon. Eg, /library/icons/File.png
- "icon" swons unit "" swap write-attr ;
+ "icon" swons unit " " swap write-attr ;
: print ( string -- )
"stdio" get fprint ;
dpush(result);
}
+
+void primitive_cwd(void)
+{
+ char wd[MAXPATHLEN];
+ if(getcwd(wd,MAXPATHLEN) < 0)
+ io_error(__FUNCTION__);
+ dpush(tag_object(from_c_string(wd)));
+}
+
+void primitive_cd(void)
+{
+ chdir(to_c_string(untag_string(dpop())));
+}
void primitive_open_file(void);
void primitive_stat(void);
void primitive_read_dir(void);
+void primitive_cwd(void);
+void primitive_cd(void);
primitive_allot_profiling,
primitive_word_allot_count,
primitive_set_word_allot_count,
- primitive_dump
+ primitive_dump,
+ primitive_cwd,
+ primitive_cd
};
CELL primitive_to_xt(CELL primitive)
extern XT primitives[];
-#define PRIMITIVE_COUNT 148
+#define PRIMITIVE_COUNT 150
CELL primitive_to_xt(CELL primitive);