001: package gnu.jemacs.buffer;
002:
003: import gnu.mapping.*;
004: import gnu.lists.*;
005: import gnu.jemacs.lang.ELisp;
006: import gnu.math.IntNum;
007:
008: public class Command {
009: static Object resolveSymbol(Object command) {
010: int count = 100;
011: for (;;) {
012: if (command instanceof String)
013: command = Namespace.getDefaultSymbol((String) command);
014: if (command instanceof Symbol) {
015: Symbol sym = (Symbol) command;
016: Environment env = Environment.getCurrent();
017: command = env.getFunction(sym, null);
018: if (command == null)
019: command = env.get(sym, null);
020: } else
021: return command;
022: if (--count < 0)
023: throw new Error("circular binding for " + command);
024: }
025: }
026:
027: /** Perform a given command as appropriate for its class. */
028: public static void perform(Object command) {
029: perform(command, EWindow.getSelected());
030: }
031:
032: public static void perform(Object command, EWindow window) {
033: window.handleCommand(command);
034: }
035:
036: public static Object[] processInteractionString(String str) {
037: int len = str.length();
038: int i = 0;
039: int start = 0;
040: int argCount = 0;
041: Buffer buffer = Buffer.getCurrent();
042: while (i < len) {
043: char ch = str.charAt(i++);
044: switch (ch) {
045: case '\n':
046: continue;
047: case '@':
048: if (start == i - 1)
049: start = i;
050: // FIXME: select-window
051: break;
052: case '*':
053: if (start == i - 1)
054: start = i;
055: // FIXME: check readonly
056: break;
057: case '_':
058: if (start == i - 1)
059: start = i;
060: // FIXME: region stays:
061: break;
062: case 'r':
063: argCount++;
064: // ... fall through ...
065: default:
066: argCount++;
067: while (i < len) {
068: ch = str.charAt(i++);
069: if (ch == '\n')
070: break;
071: }
072: }
073: }
074: Object[] args = new Object[argCount];
075: int argIndex = 0;
076: i = start;
077: while (i < len) {
078: char ch = str.charAt(i++);
079: int promptStart = i;
080: int promptLength;
081: for (;;) {
082: if (i >= len) {
083: promptLength = i - promptStart;
084: break;
085: }
086: char c = str.charAt(i++);
087: if (c == '\n') {
088: promptLength = i - 1 - promptStart;
089: break;
090: }
091: }
092: switch (ch) {
093: case 'P':
094: args[argIndex++] = ELisp.FALSE; // FIXME
095: break;
096: case 'p':
097: args[argIndex++] = IntNum.one(); // FIXME
098: break;
099: case 'r':
100: int mark = buffer.checkMark() + 1;
101: int point = buffer.getPoint();
102: if (mark <= point) {
103: args[argIndex++] = IntNum.make(mark);
104: args[argIndex++] = IntNum.make(point);
105: } else {
106: args[argIndex++] = IntNum.make(point);
107: args[argIndex++] = IntNum.make(mark);
108: }
109: break;
110: case 'F': // FIXME
111: case 's':
112: case 'S':
113: String answer = EFrame.selectedFrame.ask(str.substring(
114: promptStart, promptStart + promptLength));
115: args[argIndex++] = (ch == 'S' ? (Object) answer
116: .intern() : (Object) new FString(answer));
117: break;
118: default:
119: System.err.println("un-implemented interactive prompt:"
120: + ch);
121: args[argIndex++] = ELisp.FALSE;
122: }
123: }
124: return args;
125: }
126: }
|