Confusing/Frustrating folding behavior
-
Hello,
Using version 8.9.6.4 s4-bit
Windows 11
Language: PythonI’ve noticed this for awhile, even in previous versions.
I normally like to keep my functions folded so I can navigate easily, unfolding them as needed, when editing, then folding them back up.My issue is that often, not always, but often, once I fold the function back up, the FUNCTION BELOW IT has somehow opened, so I close THAT one and…
The NEXT one is now unfolded, so I fold that…
This continues all the way down my file. I will have to manually fold every. single. function. And no, I am not forgetting to fold them up and only noticing it later. I at first thought that was what was happening, but no, they are unfolding on their own. Sure, I can fold them up again, but it is annoying. Also, it doesn’t always happen. Only sometimes.
-
That sounds similar to Issue #18093, where the seemingly-random unfolding was happening for a UDL instead of for Python. In that issue, it’s because of the presence of a comment in the second block (but my experiment below shows that’s not the case for the python folding… at least, not the sole cause)
I don’t know if it’s related or not. Can you share a small piece of code (maybe 3 blocks long) that shows the problem if that’s all you have in the file? For example, I cannot replicate your problem with
def first(): more() return def more(): # commented pass def most(): first() more() returnI will have to manually fold every. single. function
Well, that’s the easy part.
Alt+0folds everything with one keystroke (the default keystroke for View > Fold All). -
@PeterJones Thanks for the keyboard shortcut. I’m embarrassed to say I never considered that approach. But here are some function blocks. I’m doing this quick and dirty right now, so forgive the inelegant code.
(This is for a character generator for an obscure RPG you probably haven’t heard of)
def get_bonus(self, score): if score > 18: return "+4" elif score > 16: return "+3" elif score > 14: return "+2" elif score > 12: return "+1" elif score > 8: return "+0" else: return "-1" def roll(self, n=1, d=6): total = 0 for i in range(n): total += randint(1, d) return total #CLASS FUNCTIONS def choose_class(self): print( """First, choose your character's class by entering the letter of your choice: WARRIORS MAGICIANS SPECIALISTS -------- --------- ----------- A) Amazon F) Elementalist K) Hunter B) Barbarian G) Lyrist L) Thief C) Centaur H) Nymph D) Noble I) Priest E) Spearman J) Sorceror """) while True: self.code = "" self.code = input("Your Choice [A-L]: ")[0].upper() if self.code in "ABCDEFGHIJKL": break match self.code: case "A": self.char_class = "Amazon" self.primary = Stat.SKILL self.secondary = Stat.GRACE case "B": self.char_class = "Barbarian" self.primary = Stat.MIGHT self.secondary = Stat.WILL case "C": self.char_class = "Centaur" self.primary = Stat.MIGHT self.secondary = Stat.SKILL case "D": self.char_class = "Noble" self.primary = Stat.LUCK self.secondary = Stat.OTHER case "E": self.char_class = "Spearman" self.primary = Stat.SKILL self.secondary = Stat.WILL case "F": self.char_class = "Elementalist" self.primary = Stat.WILL self.secondary = Stat.WITS case "G": self.char_class = "Lyrist" self.primary = Stat.GRACE self.secondary = Stat.LUCK case "H": self.char_class = "Nymph" self.primary = Stat.GRACE self.secondary = Stat.LUCK case "I": self.char_class = "Priest" self.primary = Stat.WILL self.secondary = Stat.LUCK case "J": self.char_class = "Sorceror" self.primary = Stat.WILL self.secondary = Stat.WITS case "K": self.char_class = "Hunter" self.primary = Stat.SKILL self.secondary = Stat.WITS case "L": self.char_class = "Thief" self.primary = Stat.WITS self.secondary = Stat.LUCK case _: # Default action if no other case matches print("ERROR") exit() -
But here are some function blocks
Sorry, I cannot get it to replicate your problem description. Maybe it has to do with the way you pasted it into your post – I had used moderator powers to move the ``` to the beginning of the line, so it would actually do the full code as a block in the forum… but the indentation didn’t seem consistent even after that. But whether (1) I try with get_bonus() fully on the left, with its contents double-indented, and the the roll() and choose_class() are both one level indented more than the start of get_bonus(); or whether (2) I indent choose_class() to match the other two; or whether (3) I do 2, but also prefix with a dummy class header – no matter which of those I do, I cannot replicate your problem.
Can you confirm whether the indentation matches what you’re using… and if not, post the code again, more carefully, so that we get an exact representation of your indentation (and maybe a screenshot of what it looks like in Notepad++, to make sure). And then, a blow-by-blow account of the actions you take, like, “I fold get_bonus(), fold roll(), fold choose_class(), then when I unfold roll(), work in it, and edit something inside it (be detailed), and fold it back up again, then choose_class magically unfolds” – or even more detailed, including line numbers, and exact things you type. Because unless someone can replicate your problem, it will be hard to help you.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login