什么vim errorformat用于Android的layoutopt工具?

时间:2011-06-10 18:57:32

标签: android vim layout-optimization

运行Android的layoutopt工具时,您使用了什么vim错误格式? (因此,您可以在Vim的quickfix窗口中加载结果。)

示例layoutopt输出:

res/layout/main.xml
    31:31 Use an android:layout_height of 0dip instead of fill_parent for better performance

1 个答案:

答案 0 :(得分:2)

我认为31:31表示从第31行到第31行。所以我们可以忽略第二个数字(因为quickfix中没有范围)。

将以下内容放入~/.vim/after/ftplugin/android-layout.vim

" Set the error format. Output is on multiple lines, so we use %P to push the
" filename onto the stack and %Q to pop it off. There are two kinds of errors
" I've seen: regular ones (begin with \t) and fatal ones.
"
" efm=Read the filename
"   ,regular errors
"   ,fatal errors
"   ,forget the filename
setlocal efm=%-P%f
    \,\ %l:%*[0-9]\ %m
    \,[Fatal\ Error]\ :%l:%*[0-9]:\ %m
    \,%-Q


" For some reason, I can't set layoutopt as the makeprg -- it never outputs
" anything when run from vim, but it works fine from a terminal or from vim's
" :!
setlocal makeprg=make\ layoutopt

这是相应的makefile(把它放在你的项目根目录中 - 所以LAYOUTS路径是有效的。)

LAYOUTOPT = $(HOME)/data/code/android/android-sdk-linux_86/tools/layoutopt
LAYOUTS = res/layout/*.xml

layoutopt:  $(LAYOUTS)
    $(LAYOUTOPT) $(LAYOUTS)
.PHONY: layoutopt

旁注:您可以使用它来自动调用您的ftplugin(而不是制作xml文件类型的子类型):

au BufRead,BufNewFile *.xml if match(expand('%:p'), '/res/layout/', 0) >= 0 | runtime ftplugin/android-layout.vim | endif