From 4b000e09ae71b2357353213363c442de78e684f0 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 16 Dec 2008 16:27:17 +0000 Subject: [PATCH] Move %ws and %newline% replacement into snippets-only code. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3387 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/editor.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3aa60270..a7863a00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ * src/search.c: Set Find in Files directory entry to project base path or current working directory if the current file has no path. + * src/editor.c: + Move %ws and %newline% replacement into snippets-only code. 2008-12-15 Enrico Tröger diff --git a/src/editor.c b/src/editor.c index 7f40e06a..18c1e7c5 100644 --- a/src/editor.c +++ b/src/editor.c @@ -1789,7 +1789,6 @@ static void fix_line_indents(GeanyEditor *editor, gint line_start, gint line_end * NOT any hard tabs (you get those when copying document text with the Tabs * & Spaces indent mode set). * @note This doesn't scroll the cursor in view afterwards. */ -/* note: %ws% and %newline% are just for snippets, they probably shouldn't be here :-/ */ static void editor_insert_text_block(GeanyEditor *editor, const gchar *text, gint insert_pos, gint cursor_index, gint newline_indent_size) { @@ -1822,12 +1821,10 @@ static void editor_insert_text_block(GeanyEditor *editor, const gchar *text, gin /* transform line endings */ utils_string_replace_all(buf, "\n", editor_get_eol_char(editor)); - utils_string_replace_all(buf, "%newline%", editor_get_eol_char(editor)); /* transform tabs into indent widths (in spaces) */ whitespace = g_strnfill(editor_get_indent_prefs(editor)->width, ' '); utils_string_replace_all(buf, "\t", whitespace); - utils_string_replace_all(buf, "%ws%", whitespace); g_free(whitespace); if (cursor_index >= 0) @@ -1852,7 +1849,7 @@ static void editor_insert_text_block(GeanyEditor *editor, const gchar *text, gin static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, const gchar *word) { - gchar *str; + gchar *str, *whitespace; GString *pattern; gint step, str_len; gsize cur_index; @@ -1892,6 +1889,14 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons /* replace any %template% wildcards */ snippets_replace_wildcards(editor, pattern); + /* transform other wildcards */ + utils_string_replace_all(pattern, "%newline%", editor_get_eol_char(editor)); + + /* use spaces for indentation, will be fixed up */ + whitespace = g_strnfill(editor_get_indent_prefs(editor)->width, ' '); + utils_string_replace_all(pattern, "%ws%", whitespace); + g_free(whitespace); + /* find the %cursor% pos (has to be done after all other operations) */ step = utils_strpos(pattern->str, "%cursor%"); if (step != -1)