01: /*
02: * MakefileMode.java
03: *
04: * Copyright (C) 2000-2002 Peter Graves
05: * $Id: MakefileMode.java,v 1.1.1.1 2002/09/24 16:08:00 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
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
28: Constants, Mode {
29: private static final MakefileMode mode = new MakefileMode();
30:
31: private MakefileMode() {
32: super (MAKEFILE_MODE, MAKEFILE_MODE_NAME);
33: keywords = new Keywords(this );
34: setProperty(Property.USE_TABS, true);
35: }
36:
37: public static final MakefileMode getMode() {
38: return mode;
39: }
40:
41: public boolean canIndent() {
42: return true;
43: }
44:
45: public String getCommentStart() {
46: return "# ";
47: }
48:
49: public Formatter getFormatter(Buffer buffer) {
50: return new MakefileFormatter(buffer);
51: }
52:
53: protected void setKeyMapDefaults(KeyMap km) {
54: km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
55: km.mapKey(KeyEvent.VK_F9, 0, "compile");
56: km.mapKey(KeyEvent.VK_F9, InputEvent.CTRL_MASK, "recompile");
57: }
58:
59: public int getCorrectIndentation(Line line, Buffer buffer) {
60: Line model = getModel(line);
61: if (model == null)
62: return 0;
63: return buffer.getIndentation(model);
64: }
65:
66: private static Line getModel(Line line) {
67: Line model = line.previous();
68: while (model != null) {
69: if (model.isBlank() || model.charAt(0) == '#')
70: model = model.previous();
71: else
72: break;
73: }
74: return model;
75: }
76:
77: private static final String validChars = "-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
78:
79: public boolean isIdentifierStart(char c) {
80: return validChars.indexOf(c) >= 0;
81: }
82:
83: public boolean isIdentifierPart(char c) {
84: return validChars.indexOf(c) >= 0;
85: }
86: }
|