Files
Wu, Zhenyu 4ab7c731fe
Some checks failed
CI / Test (v7.4) (push) Has been cancelled
CI / Test (v8.0.0000) (push) Has been cancelled
CI / Test (v8.1.0000) (push) Has been cancelled
CI / Test (v8.2.0000) (push) Has been cancelled
CI / Test (v8.2.1000) (push) Has been cancelled
CI / Test (v9.0.0000) (push) Has been cancelled
CI / Test (v9.1.0000) (push) Has been cancelled
reviewdog / runner / vint (push) Has been cancelled
extensions: Add a zhihu Neovim extension
closes: #2740

Signed-off-by: Wu, Zhenyu <wuzhenyu@ustc.edu>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2026-02-27 09:42:31 +01:00

46 lines
1.5 KiB
VimL

" MIT License. Copyright (c) 2026-2026 Wu Zhenyu et al
" Plugin: https://github.com/pxwg/zhihu.nvim
" vim: et ts=2 sts=2 sw=2
scriptencoding utf-8
if !airline#util#has_zhihu()
finish
endif
let s:has_percent_eval = v:version > 802 || (v:version == 802 && has("patch2854"))
function! airline#extensions#zhihu#bufname() abort
let fmod = (exists("+autochdir") && &autochdir) ? ':p' : ':.'
let name = fnamemodify(bufname('%'), fmod)
if empty(name)
return ''
endif
if match(name, 'zhihu://') == -1
return s:has_percent_eval ? '%f' : name
endif
return get(get(b:, 'article', {}), 'title', name)
endfunction
function! airline#extensions#zhihu#init(ext) abort
let prct = s:has_percent_eval ? '%' : ''
if exists("+autochdir") && &autochdir
" if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
call airline#parts#define_raw('path', '%<%{'. prct. 'pathshorten(airline#extensions#zhihu#bufname())' . prct . '}%m')
else
call airline#parts#define_raw('path', '%<%{' . prct . 'airline#extensions#zhihu#bufname()' . prct . '}%m')
endif
else
if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
call airline#parts#define_raw('file', '%<%{' . prct . 'pathshorten(airline#extensions#zhihu#bufname())' . prct . '}%m')
else
call airline#parts#define_raw('file', '%<%{' . prct . 'airline#extensions#zhihu#bufname()' . prct . '}%m')
endif
endif
endfunction