From 607d67337be29d8d92f3da8a528e2d87949b6f39 Mon Sep 17 00:00:00 2001 From: Alisue Date: Sun, 14 Mar 2021 22:58:40 +0900 Subject: [PATCH] Deprecate 'stick' feature of the 'smart_cursor' There is 'hide' feature so that I've decided to provide only that as 'hide_cursor'. Rel: #307, #308, #312 --- autoload/fern.vim | 9 ++++- autoload/fern/helper/async.vim | 2 - autoload/fern/internal/viewer.vim | 2 +- autoload/fern/internal/viewer/hide_cursor.vim | 22 +++++++++++ .../fern/internal/viewer/smart_cursor.vim | 39 ------------------- autoload/fern/renderer/default.vim | 11 ++---- doc/fern.txt | 28 +++++-------- test/.themisrc | 3 -- 8 files changed, 43 insertions(+), 73 deletions(-) create mode 100644 autoload/fern/internal/viewer/hide_cursor.vim delete mode 100644 autoload/fern/internal/viewer/smart_cursor.vim diff --git a/autoload/fern.vim b/autoload/fern.vim index 4b29ee8e..046dedf2 100644 --- a/autoload/fern.vim +++ b/autoload/fern.vim @@ -24,7 +24,7 @@ call s:Config.config(expand(':p'), { \ 'logfile': v:null, \ 'loglevel': g:fern#INFO, \ 'opener': 'edit', - \ 'smart_cursor': 'stick', + \ 'hide_cursor': 0, \ 'keepalt_on_edit': 0, \ 'keepjumps_on_edit': 0, \ 'disable_auto_buffer_delete': 0, @@ -32,7 +32,6 @@ call s:Config.config(expand(':p'), { \ 'disable_default_mappings': 0, \ 'disable_viewer_spinner': has('win32') && !has('gui_running'), \ 'disable_viewer_auto_duplication': 0, - \ 'disable_viewer_smart_cursor': 0, \ 'disable_drawer_auto_winfixwidth': 0, \ 'disable_drawer_auto_resize': 0, \ 'disable_drawer_smart_quit': get(g:, 'disable_drawer_auto_quit', 0), @@ -71,3 +70,9 @@ if exists('g:fern#disable_drawer_auto_quit') \ 'g:fern#disable_drawer_smart_quit', \) endif +if exists('g:fern#smart_cursor') + call fern#util#deprecated('g:fern#smart_cursor', 'g:fern#hide_cursor') +endif +if exists('g:fern#disable_viewer_smart_cursor') + call fern#util#deprecated('g:fern#disable_viewer_smart_cursor') +endif diff --git a/autoload/fern/helper/async.vim b/autoload/fern/helper/async.vim index ed55ddd3..9ab1f1b4 100644 --- a/autoload/fern/helper/async.vim +++ b/autoload/fern/helper/async.vim @@ -17,10 +17,8 @@ function! s:async_redraw() abort dict let l:Profile = fern#profile#start('fern#helper:helper.async.redraw') let helper = self.helper let fern = helper.fern - let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : '' return s:Promise.resolve() \.then({ -> fern.renderer.render(fern.visible_nodes) }) - \.then({ v -> map(v, { -> prefix . v:val }) }) \.then({ v -> fern#internal#buffer#replace(helper.bufnr, v) }) \.then({ -> helper.async.remark() }) \.then({ -> fern#hook#emit('viewer:redraw', helper) }) diff --git a/autoload/fern/internal/viewer.vim b/autoload/fern/internal/viewer.vim index b450ad2f..1445d457 100644 --- a/autoload/fern/internal/viewer.vim +++ b/autoload/fern/internal/viewer.vim @@ -57,7 +57,7 @@ function! s:init() abort autocmd CursorMoved,CursorMovedI,BufLeave let b:fern_cursor = getcurpos()[1:2] augroup END call fern#internal#viewer#auto_duplication#init() - call fern#internal#viewer#smart_cursor#init() + call fern#internal#viewer#hide_cursor#init() " Add unique fragment to make each buffer uniq let bufname = bufname('%') diff --git a/autoload/fern/internal/viewer/hide_cursor.vim b/autoload/fern/internal/viewer/hide_cursor.vim new file mode 100644 index 00000000..2904ad3e --- /dev/null +++ b/autoload/fern/internal/viewer/hide_cursor.vim @@ -0,0 +1,22 @@ +function! fern#internal#viewer#hide_cursor#init() abort + if !g:fern#hide_cursor + return + endif + call s:hide_cursor_init() +endfunction + +function! s:hide_cursor_init() abort + augroup fern_internal_viewer_smart_cursor_init + autocmd! * + autocmd BufEnter,WinEnter,CmdwinLeave,CmdlineLeave setlocal cursorline + autocmd BufLeave,WinLeave,CmdwinEnter,CmdlineEnter setlocal nocursorline + autocmd BufEnter,WinEnter,CmdwinLeave,CmdlineLeave call fern#internal#cursor#hide() + autocmd BufLeave,WinLeave,CmdwinEnter,CmdlineEnter call fern#internal#cursor#restore() + autocmd VimLeave call fern#internal#cursor#restore() + augroup END + + " Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182) + if exists('+cursorlineopt') + setlocal cursorlineopt=number,line + endif +endfunction diff --git a/autoload/fern/internal/viewer/smart_cursor.vim b/autoload/fern/internal/viewer/smart_cursor.vim deleted file mode 100644 index e95b4466..00000000 --- a/autoload/fern/internal/viewer/smart_cursor.vim +++ /dev/null @@ -1,39 +0,0 @@ -function! fern#internal#viewer#smart_cursor#init() abort - if g:fern#disable_viewer_smart_cursor - return - endif - if g:fern#smart_cursor ==# 'stick' - call s:stick_cursor_init() - elseif g:fern#smart_cursor ==# 'hide' - call s:hide_cursor_init() - else - call fern#logger#warn(printf( - \ '"%s" is not valid g:fern#smart_cursor. Use "stick" instead.', - \ g:fern#smart_cursor, - \)) - call s:stick_cursor_init() - endif -endfunction - -function! s:hide_cursor_init() abort - augroup fern_internal_viewer_smart_cursor_init - autocmd! * - autocmd BufEnter,WinEnter,CmdwinLeave,CmdlineLeave setlocal cursorline - autocmd BufLeave,WinLeave,CmdwinEnter,CmdlineEnter setlocal nocursorline - autocmd BufEnter,WinEnter,CmdwinLeave,CmdlineLeave call fern#internal#cursor#hide() - autocmd BufLeave,WinLeave,CmdwinEnter,CmdlineEnter call fern#internal#cursor#restore() - autocmd VimLeave call fern#internal#cursor#restore() - augroup END - -" Do NOT allow cursorlineopt=number while the cursor is hidden (Fix #182) - if exists('+cursorlineopt') - setlocal cursorlineopt=number,line - endif -endfunction - -function! s:stick_cursor_init() abort - augroup fern_internal_viewer_smart_cursor_init - autocmd! * - autocmd CursorMoved,CursorMovedI call cursor(line('.'), 1, 0) - augroup END -endfunction diff --git a/autoload/fern/renderer/default.vim b/autoload/fern/renderer/default.vim index 0782275b..d7a84c23 100644 --- a/autoload/fern/renderer/default.vim +++ b/autoload/fern/renderer/default.vim @@ -38,25 +38,20 @@ function! s:lnum(index) abort endfunction function! s:syntax() abort - let prefix = !g:fern#disable_viewer_smart_cursor && g:fern#smart_cursor ==# 'stick' ? ' ' : '' - syntax match FernLeaf /^.*[^/].*$/ transparent contains=FernLeafSymbol syntax match FernBranch /^.*\/.*$/ transparent contains=FernBranchSymbol syntax match FernRoot /\%1l.*/ transparent contains=FernRootText execute printf( - \ 'syntax match FernRootSymbol /%s%s/ contained nextgroup=FernRootText', - \ prefix, + \ 'syntax match FernRootSymbol /%s/ contained nextgroup=FernRootText', \ escape(g:fern#renderer#default#root_symbol, s:ESCAPE_PATTERN), \) execute printf( - \ 'syntax match FernLeafSymbol /^%s\%%(%s\)*%s/ contained nextgroup=FernLeafText', - \ prefix, + \ 'syntax match FernLeafSymbol /^\%%(%s\)*%s/ contained nextgroup=FernLeafText', \ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN), \ escape(g:fern#renderer#default#leaf_symbol, s:ESCAPE_PATTERN), \) execute printf( - \ 'syntax match FernBranchSymbol /^%s\%%(%s\)*\%%(%s\|%s\)/ contained nextgroup=FernBranchText', - \ prefix, + \ 'syntax match FernBranchSymbol /^\%%(%s\)*\%%(%s\|%s\)/ contained nextgroup=FernBranchText', \ escape(g:fern#renderer#default#leading, s:ESCAPE_PATTERN), \ escape(g:fern#renderer#default#collapsed_symbol, s:ESCAPE_PATTERN), \ escape(g:fern#renderer#default#expanded_symbol, s:ESCAPE_PATTERN), diff --git a/doc/fern.txt b/doc/fern.txt index f37fcf46..d29d14b4 100644 --- a/doc/fern.txt +++ b/doc/fern.txt @@ -330,22 +330,16 @@ VARIABLE *fern-variable* windows style. Default: 'edit' +*g:fern#hide_cursor* + Set 1 to hide cursor and forcedly enable |cursorline| to visualize the + cursor node. The |cursorline| is automatically enabled when the focus + is on the buffer and automatically disabled when the cursor is out of + the buffer. + Note that Neovim prior to 0.5.0 cannot hide the cursor thus faint + vertical bar is used instead. + *g:fern#smart_cursor* - A type |String| of the smart cursor. Available values are - - "stick" Stick the cursor to the first column to visualize the - cursor node. In this mode, single whitespace is - prefixed as a padding for better looks. - - "hide" Hide the cursor and forcedly enable |cursorline| to - visualize the cursor node. In this mode, |cursorline| - is automatically enabled when the focus is on the - buffer and automatically disabled when the cursor is - out of the buffer. - Note that Neovim prior to 0.5.0 cannot hide the cursor - thus faint vertical bar is used instead. - - Default: "stick" + DEPRECATED: Use |g:fern#hide_cursor| instead. *g:fern#keepalt_on_edit* Set 1 to apply |keepalt| on the "open:edit" action to keep an @@ -418,11 +412,9 @@ VARIABLE *fern-variable* *g:fern#disable_viewer_hide_cursor* DEPRECATED: The cursor is not hidden any longer in default. - See |g:fern#smart_cursor| for detail. *g:fern#disable_viewer_smart_cursor* - Set 1 to disable viewer smart cursor feature. - See |g:fern#smart_cursor| for detail. + DEPRECATED: The smart cursor feature has obsoleted. *g:fern#disable_drawer_auto_winfixwidth* Set 1 to disable automatically enable 'winfixwidth' to drawer on diff --git a/test/.themisrc b/test/.themisrc index 14d50bbb..e16b1744 100644 --- a/test/.themisrc +++ b/test/.themisrc @@ -37,6 +37,3 @@ call themis#log('-----------------------------------------------------------') " Add test utilities set runtimepath+=./test/util - -" Disable 'smart_cursor' which slightly change the viewer content -let g:fern#disable_viewer_smart_cursor = 1