-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cursor issue in Markdown files #5
Comments
I believe this is because Markdown does not use indents to convey nesting of contexts. And this is an assumption of the Breadcrumbs plugin, that to find breadcrumbs you can simply find the lines with particular indentation. I was well aware that this is a limitation, but one that that lets me cover many languages at once without having to parse them. I believe that it would be hard to use indentation in a Markdown file just to fit this plugin needs. So, perhaps we should add a way to define a language specific config file which would hint how the hierarchy of concepts works for a particular language. Do you see some easy way to specify such rules? |
Ah, that makes sense. Yeah, I though of something like a solution for this, a For JSON files, hierarchy is based on number of {
"hello": "hi", // nestlevel-1
"nest": {
"hello2": "hi-again" // nestlevel-2
}
} For Markdown, hierarchy is based on amount of If you could define a regex group nestlevelgroup = match.group('nestlevel')
nestlevel = len(nestlevelgroup) For Markdown, '##' would return a nest level of 2, '###' a nest level of 3. It would look something like (this paragraph is probably kind of confusing, it's not essential atm) |
I like the simplicity of this idea. The issue with whitespace is even more complicated than you have already noticed: one can mix tabs with spaces in a way where it is not so simple to tell what is the final amount of indent without carefully checking the reminders modulo 4 of the current column number before tab. You can see the code for that which is copied from some example plugin for reindent. Perhaps, a more general solution would be to allow people to define a hierarchy as a tree in which each node has a regex. Or instead of using regexes, which is always a hack, just tap into the Sublime's token info API. |
You could solve this problem with two functions, a hierarchical element extractor, and a numerical function:
I'm not saying the Python function should be a lambda, it's just for easier notation purposes. Examples1. Markdownhel helnum
2. Pythonhel
helnum Note that the regex doesn't take into account tabs; for a real implementation, the author of the Python hel can use or statements to deal with various styles of indentation 3. HTMLThis one is more interesting, there are different kinds of hierarchies that the end-user might be interested in. When you're building a website, you want to see what the parent element of the element you're currently writing is. When you're writing a blog post, you want to see in what context you're writing in. There are probably more kinds of hierarchies that are useful to extract. Good thing is, with this approach, you can support either, if you want indentation-based hierarchy, write a helnum-function that retrieves Sublime's indentation (i.e. are you using two-space tabs, three-space tabs, four-space tabs ...?) If you want the other, write a 4. LaTeXLaTeX is a complex beast. It requires a case-study of its own to be honest. I'm fairly certain you could use the approach showed above to extract hierarchical elements out of LaTeX source code, the big question for LaTeX is only, what hierarchical elements are significant to the user? I think only the user knows. Easy things should be easy, hard things should be possible; as long as the above two primitives,
I understand the concern, but I don't think it's worth focusing on this issue in particular, this plugin's purpose is to show relevant hierarchical context. If you're working in a file that has a messed up hierarchy, I'd say too bad. Yes, there are programs out there that can deal with complex messes like these, the HTML parsers embedded in modern browsers are good examples, they deal with many weird off-spec html messes, all of these render just fine as complete documents: Sublime itself also has an answer for this same issue, try opening a JSON file with inconsistent indentation, tabs mixed with spaces, sometimes 3-space indentation, sometimes 1-space, etc... Sublime's indentation guessing feature suddenly doesn't work anymore, it's just not worth it. The only downside I see right now is that someone who likes this plugin loads a document from the internet, the indentation is messed up, and this plugin won't work. Well, too bad? :S It only needs to be correct when the users wants it to be correct. AnyhowDespite this big post, another important question to ask is, do you need to be general? Do you think that this plugin will be so popular that it must support the most complicated languages? An alternative would be to roll with a simple solution like the one I proposed, and deal with insane complexities of the likes of LaTeX when the need arises, if ever. |
I like your idea.
to something you've described.
to extract the The main concern here is that this must work extremely fast. This function will be called for each of preceding lines. I see a potential problem here, as running I was using this file:
And looked into the console (which you open with ctrl+backtick) for the output. |
Unfortunately, no. I have (too) many projects I'm perpetually working on for myself, taking on another one is not high on my priority list. However, I'm be fully willing to help you test future updates, or discuss issues with you. |
For this case, I think it's really easy to solve it with hash-bashed memoizations, since a lot of the text won't change very often (especially true if the file is very large), you could compute a short hash for each line, cache the results of the regexes, and only recompute a given line if it's not in the cache. |
Nice idea! Thank you. |
I'm trying to get breadcrumbs to work in Markdown files, to show the nesting of headers (#, ##, ###, ####, #####, #######) in succession.
I came up with the following RegExp
^#{1,6}\\s*(?P<name>.*)
Which I test using Sublime's find function after slightly modifying it
^#{1,6}\s*(.*)
(removing\\s
and(?P<name> ......)
because those are not supported by the find function in contrast to sublime's config regexes)But if I insert the RegExp in the breadcrumbs setting for markdown specific syntax, I only get a breadcrumb for the line that is directly above my cursor, see the below images
When I move my cursor right below the heading line, it shows up fine
But when I move my cursor one line down, no more breadcrumbs :(
Is something wrong with my RegExp, or is this a plugin issue?
The text was updated successfully, but these errors were encountered: