-
Notifications
You must be signed in to change notification settings - Fork 30
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
Linkifying function doesn't strip certain Org markup from headers #3
Comments
Thx for testing and submitting!
|
It seems like org itself doesn't treat headings that are a links properly. If I call So, I guess, such scenarios should be fixed in org first. (For example, in the same way GitHub handles this). For now, I'm closing this. |
Would you mind if I'd hand in a workaround for this? |
It depends on what you have in mind. If it's going to be a "more or less legitimate hack", we could consider adding it. From what I've seen so far, I think the issue should be fixed on Org side first. But maybe I just don't see an existing good solution. |
My idea is simply adding an extra filter into the |
I've pushed a TOC to Github now and noticed that I didn't want to strip links, it was the Org markup that isn't displayed inside links... Assuming I have a |
Ok, I see. I guess it makes sense to strip the formatting from the link text. Unfortunately, I'm a bit busy at the moment, so don't know when I'll have a chance to look into it. |
That's no problem, I'll prepare another pull request once I've figured out how to do this properly. |
OK, this is sort of ugly: ;; strip emphasis
(goto-char (point-min))
;; the beginning of a headline deeper than the first level is
;; recognized as emphasis, so let's jump to the end of the
;; leading asterisks, then operate from there to the end of the
;; line to strip the markup
(while (re-search-forward "^\\*+ " nil t)
;; as the RE includes an extra space at the end, hop a char
;; backwards to recognize an emphasized piece of text
;; immediately following it
(backward-char)
(while (re-search-forward org-emph-re (line-end-position) t)
(replace-match "\\1\\4\\5")
;; see above
(backward-char))) BRB, taking a shower. |
FYI, I added alphapapa/org-make-toc@be4c1f8 to do this sort of thing by omitting any text in link descriptions that Org would normally make invisible. |
Hey, @alphapapa ! I was going to steal your implementation, but after looking at it, I see that we, once again, have different approach to the implementation =) In my opinion, such functionality can only operate with the text of the file and shouldn't rely on any "external" libs to do the work. I see that you use font-lock and |
@snosov1 I don't understand what you mean. The target platform in this case is What's the alternative? Messy regexp matching? Write your own Org parser in Elisp? Parse headings with |
Yes =) That's pretty much what I do with
Also, a valid option, if one prefers.
It depends on the definition of "safe". In my book, relying on something that the "target platform" never has access to, does not help in the safety department. Besides, in my experience, |
That seems to me too much like writing another Org parser inside of Emacs. :)
By "safe" I mean, most likely to work properly, least likely to have edge cases and unexpected behavior, etc. I don't understand why it would be necessary to use something the target platform (i.e.
That puzzles me. ISTM that font-locking in Emacs is extremely well optimized. But, anyway, we're talking here about fontifying a few words at a time in a dedicated buffer (that's how my code works, anyway; I do the same thing in |
You don't need a full-blown Org parser to generate the TOC. Both,
For this particular case, it might not be a real issue, but just me being too cautious/opinionated. However, this is where I'm coming from. I had several asks/contributions previously that would introduce new behavior that controls the look of the TOC by setting some elisp variable. You can think of That's why I have the feature of specifying For
I can't really make a competent comment on that, but try to open a 500 Mb json file (in
I see your point, But Still (tm) |
Sorry, I must be missing something: I don't understand how
And
500 MB is a very large file to open in a text editor and expect it to be fontified in a way that can depend on the entire contents of the file before point. Have you tried
So you're saying that |
Example (numbers and the actual behavior is fictional): If Person 1 and Person 2 work with the same repository, they will be constantly generating different TOCs and experience merge conflicts (one will strip equal signs and the other will not).
Well, yes. But not really. My reliance on Org is very limited - only the parts that are required for "links jumping" (
Where do I open it if not in Emacs, then? =) And as we agree - it's not unreasonable to ask for it if you are willing to sacrifice the "fancy features" - Emacs does it easily.
Yeah, I remember trying it out, but it didn't stick. I believe it didn't offer much on top of
Actually, I've never tried it before you asked. On my machine, I notice the delay becomes unfriendly (~1 sec) for a file of 1.5 Mb. Frankly, I don't know how inefficient my implementation is, but my guess is that using font-lock wouldn't help me in that regard =) |
In a hypothetical scenario as you describe, that could happen. In that case, I would suggest that the user on the older version upgrade Org. There would likely be other, more serious conflicts of behavior between such a large version gap. But if you want to handle it that way, up to you. :)
I don't know how other editors would perform fontifying a 500 MB file in its entirety at once. Maybe there are some that perform better. If you are inclined to improve Emacs' font-lock code, I'm sure patches would be welcome, haha. ;) |
I know you're the
My path to Emacs wasn't, like "Let me try this new shiny editor because I'm bored with my current editor". It was more like "I need a professional tool for life". Meaning - it's as reliable as it can get, it does only what I need/ask it to do (i.e. no bloat), it doesn't change to become unrecognizable with every release, it can work at scale (read 500Mb files, work on Android source base ~10Gb, etc.). And Emacs proved itself in situations where other tools failed miserably.
Actually, I'm more on the Douglas Crockford's side with respect to code coloring:
So, when I can have it - great. When I don't have it - I don't mind too much =) |
[runs away screaming] =) |
I've tried this on my init.org and found two examples of stripping not being zealous enough:
The text was updated successfully, but these errors were encountered: