When writing Python code in the body pane, I see the cursor position
so I can watch the line length to not exceed a certain value. However, when a line gets written into a derived file, its length may increase (due to indentation) and pylint complains about long lines. This is a situation I'd like to avoid. Any suggestions?
> Interesting question.
>
> Let us define p.fileLevel() for any position p as follows: p.fileLevel() is
> 0 if p is not a descendant of any kind of @file node. Otherwise, suppose
> root is the position of the enclosing @file node (or @thin node, etc.)
> p.fileLevel() is p.level() - root.level() and the "effective" column is the
> node's column plus p.fileLevel() * c.tab_width. This could be displayed in
> the status line.
I must admit I lack knowledge to implement this (I've got no
experience with Python GUI programming at all). Would this feature
appear in the next leo release?
The question that popped up today after diving into the souces of leo is: why one shall
associate fileLevel with a position, not with a vnode directly (to be
more exact, with that v, that is passed to p.__init__() and becomes p.v)?
> Would you guys mind if I post a small patch here so we could discuss
> it?
Can't see a problem as long as it's not too big.
What are you doing? Adding scroll bars to bodytext?
Cheers -Terry
I've been trying to implement the feature discussed in the first two
posts of this thread.
I'd like to point from the start that thinking about fileLevel as
being a multiple of c.tab_width is wrong.
Ok, it is true for derived
files that contain Python code, but that's because Python is very
strict about indentation. For other languages (like C), another
approach is needed.
I would like to think that my algorithm is good, because it walks the
outline branch only once, from c.currentPosition() up to min (root, a
derived file node). But feel free to criticize or improve it.
A special note: I do admit that some of the variable names are kinda
ugly and long. Feel free to refactor the code to make it "leo-style"
in terms of variable names.
Edward, in your initial reply you actually introduced fileLevel by
describing the algorithm of its computation.
The implementation of
p.level() doesn't contain a docstring. The "and" between a class
instance and an integer is a bit confusing, but seeing len(p.stack)
there, I can conclude that p.level() shows how "deep" a node is placed
in the outline
And p.fileLevel() must show how "deep" a node is placed in a derived file subtree.
that it has a wrong name, because it calculates the offset of the text
contained in a node in the derived file this node belongs to.
This idea is absolutely different.
However, I think it is more exact to say not "I want to be able to
detect overly-long lines when a file subtree gets written into a
derived file", but "I want to be able to watch the line length
(interactively, as I type), and this line length shall be relative to
the derived file it gets written to, not to the node it belongs".
Speaking in terms of leo GUI, "col" is the cursor position in the body
panel (relative to the current node), we introduce "fcol" as in "file
col", that is relative to the flat derived file this node gets written
to.
So writing the whole file, even to a string, every time when the
cursor position in the body panel changes (please correct me if I'm
getting your idea wrong) is a waste of time.
Then please tell me what are the requirements for this to happen.
Would you take care to add the code to trunk yourself or there's
something else I shall do first?
@test languageForExtension fails. Did this not fail for you?
Please fix this by defining the new extension in extra_extension_dict.
Edward
Oh. I forgot to mention that you have to remove the entry in extension_dict :-)
I'm letting you do this work yourself so you can get experience with
the unit tests. This is essential as we get more and more people
adding to Leo.
The point is that Leo makes assumptions about entries in
extension_dict, namely that there are corresponding entries in
leo/Modes. You don't necessarily have to know about these
assumptions, but the unit tests will remind you that something isn't
right.
Edward
> However, this thread got a bit messed. Let's go back to the original
> topic. Please update the site docs. You shall see a new screenshot
> after that (which shows 3 numbers in the status area) and a new FAQ
> entry (I've considered this to be the best place) which describes the
> feature. Feel free to modify the docs if you will consider that the
> feature is not explained well enough.
>
> The link should be http://webpages.charter.net/edreamleo/FAQ.html#how-can-i-avoid-getting-long-lines-in-derived-files
I've just updated the FAQ. Thanks for this work.
Edward
Sorry about that. I'll fix this today.
Edward