Basic Language and Folding Questions
-
@PeterJones
I’m not sure if this can be done so easily, as different lexers use different folding strategies.
Basically, a lexer puts a mask on a line and if the next line has a higher value than the previous one, scinitilla adds the fold point.
But to be honest - I haven’t dug enough to be 100% sure.
I’ll see what I can get out of it. -
No, I don’t see a reasonable way to do this, mainly because
a lexer will eventually overwrite what a python script did. -
Hmm maybe I’m wrong - the python script is always called after the lexer, so it’s just a matter of figuring out how the lexer does it in the first place.
-
@Ekopalypse said in Basic Language and Folding Questions:
a lexer will eventually overwrite what a python script did.
Oh, right. I hadn’t thought about that implication, since the lexer is constantly re-parsing as things change…
Sorry @David-Lin , as of now, it doesn’t look like adding new folding to a lexer is possible.
While I was typing, @Ekopalypse added,
Hmm maybe I’m wrong
Well, that gives a glimmer of hope, anyway.
@David-Lin , the other long-term possibility might be to put in a request with the Scintilla project, because the lexers are inherited from the Scintilla IP. But then they would have to decide to add the folding to the SQL lexer (assuming that the new folding was generic enough that other people would want folding there, too – and not just something specific to your unique circumstances) and release a new Scintilla… and after that, you could start lobbying the Notepad++ developers to update Scintilla – but they rarely do that (it can go years between Scintilla updates in Notepad++).
Of course, if @Ekopalypse ever gets the right Round Tuit™, it may become easier for people to decide to write their own lexers, so that we are not beholden to the limited set that Scintilla includes or the limited syntax for UDL.
-
There is already a file HowToCreateAScintillaLexer.txt on my computer :-)
-
@PeterJones and @Ekopalypse thanks for the answers!
From a basic user’s perspective, it is very helpful to know that it is complicated and not easily done.If it’s proprietary as you say/believe - it is unfortunate that there is no way to get into the code the get a list of the folding words and characters. Especially since, from my perspective, nesting /folding of code across all languages isn’t a property unique to a language the way keywords and specific functions are.
While for some languages, there are very clear aspects of the coding that make many elements of nesting super obvious like in xml…
At least in my case, for SQL it is just a guessing game of what the developers decided will make the code fold.I’m sure this may have been discussed to death, but maybe indent-based code folding as an option could help. Do you know if there is any simple solution to do this?
-
@David-Lin said in Basic Language and Folding Questions:
maybe indent-based code folding as an option could help
I know the Python language lexer uses indent-based folding. But once again, that’s not transferrable to any other arbitrary lexer, and the UDL does not implement indent-based folding.
Especially since, from my perspective, nesting /folding of code across all languages isn’t a property unique to a language the way keywords and specific functions are.
From my perspective, it very much is language dependent. In Python, indenting is the only way of indicating blocks; in Perl, indentation only matters for the human reader, and blocks are defined by {}. In other languages, there are keywords like BEGIN/END or FOR/NEXT or IF/ELSE IF/ELSE/ENDIF which will define levels. Each lexer only codes in the level-determining code necessary for its language, because each lexer is completely separate. (And, once again, that’s not something that’s likely to change in Notepad++, because Notepad++ just passes along the lexers that were released with Scintilla.)
-
The source code is publicly available and the folding function
is this one. -
@Ekopalypse said in Basic Language and Folding Questions:
The source code is publicly available and the folding function
is this one.Great! Thank you!
-
@PeterJones said in Basic Language and Folding Questions:
@David-Lin said in Basic Language and Folding Questions:
maybe indent-based code folding as an option could help
I know the Python language lexer uses indent-based folding. But once again, that’s not transferrable to any other arbitrary lexer, and the UDL does not implement indent-based folding.
Especially since, from my perspective, nesting /folding of code across all languages isn’t a property unique to a language the way keywords and specific functions are.
From my perspective, it very much is language dependent. In Python, indenting is the only way of indicating blocks; in Perl, indentation only matters for the human reader, and blocks are defined by {}. In other languages, there are keywords like BEGIN/END or FOR/NEXT or IF/ELSE IF/ELSE/ENDIF which will define levels. Each lexer only codes in the level-determining code necessary for its language, because each lexer is completely separate. (And, once again, that’s not something that’s likely to change in Notepad++, because Notepad++ just passes along the lexers that were released with Scintilla.)
Got it. thanks for the explanation - now i understand why my use case in SQL is different than the intent of the built-in code folding. For me, there are not generally large blocks of code between “level-determining code necessary for its language”, because in my use for preparing data tables, there is little purpose to long nested statements or loops, just moving around and rearranging data for other programs to eventually access and do analysis looping etc… occasionally there is a very long nested query. Procedures that might involve longer segments of code within loops are quite painful in SQL.
For my use, I am separating large sections of code into my subjective segments that I would like to see nested, but these are not exactly “necessary” for the language.