awth13 / org-appear

Toggle visibility of hidden Org mode element parts upon entering and leaving an element
MIT License
369 stars 19 forks source link

Question: What about other togglable elements #2

Closed SPFabGerman closed 3 years ago

SPFabGerman commented 3 years ago

I have a question: Would you like to add support for Subscript (_) and Superscript (^) markers? (These are automatically hidden by org mode, when org-pretty-entites is t.) I have a working prototype, which implements toggling of Sub-/Superscripts, based on this package.

But I'm not really sure, if this package would be the right place to add this, since handling Sub-/Superscripts can be a bit more complicated, because there are multiple edge cases that one would have to consider and not all of the code can be reused. But I think it would make sense to add this functionality to this package, since it is has a very simmilar idea.

So what do you think? If you are interested in my code, I could open a pull request, after I clean the code up a bit.

awth13 commented 3 years ago

Someone else in the System Crafters discord channel already asked me about toggling links so I played around with the idea of turning this into a collection of org-autotoggles. From this perspective, your idea certainly seems interesting! I think we'll have to rework the code to make it support multiple "toggle-entities" in a sane way but, as a starter, please go ahead and submit what you have.

Have you looked into org-raise-scripts? It should be helpful to see how Org itself handles edge cases for sub/superscripts.

SPFabGerman commented 3 years ago

Nice. I clean up my code and open a PR, when it's ready. Thank you for the suggestion with org-raise-scripts, that could prove helpful.

awth13 commented 3 years ago

Thank you for taking interest!

I closed the issue.

awth13 commented 3 years ago

While waiting for @SPFabGerman 's PR, I sketched out the move to a multi-purpose org-togglers package in a feature branch. Please see org-togglers--enable for a working example of how general-purpose enabler will dispatch the type-specific toggle.

japhir commented 3 years ago

Hey, just found this issue. Did you work out how to hop into org-entities as well? It would be great to show i.e. \to and \Delta org-entities with org-toggle-pretty-entities but to 'hop in' so you can edit them if point is on any of them.

Cheers for the great package! :)

japhir commented 3 years ago

Here's my wishlist for the package :).

I don't have the org-togglers--enable function loadable, so maybe I'm doing something wrong with running the latest version…

awth13 commented 3 years ago

Hey, @japhir!

This issue was discussed quite some time ago, during our prototyping phase. Since then, there have been some major changes to the codebase. Notably,

I thought that org-entities are handled by org-fragtog I avoided looking into it. Now I see that they're not. Thank you for the suggestion, I will explore this further -- feel free to post a PR too.

SPFabGerman commented 3 years ago

Hey. Yeah originally I also wanted to implement the org-entities, but I never really use them myself and then just forget about them, lol.

japhir commented 3 years ago

Awesome, thanks to both of you for the explanation and the quick work-in-progress branch! :)

Inc0n commented 3 years ago

I would like to bring attention to subscript/superscripts, where org-appear seems to be doing nothing inside a latex fragment while editing, it would very helpful if there are any workarounds or potential fixes for this.

SPFabGerman commented 3 years ago

Hi @Inc0ns1st3nt, I already have a WIP branch for this exact issue. (https://github.com/SPFabGerman/org-appear/tree/cleanlatex) Currently I only try to show everything in a Latex fragment. (So multiple Sub/Superscripts in the same fragment are all toggled at the same time.) I have not created a pull request yet, since the behaviour is still somewhat buggy, but it works for now. You have to set the org-appear-clearlatex variable to non-nil to enable this feature.

There are some problems when supporting the Latex fragments. Most notably, the reliance on the org-element-context function does not return individual Sub/Superscripts or Entities, but only the full Latex Fragment. This makes toggling individual parts in the same Latex Fragment really difficult without heavy rewrites of the code. Secondly, Entity toggling does not work for some reason. Maybe there is something I'm missing, but it seems we can not simply remove the composition of Entities in a Latex Fragment. At least, again, not without heavy rewrites. Lastly, Org Mode has some wierd behaviour where it Re-Fonitfies the Latex Fragment after editing, but only after a certain amount of time. This means when you edit the Latex Fragment, the Sub/Superscripts can disappear and reapper somewhat randomly. (Since simple movement commands trigger our code to show the Sub/Superscript markers again.)

So yeah, if you want to have somewhat working support for Latex Fragments you could use this branch and see how well it works for you.

awth13 commented 3 years ago

The first question to ask, I think, is should org-appear handle things inside LaTeX fragments?

If yes, then we will have to stop relying on org-element and write our own parser -- or, at least, "borrow" it with modifications from org-element. This is entirely possible. @SPFabGerman must remember that, at first, org-appear used regular expressions instead of org-element. But it's also a lot of work involving a complete rewrite of org-appear.

For my personal use, the benefit of this does not outweigh the extra work. I don't want elements inside LaTeX fragments moving anyway. Although, to be fair, I have some grievances with my choice to use org-element.

japhir commented 3 years ago

It might be valueable for me, as I often write inline LaTeX code such as \SI{45}{\metre} (from siunitx) or \ce{CO2} (from mhchem) but rendering all of that sounds like way too much of a hassle ;-).

awth13 commented 3 years ago

inline LaTeX code such as \SI{45}{\metre}

You can use org-fragtog to automatically toggle inline LaTeX. It has to be enclosed in $...$, however, as far as I can tell.

japhir commented 3 years ago

ah yeah, I do use org-fragtog but indeed it only works when putting things in \[...\] or $...$, which puts them in math mode in the export:

#+latex_header: \usepackage{siunitx}

- \SI{35}{\metre}     # this one doesn't preview in org-fragtog
- $\SI{35}{\metre}$ # this one and the next three produce nice previews in org-fragtog
- \(\SI{35}{\metre}\)
- \[\SI{35}{\metre}\]

but this is the relevant section of the exported tex file:

\begin{itemize}
\item \SI{35}{\metre}
\item \(\SI{35}{\metre}\)
\item \(\SI{35}{\metre}\)
\item \[\SI{35}{\metre}\]
\end{itemize}

perhaps I could file an issue with them to see if they could search for particular \... constructs somehow.

japhir commented 3 years ago

Hey again! One more link type that currently doesn't do anything is inline images that are previewed. Not sure if that would be desirable, as it's already lagging significantly when point is over those images (in evil normal-mode) and lags even more if I change the line (i.e. dd in evil normal-mode to delete the line)

awth13 commented 3 years ago

Hey!

My personal opinion is that at-point image toggling would be too disruptive, both in terms of lag from processing and in general, with little benefit. That being said, I feel the same way about link toggling. If you think it is a useful addition to org-appear, I will look into implementing it.

japhir commented 3 years ago

It's not really a feature that I would want, but I just thought of it as another link type that this approach could be applied to for the completionist's sake ;-).

awth13 commented 3 years ago

Maybe later, once the new idle-delay feature is stable -- this makes more sense when you have to stop the cursor and wait to make the image appear. Thanks for the suggestion, @japhir.

Closing this issue for the time being.