diff --git a/moo/mooedit/mooedit.c b/moo/mooedit/mooedit.c index 97238db4..a7966ff8 100644 --- a/moo/mooedit/mooedit.c +++ b/moo/mooedit/mooedit.c @@ -570,10 +570,12 @@ moo_edit_set_var (MooEdit *edit, if (is_ascii (name)) key = g_ascii_strdown (name, -1); + else + key = g_strdup (name); - g_hash_table_insert (edit->priv->vars, - key ? key : g_strdup (name), - g_strdup (value)); + g_strdelimit (key, "-_", '-'); + + g_hash_table_insert (edit->priv->vars, key, g_strdup (value)); } @@ -654,8 +656,8 @@ out: #define KATE_MODE_STRING "kate:" #define KATE_VAR_VAL_SEPARATOR " " -#define VI_MODE_STRING "-*-" -#define VI_VAR_VAL_SEPARATOR ":" +#define EMACS_MODE_STRING "-*-" +#define EMACS_VAR_VAL_SEPARATOR ":" static void try_mode (MooEdit *edit) @@ -669,12 +671,23 @@ try_mode (MooEdit *edit) gtk_text_iter_forward_to_line_end (&end); text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); try_mode_string (edit, text, KATE_MODE_STRING, KATE_VAR_VAL_SEPARATOR); - try_mode_string (edit, text, VI_MODE_STRING, VI_VAR_VAL_SEPARATOR); + try_mode_string (edit, text, EMACS_MODE_STRING, EMACS_VAR_VAL_SEPARATOR); g_free (text); gtk_text_buffer_get_end_iter (buffer, &end); - start = end; - gtk_text_iter_set_line_offset (&start, 0); + + if (gtk_text_iter_starts_line (&end)) + { + gtk_text_iter_backward_line (&end); + start = end; + gtk_text_iter_forward_to_line_end (&end); + } + else + { + start = end; + gtk_text_iter_set_line_offset (&start, 0); + } + text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); try_mode_string (edit, text, KATE_MODE_STRING, KATE_VAR_VAL_SEPARATOR); g_free (text); diff --git a/moo/mooedit/mooeditfileops.c b/moo/mooedit/mooeditfileops.c index 37bd2a59..471642f5 100644 --- a/moo/mooedit/mooeditfileops.c +++ b/moo/mooedit/mooeditfileops.c @@ -312,8 +312,11 @@ moo_edit_load_default (G_GNUC_UNUSED MooEditLoader *loader, if (success) { + /* XXX */ gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_place_cursor (buffer, &start); + edit->priv->status = 0; + moo_edit_set_modified (edit, FALSE); _moo_edit_set_filename (edit, file, encoding); _moo_edit_start_file_watch (edit); } @@ -327,11 +330,6 @@ moo_edit_load_default (G_GNUC_UNUSED MooEditLoader *loader, else moo_text_view_end_not_undoable_action (view); - edit->priv->status = 0; - moo_edit_set_modified (edit, FALSE); - -// _moo_text_buffer_dump (buffer, "/tmp/dump.c"); - return success; } @@ -442,6 +440,7 @@ do_load (MooEdit *edit, } +/* XXX */ static gboolean moo_edit_reload_default (MooEditLoader *loader, MooEdit *edit, GError **error) diff --git a/moo/mooedit/mooindenter.c b/moo/mooedit/mooindenter.c index eae24357..dff434bb 100644 --- a/moo/mooedit/mooindenter.c +++ b/moo/mooedit/mooindenter.c @@ -613,12 +613,14 @@ set_value_default (MooIndenter *indenter, } else if (!g_ascii_strcasecmp (var, "indent-tabs-mode")) { - if (!g_ascii_strcasecmp (value, "t")) - indenter->use_tabs = TRUE; - else - indenter->use_tabs = FALSE; + indenter->use_tabs = !g_ascii_strcasecmp (value, "t"); } - else if (!g_ascii_strcasecmp (var, "c-basic-offset")) + else if (!g_ascii_strcasecmp (var, "space-indent")) + { + indenter->use_tabs = !!g_ascii_strcasecmp (value, "on"); + } + else if (!g_ascii_strcasecmp (var, "c-basic-offset") || + !g_ascii_strcasecmp (var, "indent-width")) { guint64 indent = g_ascii_strtoull (value, NULL, 10); diff --git a/moo/mooutils/mooprefs.c b/moo/mooutils/mooprefs.c index 3aac838f..7cc34e32 100644 --- a/moo/mooutils/mooprefs.c +++ b/moo/mooutils/mooprefs.c @@ -331,28 +331,32 @@ prefs_new_key_from_string (MooPrefs *prefs, const char *value) { PrefsItem *item; - GValue gval; + GValue val, default_val; g_return_if_fail (key && key[0]); g_return_if_fail (g_utf8_validate (key, -1, NULL)); item = prefs_get_item (prefs, key); - gval.g_type = 0; - g_value_init (&gval, G_TYPE_STRING); - g_value_set_string (&gval, value); + val.g_type = 0; + g_value_init (&val, G_TYPE_STRING); + g_value_set_string (&val, value); + default_val.g_type = 0; + g_value_init (&default_val, G_TYPE_STRING); if (!item) { - prefs_new_key (prefs, key, G_TYPE_STRING, &gval); + prefs_new_key (prefs, key, G_TYPE_STRING, &default_val); item = prefs_get_item (prefs, key); + item_set (item, &val); } else { - moo_value_convert (&gval, &item->value); + moo_value_convert (&val, &item->value); } - g_value_unset (&gval); + g_value_unset (&val); + g_value_unset (&default_val); prefs_emit_notify (prefs, key, item_value (item)); } diff --git a/moo/mooutils/mooutils-gobject.c b/moo/mooutils/mooutils-gobject.c index 74b473ae..1c3dc39f 100644 --- a/moo/mooutils/mooutils-gobject.c +++ b/moo/mooutils/mooutils-gobject.c @@ -167,7 +167,7 @@ moo_value_convert (const GValue *src, if (dest_type == G_TYPE_BOOLEAN) { - if (!string) + if (!string || !string[0]) g_value_set_boolean (dest, FALSE); else g_value_set_boolean (dest, @@ -179,7 +179,7 @@ moo_value_convert (const GValue *src, if (dest_type == G_TYPE_DOUBLE) { - if (!string) + if (!string || !string[0]) g_value_set_double (dest, 0); else g_value_set_double (dest, g_ascii_strtod (string, NULL)); @@ -188,7 +188,7 @@ moo_value_convert (const GValue *src, if (dest_type == G_TYPE_INT) { - if (!string) + if (!string || !string[0]) g_value_set_int (dest, 0); else g_value_set_int (dest, g_ascii_strtod (string, NULL)); @@ -199,7 +199,7 @@ moo_value_convert (const GValue *src, { GdkColor color; - if (!string) + if (!string || !string[0]) { g_value_set_boxed (dest, NULL); return TRUE; @@ -222,7 +222,7 @@ moo_value_convert (const GValue *src, if (!string || !string[0]) { g_value_set_enum (dest, 0); - g_return_val_if_reached (TRUE); + return TRUE; } klass = g_type_class_ref (dest_type);