Skip to content
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

Support multi-filetype wikis with g:wiki_link_creation #299

Merged
merged 2 commits into from
May 7, 2023

Conversation

lervag
Copy link
Owner

@lervag lervag commented May 4, 2023

See the discussion in #296. This PR implements a first version of the proposed g:wiki_link_creation.

The new option provides a more flexible filetype-dependent behaviour. It deprecates four other options and makes configuring wiki.vim easier for most people. Since the new option provides sensible defaults, it also means most people will require less customization.

The following options are deprecated as the related features are all now more flexibly controlled by g:wiki_link_creation:

  • g:wiki_map_text_to_link
  • g:wiki_map_create_page
  • g:wiki_link_extension
  • g:wiki_link_target_type

lervag added 2 commits May 4, 2023 23:12
This option provides a more flexible filetype dependent behaviour. It
also deprecates four other options and thus makes configuring wiki.vim
easier for most people. And since the new option provides sensible
defaults, it also means most people will require less customization.

The following options are deprecated:
* g:wiki_map_text_to_link
* g:wiki_map_create_page
* g:wiki_link_extension
* g:wiki_link_target_type

refer: #296
Copy link
Contributor

@saccarosium saccarosium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be all good. But, as I was testing, I've found a strange bug where I can modify values in g:wiki_link_creation because it says that I'm trying to index a nil value.

INFO

  • version: NVIM v0.9.0
  • OS: MacOS Ventura
  • Package manager: Paq (uses vim's default package management)

What I've wrote:

-- lua
vim.g.wiki_link_creation.adoc.url_transform = function(x) return { x:lower():gsub(' ', '-'), x } end
" viml
let g:wiki_link_creation.adoc.url_transform = { x -> substitute(tolower(x), '\s\+', '-', 'g') }

error

Error detected while processing /Users/sacca/Repos/dot/config/nvim/init.lua:
E5113: Error while calling lua chunk: /Users/sacca/Repos/dot/config/nvim/init.lua:112: attempt to index field 'wiki_link_creation' (a nil value)
stack traceback:
        /Users/sacca/Repos/dot/config/nvim/init.lua:112: in main chunk

I've tried:

  • calling variable from Lua with vim.g table
  • using a viml file in plugin directory same problem
  • using a viml file in after/plugin directory same problem
  • calling viml with neovim vim.cmd function same problem
  • changing the variable within command mode worked

@lervag
Copy link
Owner Author

lervag commented May 5, 2023

Ah, yes, I believe your problem is that you are trying to set a key of the option before the option was fully defined. wiki.vim will define the default options when it is defined (it will not override user settings, though). But if you are trying to set options before wiki.vim is loaded, then you must define the entire dictionary.

Since wiki.vim merges user options with the default, I believe the following should suffice:

vim.g.wiki_link_creation = {
  adoc = {
    url_transform = function(x) return x:lower():gsub(' ', '-') end
  }
}
let g:wiki_link_creation = {
      \ 'adoc': {
      \   'url_transform': { x -> substitute(tolower(x), '\s\+', '-', 'g') }
      \ }
      \}

I.e., the url_extension and link_type should be initialized by wiki.vim to the default values if you do not change them yourself.

@lervag
Copy link
Owner Author

lervag commented May 5, 2023

Seems to be all good.

Oh, and thanks for testing! Do you have any thoughts on the choice of names?

  • calling variable from Lua with vim.g table

  • using a viml file in after/plugin directory same problem

  • calling viml with neovim vim.cmd function same problem

Hmm. I believe one or more of these should work. It all depends on the load order, which you can inspect with :scriptnames. If you are trying to change only a key as in your example, then the plugin/wiki.vim file from wiki.vim must be sourced first. You could actually test this by adding runtime plugin/wiki.vim to your config file.

However, if you are lazy loading wiki.vim, then this might not work. But then my previous suggestion of defining the entire dictionary should work.

@saccarosium
Copy link
Contributor

Oh, and thanks for testing! Do you have any thoughts on the choice of names?

I think there are very clear. I like this changes a lot.

The only thing is figuring out this issue and document it. When I'm at home i will test your suggestions

@lervag
Copy link
Owner Author

lervag commented May 5, 2023

Thanks, I appreciate that! Perhaps we need to clarify something in the docs here.

PS! I will create some new issue with feature requests based on our other discussion. I'll try to make some "specs" and you if you want to take a shot at one of them, feel free. I advice that you let me know first, just to avoid that we work on the same thing in parallell.

@saccarosium
Copy link
Contributor

saccarosium commented May 5, 2023

vim.g.wiki_link_creation = {
 adoc = {
   url_transform = function(x) return x:lower():gsub(' ', '-') end
 }
}

This did it.

@lervag
Copy link
Owner Author

lervag commented May 6, 2023

I've now released v0.7 with an announcement. I'll therefore not mind merging these new changes. I believe this PR is ready to merge. Or did I miss anything? If I don't hear any objections I'll merge probably tomorrow.

@saccarosium
Copy link
Contributor

saccarosium commented May 6, 2023

From my part I don't see any errors/bugs.

@lervag lervag merged commit 111c081 into master May 7, 2023
@lervag lervag deleted the feat/link-creation branch May 7, 2023 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants