reddit / emacs

Creating a new org-element

opensrc-philosophy · 2022-08-27 17:59
I am currently working on a package which allows writing natural deduction proofs (Quine Style) in an org-mode table and then exports them to LaTeX. I intend to add quite some features to it, for example \- editing the proof in a separate window similar to how `org-src--edit-element` does it \- changing how the table is exported \- displaying special overlays within that table \- allowing LaTeX-previews of the proof. I know this is a bunch of different features, so I need to start adjusting at a very basic level. What seems to be a good idea is to define a new org-element `ndproof` which allows for just that. Does anyone of you have any experience in how to approach this, or whether this even makes any sense?
yantar92 · 2022-08-28 02:24
> Does anyone of you have any experience in how to approach this, or whether this even makes any sense? It does make sense. We even have a similar feature request: https://list.orgmode.org/orgmode/87letvrege.fsf@localhost/ You may also take a look at https://github.com/alhassy/org-special-block-extras
opensrc-philosophy · 2022-08-28 09:19
Thanks for answering! I could very well imagine nested blocks to be useful, and I don't even think it's too hard to implement. I have a hard time seeing the similarities between your feature request, though: It seems to be about special blocks and `tex-info`. Now all special blocks are of the same `org-element` type, namely `special-block` (see `org-element-all-elements`). My aim is to create a whole new `org-element` which is not a special block, but a special *table*; it is easy to define a predicate which returns `non-nil` iff `point` is at a natural deduction proof table (because of the table's headline). The idea is that if you have a whole new `org-element`, you can without too much hassle define element-specific overlays and export. I don't see how `org-mode` allows creating a new `org-element`, though.
yantar92 · 2022-08-28 09:37
I mentioned special block because it is meant to be extendable. Creating new elements is not something Org is going to support. It will make sharing org documents between users difficult. So, if you want to create a custom element, I suggest to wrap it into a special block. If it is a table, you can still do it. Or you can write a package that will extend Org export and add fontification. See https://orgmode.org/manual/Hacking.html#Hacking
yantar92 · 2022-08-28 09:38
> Now all special blocks are of the same org-element type, namely special-block Yes and no. `special-block` elements also have `:type` property.
opensrc-philosophy · 2022-08-28 13:12
Yes, they have the type-property, but nonetheless, they are all of the same `org-element`. Or do you want to allude that it is not necessary to create a new `org-element` but just add another type `natded` to the `table` element? The problem I see here is the different syntax highlighting. Do you know which functions are responsible for that, or can you recommend a good read?
yantar92 · 2022-08-28 13:29
> The problem I see here is the different syntax highlighting. Do you know which functions are responsible for that, or can you recommend a good read? `org-font-lock-set-keywords-hook`. More functionality may be added in future (https://orgmode.org/list/87ee7c9quk.fsf@localhost). In general, you can read `font-lock-keywords` docstring to understand how syntax highlighting works in Emacs. It can be extended arbitrarily.