|
| 1 | +from talon import Module, Context, actions |
| 2 | + |
| 3 | +mod = Module() |
| 4 | + |
| 5 | +ctx = Context() |
| 6 | +ctx.matches = r""" |
| 7 | +app: neovim |
| 8 | +and not tag: user.vim_mode_command |
| 9 | +""" |
| 10 | + |
| 11 | +ctx.tags = ["user.splits"] |
| 12 | + |
| 13 | + |
| 14 | +# https://dev.to/mr_destructive/vim-window-splits-p3p |
| 15 | +@ctx.action_class("user") |
| 16 | +class UserActions: |
| 17 | + # ----- split creation ----- |
| 18 | + def split_window_vertically(): |
| 19 | + actions.user.vim_set_normal_exterm() |
| 20 | + actions.key("ctrl-w") |
| 21 | + actions.key("v") |
| 22 | + |
| 23 | + def split_window_horizontally(): |
| 24 | + actions.user.vim_set_normal_exterm() |
| 25 | + actions.key("ctrl-w") |
| 26 | + actions.key("s") |
| 27 | + |
| 28 | + # ----- split arrangement ---- |
| 29 | + def split_move_up(): |
| 30 | + actions.user.vim_set_normal_exterm() |
| 31 | + actions.key("ctrl-w") |
| 32 | + actions.key("K") |
| 33 | + |
| 34 | + def split_move_down(): |
| 35 | + actions.user.vim_set_normal_exterm() |
| 36 | + actions.key("ctrl-w") |
| 37 | + actions.key("J") |
| 38 | + |
| 39 | + def split_move_left(): |
| 40 | + actions.user.vim_set_normal_exterm() |
| 41 | + actions.key("ctrl-w") |
| 42 | + actions.key("H") |
| 43 | + |
| 44 | + def split_move_right(): |
| 45 | + actions.user.vim_set_normal_exterm() |
| 46 | + actions.key("ctrl-w") |
| 47 | + actions.key("L") |
| 48 | + |
| 49 | + # ----- Split navigation ----- |
| 50 | + # TODO: use vim_set_normal_exterm() instead of vim_set_normal() similar |
| 51 | + # to other below? |
| 52 | + def split_focus_up(): |
| 53 | + actions.user.vim_run_normal("\\<c-w>k") |
| 54 | + |
| 55 | + def split_focus_down(): |
| 56 | + actions.user.vim_run_normal("\\<c-w>j") |
| 57 | + |
| 58 | + def split_focus_left(): |
| 59 | + actions.user.vim_run_normal("\\<c-w>h") |
| 60 | + |
| 61 | + def split_focus_right(): |
| 62 | + actions.user.vim_run_normal("\\<c-w>l") |
| 63 | + |
| 64 | + def split_focus_next(): |
| 65 | + actions.user.vim_set_normal_exterm() |
| 66 | + actions.key("ctrl-w") |
| 67 | + actions.key("w") |
| 68 | + |
| 69 | + def split_focus_last(): |
| 70 | + actions.user.vim_set_normal_exterm() |
| 71 | + actions.key("ctrl-w") |
| 72 | + actions.key("W") |
| 73 | + |
| 74 | + def split_focus_number(index: int): |
| 75 | + actions.user.vim_set_normal_exterm() |
| 76 | + actions.insert(f"{index}") |
| 77 | + actions.key("ctrl-w ctrl-w") |
| 78 | + |
| 79 | + # FIXME: This name is subject to change pending https://github.com/talonhub/community/pull/1446 decisions |
| 80 | + def split_focus_most_recent(): |
| 81 | + actions.user.vim_set_normal_exterm() |
| 82 | + actions.key("ctrl-w") |
| 83 | + actions.key("p") |
| 84 | + |
| 85 | + # ----- Split resize ----- |
| 86 | + def split_shrink_width(): |
| 87 | + actions.user.vim_set_normal_exterm() |
| 88 | + actions.key("ctrl-w") |
| 89 | + actions.key("<") |
| 90 | + # XXX - This should restore the original mode, as sometimes I use this from |
| 91 | + # terminal mode |
| 92 | + |
| 93 | + def split_shrink_height(): |
| 94 | + actions.user.vim_set_normal_exterm() |
| 95 | + actions.key("ctrl-w") |
| 96 | + actions.key("-") |
| 97 | + # XXX - This should restore the original mode, as sometimes I use this from |
| 98 | + # terminal mode |
| 99 | + |
| 100 | + def split_expand_width(): |
| 101 | + actions.user.vim_set_normal_exterm() |
| 102 | + actions.key("ctrl-w") |
| 103 | + actions.key(">") |
| 104 | + # XXX - This should restore the original mode, as sometimes I use this from |
| 105 | + # terminal mode |
| 106 | + |
| 107 | + def split_expand_height(): |
| 108 | + actions.user.vim_set_normal_exterm() |
| 109 | + actions.key("ctrl-w") |
| 110 | + actions.key("+") |
| 111 | + # XXX - This should restore the original mode, as sometimes I use this from |
| 112 | + # terminal mode |
| 113 | + |
| 114 | + # ----- Split layout ----- |
| 115 | + def split_layout_toggle(): |
| 116 | + actions.user.vim_set_normal_exterm() |
| 117 | + actions.key("ctrl-w") |
| 118 | + actions.key("r") |
| 119 | + |
| 120 | + def split_clear(): |
| 121 | + actions.user.vim_set_normal_exterm() |
| 122 | + actions.key("ctrl-w") |
| 123 | + actions.key("q") |
| 124 | + |
| 125 | + def split_clear_all(): |
| 126 | + actions.user.vim_set_normal_exterm() |
| 127 | + actions.key("ctrl-w") |
| 128 | + actions.key("o") |
| 129 | + |
| 130 | + # Requirement: https://github.com/dhruvasagar/vim-zoom |
| 131 | + def split_maximize(): |
| 132 | + actions.user.vim_run_normal_exterm_key("ctrl-w m") |
| 133 | + |
| 134 | + |
| 135 | +@mod.action_class |
| 136 | +class SplitActions: |
| 137 | + def split_move_next_tab(): |
| 138 | + """Move the current window to the next tab""" |
| 139 | + actions.user.vim_run_command_exterm(":call MoveToNextTab()\n") |
| 140 | + |
| 141 | + def split_move_last_tab(): |
| 142 | + """Move the current window to the previous tab""" |
| 143 | + actions.user.vim_run_command_exterm(":call MoveToPrevTab()\n") |
| 144 | + |
| 145 | + def split_move_new_tab(): |
| 146 | + """Move the current window to a new tab""" |
| 147 | + actions.user.vim_run_normal_exterm_key("ctrl-w T") |
| 148 | + |
| 149 | + # FIXME: TEMPORARY: Once https://github.com/talonhub/community/pull/1446 is merged, this should be removed |
| 150 | + def split_focus_right(): |
| 151 | + """Focus on the split to the right of the current window""" |
| 152 | + |
| 153 | + def split_focus_left(): |
| 154 | + """Focus on the split to the left of the current window""" |
| 155 | + |
| 156 | + def split_focus_down(): |
| 157 | + """Focus on the split below the current window""" |
| 158 | + |
| 159 | + def split_focus_up(): |
| 160 | + """Focus on the split above the current window""" |
| 161 | + |
| 162 | + def split_focus_next(): |
| 163 | + """Goes to next split""" |
| 164 | + |
| 165 | + def split_focus_last(): |
| 166 | + """Goes to last split""" |
| 167 | + |
| 168 | + def split_focus_number(index: int): |
| 169 | + """Navigates to the specified split""" |
| 170 | + |
| 171 | + def split_focus_most_recent(): |
| 172 | + """Focus on the most recently focused split""" |
| 173 | + |
| 174 | + # Arrangement |
| 175 | + def split_move_right(): |
| 176 | + """Move the split to the right""" |
| 177 | + |
| 178 | + def split_move_left(): |
| 179 | + """Move the split to the left""" |
| 180 | + |
| 181 | + def split_move_down(): |
| 182 | + """Move the split down""" |
| 183 | + |
| 184 | + def split_move_up(): |
| 185 | + """Move the split up""" |
| 186 | + |
| 187 | + def split_layout_toggle(): |
| 188 | + """Flips the orientation of the active split""" |
| 189 | + |
| 190 | + def split_center(): |
| 191 | + """Centers the active split (eg: zen mode)""" |
| 192 | + |
| 193 | + def split_rotate_right(): |
| 194 | + """Rotates the splits to the right""" |
| 195 | + |
| 196 | + def split_rotate_left(): |
| 197 | + """Rotates the splits to the left""" |
| 198 | + |
| 199 | + # Resizing |
| 200 | + def split_maximize(): |
| 201 | + """Maximizes the active split""" |
| 202 | + |
| 203 | + def split_reset(): |
| 204 | + """Resets all the split sizes""" |
| 205 | + |
| 206 | + def split_expand_width(): |
| 207 | + """Expands the split width""" |
| 208 | + |
| 209 | + def split_expand_height(): |
| 210 | + """Expands the split height""" |
| 211 | + |
| 212 | + def split_shrink_width(): |
| 213 | + """Shrinks the split width""" |
| 214 | + |
| 215 | + def split_shrink_height(): |
| 216 | + """Shrinks the split height""" |
| 217 | + |
| 218 | + def split_set_width(width: int): |
| 219 | + """Sets the split width""" |
| 220 | + |
| 221 | + def split_set_height(height: int): |
| 222 | + """Sets the split height""" |
0 commit comments