@@ -234,8 +234,10 @@ and the supported values associated with them:
234
234
* - Key
235
235
- Supported values
236
236
* - ``indent_style ``
237
- - Set to ``tab `` or ``space `` to use hard tabs or soft tabs respectively. The
238
- values are case insensitive.
237
+ - Set to ``tab `` or ``space `` to use tabs or spaces for indentation, respectively. Option ``tab ``
238
+ implies that an indentation is to be filled by as many hard tabs as possible, with the rest of the
239
+ indentation filled by spaces. A non-normative explanation can be found in the indentation _ section.
240
+ The values are case insensitive.
239
241
* - ``indent_size ``
240
242
- Set to a whole number defining the number of columns used for each
241
243
indentation level and the width of soft tabs (when supported). If this
@@ -285,6 +287,74 @@ Pair keys are case insensitive. All keys are lowercased after parsing.
285
287
Cores must accept keys and values with lengths up to and including 1024 and 4096 characters respectively.
286
288
Beyond that, each implementation may choose to define its own upper limits or no explicit upper limits at all.
287
289
290
+ .. indentation:
291
+
292
+ Indentation (Non-Normative)
293
+ ===========================
294
+ The indentation related options (``indent_style ``, ``indent_size `` and ``tab_width ``) require a special documentation
295
+ section to specify their behavior. Consider the following code snippet:
296
+
297
+ .. code-block :: python
298
+
299
+ def execute ():
300
+ source = " indentation is important"
301
+ for i in source.split(" " ):
302
+ print (i)
303
+
304
+ The ``indent_size `` setting for this code snippet equals 4, because ``indent_size `` means how many columns are required
305
+ to indent the next line in relation to previous (if indentation, of course, is applicable for this line). Then the next question
306
+ is *how * this indentation of 4 columns is achieved. It may be 4 consequent spaces/soft tabs,
307
+ a single tab with width equal to 4, or two tabs with width equal to 2.
308
+
309
+ This is when ``indent_style `` comes into picture. It specifies what character should be used **whenever possible ** in order to
310
+ achieve the indentation size specified in ``indent_size ``. To fully understand what "whenever possible" actually means, lets
311
+ assume that the editorconfig rules are specified for the file above:
312
+
313
+ .. code-block :: ini
314
+
315
+ root = true
316
+ [example_file.py]
317
+ indent_style = tab
318
+ indent_size = 4
319
+ tab_width = 3
320
+
321
+ The ``indent_size `` of 4 is not achievable by placing 1 or 2 consequent tabs, because ``tab_width = 3 ``. Therefore,
322
+ in order to comply with this EditorConfig configuration, the new lines (where indentation is applicable) **must be precisely
323
+ indented with one tab, and one space **. That is because by placing one tab we're not achieving the ``indent_size `` required, but by
324
+ placing the 2 consequent tabs we're overreaching. Therefore, although ``indent_style `` is ``tab ``, we still have to supplement
325
+ with one space character to fulfill the requirement.
326
+
327
+ For another example, if we have the following EditorConfig rules defined:
328
+
329
+ .. code-block :: ini
330
+
331
+ root = true
332
+ [another_file.py]
333
+ indent_style = tab
334
+ indent_size = 8
335
+ tab_width = 4
336
+
337
+ One **MUST ** expect that spaces will not be used at all for indentation, since all the indentation can be achieved via tabs only.
338
+
339
+ Additionally, it is possible to have ``indent_size `` less then the ``tab_width ``.
340
+
341
+ [another_file.py]
342
+ indent_style = tab
343
+ indent_size = 4
344
+ tab_width = 8
345
+
346
+ To understand the way it works, let's look at the following example:
347
+
348
+ .. code-block :: python
349
+
350
+ def func ():
351
+ if True :
352
+ return True
353
+
354
+ In this case, the line where the ``if `` statement condition is specified is indented with 4 spaces, because the ``indent_size = 4 ``
355
+ and the tab cannot fit in. On the other hand, the line with ``return `` statement must be indented with one tab, because the
356
+ indentation level for this line is 8 columns, and a tab can fit in.
357
+
288
358
Suggestions for Plugin Developers
289
359
=================================
290
360
0 commit comments