Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- declare-option str-list portals
- declare-option str-list holes
- declare-option range-specs portal_selections
- define-command portal-new -params 1 -buffer-completion %{
- new "
- evaluate-commands -client %val(client) \
- set-option -add window portals %arg(1) %%val(client)
- buffer %arg(1)
- hook -always -once window RuntimeError .* %%{
- evaluate-commands -client %val(client) \
- portal-close %arg(1)
- }
- evaluate-commands %%sh{
- if test %val(bufname) = %arg(1); then
- notify-send ""%val(bufname):%arg(1):%val(selections_desc)""
- echo select %val(selections_desc)
- fi
- }
- hook -always global WinDisplay '.*' ""portal-focus-change-listener2 %arg(1) %%val(client)""
- add-highlighter window/portal-selections ranges portal_selections
- "
- # kak -ui dummy -c $kak_session -e "
- # evaluate-commands -client $kak_client \
- # set-option -add window portals %($1) %val(client)
- # buffer %($1)
- # " < /dev/null > /dev/null 2>&1 &
- }
- define-command portal-close -params 0..1 -buffer-completion %{ evaluate-commands %sh{
- if test $# = 0; then
- echo portal-close-all
- exit
- fi
- match=false
- buffer_close=$1
- eval "set -- $kak_opt_portals"
- echo "unset-option window portals"
- while test $# -ge 2; do
- buffer=$1
- client=$2
- shift 2
- if test "$buffer" = "$buffer_close"; then
- match=true
- printf 'try %%(evaluate-commands -client %s quit)\n' "$client"
- else
- printf 'set-option -add window portals %%(%s) %%(%s)\n' "$buffer" "$client"
- fi
- done
- if test $match = false; then
- printf 'fail No portal connected to %s\n' "$buffer_close"
- fi
- }}
- define-command -hidden portal-close-all %{
- evaluate-commands %sh{
- eval "set -- $kak_opt_portals"
- while test $# -ge 2; do
- buffer=$1
- client=$2
- shift 2
- printf 'try %%(evaluate-commands -client %s quit)\n' "$client"
- done
- }
- unset-option window portals
- remove-hooks window portal
- }
- define-command -hidden portal-listener %{ evaluate-commands %sh{
- eval "set -- $kak_opt_portals"
- while test $# -ge 2; do
- buffer=$1
- client=$2
- shift 2
- if test "$buffer" = "$kak_bufname"; then
- # Sync view
- notify-send "$kak_bufname"
- selections=$(echo $kak_selections_desc | sed --regexp-extended s/'([0-9]+)[.]([0-9]+),([0-9]+)[.]([0-9]+)'/'\1.\2,\3.\4|SecondarySelection'/g)
- printf '
- evaluate-commands -client %s %%{
- set-option window portal_selections %%val(timestamp) %s
- }
- ' "$client" "$selections"
- else
- printf '
- try %%{
- execute-keys -client %s -with-hooks -with-maps %%(%s)
- } catch %%{
- nop %%sh(notify-send err)
- portal-close %%(%s)
- }
- ' "$client" "$kak_hook_param" "$buffer"
- fi
- done
- }}
- define-command -hidden portal-focus-change-listener -params 2 %{ evaluate-commands %sh{
- buffer=$1
- client=$2
- if test "$kak_client" = "$client"; then
- notify-send "WIN -> $kak_hook_param:$kak_client:$kak_opt_portals"
- printf 'buffer %%(%s)\n' "$buffer"
- echo portal-close-all
- fi
- }}
- define-command -hidden portal-focus-change-listener2 -params 2 %{ evaluate-commands %sh{
- buffer=$1
- client=$2
- if test "$kak_client" = "$client"; then
- notify-send "WIN -> $kak_hook_param:$kak_client:$kak_opt_portals"
- echo quit
- fi
- }}
- define-command portal-open %{
- hook -always -once window NormalIdle '.*' %{
- hook -always window -group portal RawKey .* portal-listener
- }
- hook -always window WinClose '.*' %(nop %sh(notify-send Close))
- # Issue:
- hook -always global WinDisplay '.*' "portal-focus-change-listener %val(bufname) %val(client)"
- hook -always global -group portal RuntimeError .* %{
- nop %sh(notify-send "ERROR")
- portal-close-all
- remove-hooks window portal
- }
- }
- define-command i %{
- edit t.txt
- execute-keys '<a-a><a-w>l<a-i><a-w>'
- edit f.txt
- buffer t.txt
- portal-new f.txt
- portal-new t.txt
- focus client0
- portal-open
- }
Add Comment
Please, Sign In to add comment