Changeset 120


Ignore:
Timestamp:
10/13/02 16:51:57 (21 years ago)
Author:
piso
Message:

Indentation.

File:
1 edited

Legend:

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

    r2 r120  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: LispMode.java,v 1.1.1.1 2002-09-24 16:08:17 piso Exp $
     5 * $Id: LispMode.java,v 1.2 2002-10-13 16:51:57 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    3232        super(LISP_MODE, LISP_MODE_NAME);
    3333        keywords = new Keywords(this);
     34        setProperty(Property.INDENT_SIZE, 2);
    3435    }
    3536
     
    5657    protected void setKeyMapDefaults(KeyMap km)
    5758    {
     59        km.mapKey(KeyEvent.VK_TAB, 0, "tab");
    5860        km.mapKey(KeyEvent.VK_ENTER, 0, "newlineAndIndent");
    5961        km.mapKey(KeyEvent.VK_T, CTRL_MASK, "findTag");
     
    106108        return inQuote;
    107109    }
     110
     111    public boolean canIndent()
     112    {
     113        return true;
     114    }
     115
     116    public int getCorrectIndentation(Line line, Buffer buffer)
     117    {
     118        Position here = new Position(line, 0);
     119        Position start = findStartOfDefun(here);
     120        LispSyntaxIterator it = new LispSyntaxIterator(start);
     121        int depth = 0;
     122        while (it.getPosition().isBefore(here)) {
     123            char c = it.nextChar();
     124            if (c == '(')
     125                ++depth;
     126            else if (c == ')')
     127                --depth;
     128        }
     129        return buffer.getIndentSize() * depth;
     130    }
     131
     132    private Position findStartOfDefun(Position pos)
     133    {
     134        Line line = pos.getLine();
     135        while (true) {
     136            if (line.getText().startsWith("(def"))
     137                return new Position(line, 0);
     138            Line prev = line.previous();
     139            if (prev == null)
     140                return new Position(line, 0);
     141            line = prev;
     142        }
     143    }
    108144}
Note: See TracChangeset for help on using the changeset viewer.