From: Oleg Broytman Date: Sun, 2 Feb 2020 15:33:30 +0000 (+0300) Subject: .vimrc: Use `empty()` instead of `len`/`strlen` X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=5f5dda45d35697bcc169ba8383e98ee9e5c3d8b3;p=dotfiles.git .vimrc: Use `empty()` instead of `len`/`strlen` --- diff --git a/.vim/ftplugin/html.vim b/.vim/ftplugin/html.vim index 3950834..5549c67 100644 --- a/.vim/ftplugin/html.vim +++ b/.vim/ftplugin/html.vim @@ -6,7 +6,7 @@ if version >= 702 && has("iconv") && !exists('b:encoding_set') " Try to recognize the file encoding and convert the file let encoding = system("get_html_encoding.py " . shellescape(expand("%"))) if !v:shell_error - if strlen(encoding) != 0 + if !empty(encoding) call SetupEncoding(encoding) endif endif diff --git a/.vim/ftplugin/xml.vim b/.vim/ftplugin/xml.vim index 9069c20..a985607 100644 --- a/.vim/ftplugin/xml.vim +++ b/.vim/ftplugin/xml.vim @@ -6,7 +6,7 @@ if version >= 702 && has("iconv") && !exists('b:encoding_set') " Try to recognize the file encoding and convert the file let encoding = system("get_xml_encoding.py " . shellescape(expand("%"))) if !v:shell_error - if strlen(encoding) == 0 + if empty(encoding) " By default XML files are in UTF-8 let encoding = "UTF-8" endif diff --git a/.vimrc b/.vimrc index 750786d..39ca62d 100644 --- a/.vimrc +++ b/.vimrc @@ -386,13 +386,13 @@ autocmd BufReadPost * call RestorePosition() function! SetupEncoding(encoding) - if !has("iconv") || exists('b:encoding_set') || strlen(a:encoding) == 0 + if !has("iconv") || exists('b:encoding_set') || empty(a:encoding) return endif call RestorePosition() let b:encoding_set = 1 - if len(expand('%')) + if !empty(expand('%')) execute "edit ++enc=" . a:encoding endif endfunction @@ -458,7 +458,7 @@ function! ExtractURL() let line = getline('.') let parts = split(line, s:URL_re . '\zs') - if len(parts) == 0 + if empty(parts) throw 'ExtractURLCannotFindURL' " No URL found endif