Created
October 20, 2014 13:42
-
-
Save DanSnow/6dd654cc83742f324c9d to your computer and use it in GitHub Desktop.
vim nasm indent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if exists("b:did_indent") | |
finish | |
endif | |
let b:did_indent = 1 | |
setlocal indentexpr=GetNasmIndent(v:lnum) | |
setlocal indentkeys+=<:> | |
if exists("*GetNasmIndent") | |
finish | |
endif | |
function! s:GetPrevNonCommentLineNum(line_num) | |
let SKIP_LINES = '^\s*;.*' | |
let nline = a:line_num | |
while nline > 0 | |
let nline = prevnonblank(nline - 1) | |
if getline(nline) !~? SKIP_LINES | |
break | |
endif | |
endwhile | |
return nline | |
endfunction | |
function! GetNasmIndent(lnum) | |
if a:lnum == 0 | |
return 0 | |
endif | |
let this_line = getline(a:lnum) | |
let prev_code_num = s:GetPrevNonCommentLineNum(a:lnum) | |
let prev_code = getline(prev_code_num) | |
let indnt = indent(prev_code_num) | |
if this_line =~ '^\s;' | |
return indent(a:lnum) | |
endif | |
if this_line =~ '^\s*.*:' | |
return 0 | |
endif | |
if this_line =~ '\v.*d(b|w|d)' | |
return 0 | |
endif | |
if prev_code =~ '.*:' | |
return indnt + &shiftwidth | |
endif | |
return indnt | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment