2011-06-10 63 views
2

運行Android的layoutopt工具時,您使用了什麼vim errorformat? (所以你可以加載Vim的quickfix窗口的結果。)vim errorformat用於Android的layoutopt工具?

樣品layoutopt輸出:

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

回答

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(把這個項目中的根 - 所以佈局路徑是有效的)。

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