kitty.kak (17137B)
1 # https://sw.kovidgoyal.net/kitty/ 2 3 hook global BufCreate .*/kitty/.*[.]conf %{ 4 set-option buffer filetype kitty-conf 5 } 6 7 hook global BufCreate .*/kitty/.*[.]session %{ 8 set-option buffer filetype kitty-session 9 } 10 11 hook global WinSetOption filetype=kitty-conf %{ 12 require-module kitty-conf 13 set-option window static_words %opt{kitty_conf_static_words} 14 15 hook window ModeChange pop:insert:.* -group kitty-conf-trim-indent kitty-conf-trim-indent 16 hook window InsertChar \n -group kitty-conf-insert kitty-conf-insert-on-new-line 17 hook window InsertChar \n -group kitty-conf-indent kitty-conf-indent-on-new-line 18 19 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kitty-conf-.+ } 20 } 21 22 hook -group kitty-conf-highlight global WinSetOption filetype=kitty-conf %{ 23 add-highlighter window/kitty-conf ref kitty-conf 24 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kitty-conf } 25 } 26 27 hook global WinSetOption filetype=kitty-session %{ 28 require-module kitty-session 29 set-option window static_words %opt{kitty_session_static_words} 30 31 hook window ModeChange pop:insert:.* -group kitty-session-trim-indent kitty-session-trim-indent 32 hook window InsertChar \n -group kitty-session-insert kitty-session-insert-on-new-line 33 hook window InsertChar \n -group kitty-session-indent kitty-session-indent-on-new-line 34 35 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window kitty-session-.+ } 36 } 37 38 hook -group kitty-session-highlight global WinSetOption filetype=kitty-session %{ 39 add-highlighter window/kitty-session ref kitty-session 40 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/kitty-session } 41 } 42 43 provide-module kitty-conf %{ 44 45 # Highlighters 46 # ‾‾‾‾‾‾‾‾‾‾‾‾ 47 48 add-highlighter shared/kitty-conf regions 49 add-highlighter shared/kitty-conf/code default-region group 50 51 52 add-highlighter shared/kitty-conf/line_comment region ^# $ fill comment 53 add-highlighter shared/kitty-conf/string region '"' (?<!\\)(\\\\)*" fill string 54 add-highlighter shared/kitty-conf/string2 region "'" (?<!\\)(\\\\)*' fill string 55 56 add-highlighter shared/kitty-conf/code/keybind regex ^\s*map\s([^\s]+) 1:value 57 add-highlighter shared/kitty-conf/code/kitty_mod regex ^\s*kitty_mod\s([^\s]+) 1:value 58 add-highlighter shared/kitty-conf/code/include regex ^\s*include\s(.*) 1:string 59 add-highlighter shared/kitty-conf/code/globinclude regex ^\s*globinclude\s(.*) 1:string 60 add-highlighter shared/kitty-conf/code/geninclude regex ^\s*geninclude\s(.*) 1:string 61 add-highlighter shared/kitty-conf/code/envinclude regex ^\s*envinclude\s(.*) 1:string 62 63 add-highlighter shared/kitty-conf/code/ regex \b(yes|no|no-op)\b 0:value 64 add-highlighter shared/kitty-conf/code/ regex '(?i)\b0x[\da-f]+\b' 0:value 65 add-highlighter shared/kitty-conf/code/ regex '(?i)\b0o?[0-7]+\b' 0:value 66 add-highlighter shared/kitty-conf/code/ regex '(?i)\b0b[01]+\b' 0:value 67 add-highlighter shared/kitty-conf/code/ regex '(?i)\bU\+[\da-f]+\b' 0:value 68 add-highlighter shared/kitty-conf/code/ regex '(?i)[^\w]#([\da-f]{8}|[\da-f]{6}|[\da-f]{3})\b' 0:value 69 add-highlighter shared/kitty-conf/code/ regex '(?i)\s([1-9]\d*|0)\b' 0:value 70 add-highlighter shared/kitty-conf/code/ regex '(\b\d+)?\.\d+\b' 0:value 71 72 evaluate-commands %sh{ 73 kitty_mods="alt super cmd command ⌘ control ctrl ^ kitty_mod opt option ⌥ shift ⇧" 74 kitty_keywords="action_alias active_border_color active_tab_background 75 active_tab_font_style active_tab_foreground active_tab_title_template 76 allow_cloning allow_hyperlinks allow_remote_control background 77 background_blur background_image background_image_layout 78 background_image_linear background_opacity background_tint 79 background_tint_gaps bell_border_color bell_on_tab bell_path bold_font 80 bold_italic_font box_drawing_scale clear_all_mouse_actions 81 clear_all_shortcuts clear_selection_on_clipboard_loss click_interval 82 clipboard_control clipboard_max_size clone_source_strategies 83 close_on_child_death color0 color1 color2 color3 color4 color5 color6 84 color7 color8 color9 color10 color11 color12 color13 color14 color15 85 color16 color17 color18 color19 color20 color21 color22 color23 color24 86 color25 color26 color27 color28 color29 color30 color31 color32 color33 87 color34 color35 color36 color37 color38 color39 color40 color41 color42 88 color43 color44 color45 color46 color47 color48 color49 color50 color51 89 color52 color53 color54 color55 color56 color57 color58 color59 color60 90 color61 color62 color63 color64 color65 color66 color67 color68 color69 91 color70 color71 color72 color73 color74 color75 color76 color77 color78 92 color79 color80 color81 color82 color83 color84 color85 color86 color87 93 color88 color89 color90 color91 color92 color93 color94 color95 color96 94 color97 color98 color99 color100 color101 color102 color103 color104 95 color105 color106 color107 color108 color109 color110 color111 color112 96 color113 color114 color115 color116 color117 color118 color119 color120 97 color121 color122 color123 color124 color125 color126 color127 color128 98 color129 color130 color131 color132 color133 color134 color135 color136 99 color137 color138 color139 color140 color141 color142 color143 color144 100 color145 color146 color147 color148 color149 color150 color151 color152 101 color153 color154 color155 color156 color157 color158 color159 color160 102 color161 color162 color163 color164 color165 color166 color167 color168 103 color169 color170 color171 color172 color173 color174 color175 color176 104 color177 color178 color179 color180 color181 color182 color183 color184 105 color185 color186 color187 color188 color189 color190 color191 color192 106 color193 color194 color195 color196 color197 color198 color199 color200 107 color201 color202 color203 color204 color205 color206 color207 color208 108 color209 color210 color211 color212 color213 color214 color215 color216 109 color217 color218 color219 color220 color221 color222 color223 color224 110 color225 color226 color227 color228 color229 color230 color231 color232 111 color233 color234 color235 color236 color237 color238 color239 color240 112 color241 color242 color243 color244 color245 color246 color247 color248 113 color249 color250 color251 color252 color253 color254 color255 114 command_on_bell confirm_os_window_close copy_on_select cursor 115 cursor_beam_thickness cursor_blink_interval cursor_shape 116 cursor_shape_unfocused cursor_stop_blinking_after cursor_text_color 117 cursor_trail cursor_trail_decay cursor_trail_start_threshold 118 cursor_underline_thickness default_pointer_shape detect_urls dim_opacity 119 disable_ligatures draw_minimal_borders dynamic_background_opacity editor 120 enable_audio_bell enabled_layouts env exe_search_path 121 file_transfer_confirmation_bypass filter_notification focus_follows_mouse 122 font_family font_features font_size force_ltr foreground forward_stdio 123 hide_window_decorations inactive_border_color inactive_tab_background 124 inactive_tab_font_style inactive_tab_foreground inactive_text_alpha 125 initial_window_height initial_window_width input_delay italic_font 126 kitten_alias kitty_mod linux_bell_theme linux_display_server listen_on 127 macos_colorspace macos_custom_beam_cursor macos_hide_from_tasks 128 macos_menubar_title_max_length macos_option_as_alt 129 macos_quit_when_last_window_closed macos_show_window_title_in 130 macos_thicken_font macos_titlebar_color macos_traditional_fullscreen 131 macos_window_resizable map mark1_background mark1_foreground 132 mark2_background mark2_foreground mark3_background mark3_foreground 133 menu_map modify_font mouse_hide_wait mouse_map narrow_symbols 134 notify_on_cmd_finish open_url_with paste_actions placement_strategy 135 pointer_shape_when_dragging pointer_shape_when_grabbed 136 remember_window_size remote_control_password repaint_delay 137 resize_debounce_time resize_in_steps scrollback_fill_enlarged_window 138 scrollback_indicator_opacity scrollback_lines scrollback_pager 139 scrollback_pager_history_size select_by_word_characters 140 select_by_word_characters_forward selection_background 141 selection_foreground shell shell_integration show_hyperlink_targets 142 single_window_margin_width single_window_padding_width startup_session 143 strip_trailing_spaces symbol_map sync_to_monitor tab_activity_symbol 144 tab_bar_align tab_bar_background tab_bar_edge tab_bar_margin_color 145 tab_bar_margin_height tab_bar_margin_width tab_bar_min_tabs tab_bar_style 146 tab_fade tab_powerline_style tab_separator tab_switch_strategy 147 tab_title_max_length tab_title_template term terminfo_type 148 text_composition_strategy text_fg_override_threshold 149 touch_scroll_multiplier transparent_background_colors undercurl_style 150 underline_exclusion underline_hyperlinks update_check_interval url_color 151 url_excluded_characters url_prefixes url_style visual_bell_color 152 visual_bell_duration visual_window_select_characters watcher 153 wayland_enable_ime wayland_titlebar_color wheel_scroll_min_lines 154 wheel_scroll_multiplier window_alert_on_bell window_border_width 155 window_logo_alpha window_logo_path window_logo_position window_logo_scale 156 window_margin_width window_padding_width window_resize_step_cells 157 window_resize_step_lines" 158 kitty_actions="change_font_size clear_selection clear_terminal click close_os_window 159 close_other_os_windows close_other_tabs_in_os_window 160 close_other_windows_in_tab close_shared_ssh_connections close_tab 161 close_window close_window_with_confirmation combine 162 copy_and_clear_or_interrupt copy_ansi_to_clipboard copy_or_interrupt 163 copy_to_buffer copy_to_clipboard create_marker debug_config detach_tab 164 detach_window disable_ligatures_in discard_event doubleclick doublepress 165 dump_lines_with_attrs edit_config_file eighth_window fifth_window 166 first_window focus_visible_window fourth_window goto_layout goto_tab 167 hide_macos_app hide_macos_other_apps input_unicode_character kitten 168 kitty_shell last_used_layout launch layout_action load_config_file 169 minimize_macos_window mouse_click_url mouse_click_url_or_select 170 mouse_handle_click mouse_select_command_output mouse_selection 171 mouse_show_command_output move_tab_backward move_tab_forward move_window 172 move_window_backward move_window_forward move_window_to_top 173 neighboring_window new_os_window new_os_window_with_cwd new_tab 174 new_tab_with_cwd new_window new_window_with_cwd next_layout next_tab 175 next_window ninth_window no-op nth_os_window nth_window open_url 176 open_url_with_hints pass_selection_to_program paste paste_from_buffer 177 paste_from_clipboard paste_from_selection paste_selection 178 paste_selection_or_clipboard pop_keyboard_mode press previous_tab 179 previous_window push_keyboard_mode quit release remote_control 180 remote_control_script remove_marker reset_window_sizes resize_window 181 scroll_end scroll_home scroll_line_down scroll_line_up scroll_page_down 182 scroll_page_up scroll_prompt_to_bottom scroll_prompt_to_top scroll_to_mark 183 scroll_to_prompt second_window select_tab send_key send_text 184 set_background_opacity set_colors set_tab_title set_window_title 185 seventh_window show_error show_first_command_output_on_screen 186 show_kitty_doc show_kitty_env_vars show_last_command_output 187 show_last_non_empty_command_output show_last_visited_command_output 188 show_scrollback signal_child sixth_window sleep start_resizing_window 189 swap_with_window tenth_window third_window toggle_fullscreen toggle_layout 190 toggle_macos_secure_keyboard_entry toggle_marker toggle_maximized 191 toggle_tab triplepress" 192 kitty_include="envinclude geninclude globinclude include" 193 194 join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } 195 196 printf %s\\n "declare-option str-list kitty_conf_static_words $(join "${kitty_mods}" ' ') $(join "${kitty_keywords}" ' ') $(join "${kitty_actions}" ' ') $(join "${kitty_include}" ' ')" 197 198 printf %s\\n "add-highlighter shared/kitty-conf/code/ regex '\b($(join "${kitty_mods}" '|'))\b' 0:keyword" 199 printf %s\\n "add-highlighter shared/kitty-conf/code/ regex '\b($(join "${kitty_keywords}" '|'))\b' 0:keyword" 200 printf %s\\n "add-highlighter shared/kitty-conf/code/ regex '\b($(join "${kitty_actions}" '|'))\b' 0:function" 201 printf %s\\n "add-highlighter shared/kitty-conf/code/ regex '\b($(join "${kitty_include}" '|'))\b' 0:keyword" 202 } 203 204 # Commands 205 # ‾‾‾‾‾‾‾‾ 206 207 define-command -hidden kitty-conf-trim-indent %{ 208 # remove trailing white spaces 209 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 210 } 211 212 define-command -hidden kitty-conf-insert-on-new-line %{ 213 evaluate-commands -draft -itersel %{ 214 # copy # comments prefix and following white spaces 215 try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P } 216 } 217 } 218 219 define-command -hidden kitty-conf-indent-on-new-line %{ 220 evaluate-commands -draft -itersel %{ 221 # preserve previous line indent 222 try %{ execute-keys -draft <semicolon> K <a-&> } 223 # filter previous line 224 try %{ execute-keys -draft k : kitty-conf-trim-indent <ret> } 225 } 226 } 227 228 } 229 230 provide-module kitty-session %{ 231 232 # Highlighters 233 # ‾‾‾‾‾‾‾‾‾‾‾‾ 234 235 add-highlighter shared/kitty-session regions 236 add-highlighter shared/kitty-session/code default-region group 237 238 add-highlighter shared/kitty-session/line_comment region ^# $ fill comment 239 add-highlighter shared/kitty-session/string region '"' (?<!\\)(\\\\)*" fill string 240 add-highlighter shared/kitty-session/string2 region "'" (?<!\\)(\\\\)*' fill string 241 242 add-highlighter shared/kitty-session/code/ regex '(?i)\b0x[\da-f]+\b' 0:value 243 add-highlighter shared/kitty-session/code/ regex '(?i)\b0o?[0-7]+\b' 0:value 244 add-highlighter shared/kitty-session/code/ regex '(?i)\b0b[01]+\b' 0:value 245 add-highlighter shared/kitty-session/code/ regex '(?i)\bU\+[\da-f]+\b' 0:value 246 add-highlighter shared/kitty-session/code/ regex '(?i)\s([1-9]\d*|0)\b' 0:value 247 add-highlighter shared/kitty-session/code/ regex '(\b\d+)?\.\d+\b' 0:value 248 249 evaluate-commands %sh{ 250 kitty_session_commands="new_tab new_os_window layout launch focus enabled_layouts cd title os_window_size os_window_class" 251 252 join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } 253 254 printf %s\\n "declare-option str-list kitty_session_static_words $(join "${kitty_session_commands}" ' ')" 255 256 printf %s\\n "add-highlighter shared/kitty-session/code/ regex '\b($(join "${kitty_session_commands}" '|'))\b' 0:keyword" 257 } 258 259 # Commands 260 # ‾‾‾‾‾‾‾‾ 261 262 define-command -hidden kitty-session-trim-indent %{ 263 # remove trailing white spaces 264 try %{ execute-keys -draft -itersel x s \h+$ <ret> d } 265 } 266 267 define-command -hidden kitty-session-insert-on-new-line %{ 268 evaluate-commands -draft -itersel %{ 269 # copy # comments prefix and following white spaces 270 try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P } 271 } 272 } 273 274 define-command -hidden kitty-session-indent-on-new-line %{ 275 evaluate-commands -draft -itersel %{ 276 # preserve previous line indent 277 try %{ execute-keys -draft <semicolon> K <a-&> } 278 # filter previous line 279 try %{ execute-keys -draft k : kitty-session-trim-indent <ret> } 280 } 281 } 282 283 }