SF.net SVN: geany: [1427] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Wed Mar 28 12:11:37 UTC 2007
Revision: 1427
http://svn.sourceforge.net/geany/?rev=1427&view=rev
Author: ntrel
Date: 2007-03-28 05:11:37 -0700 (Wed, 28 Mar 2007)
Log Message:
-----------
Don't auto-indent {} braces for filetypes that don't use them.
Add lexer_has_braces(), do_indent() for in place buffer indentation.
Rewrite some of get_indent().
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/sci_cb.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-03-27 15:48:16 UTC (rev 1426)
+++ trunk/ChangeLog 2007-03-28 12:11:37 UTC (rev 1427)
@@ -1,3 +1,11 @@
+2007-03-28 Nick Treleaven <nick.treleaven at btinternet.com>
+
+ * src/sci_cb.c:
+ Don't auto-indent {} braces for filetypes that don't use them.
+ Add lexer_has_braces(), do_indent() for in place buffer indentation.
+ Rewrite some of get_indent().
+
+
2007-03-27 Nick Treleaven <nick.treleaven at btinternet.com>
* src/keybindings.c, src/keybindings.h, src/sci_cb.c, src/sci_cb.h,
Modified: trunk/src/sci_cb.c
===================================================================
--- trunk/src/sci_cb.c 2007-03-27 15:48:16 UTC (rev 1426)
+++ trunk/src/sci_cb.c 2007-03-28 12:11:37 UTC (rev 1427)
@@ -377,9 +377,48 @@
}
+static gboolean lexer_has_braces(ScintillaObject *sci)
+{
+ gint lexer = SSM(sci, SCI_GETLEXER, 0, 0);
+
+ switch (lexer)
+ {
+ case SCLEX_CPP:
+ case SCLEX_D:
+ case SCLEX_HTML: // for PHP & JS
+ case SCLEX_PASCAL: // for multiline comments?
+ case SCLEX_BASH:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+// in place indentation of one tab or equivalent spaces
+static void do_indent(gchar *buf, gsize len, guint *index)
+{
+ guint j = *index;
+
+ if (app->pref_editor_use_tabs)
+ {
+ if (j < len - 1) // leave room for a \0 terminator.
+ buf[j++] = '\t';
+ }
+ else
+ { // insert as many spaces as a tab would take
+ guint k;
+ for (k = 0; k < (guint) app->pref_editor_tab_width && k < len - 1; k++)
+ buf[j++] = ' ';
+ }
+ *index = j;
+}
+
+
+/* "use_this_line" to auto-indent only if it is a real new line
+ * and ignore the case of sci_cb_close_block */
static void get_indent(ScintillaObject *sci, gint pos, gboolean use_this_line)
{
- // very simple indentation algorithm
guint i, len, j = 0;
gint prev_line;
gchar *linebuf;
@@ -392,51 +431,36 @@
for (i = 0; i < len && j <= (sizeof(indent) - 1); i++)
{
- if (linebuf[i] == ' ' || linebuf[i] == '\t')
+ if (linebuf[i] == ' ' || linebuf[i] == '\t') // simple indentation
indent[j++] = linebuf[i];
- // "&& ! use_this_line" to auto-indent only if it is a real new line
- // and ignore the case of sci_cb_close_block
- else if (linebuf[i] == '{' && ! use_this_line &&
- app->pref_editor_indention_mode == INDENT_ADVANCED)
+ else if (app->pref_editor_indention_mode != INDENT_ADVANCED)
+ break;
+ else if (use_this_line)
+ break;
+ else // sci_cb_close_block
{
- if (app->pref_editor_use_tabs)
+ if (! lexer_has_braces(sci))
+ break;
+
+ if (linebuf[i] == '{')
{
- indent[j++] = '\t';
+ do_indent(indent, sizeof(indent), &j);
+ break;
}
else
- { // insert as many spaces as a tabulator would take
- gint k;
- for (k = 0; k < app->pref_editor_tab_width; k++)
- indent[j++] = ' ';
- }
+ {
+ gint k = len - 1;
- break;
- }
- else
- {
- gint k = len - 1;
+ while (k > 0 && isspace(linebuf[k])) k--;
- if (use_this_line)
- break; // break immediately in the case of sci_cb_close_block
-
- while (k > 0 && isspace(linebuf[k])) k--;
-
- // if last non-whitespace character is a { increase indention by a tab
- // e.g. for (...) {
- if (app->pref_editor_indention_mode == INDENT_ADVANCED && linebuf[k] == '{')
- {
- if (app->pref_editor_use_tabs)
+ // if last non-whitespace character is a { increase indentation by a tab
+ // e.g. for (...) {
+ if (linebuf[k] == '{')
{
- indent[j++] = '\t';
+ do_indent(indent, sizeof(indent), &j);
}
- else
- { // insert as many spaces as a tabulator would take
- gint n;
- for (n = 0; n < app->pref_editor_tab_width; n++)
- indent[j++] = ' ';
- }
+ break;
}
- break;
}
}
indent[j] = '\0';
@@ -503,7 +527,7 @@
void sci_cb_close_block(gint idx, gint pos)
{
gint x = 0, cnt = 0;
- gint start_brace, line, line_start, line_len, eol_char_len, lexer;
+ gint start_brace, line, line_start, line_len, eol_char_len;
gchar *text, *line_buf;
ScintillaObject *sci;
@@ -511,9 +535,7 @@
sci = doc_list[idx].sci;
- lexer = SSM(sci, SCI_GETLEXER, 0, 0);
- if (lexer != SCLEX_CPP && lexer != SCLEX_HTML && lexer != SCLEX_PASCAL &&
- lexer != SCLEX_D && lexer != SCLEX_BASH)
+ if (! lexer_has_braces(sci))
return;
start_brace = brace_match(sci, pos);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list