Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a minor indentation rule for multi-line strings
- Loading branch information
Bruno Sutic
committed
Nov 16, 2014
1 parent
d9c94d5
commit 771a2a4
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
if exists("b:did_indent") | |||
finish | |||
endif | |||
let b:did_indent = 1 | |||
let b:current_indent = "tmux" | |||
|
|||
setlocal nosmartindent | |||
|
|||
setlocal indentexpr=GetTmuxIndent() | |||
|
|||
setlocal indentkeys=o | |||
|
|||
" Only define the function once. | |||
if exists("*GetTmuxIndent") | |||
finish | |||
endif | |||
|
|||
let s:cpo_save = &cpo | |||
set cpo&vim | |||
|
|||
function! s:highlight_group(line, col) | |||
return synIDattr(synID(a:line, a:col, 1), "name") | |||
endfunction | |||
|
|||
function! s:prev_line_ends_with_open_string(lnum) | |||
if a:lnum > 1 | |||
let prev_line_len = len(getline(a:lnum - 1)) | |||
if s:highlight_group(a:lnum - 1, prev_line_len) ==# 'tmuxString' | |||
return 1 | |||
endif | |||
endif | |||
return 0 | |||
endfunction | |||
|
|||
function! GetTmuxIndent() | |||
" If the string is not closed and was previously indented, then keep the | |||
" indentation. | |||
if s:prev_line_ends_with_open_string(v:lnum) | |||
return indent('.') | |||
else | |||
return 0 | |||
endif | |||
endfunction | |||
|
|||
let &cpo = s:cpo_save | |||
unlet s:cpo_save | |||
|
|||
" vim:set sw=2 sts=2 ts=8 et: |