1 21 22 package org.armedbear.j; 23 24 import java.awt.event.InputEvent ; 25 import java.awt.event.KeyEvent ; 26 27 public final class MakefileMode extends AbstractMode implements Constants, Mode 28 { 29 private static final MakefileMode mode = new MakefileMode(); 30 31 private MakefileMode() 32 { 33 super(MAKEFILE_MODE, MAKEFILE_MODE_NAME); 34 keywords = new Keywords(this); 35 setProperty(Property.USE_TABS, true); 36 } 37 38 public static final MakefileMode getMode() 39 { 40 return mode; 41 } 42 43 public boolean canIndent() 44 { 45 return true; 46 } 47 48 public String getCommentStart() 49 { 50 return "# "; 51 } 52 53 public Formatter getFormatter(Buffer buffer) 54 { 55 return new MakefileFormatter(buffer); 56 } 57 58 protected void setKeyMapDefaults(KeyMap km) 59 { 60 km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent"); 61 km.mapKey(KeyEvent.VK_F9, 0, "compile"); 62 km.mapKey(KeyEvent.VK_F9, InputEvent.CTRL_MASK, "recompile"); 63 } 64 65 public int getCorrectIndentation(Line line, Buffer buffer) 66 { 67 Line model = getModel(line); 68 if (model == null) 69 return 0; 70 return buffer.getIndentation(model); 71 } 72 73 private static Line getModel(Line line) 74 { 75 Line model = line.previous(); 76 while (model != null) { 77 if (model.isBlank() || model.charAt(0) == '#') 78 model = model.previous(); 79 else 80 break; 81 } 82 return model; 83 } 84 85 private static final String validChars = 86 "-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; 87 88 public boolean isIdentifierStart(char c) 89 { 90 return validChars.indexOf(c) >= 0; 91 } 92 93 public boolean isIdentifierPart(char c) 94 { 95 return validChars.indexOf(c) >= 0; 96 } 97 } 98 | Popular Tags |