KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > LispShellMode


1 /*
2  * LispShellMode.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: LispShellMode.java,v 1.15 2004/09/04 13:29:07 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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.KeyEvent JavaDoc;
25
26 public final class LispShellMode extends LispMode implements Constants, Mode
27 {
28     private static final LispShellMode mode = new LispShellMode();
29
30     protected LispShellMode()
31     {
32         super(LISP_SHELL_MODE, LISP_SHELL_MODE_NAME);
33         setProperty(Property.VERTICAL_RULE, 0);
34         setProperty(Property.SHOW_LINE_NUMBERS, false);
35         setProperty(Property.SHOW_CHANGE_MARKS, false);
36         setProperty(Property.HIGHLIGHT_BRACKETS, true);
37         setProperty(Property.INDENT_SIZE, 2);
38     }
39
40     public static final Mode getMode()
41     {
42         return mode;
43     }
44
45     public Formatter getFormatter(Buffer buffer)
46     {
47         return new LispShellFormatter(buffer);
48     }
49
50     protected void setKeyMapDefaults(KeyMap km)
51     {
52         km.mapKey(KeyEvent.VK_HOME, 0, "shellHome");
53         km.mapKey(KeyEvent.VK_BACK_SPACE, 0, "shellBackspace");
54         km.mapKey(KeyEvent.VK_ESCAPE, 0, "shellEscape");
55         km.mapKey(KeyEvent.VK_P, CTRL_MASK, "shellPreviousInput");
56         km.mapKey(KeyEvent.VK_N, CTRL_MASK, "shellNextInput");
57         km.mapKey(KeyEvent.VK_P, CTRL_MASK | ALT_MASK, "shellPreviousPrompt");
58         km.mapKey(KeyEvent.VK_N, CTRL_MASK | ALT_MASK, "shellNextPrompt");
59         km.mapKey(KeyEvent.VK_ENTER, 0, "LispShellMode.enter");
60         km.mapKey(KeyEvent.VK_ENTER, ALT_MASK, "newlineAndIndent");
61         km.mapKey(KeyEvent.VK_R, CTRL_MASK, "resetLisp");
62         km.mapKey(KeyEvent.VK_TAB, 0, "indentLineOrRegion");
63         km.mapKey(KeyEvent.VK_C, CTRL_MASK | ALT_MASK, "shellInterrupt");
64         km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
65         km.mapKey(KeyEvent.VK_F9, CTRL_MASK, "recompile");
66         km.mapKey(')', "closeParen");
67         km.mapKey(KeyEvent.VK_F1, ALT_MASK, "hyperspec");
68         km.mapKey(KeyEvent.VK_M, CTRL_MASK, "lispFindMatchingChar");
69         km.mapKey(KeyEvent.VK_M, CTRL_MASK | SHIFT_MASK, "lispSelectSyntax");
70     }
71
72     public void populateModeMenu(Editor editor, Menu menu)
73     {
74         menu.add(editor, "Reset Lisp", 'L', "resetLisp", true);
75         menu.addSeparator();
76         menu.add(editor, "Previous Input", 'P', "shellPreviousInput", true);
77         menu.add(editor, "Next Input", 'N', "shellNextInput", true);
78         menu.add(editor, "Goto Previous Prompt", 'R', "shellPreviousPrompt", true);
79         menu.add(editor, "Goto Next Prompt", 'T', "shellNextPrompt", true);
80     }
81
82     public boolean isTaggable()
83     {
84         return false;
85     }
86
87     public Tagger getTagger(SystemBuffer buffer)
88     {
89         return null;
90     }
91
92     public boolean acceptsLinePaste(Editor editor)
93     {
94         if (editor.getBuffer() instanceof LispShell) {
95             Position pos = ((LispShell)editor.getBuffer()).getEndOfOutput();
96             if (pos != null)
97                 pos.getLine().setFlags(STATE_INPUT);
98         }
99         return false;
100     }
101
102     public static void enter()
103     {
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     {
118         final Editor editor = Editor.currentEditor();
119         final Buffer buffer = editor.getBuffer();
120         if (buffer.getMode() != mode) {
121             Debug.bug();
122             return;
123         }
124         if (buffer instanceof LispShell)
125             ((LispShell)buffer).resetLisp();
126         else if (buffer instanceof JLisp)
127             ;
128         else
129             Debug.bug();
130     }
131 }
132
Popular Tags