Revision: 549 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=549&view=rev Author: frlan Date: 2009-03-16 23:22:28 +0000 (Mon, 16 Mar 2009)
Log Message: ----------- GeanyLaTeX: Added a function to bulk replace special characters inside marked text by keybinding
Modified Paths: -------------- trunk/geanylatex/ChangeLog trunk/geanylatex/src/geanylatex.c
Modified: trunk/geanylatex/ChangeLog =================================================================== --- trunk/geanylatex/ChangeLog 2009-03-16 23:20:12 UTC (rev 548) +++ trunk/geanylatex/ChangeLog 2009-03-16 23:22:28 UTC (rev 549) @@ -1,3 +1,9 @@ +2009-03-15 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * Added a function to bulk replace special characters + inside marked text by keybinding + + 2009-03-13 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* Don't offer insert environment dialog in case of no document is open.
Modified: trunk/geanylatex/src/geanylatex.c =================================================================== --- trunk/geanylatex/src/geanylatex.c 2009-03-16 23:20:12 UTC (rev 548) +++ trunk/geanylatex/src/geanylatex.c 2009-03-16 23:22:28 UTC (rev 549) @@ -66,6 +66,7 @@ LATEX_TOGGLE_ACTIVE, LATEX_ENVIRONMENT_INSERT, LATEX_INSERT_NEWITEM_KB, + LATEX_REPLACE_SPECIAL_CHARS, COUNT_KB };
@@ -121,11 +122,53 @@ } } } - return FALSE; }
+static void replace_special_character() +{ + GeanyDocument *doc = NULL; + doc = document_get_current(); + + if (doc != NULL && sci_has_selection(doc->editor->sci)) + { + gint selection_len = sci_get_selected_text_length(doc->editor->sci); + gchar *selection = g_malloc(selection_len + 1); + GString *replacement = g_string_new(NULL); + gint i; + gchar *new = NULL; + gchar *entity = NULL; + gchar buf[7]; + gint len; + + sci_get_selected_text(doc->editor->sci, selection); + + selection_len = sci_get_selected_text_length(doc->editor->sci) - 1; + for (i = 0; i < selection_len; i++) + { + len = g_unichar_to_utf8(g_utf8_get_char(selection + i), buf); + i = len - 1 + i; + buf[len] = '\0'; + entity = glatex_get_entity(buf); + + if (entity != NULL) + { + replacement = g_string_append(replacement, entity); + } + else + { + replacement = g_string_append(replacement, buf); + } + } + new = g_string_free(replacement, FALSE); + sci_replace_sel(doc->editor->sci, new); + g_free(selection); + g_free(new); + g_free(entity); + } +} + /* Called when keys were pressed */ static void kblatex_toggle(G_GNUC_UNUSED guint key_id) { @@ -147,7 +190,6 @@ { GeanyDocument *doc = NULL;
- doc = document_get_current();
if (doc != NULL && string != NULL) @@ -950,6 +992,13 @@ glatex_insert_string("\item ", TRUE); }
+static void kb_replace_special_chars(G_GNUC_UNUSED guint key_id) +{ + if (NULL == document_get_current()) + return; + replace_special_character(); +} + /*static void kb_bibtex_entry_insert(G_GNUC_UNUSED guint key_id) { insert_bibtex_entry(NULL, NULL); @@ -974,6 +1023,8 @@ _("Run insert environment dialog"), menu_latex_insert_environment); keybindings_set_item(plugin_key_group, LATEX_INSERT_NEWITEM_KB, kb_insert_newitem, 0, 0, "latex_insert_item", _("Insert \item"), NULL); + keybindings_set_item(plugin_key_group, LATEX_REPLACE_SPECIAL_CHARS, + kb_replace_special_chars, 0, 0, "latex_replace_chars", _("Replacement of special characters"), NULL); }
void plugin_help()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.