Добрый день, господа. Перехожу с Vim-а на Emacs и появилась нужда перенести каким-то образом indentation код для одного из режимов vim-a. Вот, собственно, как он выглядит: " This function gets indentation level relative to an outer block and returns " present indent or -1 if outer block doesn't exist. function! s:ComputeIndent(shift) let lnum = search('^\S', 'bW') while lnum > 0 && synIDattr(synID(lnum, 1, 0), "name") !~ "Symbol" let lnum = search('^\S', 'bW') endwhile if lnum == 0 let lnum = 1 endif " echomsg "lnum =" lnum let open_brs = 0 if getline(v:lnum) =~ "}$" let close_brs = -1 else let close_brs = 0 endif " exec "normal " . lnum . "G^" exec lnum while search('{', 'W') && line(".") < v:lnum if synIDattr(synID(line("."), col("."), 0), "name") !~ "Symbol\\|Comment" let open_brs = open_brs + 1 endif endwhile " exec "normal " . lnum . "G^" exec lnum while search('}', 'W') && line(".") <= v:lnum if synIDattr(synID(line("."), col("."), 0), "name") !~ "Symbol\\|Comment" let close_brs = close_brs + 1 endif endwhile " echomsg "open_brs =" open_brs " echomsg "close_brs =" close_brs if open_brs > close_brs " exec "normal " . v:lnum . "G$" exec v:lnum let block_start = searchpair('{', '', '}', 'bW', \ 'synIDattr(synID(line("."), col("."), 0), "name") =~ "Symbol\\|Comment"') if block_start > 0 " exec "normal " . s:top_line . "G^" " exec "normal " . s:bot_line . "G^" return indent(block_start) + a:shift * &sw endif endif " echo search('\%$') " exec "normal " . s:top_line . "G^" " exec "normal " . s:bot_line . "G^" if a:shift > 0 return (a:shift - 1) * &sw endif return -1 endfunction function! GetRefalIndent() " normal H " let s:top_line = line(".") " normal L " let s:bot_line = line(".") " echomsg s:top_line s:bot_line " For closing brace use indentation of outer block (i.e. opening brace). if getline(v:lnum) =~ '^[}[:blank:]]*}' " normal h " echomsg "}" return s:ComputeIndent(0) endif " Find a non-blank line above the current line. let lnum = prevnonblank(v:lnum - 1) let prev_line = getline(lnum) " " If previous line was begining of a function definition then indent by one. " if prev_line !~ ';\s*$' && synIDattr(synID(lnum, 1, 0), "name") =~ "Symbol" " return &sw " endif " After opening brace always increase indentation by one. if prev_line =~ '{\s*$' && \ synIDattr(synID(lnum, strlen(getline(lnum)), 0), "name") !~ \ "Symbol\\|Comment" " echomsg "{" return indent(lnum) + &sw endif " Shift new sentence by one from outer block. if prev_line =~ ';\s*$' return s:ComputeIndent(1) endif " Shift continuing of a sentence by two. if prev_line =~ '[=,]\|\\!\|\\?\s*$' return s:ComputeIndent(2) endif " Leave everything else as is. return -1 endfunction Буду очень благодарен за любую помощь...
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.
Похожие темы
- Форум Node REPL, vim и костыли (2019)
- Форум vim высокое потребление процессорного времени (2015)
- Форум Веб-разработка в Vim (2014)
- Форум vim indentation (2013)
- Форум Emacs, indentation. (2013)
- Форум Emacs indentation (2014)
- Форум Ужасно медленная работа syntax on vim в больших файлах (2018)
- Форум Vim pep8 indent (2016)
- Форум vim html indent (2008)
- Форум vim html indent (2010)