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 683678 - Visibility of leading, internal and trailing spaces for individual types of whitespaces
Visibility of leading, internal and trailing spaces for individual types of w...
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
git master
Other All
: Normal enhancement
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2012-09-09 18:18 UTC by lamefun
Modified: 2016-09-25 17:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
The patch (10.15 KB, text/plain)
2012-09-09 18:18 UTC, lamefun
  Details
The patch (10.76 KB, patch)
2012-09-09 19:13 UTC, lamefun
none Details | Review
The patch (10.45 KB, patch)
2012-11-12 07:01 UTC, lamefun
reviewed Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (12.05 KB, patch)
2014-10-05 23:17 UTC, Robert Roth
needs-work Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (13.37 KB, patch)
2014-10-10 19:12 UTC, Robert Roth
needs-work Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (14.03 KB, patch)
2014-10-11 01:25 UTC, Robert Roth
needs-work Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (14.68 KB, patch)
2014-10-11 13:00 UTC, Robert Roth
none Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (14.70 KB, patch)
2014-10-11 13:08 UTC, Robert Roth
needs-work Details | Review
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678 (14.59 KB, patch)
2014-10-11 14:45 UTC, Robert Roth
accepted-commit_after_freeze Details | Review
Fine-grained control for drawing whitespaces. (14.59 KB, patch)
2014-10-11 15:51 UTC, Robert Roth
reviewed Details | Review
Sublime screenshot (14.00 KB, image/png)
2014-10-12 13:24 UTC, Robert Roth
  Details

Description lamefun 2012-09-09 18:18:14 UTC
Created attachment 223858 [details]
The patch

Adds support for independent control of visibility of leading, internal and trailing spaces for individual types of whitespaces. Also fixes non-breaking spaces still being shown as normal spaces if NBSP flag was off but SPACE flag was on.
Comment 1 lamefun 2012-09-09 19:13:46 UTC
Created attachment 223860 [details] [review]
The patch

A properly formatted patch
Comment 2 lamefun 2012-11-12 07:01:26 UTC
Created attachment 228754 [details] [review]
The patch

