From 0354eff320478cabe1f881322086bd7b64306bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 10 Mar 2021 10:06:54 +0100 Subject: [PATCH 1/3] Fix typo in gitconfig --- symlinks/gitconfig.optimum | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symlinks/gitconfig.optimum b/symlinks/gitconfig.optimum index 3b6d908..98c35aa 100644 --- a/symlinks/gitconfig.optimum +++ b/symlinks/gitconfig.optimum @@ -1,3 +1,3 @@ [user] - name = Enasr Sarajčić + name = Ensar Sarajčić email = ensar@optimum.ba From bbafb92447f5d9e6d0f26dfcba03d291dec0032f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 10 Mar 2021 10:15:54 +0100 Subject: [PATCH 2/3] Update config README to reflect new vim/neovim state --- symlinks/config/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symlinks/config/README.md b/symlinks/config/README.md index ae3310a..064dbf2 100644 --- a/symlinks/config/README.md +++ b/symlinks/config/README.md @@ -6,4 +6,4 @@ Contains configurations for many applications, most importantly: - `sway` - Wayland compositor - `newsboat` - my RSS reader - `alacritty` - my terminal emulator - - `coc` - `coc.nvim` plugin settings for `neovim` + - `coc` - `coc.nvim` plugin settings for `vim` From ad01edc96b9553a1fca2adf5e3ca7d57bad301bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 10 Mar 2021 14:26:49 +0100 Subject: [PATCH 3/3] Add better handling for vimwiki reviews indexes --- .../nvim/lua/plugin/vimwiki_reviews.lua | 28 +++++------ symlinks/config/nvim/lua/vimwiki_reviews.lua | 49 ++++++++++--------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/symlinks/config/nvim/lua/plugin/vimwiki_reviews.lua b/symlinks/config/nvim/lua/plugin/vimwiki_reviews.lua index 8ab74b0..c31d903 100644 --- a/symlinks/config/nvim/lua/plugin/vimwiki_reviews.lua +++ b/symlinks/config/nvim/lua/plugin/vimwiki_reviews.lua @@ -4,20 +4,20 @@ -- DEPENDS ON VIMWIKI PLUGIN ------------------------------------------------------------------------------- -vim.cmd[[command! -nargs=? VimwikiWeeklyReview :lua require('vimwiki_reviews').vimwiki_weekly_review()]] -vim.cmd[[command! -nargs=? VimwikiWeeklyTemplate :lua require('vimwiki_reviews').open_review_weekly_template()]] -vim.cmd[[command! -nargs=? VimwikiMonthlyReview :lua require('vimwiki_reviews').vimwiki_monthly_review()]] -vim.cmd[[command! -nargs=? VimwikiMonthlyTemplate :lua require('vimwiki_reviews').open_review_monthly_template()]] -vim.cmd[[command! -nargs=? VimwikiYearlyReview :lua require('vimwiki_reviews').vimwiki_yearly_review()]] -vim.cmd[[command! -nargs=? VimwikiYearlyTemplate :lua require('vimwiki_reviews').open_review_yearly_template()]] -vim.cmd[[command! -nargs=? VimwikiReviewIndex :lua require('vimwiki_reviews').vimwiki_review_index()]] +vim.cmd[[command! -count=0 VimwikiWeeklyReview :lua require('vimwiki_reviews').vimwiki_weekly_review()]] +vim.cmd[[command! -count=0 VimwikiWeeklyTemplate :lua require('vimwiki_reviews').open_review_weekly_template()]] +vim.cmd[[command! -count=0 VimwikiMonthlyReview :lua require('vimwiki_reviews').vimwiki_monthly_review()]] +vim.cmd[[command! -count=0 VimwikiMonthlyTemplate :lua require('vimwiki_reviews').open_review_monthly_template()]] +vim.cmd[[command! -count=0 VimwikiYearlyReview :lua require('vimwiki_reviews').vimwiki_yearly_review()]] +vim.cmd[[command! -count=0 VimwikiYearlyTemplate :lua require('vimwiki_reviews').open_review_yearly_template()]] +vim.cmd[[command! -count=0 VimwikiReviewIndex :lua require('vimwiki_reviews').vimwiki_review_index()]] local default_opts = {noremap=true} local function set_keymap(...) vim.api.nvim_set_keymap(...) end -set_keymap('n', 'wrw', 'VimwikiWeeklyReview', default_opts) -set_keymap('n', 'wrtw', 'VimwikiWeeklyTemplate', default_opts) -set_keymap('n', 'wrm', 'VimwikiMonthlyReview', default_opts) -set_keymap('n', 'wrtm', 'VimwikiMonthlyTemplate', default_opts) -set_keymap('n', 'wry', 'VimwikiYearlyReview', default_opts) -set_keymap('n', 'wrty', 'VimwikiYearlyTemplate', default_opts) -set_keymap('n', 'wri', 'VimwikiReviewIndex', default_opts) +set_keymap('n', 'wrw', "lua require('vimwiki_reviews').vimwiki_weekly_review(vim.v.count)", default_opts) +set_keymap('n', 'wrtw', "lua require('vimwiki_reviews').open_review_weekly_template(vim.v.count)", default_opts) +set_keymap('n', 'wrm', "lua require('vimwiki_reviews').vimwiki_monthly_review(vim.v.count)", default_opts) +set_keymap('n', 'wrtm', "lua require('vimwiki_reviews').open_review_monthly_template(vim.v.count)", default_opts) +set_keymap('n', 'wry', "lua require('vimwiki_reviews').vimwiki_yearly_review(vim.v.count)", default_opts) +set_keymap('n', 'wrty', "lua require('vimwiki_reviews').open_review_yearly_template(vim.v.count)", default_opts) +set_keymap('n', 'wri', "lua require('vimwiki_reviews').vimwiki_review_index(vim.v.count)", default_opts) diff --git a/symlinks/config/nvim/lua/vimwiki_reviews.lua b/symlinks/config/nvim/lua/vimwiki_reviews.lua index c76a9fc..94d3ef9 100644 --- a/symlinks/config/nvim/lua/vimwiki_reviews.lua +++ b/symlinks/config/nvim/lua/vimwiki_reviews.lua @@ -6,13 +6,18 @@ local Path = require('plenary.path') local scandir = require('plenary.scandir') -- Gets path to reviews dir of provided vimwiki (by index) -local function get_reviews_dir(...) +local function get_reviews_dir(vimwiki_index) local vimwiki = {} - if (select('#', ...) == 0) + if (vimwiki_index == 0) then - vimwiki = vim.g.vimwiki_list[1] + local current_index = vim.fn['vimwiki#vars#get_bufferlocal']('wiki_nr') + if (current_index < 0) + then + current_index = 0 + end + vimwiki = vim.g.vimwiki_list[current_index + 1] else - vimwiki = vim.g.vimwiki_list[tonumber(select(1, ...))] + vimwiki = vim.g.vimwiki_list[vimwiki_index] end return vimwiki.path .. 'reviews/' @@ -34,7 +39,7 @@ end -- - %date% (Puts different date based on review type) local function read_review_template_into_buffer(vimwiki_reviews_path, review_type) local template_path = get_review_template_path(vimwiki_reviews_path, review_type) - if (vim.fn.filereadable(vim.fn.glob(template_path))) + if (vim.fn.filereadable(vim.fn.glob(template_path)) ~= 0) then vim.cmd('read ' .. template_path) vim.cmd('0d') @@ -69,28 +74,28 @@ end local M = {} -- Edits weekly review template -function M.open_review_weekly_template(...) - local reviews_dir = get_reviews_dir(...) +function M.open_review_weekly_template(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) vim.cmd('edit ' .. get_review_template_path(reviews_dir, 'week')) end -- Edits monthly review template -function M.open_review_monthly_template(...) - local reviews_dir = get_reviews_dir(...) +function M.open_review_monthly_template(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) vim.cmd('edit ' .. get_review_template_path(reviews_dir, 'month')) end -- Edits yearly review template -function M.open_review_yearly_template(...) - local reviews_dir = get_reviews_dir(...) +function M.open_review_yearly_template(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) vim.cmd('edit ' .. get_review_template_path(reviews_dir, 'year')) end -- Open current week weekly review file -- Created buffer is dated to Sunday of current week -- Opens current week because Sunday is good time to do this review -function M.vimwiki_weekly_review(...) - local reviews_dir = get_reviews_dir(...) +function M.vimwiki_weekly_review(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) local days_to_sunday = 7 - tonumber(os.date('%u')) local week_date = os.date('%Y-%m-%d', os.time() + days_to_sunday * 24 * 60 * 60) local file_name = reviews_dir .. week_date .. '-week.md' @@ -108,8 +113,8 @@ end -- Created buffer is dated to previous month -- Previous month is calculated in an erroneous way -- 28 days are subtracted from current time to get previous month -function M.vimwiki_monthly_review(...) - local reviews_dir = get_reviews_dir(...) +function M.vimwiki_monthly_review(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) local month_time = os.time() - 28 * 24 * 60 * 60 local month_date = os.date('%Y-%m', month_time) local file_name = reviews_dir .. month_date .. '-month.md' @@ -124,8 +129,8 @@ end -- Open past year yearly review file -- Created buffer is dated to previous year -function M.vimwiki_yearly_review(...) - local reviews_dir = get_reviews_dir(...) +function M.vimwiki_yearly_review(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) local year_date = (tonumber(os.date('%Y')) - 1) local file_name = reviews_dir .. year_date .. '-year.md' local exists = file_exists_or_open(file_name) @@ -140,8 +145,8 @@ end -- Generates review index table -- Takes arguments similar to all vimwiki calls -- (no args, or 1 arg representing vimwiki index) -function M.get_review_index(...) - local reviews_dir = get_reviews_dir(...) +function M.get_review_index(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) local reviews_path = Path:new(reviews_dir):expand() local entries = scandir.scan_dir( @@ -209,11 +214,11 @@ function M.get_review_index(...) end -- Open reviews index file -function M.vimwiki_review_index(...) - local reviews_dir = get_reviews_dir(...) +function M.vimwiki_review_index(vimwiki_index) + local reviews_dir = get_reviews_dir(vimwiki_index) vim.cmd('edit ' .. reviews_dir .. 'reviews.md') - local index = M.get_review_index(...) + local index = M.get_review_index(vimwiki_index) local lines = { '# Reviews',