Skip to content

Commit

Permalink
PORT: Support when v:none doesn't exist
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
LucHermitte committed Jan 2, 2025
1 parent 47c5380 commit 17d75d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 7 additions & 4 deletions autoload/lh/option.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
" Version: 5.4.1
let s:k_version = 50401
" Created: 24th Jul 2004
" Last Update: 13th Dec 2024
" Last Update: 02nd Jan 2025
"------------------------------------------------------------------------
" Description:
" Defines the global function lh#option#get().
" Aimed at (ft)plugin writers.
"
" History: {{{2
" v5.4.1
" (*) ENH: Extend lh#option#is_set() to v:none
" (*) ENH: Extend lh#option#is_set() to v:none/v:null
" v5.3.3
" (*) REFACT: Small improvments in `lh#option#get()`
" v5.3.1
Expand Down Expand Up @@ -119,13 +119,16 @@ endfunction


" Function: lh#option#is_unset(expr) {{{3
" type(v:none) == type(v:null) == 7
let s:t_none = get(v:, 't_none', 7)
let s:t_dict = get(v:, 't_dict', 4)
function! lh#option#is_unset(expr) abort
return (a:expr is v:none) || ((type(a:expr) == type ({})) && has_key(a:expr, '__lhvl_unset_type'))
return (type(a:expr) == s:t_none) || ((type(a:expr) == s:t_dict) && has_key(a:expr, '__lhvl_unset_type'))
endfunction

" Function: lh#option#is_set(expr) {{{3
function! lh#option#is_set(expr) abort
return (a:expr isnot v:none) && ! ((type(a:expr) == type ({})) && has_key(a:expr, '__lhvl_unset_type'))
return (type(a:expr) != s:t_none) && ! ((type(a:expr) == s:t_dict) && has_key(a:expr, '__lhvl_unset_type'))
endfunction

" Function: lh#option#get(names [, default [, scope]]) {{{3
Expand Down
23 changes: 17 additions & 6 deletions autoload/lh/type.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
" File: autoload/lh/type.vim {{{1
" Author: Luc Hermitte <EMAIL:luc {dot} hermitte {at} gmail {dot} com>
" <URL:http://github.com/LucHermitte/lh-vim-lib>
" Version: 4.0.0.0.
let s:k_version = '4000'
" Version: 5.4.1
let s:k_version = '050401'
" Created: 20th Feb 2017
" Last Update: 10th Apr 2017
" Last Update: 02nd Jan 2025
"------------------------------------------------------------------------
" Description:
" Helper functions around |type()|
Expand Down Expand Up @@ -61,12 +61,23 @@ let s:names =
\, 9 : 'channel'
\ }
if exists('v:true')
let s:names[v:true] = 'bool'
let s:names[v:false] = 'bool'
let s:names[type(v:true)] = 'bool'
" let s:names[v:false] = 'bool'
endif
if exists('v:null')
let s:names[type(v:null)] = 'none'
endif
if exists('v:none')
let s:names[v:none] = 'None'
let s:names[type(v:none)] = 'none'
endif
if exists('v:t_blob') | let s:names[v:t_bool] = 'blob' | endif
if exists('v:t_class') | let s:names[v:t_bool] = 'class' | endif
if exists('v:t_object') | let s:names[v:t_bool] = 'object' | endif
if exists('v:t_typealias') | let s:names[v:t_bool] = 'typealias' | endif
if exists('v:t_enum') | let s:names[v:t_bool] = 'enum' | endif
if exists('v:t_enumvalue') | let s:names[v:t_bool] = 'enumvalue' | endif


function! lh#type#name(type) abort
return get(s:names, a:type, 'unknown')
endfunction
Expand Down

0 comments on commit 17d75d6

Please sign in to comment.