Skip to content

Instantly share code, notes, and snippets.

@DanSnow
Created October 20, 2014 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanSnow/6dd654cc83742f324c9d to your computer and use it in GitHub Desktop.
Save DanSnow/6dd654cc83742f324c9d to your computer and use it in GitHub Desktop.
vim nasm indent
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