Repository: spyder-ide/spyder

Issue:
Indent guides going too far down
Another 2c bug.

In my opinion indent guides are going too far.

![image](https://user-images.githubusercontent.com/6706662/41836946-7e959114-785c-11e8-8d9c-9d1c431c0eb2.png)

Even worst

![image](https://user-images.githubusercontent.com/6706662/41836905-5ba54230-785c-11e8-9f16-9553407d00d8.png)

Thanks.


Discussion:
I don't understand what you mean. Are you suggesting that we shouldn't show the indentation guides in those two cases?
Not exactly, I think the vertical line goes 1 or 2 lines too far (going down) – it is too long. It is clear in the 2nd example, it should not be displayed above the comment. It should stick to the concerned block.
 
 
 
De : Carlos Cordoba <notifications@github.com> 
Envoyé : lundi 25 juin 2018 18:15
À : spyder-ide/spyder <spyder@noreply.github.com>
Cc : sylvain-bougnoux <bougnoux@imra-europe.com>; Author <author@noreply.github.com>
Objet : Re: [spyder-ide/spyder] Indent guides going too far down (#7339)
 
I don't understand what you mean. Are you suggesting that we shouldn't show the indentation guides in those two cases?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
I see, thanks for the clarification.
Situation:  I am creating Python code that has no control statements at all.  Just straight down executable statements beginning in column 1.  I do this frequently for computing scalars and vectors while taking a Physics exam on-line.

I find that spyder often automatically indents when there is no reason to (no control statements).
E.g. After typing in the following statement, starting in column 1,

`print("#11 downslope acceleration:", sigfig(a,2))`

I see indentation.  So, I have to carefully space back to column 1 before starting the next executable statement.
@texadactyl, that's a completely different problem from the one reported here. Please open a new issue about it, instead of trying to hijack this one.
I thought they were similar enough.  Since Spyder has ~660 open issues, I was trying to find an existing issue though my symptom was different.  Both are indentation problems.

"Hijacked" is rather strong language.
Sorry, not an English-native speaker here (*derailed* perhaps is better). This issue is about a new feature in our master branch, so it has nothing to do with your problem.
Can confirm this is an issue, I am running Spyder 4.0.0b1 and I get something similar with the Indent Guides.

![capture](https://user-images.githubusercontent.com/11433737/44219276-7c41f680-a130-11e8-814f-3bf3c6ebe84c.PNG)

As you can see, the Indent Guide will go straight through comments, but it will stop at the first line of real python code

![capture2](https://user-images.githubusercontent.com/11433737/44219380-b7dcc080-a130-11e8-8995-b360427b0f36.PNG)

I think the Indent will keep going until there is a line of real python code, as seen below...

![capture3](https://user-images.githubusercontent.com/11433737/44219436-db077000-a130-11e8-9af2-aa944c65f010.PNG)

There are no tabs on lines 6 or 7, but the Indent Guide keeps going down until the print statement.

I hope that clarifies things Carlos, I'm loving the new additions to Spyder 4 already!


Resolving patch:
diff --git a/spyder/plugins/editor/panels/indentationguides.py b/spyder/plugins/editor/panels/indentationguides.py
--- a/spyder/plugins/editor/panels/indentationguides.py
+++ b/spyder/plugins/editor/panels/indentationguides.py
@@ -1,3 +1,4 @@
+
 # -*- coding: utf-8 -*-
 #
 # Copyright © Spyder Project Contributors
@@ -14,6 +15,7 @@
 from spyder.plugins.editor.utils.editor import TextBlockHelper
 from spyder.api.panel import Panel
 
+
 class IndentationGuide(Panel):
     """Indentation guides to easy identify nested blocks."""
 
@@ -21,7 +23,6 @@ class IndentationGuide(Panel):
     # -----------------------------------------------------------------
     def __init__(self, editor):
         """Initialize IndentationGuide panel.
-
         i_width(int): identation width in characters.
         """
         Panel.__init__(self, editor)
@@ -35,15 +36,48 @@ def paintEvent(self, event):
         color = QColor(self.color)
         color.setAlphaF(.5)
         painter.setPen(color)
+        offset = self.editor.document().documentMargin() + \
+            self.editor.contentOffset().x()
+
+        for _, line_number, block in self.editor.visible_blocks:
+
+            indentation = TextBlockHelper.get_fold_lvl(block)
+            ref_lvl = indentation
+            block = block.next()
+            last_line = block.blockNumber()
+            lvl = TextBlockHelper.get_fold_lvl(block)
+            if ref_lvl == lvl:  # for zone set programmatically such as imports
+                # in pyqode.python
+                ref_lvl -= 1
+
+            while (block.isValid() and
+                   TextBlockHelper.get_fold_lvl(block) > ref_lvl):
+                last_line = block.blockNumber()
+                block = block.next()
+
+            end_of_sub_fold = block
+            if last_line:
+                block = block.document().findBlockByNumber(last_line)
+                while ((block.blockNumber()) and (block.text().strip() == ''
+                       or block.text().strip().startswith('#'))):
+                    block = block.previous()
+                    last_line = block.blockNumber()
 
-        for top, line_number, block in self.editor.visible_blocks:
+            block = self.editor.document().findBlockByNumber(line_number)
+            top = int(self.editor.blockBoundingGeometry(block).translated(
+                self.editor.contentOffset()).top())
             bottom = top + int(self.editor.blockBoundingRect(block).height())
 
             indentation = TextBlockHelper.get_fold_lvl(block)
 
             for i in range(1, indentation):
-                x = self.editor.fontMetrics().width(i * self.i_width * '9')
-                painter.drawLine(x, top, x, bottom)
+                if (line_number > last_line and
+                        TextBlockHelper.get_fold_lvl(end_of_sub_fold) <= i):
+                    continue
+                else:
+                    x = self.editor.fontMetrics().width(i * self.i_width *
+                                                        '9') + offset
+                    painter.drawLine(x, top, x, bottom)
 
     # --- Other methods
     # -----------------------------------------------------------------


Test patch: