From 4248686c2613c162840b259e265c78415ad9c9f7 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Sun, 6 Oct 2024 23:57:46 +0200 Subject: [PATCH] kak: preview for hex color codes originally by alexherbo2 (hex codes with leading # sign) (https://discuss.kakoune.com/t/colorize-hexadecimal-colors/1623/19) second function is mine (hex codes without leading # sign) --- config/dot-config/kak/kakrc | 106 +++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 27 deletions(-) diff --git a/config/dot-config/kak/kakrc b/config/dot-config/kak/kakrc index f993f822..7d86412a 100644 --- a/config/dot-config/kak/kakrc +++ b/config/dot-config/kak/kakrc @@ -195,6 +195,54 @@ define-command -hidden -params 2 inc %{ try %{ execute-keys l }} +# preview hex color codes with a leading # +declare-option -hidden range-specs hex_color_code_ranges +add-highlighter shared/hex_color_code ranges hex_color_code_ranges + +define-command update_hex_color_code_ranges %{ + set-option window hex_color_code_ranges %val{timestamp} + evaluate-commands -draft %{ + execute-keys 'gtGbx' + evaluate-commands -draft -verbatim try %{ + execute-keys 's\B#([0-9A-Fa-f]{6})\b' + evaluate-commands -itersel %{ + set-option -add window hex_color_code_ranges "%val{selection_desc}|default,rgb:%reg{1}" + } + } + evaluate-commands -draft -verbatim try %{ + execute-keys 's\B#([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])\b' + evaluate-commands -itersel %{ + set-option -add window hex_color_code_ranges "%val{selection_desc}|default,rgb:%reg{1}%reg{1}%reg{2}%reg{2}%reg{3}%reg{3}" + } + } + } +} + +hook -always global NormalIdle '' update_hex_color_code_ranges +hook -always global InsertIdle '' update_hex_color_code_ranges +hook -always global PromptIdle '' update_hex_color_code_ranges + +# preview hex color codes without leading # +declare-option -hidden range-specs hex_color_code_ranges2 +add-highlighter shared/hex_color_code2 ranges hex_color_code_ranges2 + +define-command update_hex_color_code_ranges2 %{ + set-option window hex_color_code_ranges2 %val{timestamp} + evaluate-commands -draft %{ + execute-keys 'gtGbx' + evaluate-commands -draft -verbatim try %{ + execute-keys 's\B"([0-9A-Fa-f]{6})\b"' + execute-keys -draft 'S"' + evaluate-commands -itersel %{ + set-option -add window hex_color_code_ranges2 "%val{selection_desc}|default,rgb:%reg{1}" + } + } + } +} + +hook -always global NormalIdle '' update_hex_color_code_ranges2 +hook -always global InsertIdle '' update_hex_color_code_ranges2 +hook -always global PromptIdle '' update_hex_color_code_ranges2 # normal mode kks mappings # ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── @@ -216,44 +264,48 @@ map global normal -docstring 'comment line' '#' ': map global normal -docstring 'comment block' ': comment-block' map global normal -docstring 'Next buffer ' ': buffer-next' map global normal -docstring 'Previous buffer' ': buffer-previous' -map global normal -docstring '(^) add 1 int' '^' ': inc %val{count} +' -map global normal -docstring '(S-^) substract 1 int' ': inc %val{count} -' +map global normal -docstring 'add 1 int' '^' ': inc %val{count} +' +map global normal -docstring 'substract 1 int' ': inc %val{count} -' # default user mode # ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -map global user -docstring '(b)uffer mode' b ': enter-user-mode buffermode' -map global user -docstring '(s)election mode' s ': enter-user-mode selmode' -map global user -docstring '(E)dit kakrc' E ': e ~/.config/kak/kakrc' -map global user -docstring ':::::::::::::::::::::::::::::::: ::' : ': ' -map global user -docstring 'goto (S)cratch buffer' S ': buffer *scratch*' -map global user -docstring 'goto (D)ebug buffer' D ': buffer *debug*' -map global user -docstring '(e)xpand selection' e ': expand' -map global user -docstring 'insert (n)ewline above current' n ' Oj' -map global user -docstring 'insert (N)ewline below current' N ' ok' -map global user -docstring '(r)elative line numbers enable' r ': addhl window/nl number-lines -min-digits -1 -relative -hlcursor' -map global user -docstring '(R)elative line numbers disable' R ': remove-highlighter window/nl' +map global user -docstring 'buffer mode' b ': enter-user-mode buffermode' +map global user -docstring 'selection mode' s ': enter-user-mode selmode' +map global user -docstring 'Edit kakrc' E ': e ~/.config/kak/kakrc' +map global user -docstring 'highlight hex color without leading #' p ': addhl global/hex_color_code2 ref hex_color_code2' +map global user -docstring 'unhighlight hex color without leading #' ': rmhl global/hex_color_code2' +map global user -docstring 'highlight hex color with leading #' '#' ': addhl global/hex_color_code ref hex_color_code' +map global user -docstring 'unhighlight hex color with leading #' ': rmhl global/hex_color_code' +map global user -docstring ':::::::::::::::::::::::::::::::: ::' : ': ' +map global user -docstring 'Scratch buffer' S ': buffer *scratch*' +map global user -docstring 'Debug buffer' D ': buffer *debug*' +map global user -docstring 'expand selection' e ': expand' +map global user -docstring 'insert newline above current' n ' Oj' +map global user -docstring 'insert newline below current' N ' ok' +map global user -docstring 'relative line numbers enable' r ': addhl window/nl number-lines -min-digits -1 -relative -hlcursor' +map global user -docstring 'relative line numbers disable' R ': rmhl window/nl' # buffer user mode # ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── declare-user-mode buffermode -map global buffermode -docstring 'enable (a)utocomplete' a ': set-option -add buffer autocomplete insert' -map global buffermode -docstring 'disable (A)utocomplete' A ': set-option -remove buffer autocomplete insert' -map global buffermode -docstring '(c)lean tabs and trailing whitespaces' c ': clean-buffer' -map global buffermode -docstring '(d)elete buffer' d ': delete-buffer' -map global buffermode -docstring 'show file (i)nfo' i ': info "file saved at %sh{date}"' -map global buffermode -docstring '(l)ist buffers' l ': kks-connect terminal-popup kks-buffers' -map global buffermode -docstring '(L)int buffer' L ': buffer *lint-output*' -map global buffermode -docstring '(n)ext buffer' n ': buffer-next' -map global buffermode -docstring '(p)revious buffer' p ': buffer-previous' -map global buffermode -docstring '(w)rap enable' w ': add-highlighter buffer/bw wrap' -map global buffermode -docstring '(W)rap disable' W ': remove-highlighter buffer/bw' +map global buffermode -docstring 'enable autocomplete' a ': set-option -add buffer autocomplete insert' +map global buffermode -docstring 'disable Autocomplete' A ': set-option -remove buffer autocomplete insert' +map global buffermode -docstring 'clean tabs and trailing whitespaces' c ': clean-buffer' +map global buffermode -docstring 'delete buffer' d ': delete-buffer' +map global buffermode -docstring 'show file info' i ': info "file saved at %sh{date}"' +map global buffermode -docstring 'list buffers' l ': kks-connect terminal-popup kks-buffers' +map global buffermode -docstring 'Lint buffer' L ': buffer *lint-output*' +map global buffermode -docstring 'next buffer' n ': buffer-next' +map global buffermode -docstring 'previous buffer' p ': buffer-previous' +map global buffermode -docstring 'wrap enable' w ': add-highlighter buffer/bw wrap' +map global buffermode -docstring 'Wrap disable' W ': remove-highlighter buffer/bw' # selection user mode # ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── declare-user-mode selmode -map global selmode -docstring 'clean tabs and trailing whitespaces' c ': clean-selections' -map global selmode -docstring 'sort words (H)orizontally in selection' h '| xargs -n1 | sort -u | xargs ' -map global selmode -docstring 'sort words (V)ertically in selection ' v '| sort -n ' +map global selmode -docstring 'clean tabs and trailing whitespaces' c ': clean-selections' +map global selmode -docstring 'sort words Horizontally in selection' h '| xargs -n1 | sort -u | xargs ' +map global selmode -docstring 'sort words Vertically in selection ' v '| sort -n ' # terminal config (via foot.kak) # ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── -- 2.51.2