Fix documentation, fix patch formatting (now I hope it's really properly formatted).
Comment 3 Sébastien Wilmet 2013-12-21 18:54:38 UTC
(In reply to comment #0)
> Also fixes non-breaking
> spaces still being shown as normal spaces if NBSP flag was off but SPACE flag
> was on.

Please provide a separate patch for this bug fix, if it is still relevant for the current code.
Comment 4 Sébastien Wilmet 2013-12-21 19:02:03 UTC
Review of attachment 228754 [details] [review]:

I wonder if we can instead combine different flags. Have an enum for leading, internal and trailing spaces. And have another enum for the different types of spaces. And be able to e.g. combine leading spaces with tabs, so only leading tabs are shown.

With such a solution, what to do with line breaks? Should they always be combined with the trailing flag?

Is it possible to implement this solution in a compatible way with the current API? If not, it's not a big problem to deprecate the current API, if the new API is better.
Comment 5 lamefun 2013-12-24 06:00:54 UTC
Combine enums how? Like this?

typedef enum
{
  SPACE   = 0,
  NBSP    = 1,
  TAB     = 2,
  NEWLINE = 3
} SpaceType;

typedef enum
{
  LEADING  = 0,
  TRAILING = 1,
  INTERNAL = 2,
  N_SPACE_TYPES
} SpaceLocation;

#define COMBINE(s, w)  ((1 << ((s) * N_SPACE_TYPES)) << (w))

int flags = COMBINE(TAB, LEADING) | COMBINE(NEWLINE, TRAILING);
Comment 6 Sébastien Wilmet 2013-12-24 10:31:52 UTC
No, what I mean is to have other functions, like:

> void
> gtk_source_view_set_draw_spaces_for_type (GtkSourceView *view,
>                                           GtkSourceSpaceType space_type,
>                                           GtkSourceSpaceLocation space_location);
>
> GtkSourceSpaceLocation
> gtk_source_view_get_draw_spaces_for_type (GtkSourceView *view,
>                                           GtkSourceSpaceType space_type);

Or inversely, set or get the visible space types in function of the space location.

With 'ALL' values available in the SpaceType and SpaceLocation enums, for convenience.

This idea has the advantage to easily add a space type or space location, without having an explosion of flags in GtkSourceDrawSpacesFlags.
Comment 7 Sébastien Wilmet 2013-12-24 10:38:03 UTC
I think it is worth exploring the idea. But it's less convenient to use when we don't care about the location (that's why I propose a 'ALL' value in the enum).

And the stored settings would not be easily available with properties. One property per location or per space type would be required.
Comment 8 lamefun 2013-12-25 02:52:09 UTC
I wanted to implement it like that in the first place, but people said that it's bad and I should add flags instead. With new enums in place, what should the old function do?
Comment 9 Sébastien Wilmet 2013-12-26 08:46:04 UTC
If possible, it's better to extend the current API instead of creating a new one and deprecate the other. But having only one enum is not convenient, and is less extensible (above 32 flags I think the enum overflows).

In the future, it would be nice if Pango and GtkTextView can draw the spaces directly (see bug #721014), instead of calling gtk_text_view_get_iter_location() to locate the spaces and draw the symbols afterwards.

The API in GtkTextView is free. What we can do is to add directly the API in GtkTextView, deprecate the current GtkSourceView API, and implement the Pango space drawing later. Or we can also wait the Pango stuff before doing anything in GtkTextView.
Comment 10 Sébastien Wilmet 2013-12-26 08:54:35 UTC
(In reply to comment #8)
> With new enums in place, what should the old function do?

The 'set' function uses internally the new API, and also store the GtkSourceDrawSpacesFlags.
The 'get' function simply returns the GtkSourceDrawSpacesFlags stored with the last 'set' function. If the 'set' function from the new API is used, it is not taken into account for the old 'get' function.
Comment 11 Robert Roth 2014-10-05 23:17:25 UTC
Created attachment 287787 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the location where a given whitespace should be drawn
* The old function set_draw_spaces uses the new function internally
* Added convenience values for ALL locations ans ALL space types
This will have several benefits, including the possibility to add a Selection location
to only show the whitespaces in selected text.
Comment 12 Robert Roth 2014-10-05 23:23:40 UTC
@Sébastien: Find attached my first try for the fine-grained whitespace drawing control, a review would be welcome. Dev-related question: how can I use (see the results) the PROFILE macro used in drawing function?
Comment 13 Sébastien Wilmet 2014-10-07 21:17:34 UTC
(In reply to comment #12)
> Dev-related question: how can I use (see
> the results) the PROFILE macro used in drawing function?

At the top of gtksourceview.c, uncomment "#define ENABLE_PROFILE" and comment "#undef ENABLE_PROFILE".
Comment 14 Sébastien Wilmet 2014-10-07 21:33:19 UTC
I'll have a closer look at the patch tomorrow, I haven't thought myself about how to implement this, so at first I was a bit surprised by the hash table, but yes, it probably makes sense.

For the coding style, please add curly braces around one-line blocks too. Some old code doesn't always do that, but for new code it's better (see the file HACKING for the rationale).

In the header, the function parameters should be aligned.
Comment 15 Sébastien Wilmet 2014-10-08 11:43:12 UTC
First, there should be at least one use case where the new API would be useful. For example:
- for spaces inside the text, draw all space types except normal spaces;
- for trailing spaces, draw all spaces;
- for spaces inside selection, draw all spaces.

This is not possible with the current API.

I think it's more convenient to specify the types of spaces to draw for each location. So having the functions set_draw_spaces_for_location() and get_draw_spaces_for_location(). Think also about a configuration tool: you can have a combo box to select the location, and below have check boxes for each space type.

With this solution, GtkSourceSpaceLocation can be a normal enum (0, 1, 2, etc) with GTK_SOURCE_SPACE_LOCATION_ALL as 0 so the enum can be expanded at the end. But I'm not sure it's a good solution. It's probably safer to have flags for both enums, so the flags can be combined in any order. Also, with flags it's possible to set several locations at once with set_draw_spaces_for_location(). With a normal enum for the locations, the implementation is simpler (an array can store the space types for the different locations). But the API is more important than the implementation details of course, so flags for both enums is better.

Another thing, GTK_SOURCE_SPACE_LOCATION_SELECTION could be combined with the other locations, for example trailing spaces inside a selection. But it becomes too complicated, taking the selection as one location is easier.
Comment 16 Sébastien Wilmet 2014-10-08 12:03:27 UTC
Review of attachment 287787 [details] [review]:

::: gtksourceview/gtksourceview.c
@@ +148,2 @@
 	GtkSourceDrawSpacesFlags draw_spaces;
+	GHashTable      *draw_spaces_at_location;

Add a comment to explain what are the types of the keys and the values.
It should be SpaceLocation -> SpaceType (with gint <-> gpointer conversions).

@@ +1075,3 @@
+	if (view->priv->draw_spaces_at_location)
+	{
+		g_hash_table_destroy (view->priv->draw_spaces_at_location);

like a gobject, use g_hash_table_unref().

@@ +2119,3 @@
+	/* tab */
+	if (c == '\t')
+		result = GTK_SOURCE_SPACE_TYPE_TAB;

curly braces around one-like blocks.

@@ +3973,3 @@
+
+	GHashTableIter iter;
+	gpointer key;

Variable declarations must be at the beginning of the block.

@@ +4008,3 @@
+	{
+		if (GPOINTER_TO_INT (key) | type)
+			result = result | GPOINTER_TO_INT (value);

I'm not sure it's a good solution to add all the results.
There should maybe be a check to verify that only one @type (or one location) is given. For example when one type (or location) matches, store the result and continue the iteration, if another type/location matches, do a g_return_val.

::: gtksourceview/gtksourceview.h
@@ +137,3 @@
+ * @GTK_SOURCE_SOURCE_SPACE_TYPE_ALL: wheter all kind of spaces should be drawn.
+ *
+ * GtkSourceSpaceType determine what kind of spaces whould be drawn.

For the documentation of the enums, don't say that it is for the drawing. A SpaceType can be used for other features. Also, "whould" is a typo (but it was there before).

@@ +243,3 @@
+							(GtkSourceView   *view,
+							 GtkSourceSpaceType type,
+							 GtkSourceSpaceLocation location);

Align the parameters here.
Also, change the function as set_draw_spaces_for_location().
Comment 17 Sébastien Wilmet 2014-10-08 12:08:23 UTC
Also, do not forget the "Since: 3.16" in the GTK-Doc comments. And in another commit, deprecate the old enum, functions and property.
Comment 18 Robert Roth 2014-10-08 16:51:57 UTC
Thanks for the time for following up on this. It's mostly clear what I have to do based on the review, but I'm not sure I understand the tasks from your comment before the review, comment 15: Let us clarify if I did get it right, the proposed implementation uses enums with flags, is that OK? Should I add the *spaces_for_location methods instead of the *spaces_for_type methods?

Regarding configuration, I have been thinking of an interface to test this, the test-widget test seems a nice place to have this in, I just wanted to make sure the API is fine before extending the test (in another commit).

Will follow up with a next set of patches soon anyway, hopefully closer to the implementation you expect for this.
Comment 19 Sébastien Wilmet 2014-10-08 22:39:32 UTC
Sorry if I was not clear, when writing the comment I was at the same time thinking about the API/implementation.

I think flags for both enums is better, yes.
And spaces_for_location() seems more useful and more natural than spaces_for_type().

For the configuration, there is also a gedit plugin. It's probably easier to modify just the gedit plugin, but if you want to update test-widget, add for example a button that open a dialog window containing the combo box + check boxes, so it doesn't clutter the main window.
Comment 20 Robert Roth 2014-10-10 19:12:15 UTC
Created attachment 288253 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
This will have several benefits, including the possibility to add a Selection location
to only show the whitespaces in selected text.
Comment 21 Robert Roth 2014-10-10 19:16:09 UTC
Attached the second version of the patch, hopefully with all the review requests fulfilled. (Deprecation for the old functions will come after this one gets a positive review). Please comment, ask, If there's anything else you would like to see. I just realized that I forgot the SELECTION location enum value there, the implementation for that will come in another patch, and in the context of another bug, fairly soon after this part gets accepted.
Comment 22 Sébastien Wilmet 2014-10-10 20:22:50 UTC
Review of attachment 288253 [details] [review]:

I didn't do a thorough review for the first patch, here are more details, mainly for the code style.

::: gtksourceview/gtksourceview.c
@@ +148,3 @@
 	GtkSourceDrawSpacesFlags draw_spaces;
+	/* Mapping for GtkSourceSpaceLocation -> GtkSourceSpaceType */
+	/* with gint <-> gpointer conversions */

A single comment is better in my opinion. Something like:
/* blah
 * foobar
 */

@@ +984,3 @@
 	view->priv->right_margin_overlay_color = NULL;
 	view->priv->spaces_color = NULL;
+	view->priv->draw_spaces_at_location = g_hash_table_new (NULL,

With all the inserts() below it's better to have a function init_draw_spaces_at_location().

@@ +2121,2 @@
+	/* tab */
+	if (c == '\t')

Not really a useful comment. Reading the code is sufficient here, also for the next comments in the same function.

@@ +2151,3 @@
+	/* not a whitespace */
+	if (type == 0)
+		return FALSE;

Curly braces.

@@ +2154,3 @@
+
+	stored_for_location =  GPOINTER_TO_INT (g_hash_table_lookup (view->priv->draw_spaces_at_location,
+							    GINT_TO_POINTER (location)));

There are too spaces after the = (yes I have good eyes ;)
But more importantly, the parameters should be aligned on the parenthesis (or is it not well displayed in bugzilla?).

@@ +2156,3 @@
+							    GINT_TO_POINTER (location)));
+	/* check if the given whitespace should be drawn at the given location */
+	return type & stored_for_location;

I would remove this comment too, there is no given whitespace, just a whitespace type. And the name of the function is enough to know all what the function does.

@@ +2163,3 @@
+			    GtkTextIter        *iter,
+			    GtkTextIter        *leading,
+			    GtkTextIter        *trailing)

Nitpick, there should be only one column separation between types and parameter names.

@@ +2183,2 @@
 	}
+	return (GtkSourceSpaceLocation) flags;

Declare the variable with the GtkSourceSpaceLocation type directly.

@@ -2472,3 @@
-		if (view->priv->draw_spaces != 0)
-		{
-			draw_tabs_and_spaces (view, cr);

The "if" has been remove here. Is there a particular reason to not adapt the condition? It seems that draw_tabs_and_spaces() does the actual drawing, so if space drawing is disabled it's better to avoid calling this function I think (since it is quite slow).

@@ +3958,3 @@
+ * gtk_source_view_set_draw_spaces_for_location:
+ * @view: a #GtkSourceView.
+ * @location: a #GtkSourceSpaceLocation so set the rule for

There should maybe be a description of the function (not only documenting the parameters) to explain that @location can contain several locations. The "location(s)" at the next parameter gives a hint about that, but it's not sufficiently explicit.

@@ +3982,3 @@
+		}
+	}
+	gtk_widget_queue_draw (GTK_WIDGET (view));

Add a blank line after the end of the while block. It's important to well space out the code for better readability. Remember: optimize the time to _read_ the code, not to _write_ it, because a code is read far more often than it is written.

@@ +3989,3 @@
+ * @view: a #GtkSourceView.
+ * @location: the #GtkSourceSpaceLocation to get the drawable spaces for
+ * Returns a #GtkSourceSpaceType specifying which types of spaces will get drawn

Add a blank line to separate the parameters from the description.

@@ +3996,3 @@
+ * Since: 3.16
+ *-
+ * Return value: a #GtkSourceSpaceType value.

"Return value:" is deprecated in GTK-Doc I think, use "Returns:". It may conflict with the "Returns" at the beginning of the description, so check the result.
Only, remove the "-" (probably a leftover).

@@ +4006,3 @@
+	GtkSourceSpaceType result = 0;
+	GHashTableIter iter;
+	gpointer key, value;

Already said that in the previous review, please declare variables at the beginning of a block, here the beginning of the function, above g_return_if_fail.
Also, it's generally better to declare one variable per line, it's more convenient to remove/move/comment/change a single variable declaration, and it's better also for readability.

@@ +4010,3 @@
+	while (g_hash_table_iter_next (&iter, &key, &value))
+	{
+		if ( GPOINTER_TO_INT (key) | location)

There should be no spaces after an opening parentheses.

@@ +4015,3 @@
+		}
+	}
+	return result;

blank line after the block.

@@ +4046,3 @@
+		{
+			GtkSourceSpaceType type = 0;
+			if (flags != GTK_SOURCE_DRAW_SPACES_ALL)

space out the code in this function too.

@@ +4069,3 @@
+				type = GTK_SOURCE_SPACE_TYPE_ALL;
+			}
+			g_hash_table_insert (view->priv->draw_spaces_at_location,

blank line missing.

::: gtksourceview/gtksourceview.h
@@ +137,3 @@
+ * @GTK_SOURCE_SOURCE_SPACE_TYPE_ALL: wheter all kind of spaces should be drawn.
+ *
+ * GtkSourceSpaceType determine what kind of spaces will be shown.

Again, please to not explain that the purpose is for the drawing. Those flags could be useful for other features.

@@ +156,3 @@
+ * @GTK_SOURCE_SPACE_LOCATION_TEXT: whether whitespaces inside text should be drawn.
+ * @GTK_SOURCE_SPACE_LOCATION_TRAILING: whether trailing whitespaces should be drawn.
+ * @GTK_SOURCE_SPACE_LOCATION_SELECTION: whether whitespaces in selected text should be drawn.

Please add the SELECTION flag in the later commit that will add also the implementation. So that this commit can be merged even if the next part is not done.

::: tests/test-widget.c
@@ +343,3 @@
 	{
+		gtk_source_view_set_draw_spaces_for_location (self->priv->view,
+							  GTK_SOURCE_SPACE_LOCATION_ALL,

Align parameters on the parenthesis.
Comment 23 Robert Roth 2014-10-11 01:25:55 UTC
Created attachment 288264 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
This will have several benefits, including the possibility to add a Selection
location
to only show the whitespaces in selected text.
Comment 24 Robert Roth 2014-10-11 01:28:33 UTC
Next iteration of the patch attached.
I couldn't get the docs to show the new symbols, tried with 
 ./autogen.sh --enable-gtk-doc
 make

Is there anything else I have to do to make the docs?
Comment 25 Sébastien Wilmet 2014-10-11 11:48:04 UTC
(In reply to comment #24)
> I couldn't get the docs to show the new symbols, tried with 
>  ./autogen.sh --enable-gtk-doc
>  make

You can add --enable-gtk-doc in your jhbuildrc, see for example:
https://people.gnome.org/~swilmet/jhbuildrc-latexila

> Is there anything else I have to do to make the docs?

Yes, I forgot that, in the docs/reference/ directory, see the files gtksourceview-3.0-sections.txt and gtksourceview-3.0-unused.txt (the latter is generated by GTK-Doc).

If you need more details, see the GTK-Doc manual:
https://developer.gnome.org/gtk-doc-manual/unstable/
Comment 26 Sébastien Wilmet 2014-10-11 11:57:51 UTC
Review of attachment 288264 [details] [review]:

Still a few comments. From the previous review you also forgot to add blank lines at several places (e.g. before a "return" at the end of a function, or after a block).

::: gtksourceview/gtksourceview.c
@@ +149,3 @@
+	/* Mapping for GtkSourceSpaceLocation -> GtkSourceSpaceType
+	* with gint <-> gpointer conversions
+	*/

The *'s should be aligned, of course.

@@ +968,3 @@
+{
+	view->priv->draw_spaces_at_location = g_hash_table_new (NULL,
+								NULL);

For small parameters, you can have them all in one line.
Add also a blank line after this one.

@@ +1003,3 @@
+	init_draw_spaces_at_location (view);
+
+

Only one blank line is enough, see the HACKING file.

@@ +2127,3 @@
+		result = GTK_SOURCE_SPACE_TYPE_TAB;
+	}
+	if (g_unichar_break_type (c) == G_UNICODE_BREAK_NON_BREAKING_GLUE)

A "else if" is better, also for the next conditions.

::: gtksourceview/gtksourceview.h
@@ +132,3 @@
+ * GtkSourceSpaceType:
+ * @GTK_SOURCE_SOURCE_SPACE_TYPE_SPACE: whether the space character should be drawn.
+ * @GTK_SOURCE_SOURCE_SPACE_TYPE_TAB: whether the tab character should be drawn.

Hrm, please describe those symbols as simply:
"space character"
"tab character"
etc

So the enum can be used for other purposes than drawing.

@@ +163,3 @@
+typedef enum
+{
+        GTK_SOURCE_SPACE_LOCATION_ALL        = 0x7f,

Please put "ALL" at the end, since it is a sum of all the previous flags.
Also, is 0x7f the correct value? I think it was not updated when removing SELECTION.
Comment 27 Robert Roth 2014-10-11 13:00:25 UTC
Created attachment 288271 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
This will have several benefits, including the possibility to add a Selection
location
to only show the whitespaces in selected text.
Comment 28 Robert Roth 2014-10-11 13:02:58 UTC
Yet another iteration, fixes based on last review.

(In reply to comment #26)
> Also, is 0x7f the correct value? I think it was not updated when removing
> SELECTION.
0x7f is 1111111, so it does not have to be updated until we have more than 7 location flags.
Comment 29 Robert Roth 2014-10-11 13:08:17 UTC
Created attachment 288273 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
* Added gtk-doc
This will have several benefits, including the possibility to add a Selection
location
to only show the whitespaces in selected text.
Comment 30 Sébastien Wilmet 2014-10-11 14:15:29 UTC
Review of attachment 288273 [details] [review]:

Still a few comments… If you don't understand something, you can ask questions, but I think it's clear enough.
That said, those comments are really small problems.

::: gtksourceview/gtksourceview.c
@@ +3992,3 @@
+
+	GHashTableIter iter;
+	gpointer key;

Hum, please read _all_ comments in a review, I've already said at least TWO times to put variable declarations at the beginning of a block!

@@ +4003,3 @@
+		}
+	}
+	gtk_widget_queue_draw (GTK_WIDGET (view));

And please add a blank line after the "while" block, I've already said that several times…
Comment 31 Robert Roth 2014-10-11 14:35:16 UTC
(In reply to comment #30)
> 
> Hum, please read _all_ comments in a review, I've already said at least TWO
> times to put variable declarations at the beginning of a block!
Sorry for testing your nerves, that's not my intention. I always read all the comments and fix them one by one as reading through, and I am absolutely sure I have fixed at least two of these. I must have missed some.
> 

> And please add a blank line after the "while" block, I've already said that
> several times…
Yes, and I have also done that several times, after my last patch submit I have even resubmitted it in a matter of minutes to fix two such issues.

I will check the resulting diff twice now to make sure no such issues will slip in anymore. Sorry for the trouble, I will pay more attention in the future.
Comment 32 Robert Roth 2014-10-11 14:45:35 UTC
Created attachment 288277 [details] [review]
Fine-grained control for drawing whitespaces. https://bugzilla.gnome.org/show_bug.cgi?id=683678

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
* Added gtk-doc entries
This will have several benefits, including the possibility to add a Selection
location to only show the whitespaces in selected text.
Comment 33 Sébastien Wilmet 2014-10-11 15:12:57 UTC
When I add a comment in a review, sometimes I suppose that the surrounding context is updated accordingly, or that the problem is fixed at other similar places.
Comment 34 Sébastien Wilmet 2014-10-11 15:16:13 UTC
Review of attachment 288277 [details] [review]:

Finally ready to be merged (after the freeze).
Just a minor problem that can be fixed just before pushing the patch: the commit message must have a blank line after the title. And the link to bugzilla can be at the end (it's done automatically with git-bz for example).
Comment 35 Robert Roth 2014-10-11 15:21:42 UTC
(In reply to comment #34)
> Finally ready to be merged (after the freeze).
As we're after the GNOME 3.14 release, which freeze would that be?

> Just a minor problem that can be fixed just before pushing the patch: the
> commit message must have a blank line after the title. And the link to bugzilla
> can be at the end (it's done automatically with git-bz for example).

I've pushed it with git bz attach, so I'll remove the link next time, that way the blank line will come right after the title.
Comment 36 Robert Roth 2014-10-11 15:51:34 UTC
Created attachment 288281 [details] [review]
Fine-grained control for drawing whitespaces.

* Added new enums GtkSourceSpaceLocation and GtkSourceSpaceType.
* Added new functions for setting the types of whitespaces to show
per location.
* The old function set_draw_spaces uses the new function internally.
* Added convenience values for ALL locations ans ALL space types
* Added gtk-doc entries
This will have several benefits, including the possibility to add a Selection
location to only show the whitespaces in selected text.
Comment 37 Robert Roth 2014-10-11 15:53:27 UTC
Review of attachment 288281 [details] [review]:

Marking as commit after freeze as per review from comment #34, the only change here is the change in the commit text.
Comment 38 Sébastien Wilmet 2014-10-11 16:27:37 UTC
The master branch is still for GtkSourceView 3.14. After the release of 3.14.1 this monday, we'll create the branch gnome-3-14 so the freeze ends.
Comment 39 Paolo Borelli 2014-10-11 20:19:14 UTC
I am sorry if I jump in so late after all this work has been done and I should probably read more carefully the whole bug discussion, but before checking the code or the APi, can someone explain me what is the use case we are trying to address here? What is the feature we are trying to expose to the final users? How would the UI look like?
Comment 40 Robert Roth 2014-10-11 20:48:36 UTC
(In reply to comment #39)
> I am sorry if I jump in so late after all this work has been done and I should
> probably read more carefully the whole bug discussion, but before checking the
> code or the APi, can someone explain me what is the use case we are trying to
> address here?
> What is the feature we are trying to expose to the final users?
Paolo, I wanted to tackle bug #737796 (based on a downstream requirement) and have as much as possible upstreamed. Sébastien pointed me to this bug. So the final use case I would like to handle is showing whitespaces only in selected text.
This bug shows that other people would find it useful too (e.g. I find myself most of the time checking whitespaces just to see whether there's a trailing whitespace or whether the leading whitespaces are all tabs/spaces)

> How would the UI look like?
For the basic setup the current user interface (checkbox to show/hide all whitespaces) is enough, for most advanced setups (some of which have been possible with the old API too) most editors didn't provide an UI, but if required, editors can implement it.
Comment 41 Sébastien Wilmet 2014-10-11 20:59:05 UTC
See also Comment 15 for a use-case and a possible UI. I think it makes sense, and with the ALL flags it's still convenient to use for a basic usage.

Robert: can you explain in bug #737796 what's your use case for the selection?
Comment 42 Paolo Borelli 2014-10-12 07:47:51 UTC
So it seems to me that we have this use case:

1) show white spaces in the selection

which could be addressed by simply adding a flag to the current API.


However there is a further use case that would not be addressed by the flag:

2) draw only trailing spaces in the normal view, but show all spaces in the selection


It seems to me that we could just have set/get_draw_spaces_in_selection() that takes the same flags.
I think it would be more self explaining, it would not require deprecating what we already have, and it would not introduce two new enum types.
Comment 43 Paolo Borelli 2014-10-12 09:43:19 UTC
One of the reasons why I do not like the Location enum approach is that using the getter would be awkward: you just have to try to get the value for all possible locations
Comment 44 Robert Roth 2014-10-12 13:24:24 UTC
Created attachment 288311 [details]
Sublime screenshot

Users can see if the selected text uses spaces or tabs and how
many levels of indentation is present.

In the attached screenshot you can see that in action, how easy it makes spotting incorrect indentation characters, without cluttering the whole interface with whitespace chars.
Comment 45 Sébastien Wilmet 2014-10-12 15:54:00 UTC
If we use LOCATION_ALL for the setter, for convenience the getter should also work with LOCATION_ALL. Either by doing an AND of all space types for each provided location, or doing an OR. The OR is easier and gives the same result if only LOCATION_ALL is used.

In my opinion having two enums is better, to clearly separate locations and space types. Combining them is more powerful.
Comment 46 Sébastien Wilmet 2014-10-13 12:24:20 UTC
So, bad news, Paolo wants to close this bug as WONTFIX, but I don't agree. Here are the reasons he gives (on IRC):

> it does not map properly to gobject properties

Not every state can be represented as a single property. To find a similar problem already solved in another library, we don't need to look far: GtkWidget has 4 properties for the margins, for each location. Plus one property "margin" that sets the same value to all margins, and that gets the maximum margin.

Here it is similar. For each location we want to be able to store a different value. It's not rocket science!

> the getter is broken
> it is broken because it is a getter without an underlying property
> it makes dealing with settings a lot harder

Do you prefer one property for each location? That way the gsettings binding works.

But what are the advantages of properties?
- the notify signal: we can replace that with a normal signal, if needed (but I think it's useless).
- property bindings: a text editor doesn't need that for space drawing. The setter is called normally at only one place.
- gsettings bindings: it can easily be replaced by a small function, it wouldn't be a lot of code, and there can be only one gsetting that stores a list of values, instead of one gsetting for each location (so the four properties is not really convenient in that case).
- GtkBuilder/glade: you can not build an entire app with glade… Some code is always needed. The GtkSourceView object is anyway useful to retrieve in the code, so calling a setter function in init() is not the end of the world.

> it is aesthetically unpleasing

It's subjective. I prefer the two enums, they are smaller and clearer. Defining the space types for each location is natural to me.

> it adds a lot of api (2 new types) and even if the old gets deprecated, it still means having 3 types + 4 functions in the public api for a while

GtkWidget has 5 properties and 8 functions just for margins. A deprecated API doesn't count.

I think having just a setter and getter is sufficient. Dealing with space drawing in an application is not difficult. An application not interested in the full flexibility can anyway use ALL on one or both axis.

And, as I've explained, there are real use cases where defining different space types for each location is desirable:

- for C code following the GNU coding style: draw all spaces except normal spaces for leading spaces + spaces inside text. For trailing spaces: draw all kind of spaces. The purpose is to draw spaces only when they are not allowed. Lots of people don't like having all spaces drawn everywhere all the time. And if all spaces are always drawn, it adds more noise for locating space errors.

- for LaTeX: draw only non-breaking spaces for leading spaces + spaces inside text. For trailing spaces: draw all kind of spaces. Non-breaking spaces can lead to strange errors when generating the PDF, and it is really hard to diagnose the first time. If only non-breaking spaces are drawn inside the text, the error is much more visible.

And that is just two use cases for me. Other people have probably other use cases in other languages and other coding styles.
Comment 47 Paolo Borelli 2014-10-13 13:03:21 UTC
(In reply to comment #46)
> So, bad news, Paolo wants to close this bug as WONTFIX

This is not correct. I said I do not like the api that uses the two enums because it leads to a matrix-like property, and I consider that bad for many reasons.


I am ok with implementing the support for selection, and I think the API I proposed in comment #42 addresses that specific use case which I think is relevant
Comment 48 Sébastien Wilmet 2014-10-13 14:42:50 UTC
This bug is about "Visibility of leading, internal and trailing spaces for individual types of whitespaces", and you don't want to fix that. See bug #737796 for the selection.

What we agree on is: for trailing spaces and selection, it's not needed to specify which types of spaces to draw; all kind of spaces should be drawn for those locations. So we could have two boolean properties for those locations.

But for leading and internal spaces, it should be possible to specify which types of spaces to draw, independently of each other. So we can add two SpaceType properties for that.

But having four properties just for drawing spaces is a bit too much. With only two functions it's possible to achieve the same, but with even more flexibility.
Comment 49 Robert Roth 2014-10-21 18:23:38 UTC
So, which way should we go? How do we get to a consensus here? The API from comment 42 is a lot easier to implement than the current proposed patch, but not as flexible. Are the usecases for this flexibility phantom requirements?
Comment 50 Sébastien Wilmet 2014-10-22 14:12:55 UTC
> Are the usecases for this flexibility phantom requirements?

I think I've given real use-cases. Maybe Paolo doesn't want this flexibility for gedit (especially for the UI), but there are other text editors and IDEs in the wild that uses GtkSourceView.
Comment 51 Sébastien Wilmet 2014-12-03 13:00:38 UTC
If we use a GVariant property everybody should be happy. g_param_spec_variant() exists. We must find a variant type that works fine when the GtkSourceSpaceLocation enum is expanded in the future. For example "ai", an array of integers. Each int would store the SpaceType flags for a specific location.
Comment 52 Robert Roth 2015-01-15 13:10:56 UTC
Paolo, do you agree with swilmet's proposed solution of having an "ai" g_variant setting for the source space flags?
Comment 53 Sébastien Wilmet 2016-09-25 17:26:18 UTC
Done!

With a "au" GVariant property.

commit bfffea8beb9bd9e6c1d35f2b52d504e9dd9eaa93 and previous commits.