2009-10-12 9 views

Odpowiedz

13

można programowo uzyskać listę błędów z getqflist():

getqflist()      *getqflist()* 
     Returns a list with all the current quickfix errors. Each 
     list item is a dictionary with these entries: 
      bufnr number of buffer that has the file name, use 
       bufname() to get the name 
      lnum line number in the buffer (first line is 1) 
      col column number (first column is 1) 
      vcol non-zero: "col" is visual column 
       zero: "col" is byte index 
      nr error number 
      pattern search pattern used to locate the error 
      text description of the error 
      type type of the error, 'E', '1', etc. 
      valid non-zero: recognized error message 

     When there is no error list or it's empty an empty list is 
     returned. Quickfix list entries with non-existing buffer 
     number are returned with "bufnr" set to zero. 

     Useful application: Find pattern matches in multiple files and 
     do something with them: > 
      :vimgrep /theword/jg *.c 
      :for d in getqflist() 
      : echo bufname(d.bufnr) ':' d.lnum '=' d.text 
      :endfor 

Jeśli chcesz tylko łączną liczbę użyć len(getqflist()). np:

:echo len(getqflist()) 

Jeśli chcesz tylko wiedzieć, interaktywnie, :cw otworzy listę w oknie, czy są jakieś błędy (i zamknąć go, jeśli jest już otwarty i nie ma żadnych błędów). Liczba linii w tym buforze to liczba błędów.

+3

Jeśli quickfix okno zawiera tekst nie uznawane za błąd, listy zwróconej przez 'getqflist()' będzie zawierać dane dla każdego z nich kwestia. Więc nadal możesz mieć zero błędów przy 'len (getqflist())' zwracającym wartość niezerową. Musisz sprawdzić flagę 'valid' w wynikowej liście. Użyj do tego funkcji 'filter()'. – Ben

+2

'len (filter (getqflist(), 'v: val.valid'))' poda liczbę poprawnych wpisów quickfix. W wielu przypadkach będzie równa liczbie wpisów, ale nie zawsze. Szukanie ': help filter()' byłoby dobrym początkiem do zrozumienia tego. ;-) – Ben

+0

Dzięki za odpowiedź. Po prostu przerabiam kilka tutoriali i piszę wersję regularną bez użycia 'filter()', zobacz [mój komentarz] (https://gist.github.com/ih4cku/fa5d57f9f1dc5c03b6c36155bf3e2904) jeśli jesteś zainteresowany. Oczywiście, użycie 'filter()' jest bardziej eleganckie. @Ben – nn0p

1

można po prostu użyć funkcji getqflist() (patrz :help getqflist()):

:echo printf("Have %d errors", len(getqflist()))