GNOME Bugzilla – Bug 766266
convert indentation between whitespace and tab when pasting
Last modified: 2017-03-26 03:01:32 UTC
I've tested this between two js files. How to reproduce - copy some code from a space-indented file - paste it in a tab-indented file What is expected - the pasted code should have its spaces replaced by tabs Thanks !
I'm hesitant to do anything on a paste other than simply paste clipboard contents. However, we should maybe look at implementing :retab from Vim at least. Then we could have a select-retion+retab option in the context menu.
Created attachment 348693 [details] [review] Retab: convert indetation between tabs and spaces When pasting code with diffrent indentation style then the one in the Indentation settings, the indentation style of the inserted code stays the same. A new plugin retab has been added. The retab is accessible through the Selection in the popup menu and converts the indentation style base on the Indentation setting of the file.
Review of attachment 348693 [details] [review]: Absolutely fantastic patch! It is obvious you put in effort to get this right and test it. I really appreciate your attention to detail. Couple rather small things to fix and then we can get this merged. - Address the leak when building the spaces string - Remove X-Tool-* stuff from the .plugin file and then I think we're good to go. ::: plugins/retab/gbp-retab-view-addin.c @@ +92,3 @@ + { + for (gint tab = 0; tab < tab_num * tab_width; ++tab) + new_indent = g_strconcat(" ", new_indent, NULL); Unlike auto stuff in C++, this will not free the old "new_indent" when re-assigning. So this leaks. I would suggest something like: GString *str = g_string_new (NULL); for (gint tab = 0; tab < tab_num * tab_width; ++tab) g_string_append_c (str, ' '); ::: plugins/retab/retab.plugin @@ +8,3 @@ +Hidden=true +Depends=editor +X-Tool-Name=retab You can drop the X-Tool- lines. Those are for command line tooling which I don't see as part of this patch.
Created attachment 348721 [details] [review] Retab: convert indetation between tabs and spaces When pasting code with diffrent indentation style then the one in the Indentation settings, the indentation style of the inserted code stays the same. A new plugin retab has been added. The retab is accessible through the Selection in the popup menu and converts the indentation style base on the Indentation setting of the file.
Great work! I changed one small thing to avoid an extra free of the GString. We can just use GString.str and GString.len instead of copying the string temporarily. Attachment 348721 [details] pushed as 2ecf027 - Retab: convert indetation between tabs and spaces