On Thu, 18 Dec 2008 14:40:54 +0100, Harold Aling <[email protected]> wrote:

>Dear Geany devs,
>
>After a (short) period of getting used to it, I really like the new
>feature to automatically insert quotes and brackets! It saves me a lot
>of keypresses to construct a piece of code ;)
>
>Except for this example: "$var[] = 'test';"
>
>Instead of typing [] I/we now have to type [ and right arrow key. Same
>goes for "$empty = ''", etc...
>
>
>My request:
>
>If the next character is the same as the one Geany has inserted
>(/closed), overwrite the previously inserted one.

Sounds like a good idea.

Attached is a patch which might fix it but I didn't test it well and I
want you (Harold, Guillaume, whoever else is using this feature) to
test it before, it might need some tweaking.

Regards,
Enrico

-- 
Get my GPG key from http://www.uvena.de/pub.asc
Index: src/editor.c
===================================================================
--- src/editor.c	(Revision 3401)
+++ src/editor.c	(Arbeitskopie)
@@ -91,6 +91,7 @@
 static gboolean is_code_style(gint lexer, gint style);
 static gboolean is_string_style(gint lexer, gint style);
 static void auto_close_chars(ScintillaObject *sci, gint pos, gchar c);
+static gboolean auto_close_chars_check_dup(ScintillaObject *sci, gint pos, gchar c);
 static void auto_table(GeanyEditor *editor, gint pos);
 static void close_block(GeanyEditor *editor, gint pos);
 
@@ -435,7 +436,8 @@
 		}
 		case '(':
 		{
-			auto_close_chars(sci, pos, nt->ch);
+			if (editor_prefs.autoclose_chars != 0)
+				auto_close_chars(sci, pos, nt->ch);
 			/* show calltips */
 			editor_show_calltip(editor, --pos);
 			break;
@@ -451,6 +453,9 @@
 			calltip.pos = 0;
 			calltip.sci = NULL;
 			calltip.set = FALSE;
+
+			if (editor_prefs.autoclose_chars != 0)
+				auto_close_chars_check_dup(sci, pos, nt->ch);
 			break;
 		}
 		case '{':
@@ -458,13 +463,22 @@
 		case '"':
 		case '\'':
 		{
-			auto_close_chars(sci, pos, nt->ch);
+			if (! auto_close_chars_check_dup(sci, pos, nt->ch))
+				auto_close_chars(sci, pos, nt->ch);
 			break;
 		}
+		case ']':
+		{
+			if (editor_prefs.autoclose_chars != 0)
+				auto_close_chars_check_dup(sci, pos, nt->ch);
+			break;
+		}
 		case '}':
 		{	/* closing bracket handling */
 			if (editor->auto_indent)
 				close_block(editor, pos - 1);
+			if (editor_prefs.autoclose_chars != 0)
+				auto_close_chars_check_dup(sci, pos, nt->ch);
 			break;
 		}
 		default:
@@ -1016,6 +1030,40 @@
 }
 
 
+static gboolean auto_close_chars_check_dup(ScintillaObject *sci, gint pos, gchar c)
+{
+	if (c != sci_get_char_at(sci, pos))
+		return FALSE;
+
+	switch (c)
+	{
+		case '(':
+			if (! (editor_prefs.autoclose_chars & GEANY_AC_PARENTHESIS))
+				return FALSE;
+			break;
+		case '{':
+			if (! (editor_prefs.autoclose_chars & GEANY_AC_CBRACKET))
+				return FALSE;
+			break;
+		case '[':
+			if (! (editor_prefs.autoclose_chars & GEANY_AC_SBRACKET))
+				return FALSE;
+			break;
+		case '\'':
+			if (! (editor_prefs.autoclose_chars & GEANY_AC_SQUOTE))
+				return FALSE;
+			break;
+		case '"':
+			if (! (editor_prefs.autoclose_chars & GEANY_AC_DQUOTE))
+				return FALSE;
+			break;
+	}
+	SSM(sci, SCI_DELETEBACK, 0, 0);
+	sci_set_current_position(sci, pos, FALSE);
+	return TRUE;
+}
+
+
 static void auto_close_chars(ScintillaObject *sci, gint pos, gchar c)
 {
 	const gchar *closing_char = NULL;

Attachment: pgpBLUGNq30WS.pgp
Description: PGP signature

_______________________________________________
Geany mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany

Reply via email to