From 4764e3c5e20e8bcefbcaf32c18dea8f14c3d5399 Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Tue, 25 Jul 2023 15:26:27 +0200 Subject: [PATCH 1/8] chore: lua/wiki/init.lua -> lua/wiki/ui_select.lua --- lua/wiki/{init.lua => ui_select.lua} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename lua/wiki/{init.lua => ui_select.lua} (97%) diff --git a/lua/wiki/init.lua b/lua/wiki/ui_select.lua similarity index 97% rename from lua/wiki/init.lua rename to lua/wiki/ui_select.lua index d7f9fbd..6424fd1 100644 --- a/lua/wiki/init.lua +++ b/lua/wiki/ui_select.lua @@ -1,6 +1,6 @@ local M = {} -function M.get_pages() +function M.pages() -- wiki#page#get_all returns a list of path pairs, where the first element is -- the absolute path and the second element is the path relative to wiki -- root. @@ -20,7 +20,7 @@ function M.get_pages() end) end -function M.get_tags() +function M.tags() local tags_with_locations = vim.fn["wiki#tags#get_all"]() local length = 0 From 83adbe5a29fb82183445d644d287e924b5b1c034 Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Tue, 25 Jul 2023 15:27:20 +0200 Subject: [PATCH 2/8] feat: allow custom Wiki{Pages,Tags,Toc} backends --- autoload/wiki/buffer.vim | 6 +--- doc/wiki.txt | 78 +++++++++++++++++++++++++++++++--------- plugin/wiki.vim | 24 +++++++------ 3 files changed, 77 insertions(+), 31 deletions(-) diff --git a/autoload/wiki/buffer.vim b/autoload/wiki/buffer.vim index 8e0fb7d..84da289 100644 --- a/autoload/wiki/buffer.vim +++ b/autoload/wiki/buffer.vim @@ -74,11 +74,7 @@ function! s:init_buffer_commands() abort " {{{1 command! -buffer -nargs=+ -complete=customlist,wiki#complete#tag_names \ WikiTagRename call wiki#tags#rename_ask() - if has('nvim') && g:wiki_select_method == 'ui_select' - command! -buffer WikiToc lua require('wiki').toc() - else - command! -buffer WikiToc call wiki#fzf#toc() - endif + command! -buffer WikiToc call g:wiki_select_methods.toc() command! -buffer -nargs=1 WikiClearCache call wiki#cache#clear() if b:wiki.in_journal diff --git a/doc/wiki.txt b/doc/wiki.txt index 1980469..639d828 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -819,23 +819,58 @@ a reference of all available options. Default: 1 *g:wiki_select_method* - A string to represent the UI select method used for the following commands: - - - |WikiPages| - - |WikiTags| - - |WikiToc| - - Possible values: - - - `'ui_select'` Use |vim.ui.select| (neovim only!) - - `'fzf'` Use fzf (https://github.com/junegunn/fzf.vim). This has - a few additional options for more fine tuned control: - - |g:wiki_fzf_pages_opts| - - |g:wiki_fzf_tags_opts| - - |g:wiki_fzf_pages_force_create_key| + A dictionary of functions that lets allow the user to choose his preferred + the behaviour for the builtin commands: |WikiPage|, |WikiTags| and + |WikiToc|. + + This allows the user quite a lot of flexibility in specifying how which + command will behave by letting him deciding wich builtin function use or + let him create one himself (see |wiki). + + The following table shows the option keys and the related commands: + + key command + --- ------- + `pages` |WikiPages| + `tags` |WikiTags| + `toc` |WikiToc| + + The dictionary values can be one of two types: + + - |String|: The name of a function to be executed; + - |Funcref|: A function that will be executed. + + The following builtin alternatives can be used: + + - fzf (https://github.com/junegunn/fzf.vim): + - `wiki#fzf#pages()` + - `wiki#fzf#tags()` + - `wiki#fzf#toc()` + - Note: This has a few additional options for more fine tuned control: + - |g:wiki_fzf_pages_opts| + - |g:wiki_fzf_tags_opts| + - |g:wiki_fzf_pages_force_create_key| + - Lua backend that uses |vim.ui.select| (neovim only!) + - `require("wiki.ui_select").pages()` + - `require("wiki.ui_select").tags()` + - `require("wiki.ui_select").toc()` + + Default (neovim): >lua + + vim.g.wiki_select_method = { + pages = require("wiki.ui_select").pages, + tags = 'equire("wiki.ui_select").tags, + toc = require("wiki.ui_select").toc, + } +< + Default (Vim): >vim - Default (neovim): `'ui_select'` - Default (Vim): `'fzf'` + let g:wiki_select_method = { + \ 'pages': 'wiki#fzf#pages', + \ 'tags': 'wiki#fzf#tags', + \ 'toc': 'wiki#fzf#toc', + \} +< *g:wiki_index_name* A string with the index page name for the wiki. The value should not include @@ -2265,5 +2300,16 @@ to be unencoded, then you could do something like this: >vim \ }, \} +Example 3: Customize the `wiki` select method ~ + *wiki-advanced-config-3* +>lua + + -- Using fzf-lua instead of ui-select for WikiPages + vim.g.wiki_select_method = { + pages = function() + require'fzf-lua'.files({ cwd = vim.g.wiki_root }) + end, + } + ============================================================================== vim:tw=78:ts=8:ft=help:norl:fdm=marker:cole=2: diff --git a/plugin/wiki.vim b/plugin/wiki.vim index d4f2088..99e6727 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -93,9 +93,19 @@ call wiki#init#option('wiki_template_month_names', [ \]) call wiki#init#option('wiki_root', '') if has('nvim') - call wiki#init#option('wiki_select_method', 'ui_select') +lua << EOF + vim.fn['wiki#init#option']('wiki_select_methods', { + pages = require("wiki.ui_select").pages, + tags = require("wiki.ui_select").tags, + toc = require("wiki.ui_select").toc, + }) +EOF else - call wiki#init#option('wiki_select_method', 'fzf') + call wiki#init#option('wiki_select_methods', { + \ 'pages': 'wiki#wiki#fzf#pages', + \ 'tags': 'wiki#wiki#fzf#tags', + \ 'toc': 'wiki#wiki#fzf#toc', + \}) endif call wiki#init#option('wiki_tag_list', { 'output' : 'loclist' }) call wiki#init#option('wiki_tag_search', { 'output' : 'loclist' }) @@ -130,14 +140,8 @@ command! WikiIndex call wiki#goto_index() command! -nargs=? WikiOpen call wiki#page#open() command! WikiReload call wiki#reload() command! WikiJournal call wiki#journal#open() -if has('nvim') && g:wiki_select_method == 'ui_select' - command! WikiPages lua require('wiki').get_pages() - command! WikiTags lua require('wiki').get_tags() -else - command! WikiPages call wiki#fzf#pages() - command! WikiTags call wiki#fzf#tags() -endif - +command! WikiPages call g:wiki_select_methods.pages() +command! WikiTags call g:wiki_select_methods.tags() " Initialize mappings nnoremap (wiki-index) :WikiIndex nnoremap (wiki-open) :WikiOpen From 5eadb4b4f97e483af2d4c1fe04710320ed1c623f Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Fri, 28 Jul 2023 22:45:12 +0200 Subject: [PATCH 3/8] feat: adding telescope select method --- doc/wiki.txt | 168 +++++++++++++++++++++-------------------- lua/wiki/telescope.lua | 120 +++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 82 deletions(-) create mode 100644 lua/wiki/telescope.lua diff --git a/doc/wiki.txt b/doc/wiki.txt index 639d828..c1cac99 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -706,119 +706,119 @@ The AsciiDoc link macro [0] is a generic link syntax that looks like this: > link:[] -The `[]` will be recognized by `wiki.vim` as the link text. + The `[]` will be recognized by `wiki.vim` as the link text. -[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ + [0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ -Cite links ~ - *wiki-link-cite* -The cite links are a convenient link type that can be used with e.g. Zotero -URLs. That is, instead of writing a link with URL `zot:citekey` one may simply -write `@citekey`. + Cite links ~ + *wiki-link-cite* + The cite links are a convenient link type that can be used with e.g. Zotero + URLs. That is, instead of writing a link with URL `zot:citekey` one may simply + write `@citekey`. -See also |wiki-link-url| for more info on the Zotero URL scheme and handler. + See also |wiki-link-url| for more info on the Zotero URL scheme and handler. -Iso dates ~ - *wiki-link-date* -Dates written in ISO date format, e.g. 2023-05-05, will be recognized as -a link to `journal:2023-05-05`. + Iso dates ~ + *wiki-link-date* + Dates written in ISO date format, e.g. 2023-05-05, will be recognized as + a link to `journal:2023-05-05`. -============================================================================== -OPTIONS *wiki-options* + ============================================================================== + OPTIONS *wiki-options* -`wiki.vim` has several options to configure the behaviour. The following is -a reference of all available options. + `wiki.vim` has several options to configure the behaviour. The following is + a reference of all available options. -*g:wiki_cache_root* + *g:wiki_cache_root* Specify the cache directory for `wiki.vim`. Default value: OS dependent - `Linux and MacOS`: `'~/.cache/wiki.vim/'` - `Windows`: Standard temporary folder (based on |tempname()|) + `Linux and MacOS`: `'~/.cache/wiki.vim/'` + `Windows`: Standard temporary folder (based on |tempname()|) -*g:wiki_cache_persistent* + *g:wiki_cache_persistent* Specify whether to use persistent caching. Default value: 1 -*g:wiki_completion_enabled* + *g:wiki_completion_enabled* Specify whether to override 'omnifunc' when entering a wiki buffer. Set this to 0 if you want to use another omnifunc. Default value: 1 -*g:wiki_completion_case_sensitive* + *g:wiki_completion_case_sensitive* Specify whether to use case-sensitive matching for omnicompletion of links and tags. Default value: 1 -*g:wiki_export* + *g:wiki_export* A dictionary that specifies the default configuration for |WikiExport| options. See the specifications for the options for more information. Default: >vim - let g:wiki_export = { - \ 'args' : '', - \ 'from_format' : 'markdown', - \ 'ext' : 'pdf', - \ 'link_ext_replace': v:false, - \ 'view' : v:false, - \ 'output': fnamemodify(tempname(), ':h'), - \} - -*g:wiki_filetypes* - List of filetype extensions for which `wiki.vim` should be enabled. Notice - that file extensions are not always the same as the filetype. For example, - the common extension for Markdown is `.md`, whereas the filetype is called - `markdown`. The option should list the file extensions. - - The first element of the list is considered the default filetype where that - is relevant. - - Default: `['md']` - -*g:wiki_fzf_pages_force_create_key* - Key combination that, when pressed while searching with |WikiPages|, will - create a new page with the name of the query. The value must be a string - recognized by fzf's `--expect` argument; see fzf's manual page for a list of - available keys. - - Default: `'alt-enter'` - -*g:wiki_fzf_pages_opts* - A string with additional user options for |WikiPages|. This can be used - e.g. to add a previewer. Users should be aware that the page candidates are - "prettified" with the `--with-nth=1` and `-d` options for fzf, so to obtain - the page path in a previewer option one must use the field index expression `1`. - E.g.: >vim - - let g:wiki_fzf_pages_opts = '--preview "cat {1}"' -< - Default: `''` - -*g:wiki_fzf_tags_opts* - A string with additional user options for |WikiTags|. This can be used - e.g. to add a previewer. Users should be aware that the page candidates are - "prettified" with the `-d` option for fzf, so to obtain the page path in a - previewer option one must use the field index expression `2..`. - E.g.: >vim - - let g:wiki_fzf_tags_opts = '--preview "bat --color=always {2..}"' -< - Default: `''` - -*g:wiki_global_load* - `wiki.vim` is inherently agnostic in that it assumes any recognized filetype - specifies a wiki. However, some people might want to load `wiki.vim` for - ONLY files within a globally specified directory |g:wiki_root|. To allow - this behaviour, one can set this option to 0. - - Default: 1 - -*g:wiki_select_method* + let g:wiki_export = { + \ 'args' : '', + \ 'from_format' : 'markdown', + \ 'ext' : 'pdf', + \ 'link_ext_replace': v:false, + \ 'view' : v:false, + \ 'output': fnamemodify(tempname(), ':h'), + \} + + *g:wiki_filetypes* + List of filetype extensions for which `wiki.vim` should be enabled. Notice + that file extensions are not always the same as the filetype. For example, + the common extension for Markdown is `.md`, whereas the filetype is called + `markdown`. The option should list the file extensions. + + The first element of the list is considered the default filetype where that + is relevant. + + Default: `['md']` + + *g:wiki_fzf_pages_force_create_key* + Key combination that, when pressed while searching with |WikiPages|, will + create a new page with the name of the query. The value must be a string + recognized by fzf's `--expect` argument; see fzf's manual page for a list of + available keys. + + Default: `'alt-enter'` + + *g:wiki_fzf_pages_opts* + A string with additional user options for |WikiPages|. This can be used + e.g. to add a previewer. Users should be aware that the page candidates are + "prettified" with the `--with-nth=1` and `-d` options for fzf, so to obtain + the page path in a previewer option one must use the field index expression `1`. + E.g.: >vim + + let g:wiki_fzf_pages_opts = '--preview "cat {1}"' + < + Default: `''` + + *g:wiki_fzf_tags_opts* + A string with additional user options for |WikiTags|. This can be used + e.g. to add a previewer. Users should be aware that the page candidates are + "prettified" with the `-d` option for fzf, so to obtain the page path in a + previewer option one must use the field index expression `2..`. + E.g.: >vim + + let g:wiki_fzf_tags_opts = '--preview "bat --color=always {2..}"' + < + Default: `''` + + *g:wiki_global_load* + `wiki.vim` is inherently agnostic in that it assumes any recognized filetype + specifies a wiki. However, some people might want to load `wiki.vim` for + ONLY files within a globally specified directory |g:wiki_root|. To allow + this behaviour, one can set this option to 0. + + Default: 1 + + *g:wiki_select_method* A dictionary of functions that lets allow the user to choose his preferred the behaviour for the builtin commands: |WikiPage|, |WikiTags| and |WikiToc|. @@ -854,6 +854,10 @@ a reference of all available options. - `require("wiki.ui_select").pages()` - `require("wiki.ui_select").tags()` - `require("wiki.ui_select").toc()` + - Telescope (https://github.com/nvim-telescope/telescope.nvim) + - `require("wiki.telescope").pages() + - `require("wiki.telescope").tags() + - `require("wiki.telescope").toc() Default (neovim): >lua diff --git a/lua/wiki/telescope.lua b/lua/wiki/telescope.lua new file mode 100644 index 0000000..5ad5ac2 --- /dev/null +++ b/lua/wiki/telescope.lua @@ -0,0 +1,120 @@ +local conf = require("telescope.config").values +local pickers = require "telescope.pickers" +local finders = require "telescope.finders" +local builtin = require "telescope.builtin" +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local M = {} + +function M.pages(opts) + builtin.find_files(vim.tbl_deep_extend("force", { + prompt_title = "Wiki files", + cwd = vim.g.wiki_root, + file_ignore_patterns = { + "%.stversions/", + "%.git/", + }, + path_display = function(_, path) + local name = path:match "(.+)%.[^.]+$" + return name or path + end, + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace_if(function() + return action_state.get_selected_entry() == nil + end, function() + actions.close(prompt_bufnr) + local new_name = action_state.get_current_line() + if vim.fn.empty(new_name) ~= 1 then + return + end + vim.fn["wiki#page#open"](new_name) + end) + return true + end, + }, opts or {})) +end + +function M.tags(opts) + local tags_with_locations = vim.fn["wiki#tags#get_all"]() + + local length = 0 + for tag, _ in pairs(tags_with_locations) do + if #tag > length then + length = #tag + end + end + + local root = vim.fn["wiki#get_root"]() + local items = {} + for tag, locations in pairs(tags_with_locations) do + for _, loc in pairs(locations) do + local path_rel = vim.fn["wiki#paths#relative"](loc[1], root) + local str = string.format("%-" .. length .. "s %s:%s", tag, path_rel, loc[2]) + table.insert(items, { str, loc[1], loc[2] }) + end + end + + opts = opts or {} + + local telescope_opts = vim.tbl_deep_extend("force", { + prompt_title = "Wiki Tags", + sorter = conf.generic_sorter(opts), + previewer = conf.grep_previewer(opts), + }, opts) + + pickers.new(telescope_opts, { + finder = finders.new_table { + results = items, + entry_maker = function(entry) + return { + value = entry[2], + display = entry[1], + ordinal = entry[1], + lnum = entry[3], + } + end + }, + }):find() +end + +function M.toc(opts) + local toc = vim.fn["wiki#toc#gather_entries"]() + + local items = {} + for _, hd in pairs(toc) do + local indent = vim.fn["repeat"](".", hd.level - 1) + local line = indent .. hd.header + table.insert(items, { line, hd.lnum }) + end + + opts = opts or {} + + local telescope_opts = vim.tbl_deep_extend("force", { + prompt_title = "Wiki Toc", + sorter = conf.generic_sorter(opts), + previewer = false, + }, opts) + + pickers.new(telescope_opts, { + finder = finders.new_table { + results = items, + entry_maker = function(entry) + return { + value = entry[2], + display = entry[1], + ordinal = entry[1], + lnum = entry[2], + } + end, + attach_mappings = function(prompt_buf, _) + actions.select_default:replace(function() + actions.close(prompt_buf) + local entry = action_state.get_selected_entry() + vim.cmd.execute(entry) + end) + end + }, + }):find() +end + +return M From bf6e615b8ad95470c51d6844d310607b34e75be6 Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Sat, 29 Jul 2023 18:08:55 +0200 Subject: [PATCH 4/8] doc: adding fzf-lua example --- doc/wiki.txt | 80 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 6 deletions(-) diff --git a/doc/wiki.txt b/doc/wiki.txt index c1cac99..a79e634 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -825,7 +825,7 @@ The AsciiDoc link macro [0] is a generic link syntax that looks like this: > This allows the user quite a lot of flexibility in specifying how which command will behave by letting him deciding wich builtin function use or - let him create one himself (see |wiki). + let him create one himself (see |wiki-advanced-config-3|). The following table shows the option keys and the related commands: @@ -2306,13 +2306,81 @@ to be unencoded, then you could do something like this: >vim Example 3: Customize the `wiki` select method ~ *wiki-advanced-config-3* ->lua +We support officially: Telescope, vim.ui.select and fzf.vim. But, if you want, +you can use watever fuzzy finder you want. The following is a setup using +`fzf-lua`: >lua + + local fzf = require "fzf-lua" + local fzf_data = require "fzf-lua".config.__resume_data + + local function fzf_pages() + fzf.files({ + prompt = "Wiki files>", + cwd = vim.g.wiki_root, + actions = { + ['default'] = function(selected) + local note = selected[1] + if not note then + if not data.last_query then + return + end + note = data.last_query + end + vim.fn["wiki#page#open"](note) + end, + } + }) + end + + local function fzf_tags() + local tags_with_locations = vim.fn["wiki#tags#get_all"]() + local root = vim.fn["wiki#get_root"]() + local items = {} + for tag, locations in pairs(tags_with_locations) do + for _, loc in pairs(locations) do + local path = vim.fn["wiki#paths#relative"](loc[1], root) + local str = string.format("%s:%d:%s", tag, loc[2], path) + table.insert(items, str) + end + end + fzf.fzf_exec(items, { + actions = { + ['default'] = function(selected) + local note = vim.split(selected[1], ':')[3] + if not note then + return + end + vim.fn["wiki#page#open"](note) + end + } + }) + end + + local function fzf_toc() + local toc = vim.fn["wiki#toc#gather_entries"]() + local items = {} + for _, hd in pairs(toc) do + local indent = vim.fn["repeat"](".", hd.level - 1) + local line = indent .. hd.header + table.insert(items, string.format("%d:%s", hd.lnum, line)) + end + fzf.fzf_exec(items, { + actions = { + ['default'] = function(selected) + local ln = vim.split(selected[1], ':')[1] + if not ln then + return + end + vim.fn.execute(ln) + end + } + }) + end - -- Using fzf-lua instead of ui-select for WikiPages vim.g.wiki_select_method = { - pages = function() - require'fzf-lua'.files({ cwd = vim.g.wiki_root }) - end, + pages = fzf_pages, + tags = fzf_tags, + toc = fzf_toc, } ============================================================================== From 8b34b60c891bf3db0364704a42ca22adb65b8390 Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Sat, 29 Jul 2023 18:30:45 +0200 Subject: [PATCH 5/8] fix: fixing formatting mistake in docs --- doc/wiki.txt | 164 +++++++++++++++++++++++++-------------------------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/doc/wiki.txt b/doc/wiki.txt index a79e634..25f7f97 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -706,119 +706,119 @@ The AsciiDoc link macro [0] is a generic link syntax that looks like this: > link:[] - The `[]` will be recognized by `wiki.vim` as the link text. +The `[]` will be recognized by `wiki.vim` as the link text. - [0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ +[0]: https://docs.asciidoctor.org/asciidoc/latest/macros/link-macro/ - Cite links ~ - *wiki-link-cite* - The cite links are a convenient link type that can be used with e.g. Zotero - URLs. That is, instead of writing a link with URL `zot:citekey` one may simply - write `@citekey`. +Cite links ~ + *wiki-link-cite* +The cite links are a convenient link type that can be used with e.g. Zotero +URLs. That is, instead of writing a link with URL `zot:citekey` one may simply +write `@citekey`. - See also |wiki-link-url| for more info on the Zotero URL scheme and handler. +See also |wiki-link-url| for more info on the Zotero URL scheme and handler. - Iso dates ~ - *wiki-link-date* - Dates written in ISO date format, e.g. 2023-05-05, will be recognized as - a link to `journal:2023-05-05`. +Iso dates ~ + *wiki-link-date* +Dates written in ISO date format, e.g. 2023-05-05, will be recognized as +a link to `journal:2023-05-05`. - ============================================================================== - OPTIONS *wiki-options* +============================================================================== +OPTIONS *wiki-options* - `wiki.vim` has several options to configure the behaviour. The following is - a reference of all available options. +`wiki.vim` has several options to configure the behaviour. The following is +a reference of all available options. - *g:wiki_cache_root* +*g:wiki_cache_root* Specify the cache directory for `wiki.vim`. Default value: OS dependent - `Linux and MacOS`: `'~/.cache/wiki.vim/'` - `Windows`: Standard temporary folder (based on |tempname()|) + `Linux and MacOS`: `'~/.cache/wiki.vim/'` + `Windows`: Standard temporary folder (based on |tempname()|) - *g:wiki_cache_persistent* +*g:wiki_cache_persistent* Specify whether to use persistent caching. Default value: 1 - *g:wiki_completion_enabled* +*g:wiki_completion_enabled* Specify whether to override 'omnifunc' when entering a wiki buffer. Set this to 0 if you want to use another omnifunc. Default value: 1 - *g:wiki_completion_case_sensitive* +*g:wiki_completion_case_sensitive* Specify whether to use case-sensitive matching for omnicompletion of links and tags. Default value: 1 - *g:wiki_export* +*g:wiki_export* A dictionary that specifies the default configuration for |WikiExport| options. See the specifications for the options for more information. Default: >vim - let g:wiki_export = { - \ 'args' : '', - \ 'from_format' : 'markdown', - \ 'ext' : 'pdf', - \ 'link_ext_replace': v:false, - \ 'view' : v:false, - \ 'output': fnamemodify(tempname(), ':h'), - \} - - *g:wiki_filetypes* - List of filetype extensions for which `wiki.vim` should be enabled. Notice - that file extensions are not always the same as the filetype. For example, - the common extension for Markdown is `.md`, whereas the filetype is called - `markdown`. The option should list the file extensions. - - The first element of the list is considered the default filetype where that - is relevant. - - Default: `['md']` - - *g:wiki_fzf_pages_force_create_key* - Key combination that, when pressed while searching with |WikiPages|, will - create a new page with the name of the query. The value must be a string - recognized by fzf's `--expect` argument; see fzf's manual page for a list of - available keys. - - Default: `'alt-enter'` - - *g:wiki_fzf_pages_opts* - A string with additional user options for |WikiPages|. This can be used - e.g. to add a previewer. Users should be aware that the page candidates are - "prettified" with the `--with-nth=1` and `-d` options for fzf, so to obtain - the page path in a previewer option one must use the field index expression `1`. - E.g.: >vim - - let g:wiki_fzf_pages_opts = '--preview "cat {1}"' - < - Default: `''` - - *g:wiki_fzf_tags_opts* - A string with additional user options for |WikiTags|. This can be used - e.g. to add a previewer. Users should be aware that the page candidates are - "prettified" with the `-d` option for fzf, so to obtain the page path in a - previewer option one must use the field index expression `2..`. - E.g.: >vim - - let g:wiki_fzf_tags_opts = '--preview "bat --color=always {2..}"' - < - Default: `''` - - *g:wiki_global_load* - `wiki.vim` is inherently agnostic in that it assumes any recognized filetype - specifies a wiki. However, some people might want to load `wiki.vim` for - ONLY files within a globally specified directory |g:wiki_root|. To allow - this behaviour, one can set this option to 0. - - Default: 1 - - *g:wiki_select_method* + let g:wiki_export = { + \ 'args' : '', + \ 'from_format' : 'markdown', + \ 'ext' : 'pdf', + \ 'link_ext_replace': v:false, + \ 'view' : v:false, + \ 'output': fnamemodify(tempname(), ':h'), + \} + +*g:wiki_filetypes* + List of filetype extensions for which `wiki.vim` should be enabled. Notice + that file extensions are not always the same as the filetype. For example, + the common extension for Markdown is `.md`, whereas the filetype is called + `markdown`. The option should list the file extensions. + + The first element of the list is considered the default filetype where that + is relevant. + + Default: `['md']` + +*g:wiki_fzf_pages_force_create_key* + Key combination that, when pressed while searching with |WikiPages|, will + create a new page with the name of the query. The value must be a string + recognized by fzf's `--expect` argument; see fzf's manual page for a list of + available keys. + + Default: `'alt-enter'` + +*g:wiki_fzf_pages_opts* + A string with additional user options for |WikiPages|. This can be used + e.g. to add a previewer. Users should be aware that the page candidates are + "prettified" with the `--with-nth=1` and `-d` options for fzf, so to obtain + the page path in a previewer option one must use the field index expression `1`. + E.g.: >vim + + let g:wiki_fzf_pages_opts = '--preview "cat {1}"' +< + Default: `''` + +*g:wiki_fzf_tags_opts* + A string with additional user options for |WikiTags|. This can be used + e.g. to add a previewer. Users should be aware that the page candidates are + "prettified" with the `-d` option for fzf, so to obtain the page path in a + previewer option one must use the field index expression `2..`. + E.g.: >vim + + let g:wiki_fzf_tags_opts = '--preview "bat --color=always {2..}"' +< + Default: `''` + +*g:wiki_global_load* + `wiki.vim` is inherently agnostic in that it assumes any recognized filetype + specifies a wiki. However, some people might want to load `wiki.vim` for + ONLY files within a globally specified directory |g:wiki_root|. To allow + this behaviour, one can set this option to 0. + + Default: 1 + +*g:wiki_select_method* A dictionary of functions that lets allow the user to choose his preferred the behaviour for the builtin commands: |WikiPage|, |WikiTags| and |WikiToc|. From a50acbe82c79f592cb95cf39636d3e7fa225395f Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Sat, 29 Jul 2023 18:41:09 +0200 Subject: [PATCH 6/8] chore: renaming functions --- autoload/wiki/buffer.vim | 2 +- plugin/wiki.vim | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autoload/wiki/buffer.vim b/autoload/wiki/buffer.vim index 84da289..0bd82fa 100644 --- a/autoload/wiki/buffer.vim +++ b/autoload/wiki/buffer.vim @@ -74,7 +74,7 @@ function! s:init_buffer_commands() abort " {{{1 command! -buffer -nargs=+ -complete=customlist,wiki#complete#tag_names \ WikiTagRename call wiki#tags#rename_ask() - command! -buffer WikiToc call g:wiki_select_methods.toc() + command! -buffer WikiToc call g:wiki_select_method.toc() command! -buffer -nargs=1 WikiClearCache call wiki#cache#clear() if b:wiki.in_journal diff --git a/plugin/wiki.vim b/plugin/wiki.vim index 99e6727..9bcc6eb 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -94,14 +94,14 @@ call wiki#init#option('wiki_template_month_names', [ call wiki#init#option('wiki_root', '') if has('nvim') lua << EOF - vim.fn['wiki#init#option']('wiki_select_methods', { + vim.fn['wiki#init#option']('wiki_select_method', { pages = require("wiki.ui_select").pages, tags = require("wiki.ui_select").tags, toc = require("wiki.ui_select").toc, }) EOF else - call wiki#init#option('wiki_select_methods', { + call wiki#init#option('wiki_select_method', { \ 'pages': 'wiki#wiki#fzf#pages', \ 'tags': 'wiki#wiki#fzf#tags', \ 'toc': 'wiki#wiki#fzf#toc', @@ -140,8 +140,8 @@ command! WikiIndex call wiki#goto_index() command! -nargs=? WikiOpen call wiki#page#open() command! WikiReload call wiki#reload() command! WikiJournal call wiki#journal#open() -command! WikiPages call g:wiki_select_methods.pages() -command! WikiTags call g:wiki_select_methods.tags() +command! WikiPages call g:wiki_select_method.pages() +command! WikiTags call g:wiki_select_method.tags() " Initialize mappings nnoremap (wiki-index) :WikiIndex nnoremap (wiki-open) :WikiOpen From 8a5acdee2e0c4827127ee0be83e73eb576a4854d Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Sat, 29 Jul 2023 18:41:26 +0200 Subject: [PATCH 7/8] feat: adding deprecation notice for select_method --- plugin/wiki.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/wiki.vim b/plugin/wiki.vim index 9bcc6eb..fe781d5 100644 --- a/plugin/wiki.vim +++ b/plugin/wiki.vim @@ -161,6 +161,10 @@ let s:mappings = index(['all', 'global'], g:wiki_mappings_use_defaults) >= 0 call extend(s:mappings, get(g:, 'wiki_mappings_global', {})) call wiki#init#apply_mappings_from_dict(s:mappings, '') +if type(g:wiki_select_method) == 1 + echoerr 'Deprecation notice: wiki_select_method wants different arguments, see :h wiki_select_method to learn more' +endif + " Enable on desired filetypes augroup wiki autocmd! From e9722a0a8d1709dcd87e52cfb4b68b0739b443ee Mon Sep 17 00:00:00 2001 From: Luca Saccarola Date: Mon, 31 Jul 2023 19:28:23 +0200 Subject: [PATCH 8/8] fix: fzf-lua example --- doc/wiki.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/wiki.txt b/doc/wiki.txt index 25f7f97..acb5557 100644 --- a/doc/wiki.txt +++ b/doc/wiki.txt @@ -2321,10 +2321,9 @@ you can use watever fuzzy finder you want. The following is a setup using ['default'] = function(selected) local note = selected[1] if not note then - if not data.last_query then - return + if fzf_data.last_query then + note = fzf_data.last_query end - note = data.last_query end vim.fn["wiki#page#open"](note) end, @@ -2347,10 +2346,9 @@ you can use watever fuzzy finder you want. The following is a setup using actions = { ['default'] = function(selected) local note = vim.split(selected[1], ':')[3] - if not note then - return + if note then + vim.fn["wiki#page#open"](note) end - vim.fn["wiki#page#open"](note) end } }) @@ -2368,10 +2366,9 @@ you can use watever fuzzy finder you want. The following is a setup using actions = { ['default'] = function(selected) local ln = vim.split(selected[1], ':')[1] - if not ln then - return + if ln then + vim.fn.execute(ln) end - vim.fn.execute(ln) end } })