001: /*
002: * LispShellMode.java
003: *
004: * Copyright (C) 2002-2003 Peter Graves
005: * $Id: LispShellMode.java,v 1.15 2004/09/04 13:29:07 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.awt.event.KeyEvent;
025:
026: public final class LispShellMode extends LispMode implements Constants,
027: Mode {
028: private static final LispShellMode mode = new LispShellMode();
029:
030: protected LispShellMode() {
031: super (LISP_SHELL_MODE, LISP_SHELL_MODE_NAME);
032: setProperty(Property.VERTICAL_RULE, 0);
033: setProperty(Property.SHOW_LINE_NUMBERS, false);
034: setProperty(Property.SHOW_CHANGE_MARKS, false);
035: setProperty(Property.HIGHLIGHT_BRACKETS, true);
036: setProperty(Property.INDENT_SIZE, 2);
037: }
038:
039: public static final Mode getMode() {
040: return mode;
041: }
042:
043: public Formatter getFormatter(Buffer buffer) {
044: return new LispShellFormatter(buffer);
045: }
046:
047: protected void setKeyMapDefaults(KeyMap km) {
048: km.mapKey(KeyEvent.VK_HOME, 0, "shellHome");
049: km.mapKey(KeyEvent.VK_BACK_SPACE, 0, "shellBackspace");
050: km.mapKey(KeyEvent.VK_ESCAPE, 0, "shellEscape");
051: km.mapKey(KeyEvent.VK_P, CTRL_MASK, "shellPreviousInput");
052: km.mapKey(KeyEvent.VK_N, CTRL_MASK, "shellNextInput");
053: km.mapKey(KeyEvent.VK_P, CTRL_MASK | ALT_MASK,
054: "shellPreviousPrompt");
055: km.mapKey(KeyEvent.VK_N, CTRL_MASK | ALT_MASK,
056: "shellNextPrompt");
057: km.mapKey(KeyEvent.VK_ENTER, 0, "LispShellMode.enter");
058: km.mapKey(KeyEvent.VK_ENTER, ALT_MASK, "newlineAndIndent");
059: km.mapKey(KeyEvent.VK_R, CTRL_MASK, "resetLisp");
060: km.mapKey(KeyEvent.VK_TAB, 0, "indentLineOrRegion");
061: km
062: .mapKey(KeyEvent.VK_C, CTRL_MASK | ALT_MASK,
063: "shellInterrupt");
064: km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
065: km.mapKey(KeyEvent.VK_F9, CTRL_MASK, "recompile");
066: km.mapKey(')', "closeParen");
067: km.mapKey(KeyEvent.VK_F1, ALT_MASK, "hyperspec");
068: km.mapKey(KeyEvent.VK_M, CTRL_MASK, "lispFindMatchingChar");
069: km.mapKey(KeyEvent.VK_M, CTRL_MASK | SHIFT_MASK,
070: "lispSelectSyntax");
071: }
072:
073: public void populateModeMenu(Editor editor, Menu menu) {
074: menu.add(editor, "Reset Lisp", 'L', "resetLisp", true);
075: menu.addSeparator();
076: menu.add(editor, "Previous Input", 'P', "shellPreviousInput",
077: true);
078: menu.add(editor, "Next Input", 'N', "shellNextInput", true);
079: menu.add(editor, "Goto Previous Prompt", 'R',
080: "shellPreviousPrompt", true);
081: menu.add(editor, "Goto Next Prompt", 'T', "shellNextPrompt",
082: true);
083: }
084:
085: public boolean isTaggable() {
086: return false;
087: }
088:
089: public Tagger getTagger(SystemBuffer buffer) {
090: return null;
091: }
092:
093: public boolean acceptsLinePaste(Editor editor) {
094: if (editor.getBuffer() instanceof LispShell) {
095: Position pos = ((LispShell) editor.getBuffer())
096: .getEndOfOutput();
097: if (pos != null)
098: pos.getLine().setFlags(STATE_INPUT);
099: }
100: return false;
101: }
102:
103: public static void enter() {
104: final Editor editor = Editor.currentEditor();
105: final Buffer buffer = editor.getBuffer();
106: if (buffer.getMode() != mode) {
107: Debug.bug();
108: return;
109: }
110: if (buffer instanceof LispShell)
111: ((LispShell) buffer).enter();
112: else
113: Debug.bug();
114: }
115:
116: public static void resetLisp() {
117: final Editor editor = Editor.currentEditor();
118: final Buffer buffer = editor.getBuffer();
119: if (buffer.getMode() != mode) {
120: Debug.bug();
121: return;
122: }
123: if (buffer instanceof LispShell)
124: ((LispShell) buffer).resetLisp();
125: else if (buffer instanceof JLisp)
126: ;
127: else
128: Debug.bug();
129: }
130: }
|