diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 8a5b8f428..3f7a7948e 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -32,60 +32,65 @@ public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activa }); plugins.hook_document.connect ((d) => { - // Ensure use global settings by default - format_bar.tab_style_set_by_editor_config = false; - format_bar.tab_width_set_by_editor_config = false; - format_bar.set_document (d); + update_config.begin (d); + }); - Scratch.Widgets.SourceView view = d.source_view; - File file = d.file; + } - if (file == null || !file.query_exists ()) { - return; - } + private async void update_config (Scratch.Services.Document d) { + // Ensure use global settings by default + format_bar.tab_style_set_by_editor_config = false; + format_bar.tab_width_set_by_editor_config = false; + format_bar.set_document (d); - var handle = new EditorConfig.Handle (); - handle.set_conf_file_name (".editorconfig"); - if (handle.parse (file.get_path ()) != 0) { - return; - } + Scratch.Widgets.SourceView view = d.source_view; + File file = d.file; - for (int i = 0; i < handle.get_name_value_count (); i++) { - string name, val; - handle.get_name_value (i, out name, out val); - /* These are all properties (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties) */ - switch (name) { - case "indent_style": - format_bar.tab_style_set_by_editor_config = true; - var use_spaces = (val != "tab"); - format_bar.set_insert_spaces_instead_of_tabs (use_spaces); - break; - case "indent_size": - case "tab_width": - format_bar.tab_width_set_by_editor_config = true; - var indent_width = (int.parse (val)).clamp (2, 16); - format_bar.set_tab_width (indent_width); - break; - case "end_of_line": - break; - case "charset": - break; - case "trim_trailing_whitespace": - break; - case "insert_final_newline": - break; - case "max_line_length": - view.right_margin_position = int.parse (val); - break; - default: - warning ("unrecognised name/value %s/%s", name, val); - break; - } + if (file == null || !file.query_exists ()) { + return; + } + + var handle = new EditorConfig.Handle (); + handle.set_conf_file_name (".editorconfig"); + if (handle.parse (file.get_path ()) != 0) { + return; + } + + for (int i = 0; i < handle.get_name_value_count (); i++) { + string name, val; + handle.get_name_value (i, out name, out val); + /* These are all properties (https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties) */ + switch (name) { + case "indent_style": + format_bar.tab_style_set_by_editor_config = true; + var use_spaces = (val != "tab"); + format_bar.set_insert_spaces_instead_of_tabs (use_spaces); + break; + case "indent_size": + case "tab_width": + format_bar.tab_width_set_by_editor_config = true; + var indent_width = (int.parse (val)).clamp (2, 16); + format_bar.set_tab_width (indent_width); + break; + case "end_of_line": + break; + case "charset": + break; + case "trim_trailing_whitespace": + break; + case "insert_final_newline": + break; + case "max_line_length": + view.right_margin_position = int.parse (val); + break; + default: + warning ("unrecognised name/value %s/%s", name, val); + break; } - }); + } } - public void deactivate () { } + public void deactivate () { debug ("Editor config deactivate");} } [ModuleInit]