aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-07-23 00:04:49 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-07-23 00:04:49 +1200
commit95ccb509fc5776aa61e761f643790fa23c3fe135 (patch)
tree2110641ea8c231224deaed55f778eabc62da9c10
parentAdd spacing and comments (diff)
downloadvim-alternate-filetypes-95ccb509fc5776aa61e761f643790fa23c3fe135.tar.gz
vim-alternate-filetypes-95ccb509fc5776aa61e761f643790fa23c3fe135.zip
Refactor autoload function to reduce indents
-rw-r--r--autoload/alternate_filetypes.vim36
-rw-r--r--plugin/alternate_filetypes.vim2
2 files changed, 19 insertions, 19 deletions
diff --git a/autoload/alternate_filetypes.vim b/autoload/alternate_filetypes.vim
index 4bf16f5..18bc6d4 100644
--- a/autoload/alternate_filetypes.vim
+++ b/autoload/alternate_filetypes.vim
@@ -1,25 +1,25 @@
" Switch to next alternate filetype if specified
function! alternate_filetypes#() abort
- " We only have anything to do if there's a list of filetypes ready for us
- if exists('b:alternate_filetypes')
-
- " Get the index of the current filetype in the list of filetypes
- let filetypes = b:alternate_filetypes
- let index = index(filetypes, &filetype)
+ " We only have anything to do if there's a list of filetypes defined for
+ " this buffer; otherwise, just return
+ "
+ if !exists('b:alternate_filetypes')
+ return
+ endif
- " If the current filetype is in the list of related filetypes, switch to
- " the next filetype, or the first filetype if the current filetype is the
- " last in the list; if it's not in there at all, clear the list, as
- " something has gone wrong
- "
- if index >= 0
- let &filetype = filetypes[
- \ (index + 1) % len(filetypes)
- \]
- else
- unlet b:alternate_filetypes
- endif
+ " Get the index of the current filetype in the list of filetypes; return if
+ " it's not in there at all
+ "
+ let filetypes = b:alternate_filetypes
+ let index = index(filetypes, &filetype)
+ if index == -1
+ return
endif
+ " Switch to the next filetype, or the first filetype if the current
+ " filetype is the last in the list
+ "
+ let &filetype = filetypes[ (index + 1) % len(filetypes) ]
+
endfunction
diff --git a/plugin/alternate_filetypes.vim b/plugin/alternate_filetypes.vim
index 7919b82..45e8009 100644
--- a/plugin/alternate_filetypes.vim
+++ b/plugin/alternate_filetypes.vim
@@ -14,5 +14,5 @@ command -bar AlternateFileType
\ call alternate_filetypes#() | set filetype?
" Mapping target to run user command
-nnoremap <silent> <Plug>(AlternateFileType)
+nnoremap <Plug>(AlternateFileType)
\ :<C-U>AlternateFileType<CR>