kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

make.kak (4193B)


      1 declare-option -docstring "shell command run to build the project" \
      2     str makecmd make
      3 declare-option -docstring "pattern that describes lines containing information about errors in the output of the `makecmd` command. Capture groups must be: 1: filename 2: line number 3: optional column 4: optional error description" \
      4     regex make_error_pattern "^([^:\n]+):(\d+):(?:(\d+):)? (?:fatal )?error:(\N+)?"
      5 
      6 provide-module make %{
      7 
      8 require-module fifo
      9 require-module jump
     10 
     11 define-command -params .. -docstring %{
     12     make [<arguments>]: make utility wrapper
     13     All the optional arguments are forwarded to the make utility
     14 } make %{
     15     evaluate-commands -save-regs m %{
     16         set-register m %opt{makecmd}
     17         evaluate-commands -try-client %opt{toolsclient} %{
     18             fifo -scroll -name *make* -script %{
     19                 trap - INT QUIT
     20                 eval "$kak_reg_m \"\$@\""
     21             } -- %arg{@}
     22             set-option buffer filetype make
     23             set-option buffer jump_current_line 0
     24         }
     25     }
     26 }
     27 
     28 add-highlighter shared/make group
     29 add-highlighter shared/make/ regex "^([^:\n]+):(\d+):(?:(\d+):)?\h+(?:((?:fatal )?error)|(warning)|(note)|(required from(?: here)?))?.*?$" 1:cyan 2:green 3:green 4:red 5:yellow 6:blue 7:yellow
     30 add-highlighter shared/make/ regex "^\h*(~*(?:(\^)~*)?)$" 1:green 2:cyan+b
     31 add-highlighter shared/make/ line '%opt{jump_current_line}' default+b
     32 
     33 hook -group make-highlight global WinSetOption filetype=make %{
     34     add-highlighter window/make ref make
     35     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/make }
     36 }
     37 
     38 hook global WinSetOption filetype=make %{
     39     alias buffer jump make-jump
     40     alias buffer jump-select-next make-select-next
     41     alias buffer jump-select-previous make-select-previous
     42     hook buffer -group make-hooks NormalKey <ret> make-jump
     43     hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer make-hooks }
     44 }
     45 
     46 define-command -hidden make-open-error -params 4 %{
     47     evaluate-commands -try-client %opt{jumpclient} %{
     48         edit -existing "%arg{1}" %arg{2} %arg{3}
     49         echo -markup "{Information}{\}%arg{4}"
     50         try %{ focus }
     51     }
     52 }
     53 
     54 define-command -hidden make-jump %{
     55     evaluate-commands -save-regs a/ %{
     56         evaluate-commands -draft %{
     57             execute-keys ,
     58             try %{
     59                 execute-keys gl<a-?> "Entering directory" <ret><a-:>
     60                 # Try to parse the error into capture groups, failing on absolute paths
     61                 execute-keys s "Entering directory [`']([^']+)'.*\n([^:\n/][^:\n]*):(\d+):(?:(\d+):)?(\N+)\n?\z" <ret>l
     62                 set-option buffer jump_current_line %val{cursor_line}
     63                 set-register a "%reg{1}/%reg{2}" "%reg{3}" "%reg{4}" "%reg{5}"
     64             } catch %{
     65                 # check if error pattern matches exactly at the start of the current line, possibly spanning more lines
     66                 execute-keys ghGe 
     67                 try %{
     68                     set-register / "\A%opt{make_error_pattern}"
     69                     execute-keys s<ret>l
     70                 } catch %{ # fallback on common error pattern so that explicit jumps on warning/note lines still work
     71                     set-register / "\A^([^:\n]+):(\d+):(?:(\d+):)? (\N+)?"
     72                     execute-keys s<ret>l
     73                 }
     74                 set-option buffer jump_current_line %val{cursor_line}
     75                 set-register a "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}"
     76             }
     77         }
     78         make-open-error %reg{a}
     79     }
     80 }
     81 define-command -hidden make-select-next %{
     82         set-register / %opt{make_error_pattern}
     83         # go to the current line end, search and go to the start of selection
     84         execute-keys "%opt{jump_current_line}ggl" "/<ret><a-;>;"
     85 }
     86 define-command -hidden make-select-previous %{
     87         set-register / %opt{make_error_pattern}
     88         execute-keys "%opt{jump_current_line}g" "<a-/><ret><a-;>;"
     89 }
     90 
     91 define-command make-next-error -docstring %{alias for "jump-next *make*"} %{
     92     jump-next *make*
     93 }
     94 
     95 define-command make-previous-error -docstring %{alias for "jump-previous *make*"} %{
     96     jump-previous *make*
     97 }
     98 
     99 }
    100 
    101 hook -once global KakBegin .* %{ require-module make }