From f1bfa6316d5ee1e7148463ea3970f46012bcebd9 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Fri, 16 Jun 2023 09:14:43 +0100 Subject: [PATCH] editorconfig.vala: make hook document handler asynchronous --- plugins/editorconfig/editorconfig.vala | 87 ++++++++++++++------------ 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/plugins/editorconfig/editorconfig.vala b/plugins/editorconfig/editorconfig.vala index 79e99efb30..0cebf7b39c 100644 --- a/plugins/editorconfig/editorconfig.vala +++ b/plugins/editorconfig/editorconfig.vala @@ -32,53 +32,58 @@ public class Scratch.Plugins.EditorConfigPlugin: Peas.ExtensionBase, Peas.Activa }); plugins.hook_document.connect ((d) => { - format_bar.tab_set_by_editor_config = false; - Scratch.Widgets.SourceView view = d.source_view; - File file = d.file; + update_config.begin (d); + }); - 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; - } + private async void update_config (Scratch.Services.Document d) { + format_bar.tab_set_by_editor_config = false; + 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_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_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; - } + 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_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_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; } - }); + } } - public void deactivate () { } + public void deactivate () { warning ("Editor config deactivate");} } [ModuleInit]