Changeset 162
- Timestamp:
- 10/18/02 21:44:32 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/j/LispMode.java
r147 r162 3 3 * 4 4 * Copyright (C) 1998-2002 Peter Graves 5 * $Id: LispMode.java,v 1. 7 2002-10-15 01:32:11piso Exp $5 * $Id: LispMode.java,v 1.8 2002-10-18 21:44:32 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 121 121 public int getCorrectIndentation(Line line, Buffer buffer) 122 122 { 123 Position here = new Position(line, 0); 124 Position pos = findContainingSexp(here); 125 if (pos != null && pos.getOffset() > 0) { 123 if (line.flags() == STATE_QUOTE) 124 return 0; 125 Line model = findModel(line); 126 if (model == null) 127 return 0; 128 final String modelTrim = model.trim(); 129 if (modelTrim.length() == 0) 130 return 0; 131 if (modelTrim.charAt(0) == ';') 132 return buffer.getIndentation(model); 133 134 final int indentSize = buffer.getIndentSize(); 135 Position pos = findContainingSexp(new Position(line, 0)); 136 if (pos != null) { 126 137 SyntaxIterator it = getSyntaxIterator(pos); 127 138 while (true) { … … 135 146 } 136 147 // Otherwise... 137 if (pos.lineNumber() == here.lineNumber() - 1) { 138 pos = forwardSexp(pos); 139 if (pos != null) 140 return buffer.getCol(pos); 141 } 148 String token = gatherToken(it.getPosition()); 149 if (token.equals("if")) { 150 if (pos.getLine() == model) 151 return buffer.getCol(pos) + indentSize * 2; 152 else 153 return buffer.getCol(pos) + indentSize; 154 } 155 if (token.equals("let")) 156 return buffer.getCol(pos) + indentSize; 157 if (token.equals("while")) 158 return buffer.getCol(pos) + indentSize; 159 if (token.startsWith("def")) 160 return buffer.getCol(pos) + indentSize; 161 pos = forwardSexp(pos); 162 if (pos != null) 163 return buffer.getCol(pos); 164 142 165 break; // Fall through. 143 166 } … … 146 169 int depth = depth(new Position(line, 0), buffer); 147 170 if (depth > 0) 148 return buffer.getIndentSize()* depth;171 return indentSize * depth; 149 172 return 0; 173 } 174 175 private static Line findModel(Line line) 176 { 177 Line model = line.previous(); 178 if (line.flags() == STATE_COMMENT) { 179 // Any non-blank line is an acceptable model. 180 while (model != null && model.isBlank()) 181 model = model.previous(); 182 } else { 183 while (model != null) { 184 if (isAcceptableModel(model)) 185 break; // Found an acceptable model. 186 else 187 model = model.previous(); 188 } 189 } 190 return model; 191 } 192 193 private static boolean isAcceptableModel(Line model) 194 { 195 String trim = model.trim(); 196 if (trim.length() == 0) 197 return false; 198 if (trim.charAt(0) == ';') 199 return false; 200 return true; 201 } 202 203 private String gatherToken(Position pos) 204 { 205 FastStringBuffer sb = new FastStringBuffer(); 206 while (true) { 207 char c = pos.getChar(); 208 if (Character.isWhitespace(c)) 209 break; 210 sb.append(c); 211 if (!pos.next()) 212 break; 213 } 214 return sb.toString(); 150 215 } 151 216
Note: See TracChangeset
for help on using the changeset viewer.