2012-09-09 6 views
4

나는 내 프로젝트에 다음 코드를했다 :AStyle 중첩 된 클래스 형식

class RangeConverter { 
private: 
    struct Converter { 
     ngeConverter { 
     private: 
      struct Converter { 
       double MinimumInput; 
       double MaximumInput; 

       double MinimumOutput; 
       double MaximumOutput; 

       template <typename RangeType> 
       RangeType Convert (RangeType invalue) const { 
        double v = static_cast<double> (invalue); 
        if (v < MinimumInput) { 
         v = MinimumInput; 
        } else if (v > MaximumInput) { 
         v = MaximumInput; 
        } 
        double interpolationfactor = (v - MinimumInput)/(MaximumInput - MinimumInput); 
        return static_cast<RangeType> ((interpolationfactor * (MaximumOutput - MinimumOutput)) + MinimumOutput); 
       } 
      }; 
..... 

astyle 명령 :

astyle 
    \ --style=java 
    \ --indent=force-tab=2 
    \ --indent-classes 
    \ --indent-switches 
    \ --indent-labels 
    \ --indent-preprocessor 
    \ --indent-col1-comments 
    \ --pad-oper 
    \ --pad-paren 
    \ --delete-empty-lines 
    \ --add-brackets 
    \ --align-pointer=type 
    \ --align-reference=type 
나는 다음과 같은 AStyle과 그 코드를 포맷 한 후

class RangeConverter { 
private: 
    struct Converter { 
        double MinimumInput; 
        double MaximumInput; 

        double MinimumOutput; 
        double MaximumOutput; 

        template <typename RangeType> 
        RangeType Convert (RangeType invalue) const { 
         double v = static_cast<double> (invalue); 
         if (v < MinimumInput) { 
          v = MinimumInput; 
         } else if (v > MaximumInput) { 
          v = MaximumInput; 
         } 
         double interpolationfactor = (v - MinimumInput)/(MaximumInput - MinimumInput); 
         return static_cast<RangeType> ((interpolationfactor * (MaximumOutput - MinimumOutput)) + MinimumOutput); 
        } 
       }; 
..... 

를 얻을 수

그게 astyle의 버그입니까, 아니면 어떤 옵션을 잊어 버렸습니까? 버그 일 경우 VIM을 사용하여 C++ 코드의 형식을 지정 하시겠습니까?

답변

1

물론 버그입니다. 요즘에는 AStyle이 제대로 지원되지 않습니다. 거기에 영원히 앉아 있고 결코 해결되지 않은 버그가 많이 있습니다. 가장 가까운 미래에 상황이 개선 될 것으로 예상해서는 안됩니다. Uncrustify으로 전환하는 것이 좋습니다. 분명히, 그것도 몇 가지 문제가 있지만, 너무 심술스럽지 않고 AStyle처럼 코드를 깨지 마십시오. AStyle보다 훨씬 유연한 구성 옵션이 수백 가지 있습니다. 따라서 환자는 환자의 취향과 규칙에 맞게 조정해야합니다.

이 작업이 완료되면 당신은 제대로 빔과 통합하려는 경우, 여기 당신이에 추가 할 수있는 코드를 이동하여 .vimrc :이 기능을 매핑 할 수 있습니다 이제
" Restore cursor position, window position, and last search after running a 
" command. 
function! Preserve(command) 
    " Save the last search. 
    let search = @/ 

    " Save the current cursor position. 
    let cursor_position = getpos('.') 

    " Save the current window position. 
    normal! H 
    let window_position = getpos('.') 
    call setpos('.', cursor_position) 

    " Execute the command. 
    execute a:command 

    " Restore the last search. 
    let @/ = search 

    " Restore the previous window position. 
    call setpos('.', window_position) 
    normal! zt 

    " Restore the previous cursor position. 
    call setpos('.', cursor_position) 
endfunction 

" Specify path to your Uncrustify configuration file. 
let g:uncrustify_cfg_file_path = 
    \ shellescape(fnamemodify('~/.uncrustify.cfg', ':p')) 

" Don't forget to add Uncrustify executable to $PATH (on Unix) or 
" %PATH% (on Windows) for this command to work. 
function! Uncrustify(language) 
    call Preserve(':silent %!uncrustify' 
     \ . ' -q ' 
     \ . ' -l ' . a:language 
     \ . ' -c ' . g:uncrustify_cfg_file_path) 
endfunction 

( Uncrustify) 키 조합으로 또는 내가 사용하는 편리한 트릭을 수행 할 수 있습니다.

autocmd BufWritePre <buffer> :call Uncrustify('cpp') 

이것은 기본적으로 훅을 미리 저장할 추가 : 당신이 특히 C에 대한 어떤 빔 설정을 무시 ++ 거기에 다음 줄을 추가 할 수있는 파일 ~/.vim/after/ftplugin/cpp.vim을 만듭니다. 이제 C++ 코드로 파일을 저장하면 이전에 제공 한 구성 파일을 사용하여 Uncrustify에서 자동으로 형식을 지정합니다.

참고 : 여기에 제시된 내용은 모두 저에게 잘 테스트되고 사용되었습니다.