Changeset 169


Ignore:
Timestamp:
10/19/02 15:29:01 (21 years ago)
Author:
piso
Message:

Indentation.

Location:
trunk/j/src/org/armedbear/j
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/LispMode.java

    r162 r169  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: LispMode.java,v 1.8 2002-10-18 21:44:32 piso Exp $
     5 * $Id: LispMode.java,v 1.9 2002-10-19 15:25:49 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    131131        if (modelTrim.charAt(0) == ';')
    132132            return buffer.getIndentation(model);
    133        
     133
    134134        final int indentSize = buffer.getIndentSize();
    135135        Position pos = findContainingSexp(new Position(line, 0));
     
    148148                String token = gatherToken(it.getPosition());
    149149                if (token.equals("if")) {
     150                    int depth = depth(line, buffer);
     151                    int modelDepth = depth(model, buffer);
     152                    if (pos.getLine() == model || modelDepth > depth)
     153                        return buffer.getCol(pos) + indentSize * 2;
     154                    else
     155                        return buffer.getCol(pos) + indentSize;
     156                }
     157                if (token.equals("prog1")) {
    150158                    if (pos.getLine() == model)
    151159                        return buffer.getCol(pos) + indentSize * 2;
    152160                    else
    153161                        return buffer.getCol(pos) + indentSize;
    154                 } 
     162                }
    155163                if (token.equals("let"))
    156164                    return buffer.getCol(pos) + indentSize;
    157165                if (token.equals("while"))
     166                    return buffer.getCol(pos) + indentSize;
     167                if (token.equals("when"))
     168                    return buffer.getCol(pos) + indentSize;
     169                if (token.equals("unless"))
     170                    return buffer.getCol(pos) + indentSize;
     171                if (token.equals("unwind-protect"))
    158172                    return buffer.getCol(pos) + indentSize;
    159173                if (token.startsWith("def"))
     
    162176                if (pos != null)
    163177                    return buffer.getCol(pos);
    164                
    165178                break; // Fall through.
    166179            }
    167180        }
    168181
    169         int depth = depth(new Position(line, 0), buffer);
     182        int depth = depth(line, buffer);
    170183        if (depth > 0)
    171184            return indentSize * depth;
     
    215228    }
    216229
    217     private int depth(Position pos, Buffer buffer)
     230    private int depth(Line line, Buffer buffer)
    218231    {
    219232        if (buffer.needsRenumbering())
    220233            buffer.renumber();
     234        Position pos = new Position(line, 0);
    221235        Position start = findStartOfDefun(pos);
    222236        if (pos.equals(start))
  • trunk/j/src/org/armedbear/j/LispShellMode.java

    r148 r169  
    33 *
    44 * Copyright (C) 2002 Peter Graves
    5  * $Id: LispShellMode.java,v 1.2 2002-10-15 01:32:57 piso Exp $
     5 * $Id: LispShellMode.java,v 1.3 2002-10-19 15:29:01 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    3535        setProperty(Property.SHOW_CHANGE_MARKS, false);
    3636        setProperty(Property.HIGHLIGHT_BRACKETS, true);
     37        setProperty(Property.INDENT_SIZE, 2);
    3738    }
    3839
     
    4445    public Formatter getFormatter(Buffer buffer)
    4546    {
    46         return new ShellFormatter(buffer);
     47        return new LispShellFormatter(buffer);
    4748    }
    4849
     
    5455        km.mapKey(KeyEvent.VK_P, CTRL_MASK, "shellPreviousInput");
    5556        km.mapKey(KeyEvent.VK_N, CTRL_MASK, "shellNextInput");
    56         km.mapKey(KeyEvent.VK_ENTER, 0, "shellEnter");
    57         km.mapKey(KeyEvent.VK_TAB, 0, "shellTab");
     57        km.mapKey(KeyEvent.VK_ENTER, 0, "LispShellMode.enter");
     58        km.mapKey(KeyEvent.VK_TAB, 0, "indentLineOrRegion");
    5859        km.mapKey(KeyEvent.VK_C, CTRL_MASK | ALT_MASK, "shellInterrupt");
    5960        km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
     
    6162        km.mapKey(')', "closeParen");
    6263    }
     64
     65    public static void enter()
     66    {
     67        CommandInterpreter.shellEnter();
     68
     69        final Editor editor = Editor.currentEditor();
     70        final Display display = editor.getDisplay();
     71        final Buffer buffer = editor.getBuffer();
     72        final Mode mode = buffer.getMode();
     73        if (mode != getMode()) {
     74            Debug.bug();
     75            return;
     76        }
     77
     78        Line dotLine = editor.getDotLine();
     79        if (dotLine.length() > 0)
     80            return;
     81
     82        try {
     83            buffer.lockWrite();
     84        }
     85        catch (InterruptedException e) {
     86            Log.error(e);
     87            return;
     88        }
     89        try {
     90            buffer.getFormatter().parseBuffer();
     91            int indent = LispMode.getMode().getCorrectIndentation(dotLine, buffer);
     92            if (indent != buffer.getIndentation(dotLine)) {
     93                editor.addUndo(SimpleEdit.LINE_EDIT);
     94                buffer.setIndentation(dotLine, indent);
     95                dotLine.setFlags(STATE_AUTOINDENT);
     96                buffer.modified();
     97            }
     98            if (dotLine.length() > 0) {
     99                editor.moveDotToIndentation();
     100                editor.moveCaretToDotCol();
     101            } else {
     102                display.setCaretCol(indent - display.getShift());
     103                if (buffer.getBooleanProperty(Property.RESTRICT_CARET))
     104                    editor.fillToCaret();
     105            }
     106            buffer.resetUndo();
     107        }
     108        finally {
     109            buffer.unlockWrite();
     110        }
     111    }
    63112}
Note: See TracChangeset for help on using the changeset viewer.