[Anjuta-list] My Idea about Indentation



Hello together,

Since I was not really happy about the indetation in anjuta I got the
Idea of using the astyle code for indentation in anjuta.

This works for me, but I am not sure if anyone would be interested in
this. I will just tell you what I did and you can decide if the
project would benefit from this.

I added the files ASBeautifier.cpp, ASResource.cpp, astlye.h and
compiler_defines.h to the editor plugin and rewrote the following
function in aneditor-indent.cxx:

----------------------------------------
#include "astyle.h"

using namespace astyle;

void AnEditor::AutomaticIndentation(char ch) {

	static ASBeautifier beautifier;
	//The line number correspondening to the beautifier
	static int beauty_line=-1;
	//Get the current and check if it is lower than the last beautified line
	int curLine = GetCurrentLineNumber();
	if(curLine<=beauty_line)
	{
		//OK, we need to restart from the begining
		beauty_line=-1;
	}
	//If the beauty line is -1, we need to initilize the Beautifier
	if(beauty_line==-1)
	{
		int indentSize = SendEditor(SCI_GETINDENT);
		beautifier.setSpaceIndentation(indentSize);
		beautifier.init();
		beautifier.setSpaceIndentation(indentSize);
	}

	SString tmp_line;
	string line;
	//Get the beautifier to the state correspondening to the previous line
	while(beauty_line<curLine-1)
	{
		beauty_line++;
		GetLine(tmp_line,beauty_line);
		line=tmp_line.c_str();
		beautifier.beautify(line);
	}

	//OK, make a copy of the beautifier to beautify the current line
	ASBeautifier tmp_beautifier(beautifier);
	GetLine(tmp_line,curLine);
	line=tmp_line.c_str();
	if(line.length()==0)
	{
//Set the line to something so that the characters is set to correct position on an empty line
		line="a";
	}
	line=tmp_beautifier.beautify(line);

	//Find the indentation number and set it
	int intendation=0;
	while(line[intendation]==' ')
	{
		intendation++;
	}
	SetLineIndentation(curLine,intendation);
}
----------------------------------------

Greetings,
Nathan






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]