Add orgmode support#247
Conversation
Thanks, I'm glad you like it!
I don't mind it at all! My first impression of this PR is that it is well written and thorough, and that it fits nicely with the core ideas of wiki.vim. Still, it is a large PR, so I'll want to review it properly. I'll do that as fast as I can.
Cool. I'm curious, though; should this be active by default? It would affect existing users who do use orgmode anyway. Perhaps it would be better to keep the current default toggle map and instead document how to update? I believe it could be more or less a single line of configuration.
Perfectly reasonable.
I agree, this is well done.
Thank you for using it and for providing a PR for features you want! :) Notice that I have a different PR incoming that makes large changes to the |
| \ 'md': 'wiki#link#org#template', | ||
| \ 'org': 'wiki#link#wiki#template', | ||
| \ 'adoc_xref_bracket': 'wiki#link#adoc_xref_inline#template', | ||
| \ 'adoc_xref_inline': 'wiki#link#adoc_xref_bracket#template', |
autoload/wiki/tags.vim
Outdated
|
|
||
|
|
||
| " {{{1 let g:wiki#tags#orgmode_parser = ... | ||
| let g:wiki#tags#orgmode_parser = { |
There was a problem hiding this comment.
Would it make sense to reuse code from the default parser, i.e. like this:
let g:wiki#tags#orgmode_parser = deepcopy(g:wiki#tags#default_parser)
let g:wiki#tags#orgmode_parser.X = YThere was a problem hiding this comment.
I've given it a try and the length and number of regexes make it a bit difficult to fit this pattern within 79 columns. Let me know if the below looks good to you and I'll commit it:
" {{{1 let g:wiki#tags#orgmode_parser = ...
let g:wiki#tags#orgmode_parser = deepcopy(g:wiki#tags#default_parser)
call extend(g:wiki#tags#orgmode_parser, {
\ 're_match': '\v^%(\c#\+filetags:\s+:[^: ]+:|\*.*:[^: ]+:$)',
\ 're_findstart': '\v^%(^\c#\+filetags:\s+|\*.*)(:\zs[^: ]+)+$',
\ 're_parse': '\v:\zs[^: ]+\ze:',
\ 're_prefix': '\v^\zs.{-}\ze:([^: ]+:)+$'
\})
function! g:wiki#tags#orgmode_parser.make(taglist, tagline) dict abort
let l:prefix = matchstr(a:tagline, self.re_prefix)
let l:tags = empty(a:taglist) ? '' : (':' . join(a:taglist, ':') . ':')
return trim(l:prefix . l:tags)
endfunction
" }}}1|
Good work; I've read through and I don't really have any major comments, except my question in the first reply and the question regarding possibility to avoid redundancy. |
For some reason, the links in test/test-graph/test-links-from-to.vim don't appear in the order expected by the test. This was already the case before I made any changes, so I assume this is a regression that snuck in at some point.
This is only a separate commit for cleaner diffs.
Orgmode links look like this: [[link]], [[link][description]]. This is very similar, but not identical to wiki links. This adds a new matcher to autoload/wiki/link/. It is carefully added to s:matchers so that cycling between wiki, markdown and orgmode links never causes a deadlock. The relevant regexes are added to autoload/wiki/rx.vim and the documentation is updated. This also includes the new matcher in the config variable g:wiki_link_toggles. Some orgmode links are added to the wiki-basic test wiki and the affected unit tests (such as counting links) are updated. The test test/test-markdown/test.vim is updated such as to toggle the existing link from Markdown to Orgmode styl The test test/test-markdown/test.vim is updated such as to toggle the existing link from markdown to orgmode style.
This adds a new tags parser in addition to the default one: g:wiki#tags#orgmode_parser. It's very similar to the default with the following differences: - *only* supports short-style tags `:tag1:tag2:`; - orgmode only allows tags in two specific instances: at the end of headlines and in the `#+FILETAGS: :tag1:tag2:` property at the beginning of a file. The parser uses these restrictions in the regexes that search for tags. The only reason that we can't use the default parser is that its `make()` method generates long style tags `:tag1: :tag2:`, which are forbidden in orgmode. The orgmode parser is added to the package, but not to any of the default settings to avoid interference with the default parser. People who wish to use it probably are best served explicitly opting in via g:wiki_tag_parsers.
This is a rather straight-forward change. The file autoload/wiki/page.vim is adjusted to also take orgmode links with descriptions into account and a unit test for it is added. The function s:convert_links_to_html() is also extended for orgmode links, though I'm not sure how to test it.
That's a good question. I'll admit I don't quite understand the purpose of toggling between wiki and markdown links, since AFAIK one link type doesn't make sense in the other filetype. That's not really relevant to this PR though. Maybe the following is a reasonable compromise? call wiki#init#option('wiki_link_toggles', {
\ 'wiki': 'wiki#link#md#template',
\ 'md': 'wiki#link#wiki#template',
+ \ 'org': 'wiki#link#org#template',
\ 'adoc_xref_bracket': 'wiki#link#adoc_xref_inline#template',
\ 'adoc_xref_inline': 'wiki#link#adoc_xref_bracket#template',
\ 'date': 'wiki#link#wiki#template',
\ 'shortcite': 'wiki#link#md#template',
\ 'url': 'wiki#link#md#template',
\})That is: wiki/md links continue to toggle between each other as before. Orgmode links toggle onto themselves (i.e. don't do anything), but can be configured to do anything else. This should not change people's workflows, but enabling orgmode only requires users to set (The alternative would be to add Let me know what you think and I'll add a commit with the necessary changes. :D |
|
Sorry for taking so long to reply!
I use this feature to change between wiki links and Markdown links - I tend to use Markdown links for everything external, and wiki links for internal links. I find it useful to be able to quickly toggle the different link styles.
Yes, I think that is a good compromise, since it is backwards compatible while making it very easy to change one setting to get a more flexible link toggle chain. |
|
No problem at all! I've made the relevant changes in additional commits and also rebased my branch to be on top of your changes to the journal code. Let me know if you find any other issues you'd like to see addressed 👍 |
|
Thanks! Merged now, I appreciate the contribution! |
Hi! 👋 I've been recently been starting to get my notes more organized and was very impressed by your plugin! In particular, I liked that it took a more filetype-agnostic approach than other plugins, which focus much more on .wiki files specifically.
I've been trying to get a setup that uses both nvim-orgmode and wiki.vim. I quickly found that I couldn't quite customize link creation from my vimrc file, so I had to modify the plugin itself.
If you're interested in maintaining support for orgmode files, I'd be delighted to upstream the changes I made. They concern four corners:
g:wiki#tags#orgmode_parser, which is not active by default; users have to opt into it by adding it tog:wiki_tag_parsers.g:wiki_completion_enabledbecause nvim-orgmode supplies its own omnifunc that would get unconditionally overridden by wiki.vim's.I've tried to split the changes into reasonably-sized commits and added further explanations to each commit message. I think I followed your general style and added documentation where necessary, but please let me know if something's missing. I'd be happy to make further changes.
I've also added whatever unit tests I could think of, but wasn't extremely thorough. Let me know if there's another use case you'd like to see covered.
In any case, thank you again for the wonderful plugin and have a nice day!