Guest User

Untitled

a guest
Dec 13th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. declare-option str-list portals
  2. declare-option str-list holes
  3. declare-option range-specs portal_selections
  4.  
  5. define-command portal-new -params 1 -buffer-completion %{
  6. new "
  7. evaluate-commands -client %val(client) \
  8. set-option -add window portals %arg(1) %%val(client)
  9. buffer %arg(1)
  10. hook -always -once window RuntimeError .* %%{
  11. evaluate-commands -client %val(client) \
  12. portal-close %arg(1)
  13. }
  14. evaluate-commands %%sh{
  15. if test %val(bufname) = %arg(1); then
  16. notify-send ""%val(bufname):%arg(1):%val(selections_desc)""
  17. echo select %val(selections_desc)
  18. fi
  19. }
  20. hook -always global WinDisplay '.*' ""portal-focus-change-listener2 %arg(1) %%val(client)""
  21. add-highlighter window/portal-selections ranges portal_selections
  22. "
  23. # kak -ui dummy -c $kak_session -e "
  24. # evaluate-commands -client $kak_client \
  25. # set-option -add window portals %($1) %val(client)
  26. # buffer %($1)
  27. # " < /dev/null > /dev/null 2>&1 &
  28. }
  29.  
  30. define-command portal-close -params 0..1 -buffer-completion %{ evaluate-commands %sh{
  31. if test $# = 0; then
  32. echo portal-close-all
  33. exit
  34. fi
  35. match=false
  36. buffer_close=$1
  37. eval "set -- $kak_opt_portals"
  38. echo "unset-option window portals"
  39. while test $# -ge 2; do
  40. buffer=$1
  41. client=$2
  42. shift 2
  43. if test "$buffer" = "$buffer_close"; then
  44. match=true
  45. printf 'try %%(evaluate-commands -client %s quit)\n' "$client"
  46. else
  47. printf 'set-option -add window portals %%(%s) %%(%s)\n' "$buffer" "$client"
  48. fi
  49. done
  50. if test $match = false; then
  51. printf 'fail No portal connected to %s\n' "$buffer_close"
  52. fi
  53. }}
  54.  
  55. define-command -hidden portal-close-all %{
  56. evaluate-commands %sh{
  57. eval "set -- $kak_opt_portals"
  58. while test $# -ge 2; do
  59. buffer=$1
  60. client=$2
  61. shift 2
  62. printf 'try %%(evaluate-commands -client %s quit)\n' "$client"
  63. done
  64. }
  65. unset-option window portals
  66. remove-hooks window portal
  67. }
  68.  
  69. define-command -hidden portal-listener %{ evaluate-commands %sh{
  70. eval "set -- $kak_opt_portals"
  71. while test $# -ge 2; do
  72. buffer=$1
  73. client=$2
  74. shift 2
  75. if test "$buffer" = "$kak_bufname"; then
  76. # Sync view
  77. notify-send "$kak_bufname"
  78. selections=$(echo $kak_selections_desc | sed --regexp-extended s/'([0-9]+)[.]([0-9]+),([0-9]+)[.]([0-9]+)'/'\1.\2,\3.\4|SecondarySelection'/g)
  79. printf '
  80. evaluate-commands -client %s %%{
  81. set-option window portal_selections %%val(timestamp) %s
  82. }
  83. ' "$client" "$selections"
  84. else
  85. printf '
  86. try %%{
  87. execute-keys -client %s -with-hooks -with-maps %%(%s)
  88. } catch %%{
  89. nop %%sh(notify-send err)
  90. portal-close %%(%s)
  91. }
  92. ' "$client" "$kak_hook_param" "$buffer"
  93. fi
  94. done
  95. }}
  96.  
  97. define-command -hidden portal-focus-change-listener -params 2 %{ evaluate-commands %sh{
  98. buffer=$1
  99. client=$2
  100. if test "$kak_client" = "$client"; then
  101. notify-send "WIN -> $kak_hook_param:$kak_client:$kak_opt_portals"
  102. printf 'buffer %%(%s)\n' "$buffer"
  103. echo portal-close-all
  104. fi
  105. }}
  106.  
  107. define-command -hidden portal-focus-change-listener2 -params 2 %{ evaluate-commands %sh{
  108. buffer=$1
  109. client=$2
  110. if test "$kak_client" = "$client"; then
  111. notify-send "WIN -> $kak_hook_param:$kak_client:$kak_opt_portals"
  112. echo quit
  113. fi
  114. }}
  115.  
  116. define-command portal-open %{
  117. hook -always -once window NormalIdle '.*' %{
  118. hook -always window -group portal RawKey .* portal-listener
  119. }
  120. hook -always window WinClose '.*' %(nop %sh(notify-send Close))
  121. # Issue:
  122. hook -always global WinDisplay '.*' "portal-focus-change-listener %val(bufname) %val(client)"
  123. hook -always global -group portal RuntimeError .* %{
  124. nop %sh(notify-send "ERROR")
  125. portal-close-all
  126. remove-hooks window portal
  127. }
  128. }
  129.  
  130. define-command i %{
  131.  
  132. edit t.txt
  133. execute-keys '<a-a><a-w>l<a-i><a-w>'
  134. edit f.txt
  135. buffer t.txt
  136. portal-new f.txt
  137. portal-new t.txt
  138. focus client0
  139. portal-open
  140.  
  141. }
Add Comment
Please, Sign In to add comment