After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 766266 - convert indentation between whitespace and tab when pasting
convert indentation between whitespace and tab when pasting
Status: RESOLVED FIXED
Product: gnome-builder
Classification: Other
Component: editor
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Builder Maintainers
GNOME Builder Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-05-11 10:34 UTC by kapouer
Modified: 2017-03-26 03:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Retab: convert indetation between tabs and spaces (17.71 KB, patch)
2017-03-25 10:17 UTC, Lucie Dvorakova
none Details | Review
Retab: convert indetation between tabs and spaces (17.76 KB, patch)
2017-03-25 19:54 UTC, Lucie Dvorakova
committed Details | Review

Description kapouer 2016-05-11 10:34:47 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 !
Comment 1 Christian Hergert 2016-05-11 11:18:47 UTC
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.
Comment 2 Lucie Dvorakova 2017-03-25 10:17:57 UTC
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.
Comment 3 Christian Hergert 2017-03-25 10:53:28 UTC
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.
Comment 4 Lucie Dvorakova 2017-03-25 19:54:01 UTC
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.
Comment 5 Christian Hergert 2017-03-26 03:01:26 UTC
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