c – AStyle嵌套类格式
发布时间:2020-12-16 07:01:18 所属栏目:百科 来源:网络整理
导读:我的项目中有以下代码: class RangeConverter {private: struct Converter { double MinimumInput; double MaximumInput; double MinimumOutput; double MaximumOutput; template typename RangeType RangeType Convert ( RangeType invalue ) const { doub
我的项目中有以下代码:
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格式化代码后,我得到以下内容: 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的错误,还是我忘了任何选择? 解决方法
当然,这是一个错误.如今,AStyle不受支持.有许多错误永远存在于那里,从未得到解决.您不应期望在不久的将来情况会有所改善.我强烈建议切换到
Uncrustify.当然,它也有一些问题,但它们不是那么讨厌,不要像AStyle那样破坏你的代码.它有数百种配置选项 – 比AStyle灵活得多 – 所以请耐心等待,你需要花一些时间来根据自己的口味和惯例进行调整.
当你完成并且你想要正确地将它与Vim集成时,你可以在这里添加你可以添加到.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)映射到一个键组合,或者你可以做我使用的方便技巧.创建一个?/ .vim / after / ftplugin / cpp.vim文件,你可以覆盖任何Vim设置,特别是C,并在那里添加以下行: autocmd BufWritePre <buffer> :call Uncrustify('cpp') 这基本上添加了一个预保存挂钩.现在,当您使用C代码保存文件时,Uncrustify将使用您之前提供的配置文件自动对其进行格式化. 注意:此处提供的所有内容都经过了充分测试,并且每天都由我使用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |