SF.net SVN: geany:[2871] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Mon Aug 11 16:14:42 UTC 2008


Revision: 2871
          http://geany.svn.sourceforge.net/geany/?rev=2871&view=rev
Author:   ntrel
Date:     2008-08-11 16:14:39 +0000 (Mon, 11 Aug 2008)

Log Message:
-----------
Fix auto-multiline comment completion for CSS.
Fix doc-comment keyword styles confusing auto-multiline comment
completion.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/editor.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-08-11 12:02:59 UTC (rev 2870)
+++ trunk/ChangeLog	2008-08-11 16:14:39 UTC (rev 2871)
@@ -3,6 +3,10 @@
  * src/editor.c:
    Add SCE_[CD]_COMMENTDOCKEYWORD(ERROR) comment detection to
    is_comment().
+ * src/editor.c:
+   Fix auto-multiline comment completion for CSS.
+   Fix doc-comment keyword styles confusing auto-multiline comment
+   completion.
 
 
 2008-08-08  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2008-08-11 12:02:59 UTC (rev 2870)
+++ trunk/src/editor.c	2008-08-11 16:14:39 UTC (rev 2871)
@@ -805,7 +805,7 @@
 
 	if (editor_prefs.auto_continue_multiline)
 	{	/* " * " auto completion in multiline C/C++/D/Java comments */
-		auto_multiline(editor, pos);
+		auto_multiline(editor, line);
 	}
 
 	if (editor_prefs.complete_snippets)
@@ -2471,32 +2471,56 @@
 }
 
 
-static gboolean is_doc_comment_char(gchar c, gint lexer)
+static gboolean in_block_comment(gint lexer, gint style)
 {
-	if (c == '*' && (lexer == SCLEX_HTML || lexer == SCLEX_CPP))
+	switch (lexer)
+	{
+		case SCLEX_CPP:
+			return (style == SCE_C_COMMENT ||
+				style == SCE_C_COMMENTDOC);
+
+		case SCLEX_D:
+			return (style == SCE_D_COMMENT ||
+				style == SCE_D_COMMENTDOC ||
+				style == SCE_D_COMMENTNESTED);
+
+		case SCLEX_HTML:
+			return (style == SCE_HPHP_COMMENT);
+
+		case SCLEX_CSS:
+			return (style == SCE_CSS_COMMENT);
+
+		default:
+			return FALSE;
+	}
+}
+
+
+static gboolean is_comment_char(gchar c, gint lexer)
+{
+	if ((c == '*' || c == '+') && lexer == SCLEX_D)
 		return TRUE;
-	else if ((c == '*' || c == '+') && lexer == SCLEX_D)
+	else
+	if (c == '*')
 		return TRUE;
-	else
-		return FALSE;
+
+	return FALSE;
 }
 
 
-static void auto_multiline(GeanyEditor *editor, gint pos)
+static void auto_multiline(GeanyEditor *editor, gint cur_line)
 {
 	ScintillaObject *sci = editor->sci;
-	gint eol_len = editor_get_eol_char_len(editor->document);
-	gint style = SSM(sci, SCI_GETSTYLEAT, pos - 1 - eol_len, 0);
-	gint lexer = SSM(sci, SCI_GETLEXER, 0, 0);
+	gint indent_pos, style;
+	gint lexer = sci_get_lexer(sci);
 
-	if ((lexer == SCLEX_CPP && (style == SCE_C_COMMENT || style == SCE_C_COMMENTDOC)) ||
-		(lexer == SCLEX_HTML && style == SCE_HPHP_COMMENT) ||
-		(lexer == SCLEX_CSS && style == SCE_CSS_COMMENT) ||
-		(lexer == SCLEX_D && (style == SCE_D_COMMENT ||
-							  style == SCE_D_COMMENTDOC ||
-							  style == SCE_D_COMMENTNESTED)))
+	/* Use the start of the line enter was pressed on, to avoid any doc keyword styles */
+	indent_pos = sci_get_line_indent_position(sci, cur_line - 1);
+	style = sci_get_style_at(sci, indent_pos);
+
+	if (in_block_comment(lexer, style))
 	{
-		gchar *previous_line = sci_get_line(sci, sci_get_line_from_position(sci, pos - 2));
+		gchar *previous_line = sci_get_line(sci, cur_line - 1);
 		/* the type of comment, '*' (C/C++/Java), '+' and the others (D) */
 		gchar *continuation = "*";
 		gchar *whitespace = ""; /* to hold whitespace if needed */
@@ -2507,13 +2531,14 @@
 		/* find and stop at end of multi line comment */
 		i = len - 1;
 		while (i >= 0 && isspace(previous_line[i])) i--;
-		if (i >= 1 && is_doc_comment_char(previous_line[i - 1], lexer) && previous_line[i] == '/')
+		if (i >= 1 && is_comment_char(previous_line[i - 1], lexer) && previous_line[i] == '/')
 		{
-			gint cur_line = sci_get_current_line(sci);
-			gint indent_pos = sci_get_line_indent_position(sci, cur_line);
-			gint indent_len = sci_get_col_from_position(sci, indent_pos);
-			gint indent_width = editor_get_indent_prefs(editor)->width;
+			gint indent_len, indent_width;
 
+			indent_pos = sci_get_line_indent_position(sci, cur_line);
+			indent_len = sci_get_col_from_position(sci, indent_pos);
+			indent_width = editor_get_indent_prefs(editor)->width;
+
 			/* if there is one too many spaces, delete the last space,
 			 * to return to the indent used before the multiline comment was started. */
 			if (indent_len % indent_width == 1)
@@ -2526,7 +2551,7 @@
 		while (i < len && isspace(previous_line[i])) i++; /* get to start of the line */
 
 		if (i + 1 < len &&
-			previous_line[i] == '/' && is_doc_comment_char(previous_line[i + 1], lexer))
+			previous_line[i] == '/' && is_comment_char(previous_line[i + 1], lexer))
 		{ /* we are on the second line of a multi line comment, so we have to insert white space */
 			whitespace = " ";
 		}


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