kakoune

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

meson.kak (2853B)


      1 # meson syntax highlighting for kakoune (https://mesonbuild.com)
      2 #
      3 # For reference see:
      4 # https://mesonbuild.com/Syntax.html
      5 # https://github.com/mesonbuild/meson/blob/master/data/syntax-highlighting/vim/syntax/meson.vim
      6 
      7 ## Detection
      8 
      9 hook global BufCreate (.*/|^)(meson\.build|meson_options\.txt) %{
     10   set-option buffer filetype meson
     11 }
     12 
     13 ## Initialization
     14 
     15 hook -group meson-highlight global WinSetOption filetype=meson %{
     16     require-module meson
     17 
     18     set-option window static_words %opt{meson_static_words}
     19 
     20     add-highlighter window/meson ref meson
     21     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/meson }
     22 }
     23 
     24 provide-module meson %§
     25 
     26 ## Highlighters
     27 
     28 add-highlighter shared/meson regions
     29 add-highlighter shared/meson/code default-region group
     30 
     31 add-highlighter shared/meson/comment region '(\h|^)#' '$' fill comment
     32 
     33 # TODO: highlight escape sequences within strings
     34 add-highlighter shared/meson/string_multiline region "'''" "'''" fill string
     35 add-highlighter shared/meson/string_single    region "'" (?<!\\)(\\\\)*' fill string
     36 
     37 # integer literals
     38 add-highlighter shared/meson/code/ regex '\b\d+\b' 0:value
     39 
     40 # operators
     41 add-highlighter shared/meson/code/ regex '(?:\+|-|\*|/|%|!=|=|<|>|\?|:)' 0:operator
     42 add-highlighter shared/meson/code/ regex '\b(?:and|not|or|in)\b' 0:operator
     43 
     44 # functions
     45 add-highlighter shared/meson/code/ regex "\b(\w+)\(" 1:function
     46 
     47 evaluate-commands %sh{
     48     values="true false"
     49 
     50     keywords="if else endif elif foreach endforeach break continue"
     51 
     52     builtins="add_global_arguments add_global_link_arguments add_languages
     53     add_project_arguments add_project_link_arguments add_test_setup
     54     alias_target assert benchmark both_libraries build_machine build_target
     55     configuration_data configure_file custom_target declare_dependency
     56     dependency disabler environment error executable files find_library
     57     find_program generator get_option get_variable gettext host_machine
     58     import include_directories install_data install_headers install_man
     59     install_subdir is_disabler is_variable jar join_paths library meson
     60     message option project run_command run_target set_variable shared_library
     61     shared_module static_library subdir subdir_done subproject summary
     62     target_machine test vcs_tag warning"
     63 
     64     join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
     65 
     66     # Add the language's grammar to the static completion list
     67     printf %s\\n "declare-option str-list meson_static_words $(join "${values} ${keywords} ${builtins}" ' ')"
     68 
     69     # Highlight keywords
     70     printf %s "
     71         add-highlighter shared/meson/code/ regex '\b($(join "${values}" '|'))\b' 0:value
     72         add-highlighter shared/meson/code/ regex '\b($(join "${keywords}" '|'))\b' 0:keyword
     73         add-highlighter shared/meson/code/ regex '\b($(join "${builtins}" '|'))\b\(' 1:builtin
     74     "
     75 }
     76 
     77 §