Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up closing and opening tabs when editor-config plugin is active #1334

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 52 additions & 47 deletions plugins/editorconfig/editorconfig.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading