1 package gnu.jemacs.buffer; 2 import gnu.mapping.*; 3 import gnu.lists.*; 4 import gnu.jemacs.lang.ELisp; 5 import gnu.math.IntNum; 6 7 public class Command 8 { 9 static Object resolveSymbol(Object command) 10 { 11 int count = 100; 12 for (;;) 13 { 14 if (command instanceof String ) 15 command = Namespace.getDefaultSymbol((String ) command); 16 if (command instanceof Symbol) 17 { 18 Symbol sym = (Symbol) command; 19 Environment env = Environment.getCurrent(); 20 command = env.getFunction(sym, null); 21 if (command == null) 22 command = env.get(sym, null); 23 } 24 else 25 return command; 26 if (--count < 0) 27 throw new Error ("circular binding for "+command); 28 } 29 } 30 31 32 33 public static void perform(Object command) 34 { 35 perform(command, EWindow.getSelected()); 36 } 37 38 public static void perform(Object command, EWindow window) 39 { 40 window.handleCommand(command); 41 } 42 43 public static Object [] processInteractionString (String str) 44 { 45 int len = str.length(); 46 int i = 0; 47 int start = 0; 48 int argCount = 0; 49 Buffer buffer = Buffer.getCurrent(); 50 while (i < len) 51 { 52 char ch = str.charAt(i++); 53 switch (ch) 54 { 55 case '\n': 56 continue; 57 case '@': 58 if (start == i-1) start = i; 59 break; 61 case '*': 62 if (start == i-1) start = i; 63 break; 65 case '_': 66 if (start == i-1) start = i; 67 break; 69 case 'r': 70 argCount++; 71 default: 73 argCount++; 74 while (i < len) 75 { 76 ch = str.charAt(i++); 77 if (ch == '\n') 78 break; 79 } 80 } 81 } 82 Object [] args = new Object [argCount]; 83 int argIndex = 0; 84 i = start; 85 while (i < len) 86 { 87 char ch = str.charAt(i++); 88 int promptStart = i; 89 int promptLength; 90 for (;;) 91 { 92 if (i >= len) 93 { 94 promptLength = i - promptStart; 95 break; 96 } 97 char c = str.charAt(i++); 98 if (c == '\n') 99 { 100 promptLength = i - 1 - promptStart; 101 break; 102 } 103 } 104 switch (ch) 105 { 106 case 'P': 107 args[argIndex++] = ELisp.FALSE; break; 109 case 'p': 110 args[argIndex++] = IntNum.one(); break; 112 case 'r': 113 int mark = buffer.checkMark() + 1; 114 int point = buffer.getPoint(); 115 if (mark <= point) 116 { 117 args[argIndex++] = IntNum.make(mark); 118 args[argIndex++] = IntNum.make(point); 119 } 120 else 121 { 122 args[argIndex++] = IntNum.make(point); 123 args[argIndex++] = IntNum.make(mark); 124 } 125 break; 126 case 'F': case 's': 128 case 'S': 129 String answer = 130 EFrame.selectedFrame.ask(str.substring(promptStart, 131 promptStart+promptLength)); 132 args[argIndex++] 133 = (ch == 'S' ? (Object ) answer.intern() 134 : (Object ) new FString(answer)); 135 break; 136 default: 137 System.err.println("un-implemented interactive prompt:"+ch); 138 args[argIndex++] = ELisp.FALSE; 139 } 140 } 141 return args; 142 } 143 } 144 | Popular Tags |