From b122b1f203c860c552e9c485fc0b2cca777c51eb Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:47:13 +0000 Subject: [PATCH 01/75] chore(deps): update actions/checkout digest to 0ad4b8f --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ad6c0ec..a7bc7b7 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -8,7 +8,7 @@ jobs: runs-on: windows-latest steps: - name: Checkout code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 - name: Install AutoHotkey with Chocolatey uses: crazy-max/ghaction-chocolatey@v3 with: From b6b9cdff7a7454440b15ffa5b5159e7c951816b4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:57:32 +0000 Subject: [PATCH 02/75] chore(deps): update actions/checkout digest to 692973e --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index a7bc7b7..434154f 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -8,7 +8,7 @@ jobs: runs-on: windows-latest steps: - name: Checkout code - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - name: Install AutoHotkey with Chocolatey uses: crazy-max/ghaction-chocolatey@v3 with: From eb3aa8b2f15b5577e8ed15bce1e1fa1266b142fc Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 14:42:35 +0900 Subject: [PATCH 03/75] fix: remove unnecessary Return statement from DisplayToolTip --- lib/vim_tooltip.ahk | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index ba56cab..03c68b8 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -17,7 +17,6 @@ class VimToolTip{ SetTimer, % display, -1000 } } - Return } DisplayToolTip(){ From f59ec5d9c56df06674342a7981ef649004df3df5 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:16:12 +0900 Subject: [PATCH 04/75] fix: remove extraneous argument from SetCaret function in vim_state.ahk --- lib/vim_state.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 2ce57ab..1880990 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -54,7 +54,7 @@ VIM_IME_SET(this.LastIME) } this.Vim.Icon.SetIcon(this.Mode, this.Vim.Conf["VimIconCheckInterval"]["val"]) - this.Vim.Caret.SetCaret(this.Mode, this.Vim.Conf["VimIconCheckInterval"]["val"]) + this.Vim.Caret.SetCaret(this.Mode) } if(g != -1){ this.g := g From 4348481dddd2d91595995a3dd135a4ea2269d384 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Thu, 26 Sep 2024 01:40:28 +0900 Subject: [PATCH 05/75] docs: add section for AutoHotkey v1 or v2 compatibility and development status --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 40aacb6..002fdd7 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,17 @@ This is vim emulation for Windows. If you are interested in the same settings for Mac, try Vim emulation for [Karabiner - Software for macOS](https://pqrs.org/osx/karabiner/): [Karabiner-Elements complex_modifications rules by rcmdnk](https://rcmdnk.com/KE-complex_modifications/). + +## AutoHotkey v1 or v2 + +This script is for AutoHotkey v1. + +Currently, vim_ahk for AutoHotkey v2 is under development in the branch [ahk_v2](https://github.com/rcmdnk/vim_ahk/tree/ahk_v2). + +If you are using AutoHotkey v2, please try the script in [ahk_v2](https://github.com/rcmdnk/vim_ahk/tree/ahk_v2). + +Any feedback is welcome. + ## Installation ### Scripts From 0075cfd46378cf21297faba5acbf0fb802ae597d Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 00:10:15 +0900 Subject: [PATCH 06/75] fix: resolve remapping issue for the period key in vim normal mode --- lib/bind/vim_normal.ahk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 0473979..6694de8 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -21,6 +21,9 @@ u::Send,^z Clipboard := bak Return +; period +.::Send, +^{Right}{BS}^v + +z::Vim.State.SetMode("Z") #If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +z:: @@ -34,9 +37,6 @@ Return Vim.State.SetMode("Vim_Normal") Return -; period -.::Send, +^{Right}{BS}^v - ; Q-dir #If Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") ; For Q-dir, ^X mapping does not work, use !X instead. From 60fe5981b6b229b8cb278adb091d0e16cf630fef Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 14:08:40 +0900 Subject: [PATCH 07/75] fix: correct tooltip control state assignment in OnMouseMove method --- lib/vim_tooltip.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index 03c68b8..dfbfd9a 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -8,7 +8,7 @@ class VimToolTip{ } OnMouseMove(wp, lp, msg, hwnd){ - this.Vim.State.CurrControl := A_GuiControl + this.Vim.State.CurrControl := hwnd if(this.Vim.State.CurrControl != this.Vim.State.PrevControl){ this.Vim.State.PrevControl := this.Vim.State.CurrControl this.RemoveToolTip() From 681a675cb17276c2e6b2a206309c4d179e4c326d Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 10:58:17 +0900 Subject: [PATCH 08/75] fix: replace all "#If" directives with "#HotIf" (for v2) --- lib/bind/vim_command.ahk | 10 +++++----- lib/bind/vim_disable.ahk | 8 ++++---- lib/bind/vim_enter_insert.ahk | 6 +++--- lib/bind/vim_enter_normal.ahk | 6 +++--- lib/bind/vim_move.ahk | 14 +++++++------- lib/bind/vim_normal.ahk | 8 ++++---- lib/bind/vim_repeat.ahk | 6 +++--- lib/bind/vim_replace.ahk | 8 ++++---- lib/bind/vim_search.ahk | 4 ++-- lib/bind/vim_shortcut.ahk | 8 ++++---- lib/bind/vim_visual.ahk | 6 +++--- lib/bind/vim_ydcxp.ahk | 14 +++++++------- lib/vim_bind.ahk | 2 +- 13 files changed, 50 insertions(+), 50 deletions(-) diff --git a/lib/bind/vim_command.ahk b/lib/bind/vim_command.ahk index a89a58b..31a4304 100644 --- a/lib/bind/vim_command.ahk +++ b/lib/bind/vim_command.ahk @@ -1,7 +1,7 @@ -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) :::Vim.State.SetMode("Command") ;(:) `;::Vim.State.SetMode("Command") ;(;) -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command")) w::Vim.State.SetMode("Command_w") q::Vim.State.SetMode("Command_q") h:: @@ -9,7 +9,7 @@ h:: Vim.State.SetMode("Vim_Normal") Return -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) Return:: Send, ^s Vim.State.SetMode("Vim_Normal") @@ -26,10 +26,10 @@ Space:: Vim.State.SetMode("Insert") Return -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) Return:: Send, !{F4} Vim.State.SetMode("Insert") Return -#If +#HotIf diff --git a/lib/bind/vim_disable.ahk b/lib/bind/vim_disable.ahk index 63539aa..5331639 100644 --- a/lib/bind/vim_disable.ahk +++ b/lib/bind/vim_disable.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("ydc") or Vim.State.StrIsInCurrentVimMode("Command") or (Vim.State.IsCurrentVimMode("Z"))) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("ydc") or Vim.State.StrIsInCurrentVimMode("Command") or (Vim.State.IsCurrentVimMode("Z"))) *a:: *b:: *c:: @@ -69,7 +69,7 @@ Space:: Vim.State.SetMode("Vim_Normal") Return -#If Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 1) +#HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 1) a:: b:: c:: @@ -165,7 +165,7 @@ _:: Space:: Return -#If Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 2) +#HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 2) *a:: *b:: *c:: @@ -194,4 +194,4 @@ Return *z:: Return -#If +#HotIf diff --git a/lib/bind/vim_enter_insert.ahk b/lib/bind/vim_enter_insert.ahk index 25345b9..032eba6 100644 --- a/lib/bind/vim_enter_insert.ahk +++ b/lib/bind/vim_enter_insert.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() && (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() && (Vim.State.IsCurrentVimMode("Vim_Normal")) i::Vim.State.SetMode("Insert") +i:: @@ -29,10 +29,10 @@ Return Return ; Q-dir -#If Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") +#HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") ; Enter insert mode to quickly locate the file/folder by using the first letter /::Vim.State.SetMode("Insert") ; Enter insert mode at rename ~F2::Vim.State.SetMode("Insert") -#If +#HotIf diff --git a/lib/bind/vim_enter_normal.ahk b/lib/bind/vim_enter_normal.ahk index 1207406..bc127c5 100644 --- a/lib/bind/vim_enter_normal.ahk +++ b/lib/bind/vim_enter_normal.ahk @@ -1,8 +1,8 @@ -#If Vim.IsVimGroup() +#HotIf Vim.IsVimGroup() Esc::Vim.State.HandleEsc() ^[::Vim.State.HandleCtrlBracket() -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1) ~j up:: ; jj: go to Normal mode. Input, jout, I T0.1 V L1, j if(ErrorLevel == "EndKey:J"){ @@ -11,4 +11,4 @@ Esc::Vim.State.HandleEsc() } Return -#If +#HotIf diff --git a/lib/bind/vim_move.ahk b/lib/bind/vim_move.ahk index f923304..f3e1d1a 100644 --- a/lib/bind/vim_move.ahk +++ b/lib/bind/vim_move.ahk @@ -1,18 +1,18 @@ ; Inner mode -#If Vim.IsVimGroup() and ((Vim.State.StrIsInCurrentVimMode("Vim_ydc")) or (Vim.State.IsCurrentVimMode("Vim_VisualChar"))) +#HotIf Vim.IsVimGroup() and ((Vim.State.StrIsInCurrentVimMode("Vim_ydc")) or (Vim.State.IsCurrentVimMode("Vim_VisualChar"))) i::Vim.State.SetInner() -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Inner")) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Inner")) w::Vim.Move.Inner("w") +w::Vim.Move.Inner("w") ; gg -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (not Vim.State.g) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (not Vim.State.g) g::Vim.State.SetMode("", 1) -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.g) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.g) g::Vim.Move.Move("g") -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) ; 1 character h::Vim.Move.Repeat("h") j::Vim.Move.Repeat("j") @@ -44,10 +44,10 @@ b::Vim.Move.Repeat("b") +g::Vim.Move.Move("+g") ; Space Space::Vim.Move.Repeat("l") -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and not WinActive("ahk_group VimNonEditor") +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and not WinActive("ahk_group VimNonEditor") ; Enter Enter:: Vim.Move.Repeat("j") Vim.Move.Move("^") Return -#If +#HotIf diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 6694de8..c19e025 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) ; Undo/Redo u::Send,^z ^r::Send,^y @@ -25,7 +25,7 @@ Return .::Send, +^{Right}{BS}^v +z::Vim.State.SetMode("Z") -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +z:: Send, ^s Send, !{F4} @@ -38,7 +38,7 @@ Return Return ; Q-dir -#If Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") +#HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") ; For Q-dir, ^X mapping does not work, use !X instead. ; ^X does not work to be sent, too, use Down/Up ; switch to left top (1), right top (2), left bottom (3), right bottom (4) @@ -52,4 +52,4 @@ Return ~e:: Return -#If +#HotIf diff --git a/lib/bind/vim_repeat.ahk b/lib/bind/vim_repeat.ahk index 4e37a91..4627f37 100644 --- a/lib/bind/vim_repeat.ahk +++ b/lib/bind/vim_repeat.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) 1:: 2:: 3:: @@ -12,10 +12,10 @@ Vim.State.SetMode("", 0, n_repeat) Return -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.n > 0) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.n > 0) 0:: ; 0 is used as {Home} for Vim.State.n=0 n_repeat := Vim.State.n*10 + A_ThisHotkey Vim.State.SetMode("", 0, n_repeat) Return -#If +#HotIf diff --git a/lib/bind/vim_replace.ahk b/lib/bind/vim_replace.ahk index adc216c..255bc3e 100644 --- a/lib/bind/vim_replace.ahk +++ b/lib/bind/vim_replace.ahk @@ -1,8 +1,8 @@ -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) r::Vim.State.SetMode("r_once") +r::Vim.State.SetMode("r_repeat") -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("r_once")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("r_once")) ~a:: ~+a:: ~b:: @@ -104,7 +104,7 @@ Return Vim.State.SetMode("Vim_Normal") Return -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("r_repeat")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("r_repeat")) ~a:: ~+a:: ~b:: @@ -204,4 +204,4 @@ Return Send, {:}{Del} Return -#If +#HotIf diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index da9274e..8b43e20 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) /:: Send, ^f Vim.State.SetMode("Insert") @@ -18,4 +18,4 @@ Return n::Send, {F3} +n::Send, +{F3} -#If +#HotIf diff --git a/lib/bind/vim_shortcut.ahk b/lib/bind/vim_shortcut.ahk index 5d8b3cf..f243a48 100644 --- a/lib/bind/vim_shortcut.ahk +++ b/lib/bind/vim_shortcut.ahk @@ -1,19 +1,19 @@ ; Launch Settings -#If +#HotIf ^!+v:: Vim.Setting.ShowGui() Return ; Check Mode -#If Vim.IsVimGroup() +#HotIf Vim.IsVimGroup() ^!+c:: Vim.State.CheckMode(4, Vim.State.Mode) Return ; Suspend/restart -#If +#HotIf ^!+s:: Vim.State.ToggleEnabled() Return -#If +#HotIf diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index 257bd5d..d8cc836 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -1,5 +1,5 @@ ; Visual Char/Block/Line -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) v::Vim.State.SetMode("Vim_VisualChar") ^v:: Send, ^b @@ -11,7 +11,7 @@ Return Send, {Home}+{Down} Return -#If Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual")) +#HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual")) v::Vim.State.SetMode("Vim_Normal") ; ydc @@ -74,4 +74,4 @@ Return Vim.State.SetMode("Vim_Normal") Return -#If +#HotIf diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index 3504606..1f4806d 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -1,4 +1,4 @@ -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) y::Vim.State.SetMode("Vim_ydc_y", 0, -1, 0) d::Vim.State.SetMode("Vim_ydc_d", 0, -1, 0) c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) @@ -37,24 +37,24 @@ Return } Return -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_y")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_y")) y:: Vim.Move.YDCMove() Send, {Left}{Home} Return -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_d")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_d")) d::Vim.Move.YDCMove() -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_c")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_c")) c::Vim.Move.YDCMove() -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) x::Send, {Delete} +x::Send, {BS} ; Paste -#If Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) +#HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) p:: ;i:=0 ;;Send, {p Up} @@ -108,4 +108,4 @@ Return KeyWait, p Return -#If +#HotIf diff --git a/lib/vim_bind.ahk b/lib/vim_bind.ahk index 3bfd86f..bb3aeab 100644 --- a/lib/vim_bind.ahk +++ b/lib/vim_bind.ahk @@ -12,4 +12,4 @@ #Include %A_LineFile%\..\bind\vim_disable.ahk ; Reset the condition -#If +#HotIf From 19c92d58985d9f6c6be58cafe8d1fe8b02bc4a7c Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:05:26 +0900 Subject: [PATCH 09/75] fix: wrap hotkey blocks in braces and remove Return (for v2) --- lib/bind/vim_command.ahk | 15 ++++++++++----- lib/bind/vim_disable.ahk | 7 ++++--- lib/bind/vim_enter_insert.ahk | 15 ++++++++++----- lib/bind/vim_enter_normal.ahk | 3 ++- lib/bind/vim_move.ahk | 3 ++- lib/bind/vim_normal.ahk | 11 +++++++---- lib/bind/vim_repeat.ahk | 6 ++++-- lib/bind/vim_replace.ahk | 12 ++++++++---- lib/bind/vim_search.ahk | 6 ++++-- lib/bind/vim_shortcut.ahk | 12 +++--------- lib/bind/vim_visual.ahk | 21 ++++++++++++++------- lib/bind/vim_ydcxp.ahk | 18 ++++++++++++------ 12 files changed, 80 insertions(+), 49 deletions(-) diff --git a/lib/bind/vim_command.ahk b/lib/bind/vim_command.ahk index 31a4304..f31c49b 100644 --- a/lib/bind/vim_command.ahk +++ b/lib/bind/vim_command.ahk @@ -5,31 +5,36 @@ w::Vim.State.SetMode("Command_w") q::Vim.State.SetMode("Command_q") h:: +{ Send, {F1} Vim.State.SetMode("Vim_Normal") -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) Return:: +{ Send, ^s Vim.State.SetMode("Vim_Normal") -Return +} q:: +{ Send, ^s Send, !{F4} Vim.State.SetMode("Insert") -Return +} Space:: +{ Send, !fa Vim.State.SetMode("Insert") -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) Return:: +{ Send, !{F4} Vim.State.SetMode("Insert") -Return +} #HotIf diff --git a/lib/bind/vim_disable.ahk b/lib/bind/vim_disable.ahk index 5331639..58df8f7 100644 --- a/lib/bind/vim_disable.ahk +++ b/lib/bind/vim_disable.ahk @@ -66,8 +66,9 @@ _:: .:: >:: Space:: +{ Vim.State.SetMode("Vim_Normal") -Return +} #HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 1) a:: @@ -163,7 +164,7 @@ _:: .:: >:: Space:: -Return +{} #HotIf Vim.IsVimGroup() and Vim.State.StrIsInCurrentVimMode("Vim_") and (Vim.Conf["VimDisableUnused"]["val"] > 2) *a:: @@ -192,6 +193,6 @@ Return *x:: *y:: *z:: -Return +{} #HotIf diff --git a/lib/bind/vim_enter_insert.ahk b/lib/bind/vim_enter_insert.ahk index 032eba6..5f15c4d 100644 --- a/lib/bind/vim_enter_insert.ahk +++ b/lib/bind/vim_enter_insert.ahk @@ -2,31 +2,36 @@ i::Vim.State.SetMode("Insert") +i:: +{ Send, {Home} Vim.State.SetMode("Insert") -Return +} a:: +{ if(! Vim.CheckChr("`n")){ Send, {Right} } Vim.State.SetMode("Insert") -Return +} +a:: +{ Send, {End} Vim.State.SetMode("Insert") -Return +} o:: +{ Send,{End}{Enter} Vim.State.SetMode("Insert") -Return +} +o:: +{ Send, {Home}{Enter}{Left} Vim.State.SetMode("Insert") -Return +} ; Q-dir #HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") diff --git a/lib/bind/vim_enter_normal.ahk b/lib/bind/vim_enter_normal.ahk index bc127c5..b469096 100644 --- a/lib/bind/vim_enter_normal.ahk +++ b/lib/bind/vim_enter_normal.ahk @@ -4,11 +4,12 @@ Esc::Vim.State.HandleEsc() #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1) ~j up:: ; jj: go to Normal mode. +{ Input, jout, I T0.1 V L1, j if(ErrorLevel == "EndKey:J"){ SendInput, {BackSpace 2} Vim.State.SetNormal() } -Return +} #HotIf diff --git a/lib/bind/vim_move.ahk b/lib/bind/vim_move.ahk index f3e1d1a..ed8cd47 100644 --- a/lib/bind/vim_move.ahk +++ b/lib/bind/vim_move.ahk @@ -47,7 +47,8 @@ Space::Vim.Move.Repeat("l") #HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and not WinActive("ahk_group VimNonEditor") ; Enter Enter:: +{ Vim.Move.Repeat("j") Vim.Move.Move("^") - Return +} #HotIf diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index c19e025..e04b661 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -8,6 +8,7 @@ u::Send,^z ; Change case ~:: +{ bak := ClipboardAll Clipboard = Send, +{Right}^x @@ -19,7 +20,7 @@ u::Send,^z } Send, ^v Clipboard := bak -Return +} ; period .::Send, +^{Right}{BS}^v @@ -27,15 +28,17 @@ Return +z::Vim.State.SetMode("Z") #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +z:: +{ Send, ^s Send, !{F4} Vim.State.SetMode("Vim_Normal") -Return +} +q:: +{ Send, !{F4} Vim.State.SetMode("Vim_Normal") -Return +} ; Q-dir #HotIf Vim.IsVimGroup() and WinActive("ahk_group VimQdir") and (Vim.State.Mode == "Vim_Normal") @@ -50,6 +53,6 @@ Return '::Send, {LControl Down}{q Down}{q Up}{LControl Up} ; Keep the e key in Normal mode, use the right button and then press the refresh (e) function, do nothing, return to the e key directly ~e:: -Return +{} #HotIf diff --git a/lib/bind/vim_repeat.ahk b/lib/bind/vim_repeat.ahk index 4627f37..6ba97c8 100644 --- a/lib/bind/vim_repeat.ahk +++ b/lib/bind/vim_repeat.ahk @@ -8,14 +8,16 @@ 7:: 8:: 9:: +{ n_repeat := Vim.State.n*10 + A_ThisHotkey Vim.State.SetMode("", 0, n_repeat) -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Vim_")) and (Vim.State.n > 0) 0:: ; 0 is used as {Home} for Vim.State.n=0 +{ n_repeat := Vim.State.n*10 + A_ThisHotkey Vim.State.SetMode("", 0, n_repeat) -Return +} #HotIf diff --git a/lib/bind/vim_replace.ahk b/lib/bind/vim_replace.ahk index 255bc3e..a4826d4 100644 --- a/lib/bind/vim_replace.ahk +++ b/lib/bind/vim_replace.ahk @@ -95,14 +95,16 @@ r::Vim.State.SetMode("r_once") ~.:: ~>:: ~Space:: +{ Send, {Del} Vim.State.SetMode("Vim_Normal") -Return +} ::: ; ":" can't be used with "~"? +{ Send, {:}{Del} Vim.State.SetMode("Vim_Normal") -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("r_repeat")) ~a:: @@ -197,11 +199,13 @@ Return ~.:: ~>:: ~Space:: +{ Send, {Del} -Return +} ::: +{ Send, {:}{Del} -Return +} #HotIf diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index 8b43e20..394e49a 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -1,10 +1,12 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) /:: +{ Send, ^f Vim.State.SetMode("Insert") -Return +} *:: +{ bak := ClipboardAll Clipboard= Send, ^{Left}+^{Right}^c @@ -13,7 +15,7 @@ Return Send, ^v!f clipboard := bak Vim.State.SetMode("Insert") -Return +} n::Send, {F3} +n::Send, +{F3} diff --git a/lib/bind/vim_shortcut.ahk b/lib/bind/vim_shortcut.ahk index f243a48..210297e 100644 --- a/lib/bind/vim_shortcut.ahk +++ b/lib/bind/vim_shortcut.ahk @@ -1,19 +1,13 @@ ; Launch Settings #HotIf -^!+v:: - Vim.Setting.ShowGui() -Return +^!+v::Vim.Setting.ShowGui() ; Check Mode #HotIf Vim.IsVimGroup() -^!+c:: - Vim.State.CheckMode(4, Vim.State.Mode) -Return +^!+c::Vim.State.CheckMode(4, Vim.State.Mode) ; Suspend/restart #HotIf -^!+s:: - Vim.State.ToggleEnabled() -Return +^!+s::Vim.State.ToggleEnabled() #HotIf diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index d8cc836..c1311b2 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -2,20 +2,23 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) v::Vim.State.SetMode("Vim_VisualChar") ^v:: +{ Send, ^b Vim.State.SetMode("Vim_VisualChar") -Return +} +v:: +{ Vim.State.SetMode("Vim_VisualLineFirst") Send, {Home}+{Down} -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual")) v::Vim.State.SetMode("Vim_Normal") ; ydc y:: +{ Clipboard := Send, ^c Send, {Right} @@ -28,9 +31,10 @@ y:: }else{ Vim.State.SetMode("Vim_Normal", 0, 0, 0) } -Return +} d:: +{ Clipboard := Send, ^x ClipWait, 1 @@ -39,9 +43,10 @@ d:: }else{ Vim.State.SetMode("Vim_Normal", 0, 0, 0) } -Return +} x:: +{ Clipboard := Send, ^x ClipWait, 1 @@ -50,9 +55,10 @@ x:: }else{ Vim.State.SetMode("Vim_Normal", 0, 0, 0) } -Return +} c:: +{ Clipboard := Send, ^x ClipWait, 1 @@ -61,9 +67,10 @@ c:: }else{ Vim.State.SetMode("Insert", 0, 0, 0) } -Return +} *:: +{ bak := ClipboardAll Clipboard := Send, ^c @@ -72,6 +79,6 @@ Return Send, ^v!f clipboard := bak Vim.State.SetMode("Vim_Normal") -Return +} #HotIf diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index 1f4806d..5bbf650 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -3,6 +3,7 @@ y::Vim.State.SetMode("Vim_ydc_y", 0, -1, 0) d::Vim.State.SetMode("Vim_ydc_d", 0, -1, 0) c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) +y:: +{ Vim.State.SetMode("Vim_ydc_y", 0, 0, 1) Sleep, 150 ; Need to wait (For variable change?) if WinActive("ahk_group VimDoubleHomeGroup"){ @@ -15,9 +16,10 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) Vim.Move.Move("") } Send, {Left}{Home} -Return +} +d:: +{ Vim.State.SetMode("Vim_ydc_d", 0, 0, 0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") @@ -25,9 +27,10 @@ Return Send, {Shift Down}{End}{Left} Vim.Move.Move("") } -Return +} +c:: +{ Vim.State.SetMode("Vim_ydc_c",0,0,0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") @@ -35,13 +38,14 @@ Return Send, {Shift Down}{End}{Left} Vim.Move.Move("") } -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_y")) y:: +{ Vim.Move.YDCMove() Send, {Left}{Home} -Return +} #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_d")) d::Vim.Move.YDCMove() @@ -56,6 +60,7 @@ x::Send, {Delete} ; Paste #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) p:: +{ ;i:=0 ;;Send, {p Up} ;Loop { @@ -96,9 +101,10 @@ p:: ;;Send, ^{Left} } KeyWait, p ; To avoid repeat, somehow it calls , print... -Return +} +p:: +{ if(Vim.State.LineCopy == 1){ Send, {Up}{End}{Enter}^v{BS}{Home} }else{ @@ -106,6 +112,6 @@ Return ;Send,^{Left} } KeyWait, p -Return +} #HotIf From 8d67572984f10673b737053ea76564179a0ca282 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:15:15 +0900 Subject: [PATCH 10/75] fix: fix Send command syntax to function-based format (for v2) --- lib/bind/vim_command.ahk | 12 ++--- lib/bind/vim_enter_insert.ahk | 10 ++-- lib/bind/vim_enter_normal.ahk | 2 +- lib/bind/vim_normal.ahk | 26 +++++----- lib/bind/vim_replace.ahk | 8 +-- lib/bind/vim_search.ahk | 12 ++--- lib/bind/vim_visual.ahk | 22 ++++---- lib/bind/vim_ydcxp.ahk | 44 ++++++++-------- lib/vim_ahk.ahk | 6 +-- lib/vim_move.ahk | 94 +++++++++++++++++------------------ lib/vim_state.ahk | 14 +++--- 11 files changed, 125 insertions(+), 125 deletions(-) diff --git a/lib/bind/vim_command.ahk b/lib/bind/vim_command.ahk index f31c49b..8876fd6 100644 --- a/lib/bind/vim_command.ahk +++ b/lib/bind/vim_command.ahk @@ -6,34 +6,34 @@ w::Vim.State.SetMode("Command_w") q::Vim.State.SetMode("Command_q") h:: { - Send, {F1} + Send("{F1}") Vim.State.SetMode("Vim_Normal") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) Return:: { - Send, ^s + Send("^s") Vim.State.SetMode("Vim_Normal") } q:: { - Send, ^s - Send, !{F4} + Send("^s") + Send("!{F4}") Vim.State.SetMode("Insert") } Space:: { - Send, !fa + Send("!fa") Vim.State.SetMode("Insert") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) Return:: { - Send, !{F4} + Send("!{F4}") Vim.State.SetMode("Insert") } diff --git a/lib/bind/vim_enter_insert.ahk b/lib/bind/vim_enter_insert.ahk index 5f15c4d..e136b89 100644 --- a/lib/bind/vim_enter_insert.ahk +++ b/lib/bind/vim_enter_insert.ahk @@ -3,33 +3,33 @@ i::Vim.State.SetMode("Insert") +i:: { - Send, {Home} + Send("{Home}") Vim.State.SetMode("Insert") } a:: { if(! Vim.CheckChr("`n")){ - Send, {Right} + Send("{Right}") } Vim.State.SetMode("Insert") } +a:: { - Send, {End} + Send("{End}") Vim.State.SetMode("Insert") } o:: { - Send,{End}{Enter} + Send("{End}{Enter}") Vim.State.SetMode("Insert") } +o:: { - Send, {Home}{Enter}{Left} + Send("{Home}{Enter}{Left}") Vim.State.SetMode("Insert") } diff --git a/lib/bind/vim_enter_normal.ahk b/lib/bind/vim_enter_normal.ahk index b469096..dcc17a7 100644 --- a/lib/bind/vim_enter_normal.ahk +++ b/lib/bind/vim_enter_normal.ahk @@ -7,7 +7,7 @@ Esc::Vim.State.HandleEsc() { Input, jout, I T0.1 V L1, j if(ErrorLevel == "EndKey:J"){ - SendInput, {BackSpace 2} + SendInput("{BackSpace 2}") Vim.State.SetNormal() } } diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index e04b661..5969217 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -1,24 +1,24 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) ; Undo/Redo -u::Send,^z -^r::Send,^y +u::Send("^z") +^r::Send("^y") ; Combine lines -+j:: Send, {End}{Space}{Delete} ++j:: Send("{End}{Space}{Delete}") ; Change case ~:: { bak := ClipboardAll Clipboard = - Send, +{Right}^x + Send("+{Right}^x") ClipWait, 1 if(Clipboard is lower){ StringUpper, Clipboard, Clipboard }else if(Clipboard is upper){ StringLower, Clipboard, Clipboard } - Send, ^v + Send("^v") Clipboard := bak } @@ -29,14 +29,14 @@ u::Send,^z #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +z:: { - Send, ^s - Send, !{F4} + Send("^s") + Send("!{F4}") Vim.State.SetMode("Vim_Normal") } +q:: { - Send, !{F4} + Send("!{F4}") Vim.State.SetMode("Vim_Normal") } @@ -45,12 +45,12 @@ u::Send,^z ; For Q-dir, ^X mapping does not work, use !X instead. ; ^X does not work to be sent, too, use Down/Up ; switch to left top (1), right top (2), left bottom (3), right bottom (4) -!u::Send, {LControl Down}{1 Down}{1 Up}{LControl Up} -!i::Send, {LControl Down}{2 Down}{2 Up}{LControl Up} -!j::Send, {LControl Down}{3 Down}{3 Up}{LControl Up} -!k::Send, {LControl Down}{4 Down}{4 Up}{LControl Up} +!u::Send("{LControl Down}{1 Down}{1 Up}{LControl Up}") +!i::Send("{LControl Down}{2 Down}{2 Up}{LControl Up}") +!j::Send("{LControl Down}{3 Down}{3 Up}{LControl Up}") +!k::Send("{LControl Down}{4 Down}{4 Up}{LControl Up}") ; Ctrl+q, menu Quick-links -'::Send, {LControl Down}{q Down}{q Up}{LControl Up} +'::Send("{LControl Down}{q Down}{q Up}{LControl Up}") ; Keep the e key in Normal mode, use the right button and then press the refresh (e) function, do nothing, return to the e key directly ~e:: {} diff --git a/lib/bind/vim_replace.ahk b/lib/bind/vim_replace.ahk index a4826d4..b8c68ee 100644 --- a/lib/bind/vim_replace.ahk +++ b/lib/bind/vim_replace.ahk @@ -96,13 +96,13 @@ r::Vim.State.SetMode("r_once") ~>:: ~Space:: { - Send, {Del} + Send("{Del}") Vim.State.SetMode("Vim_Normal") } ::: ; ":" can't be used with "~"? { - Send, {:}{Del} + Send("{:}{Del}") Vim.State.SetMode("Vim_Normal") } @@ -200,12 +200,12 @@ r::Vim.State.SetMode("r_once") ~>:: ~Space:: { - Send, {Del} + Send("{Del}") } ::: { - Send, {:}{Del} + Send("{:}{Del}") } #HotIf diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index 394e49a..f46ea9f 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -1,7 +1,7 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) /:: { - Send, ^f + Send("^f") Vim.State.SetMode("Insert") } @@ -9,15 +9,15 @@ { bak := ClipboardAll Clipboard= - Send, ^{Left}+^{Right}^c + Send("^{Left}+^{Right}^c") ClipWait, 1 - Send, ^f - Send, ^v!f + Send("^f") + Send("^v!f") clipboard := bak Vim.State.SetMode("Insert") } -n::Send, {F3} -+n::Send, +{F3} +n::Send("{F3}") ++n::Send("+{F3}") #HotIf diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index c1311b2..883983e 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -3,14 +3,14 @@ v::Vim.State.SetMode("Vim_VisualChar") ^v:: { - Send, ^b + Send("^b") Vim.State.SetMode("Vim_VisualChar") } +v:: { Vim.State.SetMode("Vim_VisualLineFirst") - Send, {Home}+{Down} + Send("{Home}+{Down}") } #HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual")) @@ -20,10 +20,10 @@ v::Vim.State.SetMode("Vim_Normal") y:: { Clipboard := - Send, ^c - Send, {Right} + Send("^c") + Send("{Right}") if WinActive("ahk_group VimCursorSameAfterSelect"){ - Send, {Left} + Send("{Left}") } ClipWait, 1 if(Vim.State.StrIsInCurrentVimMode("Line")){ @@ -36,7 +36,7 @@ y:: d:: { Clipboard := - Send, ^x + Send("^x") ClipWait, 1 if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) @@ -48,7 +48,7 @@ d:: x:: { Clipboard := - Send, ^x + Send("^x") ClipWait, 1 if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) @@ -60,7 +60,7 @@ x:: c:: { Clipboard := - Send, ^x + Send("^x") ClipWait, 1 if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Insert", 0, 0, 1) @@ -73,10 +73,10 @@ c:: { bak := ClipboardAll Clipboard := - Send, ^c + Send("^c") ClipWait, 1 - Send, ^f - Send, ^v!f + Send("^f") + Send("^v!f") clipboard := bak Vim.State.SetMode("Vim_Normal") } diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index 5bbf650..f182e42 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -7,15 +7,15 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) Vim.State.SetMode("Vim_ydc_y", 0, 0, 1) Sleep, 150 ; Need to wait (For variable change?) if WinActive("ahk_group VimDoubleHomeGroup"){ - Send, {Home} + Send("{Home}") } - Send, {Home}+{End} + Send("{Home}+{End}") if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("l") }else{ Vim.Move.Move("") } - Send, {Left}{Home} + Send("{Left}{Home}") } +d:: @@ -24,7 +24,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") }else{ - Send, {Shift Down}{End}{Left} + Send("{Shift Down}{End}{Left}") Vim.Move.Move("") } } @@ -35,7 +35,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") }else{ - Send, {Shift Down}{End}{Left} + Send("{Shift Down}{End}{Left}") Vim.Move.Move("") } } @@ -44,7 +44,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) y:: { Vim.Move.YDCMove() - Send, {Left}{Home} + Send("{Left}{Home}") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_d")) @@ -54,26 +54,26 @@ d::Vim.Move.YDCMove() c::Vim.Move.YDCMove() #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) -x::Send, {Delete} -+x::Send, {BS} +x::Send("{Delete}") ++x::Send("{BS}") ; Paste #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) p:: { ;i:=0 - ;;Send, {p Up} + ;;Send("{p Up}") ;Loop { ; if !GetKeyState("p", "P"){ ; break ; } ; if(Vim.State.LineCopy == 1){ - ; Send, {End}{Enter}^v{BS}{Home} + ; Send("{End}{Enter}^v{BS}{Home}") ; }else{ - ; Send, {Right} - ; Send, ^v + ; Send("{Right}") + ; Send("^v") ; ;Sleep, 1000 - ; Send, ^{Left} + ; Send("^{Left}") ; } ; ;TrayTip,i,%i%, ; if(i == 0){ @@ -89,16 +89,16 @@ p:: ;} if(Vim.State.LineCopy == 1){ if WinActive("ahk_group VimNoLBCopyGroup"){ - Send, {End}{Enter}^v{Home} + Send("{End}{Enter}^v{Home}") }else{ - Send, {End}{Enter}^v{BS}{Home} + Send("{End}{Enter}^v{BS}{Home}") } }else{ - Send, {Right} - Send, ^v + Send("{Right}") + Send("^v") ;Sleep, 1000 - Send, {Left} - ;;Send, ^{Left} + Send("{Left}") + ;;Send("^{Left}") } KeyWait, p ; To avoid repeat, somehow it calls , print... } @@ -106,10 +106,10 @@ p:: +p:: { if(Vim.State.LineCopy == 1){ - Send, {Up}{End}{Enter}^v{BS}{Home} + Send("{Up}{End}{Enter}^v{BS}{Home}") }else{ - Send, ^v - ;Send,^{Left} + Send("^v") + ;Send("^{Left}") } KeyWait, p } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 4b7cc07..369e577 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -217,7 +217,7 @@ class VimAhk{ } TwoLetterEnterNormal(){ - SendInput, {BackSpace 1} + SendInput("{BackSpace 1}") this.State.SetNormal() } @@ -287,8 +287,8 @@ class VimAhk{ BlockInput, Send tempClip := clipboard clipboard := "" - SendInput {Shift Down}{Right}{Shift up}{Ctrl down}c{Ctrl Up}{Left} - Sleep 10 + SendInput("{Shift Down}{Right}{Shift up}{Ctrl down}c{Ctrl Up}{Left}") + Sleep(10) ret := False If (clipboard ~= key){ ret := True diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index c0c5ba1..41914af 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -8,13 +8,13 @@ this.shift := 0 if(this.Vim.State.StrIsInCurrentVimMode("Visual") or this.Vim.State.StrIsInCurrentVimMode("ydc")){ this.shift := 1 - Send, {Shift Down} + Send("{Shift Down}") } if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (key == "k" or key == "^u" or key == "^b" or key == "g"){ - Send, {Shift Up}{End} + Send("{Shift Up}{End}") this.Zero() - Send, {Shift Down} + Send("{Shift Down}") this.Up() this.vim.state.setmode("Vim_VisualLine") } @@ -25,63 +25,63 @@ if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (key == "k" or key == "^u" or key == "^b" or key == "g"){ this.Vim.State.LineCopy := 1 - Send,{Shift Up} + Send("{Shift Up}") this.Zero() this.Down() - Send, {Shift Down} + Send("{Shift Down}") this.Up() } if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (key == "j" or key == "^d" or key == "^f" or key == "+g"){ this.Vim.State.LineCopy := 1 - Send,{Shift Up} + Send("{Shift Up}") this.Zero() - Send, {Shift Down} + Send("{Shift Down}") this.Down() } } MoveFinalize(){ - Send,{Shift Up} + Send("{Shift Up}") ydc_y := false if(this.Vim.State.StrIsInCurrentVimMode("ydc_y")){ Clipboard := - Send, ^c + Send("^c") ClipWait, 1 this.Vim.State.SetMode("Vim_Normal") ydc_y := true }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_d")){ Clipboard := - Send, ^x + Send("^x") ClipWait, 1 this.Vim.State.SetMode("Vim_Normal") }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_c")){ Clipboard := - Send, ^x + Send("^x") ClipWait, 1 this.Vim.State.SetMode("Insert") } this.Vim.State.SetMode("", 0, 0) if(ydc_y){ - Send, {Left}{Right} + Send("{Left}{Right}") } ; Sometimes, when using `c`, the control key would be stuck down afterwards. ; This forces it to be up again afterwards. - send {Ctrl Up} + send("{Ctrl Up}") } Zero(){ if WinActive("ahk_group VimDoubleHomeGroup"){ - Send, {Home} + Send("{Home}") } - Send, {Home} + Send("{Home}") } Up(n=1){ Loop, %n% { if WinActive("ahk_group VimCtrlUpDownGroup"){ - Send ^{Up} + Send("^{Up}") } else { - Send,{Up} + Send("{Up}") } } } @@ -89,9 +89,9 @@ Down(n=1){ Loop, %n% { if WinActive("ahk_group VimCtrlUpDownGroup"){ - Send ^{Down} + Send("^{Down}") } else { - Send,{Down} + Send("{Down}") } } } @@ -110,69 +110,69 @@ ; 1 character if(key == "h"){ if WinActive("ahk_group VimQdir"){ - Send, {BackSpace down}{BackSpace up} + Send("{BackSpace down}{BackSpace up}") } else { - Send, {Left} + Send("{Left}") } }else if(key == "l"){ if WinActive("ahk_group VimQdir"){ - Send, {Enter} + Send("{Enter}") } else { - Send, {Right} + Send("{Right}") } ; Home/End }else if(key == "0"){ this.Zero() }else if(key == "$"){ if(this.shift == 1){ - Send, +{End} + Send("+{End}") }else{ - Send, {End} + Send("{End}") } }else if(key == "^"){ if(this.shift == 1){ if WinActive("ahk_group VimCaretMove"){ - Send, +{Home} - Send, +^{Right} - Send, +^{Left} + Send("+{Home}") + Send("+^{Right}") + Send("+^{Left}") }else{ - Send, +{Home} + Send("+{Home}") } }else{ if WinActive("ahk_group VimCaretMove"){ - Send, {Home} - Send, ^{Right} - Send, ^{Left} + Send("{Home}") + Send("^{Right}") + Send("^{Left}") }else{ - Send, {Home} + Send("{Home}") } } ; Words }else if(key == "w"){ if(this.shift == 1){ - Send, +^{Right} + Send("+^{Right}") }else{ - Send, ^{Right} + Send("^{Right}") } }else if(key == "e"){ if(this.shift == 1){ if(this.Vim.CheckChr(" ")){ - Send, +^{Right} + Send("+^{Right}") } - Send, +^{Right}+{Left} + Send("+^{Right}+{Left}") }else{ if(this.Vim.CheckChr(" ")){ - Send, ^{Right} + Send("^{Right}") } - Send, ^{Right}{Left} + Send("^{Right}{Left}") } }else if(key == "b"){ if(this.shift == 1){ - Send, +^{Left} + Send("+^{Left}") }else{ - Send, ^{Left} + Send("^{Left}") } } } @@ -188,13 +188,13 @@ }else if(key == "^d"){ this.Down(10) }else if(key == "^b"){ - Send, {PgUp} + Send("{PgUp}") }else if(key == "^f"){ - Send, {PgDn} + Send("{PgDn}") }else if(key == "g"){ - Send, ^{Home} + Send("^{Home}") }else if(key == "+g"){ - Send, ^{End}{Home} + Send("^{End}{Home}") } if(!repeat){ @@ -216,12 +216,12 @@ YDCMove(){ this.Vim.State.LineCopy := 1 this.Zero() - Send, {Shift Down} + Send("{Shift Down}") if(this.Vim.State.n == 0){ this.Vim.State.n := 1 } this.Down(this.Vim.State.n - 1) - Send, {End} + Send("{End}") if not WinActive("ahk_group VimLBSelectGroup"){ this.Move("l") }else{ diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 1880990..66d8841 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -72,16 +72,16 @@ this.LastIME := VIM_IME_Get() if(this.LastIME){ if(VIM_IME_GetConverting(A)){ - Send, {Esc} + Send("{Esc}") Return }else{ VIM_IME_SET() } } if(this.StrIsInCurrentVimMode("Visual") or this.StrIsInCurrentVimMode("ydc")){ - Send, {Right} + Send("{Right}") if WinActive("ahk_group VimCursorSameAfterSelect"){ - Send, {Left} + Send("{Left}") } } this.SetMode("Vim_Normal") @@ -94,7 +94,7 @@ HandleEsc(){ global Vim, VimEscNormal, vimSendEscNormal, VimLongEscNormal if (!VimEscNormal) { - Send, {Esc} + Send("{Esc}") Return } ; The keywait waits for esc to be released. If it doesn't detect a release @@ -105,7 +105,7 @@ neither := !(VimLongEscNormal || LongPress) SetNormal := both or neither if (!SetNormal or (VimSendEscNormal && this.IsCurrentVimMode("Vim_Normal"))) { - Send, {Esc} + Send("{Esc}") } if (SetNormal) { this.SetNormal() @@ -120,7 +120,7 @@ HandleCtrlBracket(){ global Vim, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal if (!VimCtrlBracketNormal) { - Send, ^[ + Send("^[") Return } KeyWait, [, T0.5 @@ -129,7 +129,7 @@ neither := !(VimLongCtrlBracketNormal || LongPress) SetNormal := both or neither if (!SetNormal or (VimSendCtrlBracketNormal && this.IsCurrentVimMode("Vim_Normal"))) { - Send, ^[ + Send("^[") } if (SetNormal) { this.SetNormal() From 027752dc5d9b92bf0ee67afdd62cfcf6e75dbfa4 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:20:18 +0900 Subject: [PATCH 11/75] fix: update obsolete key Return -> Enter (for v2) --- lib/bind/vim_command.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bind/vim_command.ahk b/lib/bind/vim_command.ahk index 8876fd6..47fc487 100644 --- a/lib/bind/vim_command.ahk +++ b/lib/bind/vim_command.ahk @@ -11,7 +11,7 @@ h:: } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) -Return:: +Enter:: { Send("^s") Vim.State.SetMode("Vim_Normal") @@ -31,7 +31,7 @@ Space:: } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) -Return:: +Enter:: { Send("!{F4}") Vim.State.SetMode("Insert") From 645933f1ab7ab7d6cf0f187725f7846b64debb1e Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:27:12 +0900 Subject: [PATCH 12/75] fix: use function call syntax in KeyWait (for v2) fix: remove deprecated ErrorLevel (timeout = 1 -> LongPress), use return value of KeyWait (timeout = 0 -> 1 is ShortPress), and treat timeout condition correctly (for v2) refactor: better check of VimLongCtrlBracketNormal v.s. ShortPress condition --- lib/bind/vim_ydcxp.ahk | 4 ++-- lib/vim_state.ahk | 24 +++++++++--------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index f182e42..a21e028 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -100,7 +100,7 @@ p:: Send("{Left}") ;;Send("^{Left}") } - KeyWait, p ; To avoid repeat, somehow it calls , print... + KeyWait("p") ; To avoid repeat, somehow it calls , print... } +p:: @@ -111,7 +111,7 @@ p:: Send("^v") ;Send("^{Left}") } - KeyWait, p + KeyWait("p") } #HotIf diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 66d8841..08dcf62 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -98,22 +98,19 @@ Return } ; The keywait waits for esc to be released. If it doesn't detect a release - ; within the time limit, sets ErrorLevel to 1. - KeyWait, Esc, T0.5 - LongPress := ErrorLevel - both := VimLongEscNormal && LongPress - neither := !(VimLongEscNormal || LongPress) - SetNormal := both or neither + ; within the time limit, return 0, otherwise return 1. + ShortPress := KeyWait("Esc", "T0.5") + SetNormal := VimLongEscNormal != ShortPress if (!SetNormal or (VimSendEscNormal && this.IsCurrentVimMode("Vim_Normal"))) { Send("{Esc}") } if (SetNormal) { this.SetNormal() } - if (LongPress){ + if (!ShortPress){ ; Have to ensure the key has been released, otherwise this will get ; triggered again. - KeyWait, Esc + KeyWait("Esc") } } @@ -123,19 +120,16 @@ Send("^[") Return } - KeyWait, [, T0.5 - LongPress := ErrorLevel - both := VimLongCtrlBracketNormal && LongPress - neither := !(VimLongCtrlBracketNormal || LongPress) - SetNormal := both or neither + ShortPress := KeyWait("[", "T0.5") + SetNormal := VimLongCtrlBracketNormal != ShortPress if (!SetNormal or (VimSendCtrlBracketNormal && this.IsCurrentVimMode("Vim_Normal"))) { Send("^[") } if (SetNormal) { this.SetNormal() } - if (LongPress){ - KeyWait, [ + if (!ShortPress){ + KeyWait("[") } } From 6d1cb02e45b9554acbc2d5c33f687d036c7c2efa Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:29:11 +0900 Subject: [PATCH 13/75] fix: use function call syntax in Sleep (for v2) --- lib/bind/vim_ydcxp.ahk | 10 +++++----- lib/vim_ahk.ahk | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index a21e028..77b51da 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -5,7 +5,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) +y:: { Vim.State.SetMode("Vim_ydc_y", 0, 0, 1) - Sleep, 150 ; Need to wait (For variable change?) + Sleep(150) ; Need to wait (For variable change?) if WinActive("ahk_group VimDoubleHomeGroup"){ Send("{Home}") } @@ -72,17 +72,17 @@ p:: ; }else{ ; Send("{Right}") ; Send("^v") - ; ;Sleep, 1000 + ; ;Sleep(1000) ; Send("^{Left}") ; } ; ;TrayTip,i,%i%, ; if(i == 0){ - ; Sleep, 500 + ; Sleep(500) ; }else if(i > 100){ ; Msgbox, , Vim Ahk, Stop at 100!!! ; break ; }else{ - ; Sleep, 0 + ; Sleep(0) ; } ; i+=1 ; break @@ -96,7 +96,7 @@ p:: }else{ Send("{Right}") Send("^v") - ;Sleep, 1000 + ;Sleep(1000) Send("{Left}") ;;Send("^{Left}") } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 369e577..7710db5 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -293,7 +293,7 @@ class VimAhk{ If (clipboard ~= key){ ret := True } - sleep 10 + sleep(10) clipboard := tempClip BlockInput, off Return ret From 8acf11ef38d83f0f5d8d435d3370dd4502cf4155 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:30:53 +0900 Subject: [PATCH 14/75] fix: use function call syntax in ClipWait (for v2) --- lib/bind/vim_normal.ahk | 2 +- lib/bind/vim_search.ahk | 2 +- lib/bind/vim_visual.ahk | 10 +++++----- lib/vim_move.ahk | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 5969217..1d26c5b 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -12,7 +12,7 @@ u::Send("^z") bak := ClipboardAll Clipboard = Send("+{Right}^x") - ClipWait, 1 + ClipWait(1) if(Clipboard is lower){ StringUpper, Clipboard, Clipboard }else if(Clipboard is upper){ diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index f46ea9f..5aad034 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -10,7 +10,7 @@ bak := ClipboardAll Clipboard= Send("^{Left}+^{Right}^c") - ClipWait, 1 + ClipWait(1) Send("^f") Send("^v!f") clipboard := bak diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index 883983e..78cfb6a 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -25,7 +25,7 @@ y:: if WinActive("ahk_group VimCursorSameAfterSelect"){ Send("{Left}") } - ClipWait, 1 + ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) }else{ @@ -37,7 +37,7 @@ d:: { Clipboard := Send("^x") - ClipWait, 1 + ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) }else{ @@ -49,7 +49,7 @@ x:: { Clipboard := Send("^x") - ClipWait, 1 + ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) }else{ @@ -61,7 +61,7 @@ c:: { Clipboard := Send("^x") - ClipWait, 1 + ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Insert", 0, 0, 1) }else{ @@ -74,7 +74,7 @@ c:: bak := ClipboardAll Clipboard := Send("^c") - ClipWait, 1 + ClipWait(1) Send("^f") Send("^v!f") clipboard := bak diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index 41914af..61e0e9c 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -46,18 +46,18 @@ if(this.Vim.State.StrIsInCurrentVimMode("ydc_y")){ Clipboard := Send("^c") - ClipWait, 1 + ClipWait(1) this.Vim.State.SetMode("Vim_Normal") ydc_y := true }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_d")){ Clipboard := Send("^x") - ClipWait, 1 + ClipWait(1) this.Vim.State.SetMode("Vim_Normal") }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_c")){ Clipboard := Send("^x") - ClipWait, 1 + ClipWait(1) this.Vim.State.SetMode("Insert") } this.Vim.State.SetMode("", 0, 0) From 1c5393c94794eeffb436325530c0190a83de2f81 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:42:43 +0900 Subject: [PATCH 15/75] fix: replace Input with InputHook and adjust event handling in vim_enter_normal.ahk (for v2) --- lib/bind/vim_enter_normal.ahk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/bind/vim_enter_normal.ahk b/lib/bind/vim_enter_normal.ahk index dcc17a7..33c0a78 100644 --- a/lib/bind/vim_enter_normal.ahk +++ b/lib/bind/vim_enter_normal.ahk @@ -5,8 +5,10 @@ Esc::Vim.State.HandleEsc() #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1) ~j up:: ; jj: go to Normal mode. { - Input, jout, I T0.1 V L1, j - if(ErrorLevel == "EndKey:J"){ + jout := InputHook("jout, I T0.1 V L1", "j") + jout.Start() + jout.Wait() + if(jout.Input == "EndKey:J"){ SendInput("{BackSpace 2}") Vim.State.SetNormal() } From 1edfffcbfbccab4cd3a86cab1d62c62efcfcf819 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 11:52:34 +0900 Subject: [PATCH 16/75] fix: replace Clipboard (removed in v2) with A_Clipboard (for v2) fix: make ClipboardAll as function (for v2) fix: Give right hand for 'Clipboard := ""' (empty right hand is not allowed in v2) (for v2) refactor: bak -> ClipSaved (as in Document) --- lib/bind/vim_normal.ahk | 12 ++++++------ lib/bind/vim_search.ahk | 6 +++--- lib/bind/vim_visual.ahk | 14 +++++++------- lib/vim_ahk.ahk | 8 ++++---- lib/vim_move.ahk | 6 +++--- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 1d26c5b..2740570 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -9,17 +9,17 @@ u::Send("^z") ; Change case ~:: { - bak := ClipboardAll - Clipboard = + ClipSaved := ClipboardAll() + A_Clipboard = "" Send("+{Right}^x") ClipWait(1) - if(Clipboard is lower){ - StringUpper, Clipboard, Clipboard + if(A_Clipboard is lower){ + StringUpper, A_Clipboard, A_Clipboard }else if(Clipboard is upper){ - StringLower, Clipboard, Clipboard + StringLower, A_Clipboard, A_Clipboard } Send("^v") - Clipboard := bak + A_Clipboard := ClipSaved } ; period diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index 5aad034..b2db3a0 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -7,13 +7,13 @@ *:: { - bak := ClipboardAll - Clipboard= + ClipSaved := ClipboardAll() + A_Clipboard = "" Send("^{Left}+^{Right}^c") ClipWait(1) Send("^f") Send("^v!f") - clipboard := bak + A_clipboard := ClipSaved Vim.State.SetMode("Insert") } diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index 78cfb6a..98a3e95 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -19,7 +19,7 @@ v::Vim.State.SetMode("Vim_Normal") ; ydc y:: { - Clipboard := + A_Clipboard := "" Send("^c") Send("{Right}") if WinActive("ahk_group VimCursorSameAfterSelect"){ @@ -35,7 +35,7 @@ y:: d:: { - Clipboard := + A_Clipboard := "" Send("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ @@ -47,7 +47,7 @@ d:: x:: { - Clipboard := + A_Clipboard := "" Send("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ @@ -59,7 +59,7 @@ x:: c:: { - Clipboard := + A_Clipboard := "" Send("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ @@ -71,13 +71,13 @@ c:: *:: { - bak := ClipboardAll - Clipboard := + ClipSaved := ClipboardAll() + A_Clipboard := "" Send("^c") ClipWait(1) Send("^f") Send("^v!f") - clipboard := bak + A_Clipboard := ClipSaved Vim.State.SetMode("Vim_Normal") } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 7710db5..fd5691f 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -285,16 +285,16 @@ class VimAhk{ ; Ref: https://www.reddit.com/r/AutoHotkey/comments/4ma5b8/identifying_end_of_line_when_typing_with_ahk_and/ CheckChr(key){ BlockInput, Send - tempClip := clipboard - clipboard := "" + ClipSaved := ClipboardAll() + A_Clipboard := "" SendInput("{Shift Down}{Right}{Shift up}{Ctrl down}c{Ctrl Up}{Left}") Sleep(10) ret := False - If (clipboard ~= key){ + If (A_Clipboard ~= key){ ret := True } sleep(10) - clipboard := tempClip + A_Clipboard := ClipSaved BlockInput, off Return ret } diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index 61e0e9c..bc70ae9 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -44,18 +44,18 @@ Send("{Shift Up}") ydc_y := false if(this.Vim.State.StrIsInCurrentVimMode("ydc_y")){ - Clipboard := + A_Clipboard := "" Send("^c") ClipWait(1) this.Vim.State.SetMode("Vim_Normal") ydc_y := true }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_d")){ - Clipboard := + A_Clipboard := "" Send("^x") ClipWait(1) this.Vim.State.SetMode("Vim_Normal") }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_c")){ - Clipboard := + A_Clipboard := "" Send("^x") ClipWait(1) this.Vim.State.SetMode("Insert") From fa8a813b4448449e0653bc2236cd28b2e93c4c51 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 12:11:30 +0900 Subject: [PATCH 17/75] fix: use := for value assignment (= is not available in v2) even for function's default variables (for v2) --- lib/bind/vim_normal.ahk | 2 +- lib/bind/vim_search.ahk | 4 ++-- lib/util/vim_callstack.ahk | 2 +- lib/util/vim_ime.ahk | 6 +++--- lib/vim_caret.ahk | 4 ++-- lib/vim_icon.ahk | 4 ++-- lib/vim_ini.ahk | 4 ++-- lib/vim_move.ahk | 12 ++++++------ lib/vim_state.ahk | 10 +++++----- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 2740570..d96fc2d 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -10,7 +10,7 @@ u::Send("^z") ~:: { ClipSaved := ClipboardAll() - A_Clipboard = "" + A_Clipboard := "" Send("+{Right}^x") ClipWait(1) if(A_Clipboard is lower){ diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index b2db3a0..e9ff475 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -8,12 +8,12 @@ *:: { ClipSaved := ClipboardAll() - A_Clipboard = "" + A_Clipboard := "" Send("^{Left}+^{Right}^c") ClipWait(1) Send("^f") Send("^v!f") - A_clipboard := ClipSaved + A_Clipboard := ClipSaved Vim.State.SetMode("Insert") } diff --git a/lib/util/vim_callstack.ahk b/lib/util/vim_callstack.ahk index 9993aab..098bc90 100644 --- a/lib/util/vim_callstack.ahk +++ b/lib/util/vim_callstack.ahk @@ -4,7 +4,7 @@ FileReadLine( file, line ) { return data } -CallStack( deepness = 5, printLines = 1 ) { +CallStack( deepness:=5, printLines:=1 ) { if A_IsCompiled return loop,% deepness diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index eb1f283..5765e35 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -1,7 +1,7 @@ ; Ref for IME: http://www6.atwiki.jp/eamat/pages/17.html ; Get IME Status. 0: Off, 1: On -VIM_IME_GET(WinTitle="A"){ +VIM_IME_GET(WinTitle:="A"){ ControlGet,hwnd,HWND,,,%WinTitle% if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize @@ -18,7 +18,7 @@ VIM_IME_GET(WinTitle="A"){ , Int, 0) ;lParam : 0 } ; Get input status. 1: Converting, 2: Have converting window, 0: Others -VIM_IME_GetConverting(WinTitle="A", ConvCls="", CandCls=""){ +VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ ; Input windows, candidate windows (Add new IME with "|") ConvCls .= (ConvCls ? "|" : "") ;--- Input Window --- . "ATOK\d+CompStr" ; ATOK @@ -55,7 +55,7 @@ VIM_IME_GetConverting(WinTitle="A", ConvCls="", CandCls=""){ } ; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success -VIM_IME_SET(SetSts=0, WinTitle="A"){ +VIM_IME_SET(SetSts:=0, WinTitle:="A"){ ControlGet, hwnd, HWND, , , %WinTitle% if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index a0f0e04..febfd5a 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -8,7 +8,7 @@ class VimCaret{ , "Default": 1} } - SetCaret(Mode=""){ + SetCaret(Mode:=""){ if (this.Vim.Conf["VimChangeCaretWidth"]["val"] == 0){ return } @@ -28,7 +28,7 @@ class VimCaret{ ; Expects argument "width" in hex SetCaretWidth(width){ CARETWIDTH := width - ; SPI = SystemParametersInfo + ; SPI := SystemParametersInfo SPI_SETCARETWIDTH := 0x2007 SPIF_UPDATEINIFILE := 0x01 SPIF_SENDCHANGE := 0x02 diff --git a/lib/vim_icon.ahk b/lib/vim_icon.ahk index 846026e..98fb3be 100644 --- a/lib/vim_icon.ahk +++ b/lib/vim_icon.ahk @@ -10,8 +10,8 @@ , Default: A_AhkPath} } - SetIcon(Mode="", Interval=0){ - icon := + SetIcon(Mode:="", Interval:=0){ + icon := "" if (Interval == 0){ icon := this.icons["Default"] }else if InStr(Mode, "Normal"){ diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index d381523..6822650 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -3,7 +3,7 @@ static Ini_Default := "vim_ahk.ini" static Section_Default := "Vim Ahk Settings" - __New(vim, dir="", ini="", section=""){ + __New(vim, dir:="", ini:="", section:=""){ this.Vim := vim if(dir == ""){ dir := VimIni.IniDir_Default @@ -19,7 +19,7 @@ this.section := section } - ReadIni(conf=""){ + ReadIni(conf:=""){ if (conf == ""){ conf := this.Vim.Conf } diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index bc70ae9..1c916f1 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -4,7 +4,7 @@ this.shift := 0 } - MoveInitialize(key=""){ + MoveInitialize(key:=""){ this.shift := 0 if(this.Vim.State.StrIsInCurrentVimMode("Visual") or this.Vim.State.StrIsInCurrentVimMode("ydc")){ this.shift := 1 @@ -76,7 +76,7 @@ Send("{Home}") } - Up(n=1){ + Up(n:=1){ Loop, %n% { if WinActive("ahk_group VimCtrlUpDownGroup"){ Send("^{Up}") @@ -86,7 +86,7 @@ } } - Down(n=1){ + Down(n:=1){ Loop, %n% { if WinActive("ahk_group VimCtrlUpDownGroup"){ Send("^{Down}") @@ -96,7 +96,7 @@ } } - Move(key="", repeat=false){ + Move(key:="", repeat:=false){ if(!repeat){ this.MoveInitialize(key) } @@ -202,7 +202,7 @@ } } - Repeat(key=""){ + Repeat(key:=""){ this.MoveInitialize(key) if(this.Vim.State.n == 0){ this.Vim.State.n := 1 @@ -229,7 +229,7 @@ } } - Inner(key=""){ + Inner(key:=""){ if(key == "w"){ this.Move("b", true) this.Move("w", false) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 08dcf62..50b7453 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -23,7 +23,7 @@ this.StatusCheckObj := ObjBindMethod(this, "StatusCheck") } - CheckMode(verbose=1, Mode="", g=0, n=0, LineCopy=-1, force=0){ + CheckMode(verbose:=1, Mode:="", g:=0, n:=0, LineCopy:=-1, force:=0){ if(force == 0) and ((verbose <= 1) or ((Mode == "") and (g == 0) and (n == 0) and (LineCopy == -1))){ Return }else if(verbose == 2){ @@ -36,7 +36,7 @@ } } - SetTooltip(Title, lines=1){ + SetTooltip(Title, lines:=1){ WinGetPos, , , W, H, A ToolTip, %Title%, W - 110, H - 30 - (lines) * 20 this.Vim.VimToolTip.SetRemoveToolTip(1000) @@ -46,7 +46,7 @@ this.CheckMode(4, , , , 1) } - SetMode(Mode="", g=0, n=0, LineCopy=-1){ + SetMode(Mode:="", g:=0, n:=0, LineCopy:=-1){ this.CheckValidMode(Mode) if(Mode != ""){ this.Mode := Mode @@ -143,7 +143,7 @@ Return (inStr(this.Mode, mode)) } - CheckValidMode(mode, fullMatch=true){ + CheckValidMode(mode, fullMatch:=true){ if(this.CheckModeValue == false){ Return } @@ -163,7 +163,7 @@ } } - HasValue(haystack, needle, fullMatch=true){ + HasValue(haystack, needle, fullMatch:=true){ if(!isObject(haystack)){ return false }else if(haystack.Length() == 0){ From 146dfb04dc030a089ffb605475c928da9796b461 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 12:14:37 +0900 Subject: [PATCH 18/75] fix: use isLower, isUpper, StrUpper, StrLower functions. StrUpper/StrLower return output instead of modifying outputarg. (for v2) --- lib/bind/vim_normal.ahk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index d96fc2d..2d22eb6 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -13,10 +13,10 @@ u::Send("^z") A_Clipboard := "" Send("+{Right}^x") ClipWait(1) - if(A_Clipboard is lower){ - StringUpper, A_Clipboard, A_Clipboard - }else if(Clipboard is upper){ - StringLower, A_Clipboard, A_Clipboard + if(isLower(A_Clipboard)){ + A_Clipboard := StrUpper(A_Clipboard) + }else if(isUpper(A_Clipboard)){ + A_Clipboard := StrLower(A_Clipboard) } Send("^v") A_Clipboard := ClipSaved From 6cc0b7bebe65070f27ee54b66aa569ba3e028594 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 12:25:59 +0900 Subject: [PATCH 19/75] fix: fix SetTimer syntax to use function-style calls, use 0 instead of Off to delete it (for v2) --- lib/vim_state.ahk | 4 ++-- lib/vim_tooltip.ahk | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 50b7453..ad6d67a 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -195,10 +195,10 @@ SetStatusCheck(){ check := this.StatusCheckObj if(this.Vim.Conf["VimIconCheckInterval"]["val"] > 0){ - SetTimer, % check, % this.Vim.Conf["VimIconCheckInterval"]["val"] + SetTimer(check, this.Vim.Conf["VimIconCheckInterval"]["val"]) }else{ this.Vim.Icon.SetIcon("", 0) - SetTimer, % check, Off + SetTimer(check, 0) } } diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index dfbfd9a..45fadcf 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -14,28 +14,28 @@ class VimToolTip{ this.RemoveToolTip() if(this.Vim.Info.HasKey(this.Vim.State.CurrControl)){ display := this.DisplayToolTipObj - SetTimer, % display, -1000 + SetTimer(display, -1000) } } } DisplayToolTip(){ display := this.DisplayToolTipObj - SetTimer, % display, Off + SetTimer(display, 0) ToolTip % this.Vim.Info[this.Vim.State.CurrControl] this.SetRemoveToolTip(60000) } RemoveToolTip(){ display := this.DisplayToolTipObj - SetTimer, % display, Off + SetTimer(display, 0) remove := this.RemoveToolTipObj - SetTimer, % remove, off + SetTimer(remove, 0) ToolTip } SetRemoveToolTip(time){ remove := this.RemoveToolTipObj - SetTimer, % remove, % "-" time + SetTimer(remove, "-" time) } } From 7878dd52808f4720187e80241eca7805a0de0952 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 12:41:57 +0900 Subject: [PATCH 20/75] fix: Replace 'base' with 'super' in constructor calls for class inheritance. (for v2) --- lib/vim_about.ahk | 2 +- lib/vim_setting.ahk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index 156a76f..31f59b0 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -8,7 +8,7 @@ this.Description := "" this.Homepage := "" - base.__New(vim, "Vim Ahk") + super.__New(vim, "Vim Ahk") } MakeGui(){ diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index ee167de..78467ff 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -1,7 +1,7 @@ class VimSetting Extends VimGui{ __New(vim){ this.Vim := vim - base.__New(vim, "Vim Ahk Settings") + super.__New(vim, "Vim Ahk Settings") } MakeGui(){ From 50b5627213c751c9903b6a38742395ed93321009 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 12:51:29 +0900 Subject: [PATCH 21/75] fix: fix Loop syntax (remove first comma, remove literal syntax) (for v2) --- lib/vim_ahk.ahk | 6 ++---- lib/vim_move.ahk | 6 +++--- lib/vim_setting.ahk | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index fd5691f..615679a 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -183,8 +183,7 @@ class VimAhk{ SetGroup(){ this.GroupN++ this.GroupName := "VimGroup" this.GroupN - Loop, Parse, % this.Conf["VimGroup"]["val"], % this.GroupDel - { + Loop Parse, this.Conf["VimGroup"]["val"], this.GroupDel { if(A_LoopField != ""){ GroupAdd, % this.GroupName, %A_LoopField% } @@ -193,8 +192,7 @@ class VimAhk{ LoadTwoLetterMaps() { this.TwoLetterNormalIsSet := False - Loop, Parse, % this.Conf["VimTwoLetter"]["val"], % this.GroupDel - { + Loop Parse, this.Conf["VimTwoLetter"]["val"], this.GroupDel { if(A_LoopField != ""){ this.TwoLetterNormalIsSet := True key1 := SubStr(A_LoopField, 1, 1) diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index 1c916f1..c685cb6 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -77,7 +77,7 @@ } Up(n:=1){ - Loop, %n% { + Loop n { if WinActive("ahk_group VimCtrlUpDownGroup"){ Send("^{Up}") } else { @@ -87,7 +87,7 @@ } Down(n:=1){ - Loop, %n% { + Loop n { if WinActive("ahk_group VimCtrlUpDownGroup"){ Send("^{Down}") } else { @@ -207,7 +207,7 @@ if(this.Vim.State.n == 0){ this.Vim.State.n := 1 } - Loop, % this.Vim.State.n { + Loop this.Vim.State.n { this.Move(key, true) } this.MoveFinalize() diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index 78467ff..2068984 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -152,9 +152,8 @@ class VimSetting Extends VimGui{ VimParseList(list){ result := "" tmpArray := [] - Loop, Parse, list, `n - { - if(! tmpArray.Haskey(A_LoopField)){ + Loop Parse, list, "`n" { + if(! tmpArray.Has(A_LoopField)){ tmpArray.push(A_LoopField) if(result == ""){ result := A_LoopField From 58c665c802a45fa0fdb2f26a2780d2311e53618b Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 13:00:54 +0900 Subject: [PATCH 22/75] fix: replace legacy ToolTip syntax with new function-based syntax (for v2) --- lib/vim_state.ahk | 2 +- lib/vim_tooltip.ahk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index ad6d67a..0fa9aa3 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -38,7 +38,7 @@ SetTooltip(Title, lines:=1){ WinGetPos, , , W, H, A - ToolTip, %Title%, W - 110, H - 30 - (lines) * 20 + ToolTip(Title, W - 110, H - 30 - (lines) * 20) this.Vim.VimToolTip.SetRemoveToolTip(1000) } diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index 45fadcf..629b17c 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -22,7 +22,7 @@ class VimToolTip{ DisplayToolTip(){ display := this.DisplayToolTipObj SetTimer(display, 0) - ToolTip % this.Vim.Info[this.Vim.State.CurrControl] + ToolTip(this.Vim.Info[this.Vim.State.CurrControl]) this.SetRemoveToolTip(60000) } From ced6ac7be01d5497e25d7119081825e4c48233c6 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 13:45:00 +0900 Subject: [PATCH 23/75] fix: replace MsgBox command to function (for v2) --- lib/bind/vim_ydcxp.ahk | 2 +- lib/vim_check.ahk | 12 +++++------- lib/vim_state.ahk | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index 77b51da..c8799f5 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -79,7 +79,7 @@ p:: ; if(i == 0){ ; Sleep(500) ; }else if(i > 100){ - ; Msgbox, , Vim Ahk, Stop at 100!!! + ; MsgBox("Vim Ahk, Stop at 100!!!", "Vim Ahk") ; break ; }else{ ; Sleep(0) diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 9d5e901..2464a4f 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -6,27 +6,25 @@ CheckMenu() { ; Additional message is necessary before checking current window. ; Otherwise process name cannot be retrieved...? - Msgbox, , Vim Ahk, Checking current window... + MsgBox("Checking current window...", "Vim Ahk") WinGet, process, PID, A WinGet, name, ProcessName, ahk_pid %process% WinGetClass, class, ahk_pid %process% WinGetTitle, title, ahk_pid %process% if(this.Vim.IsVimGroup()){ - Msgbox, 0x40, Vim Ahk, - ( + MsgBox("( Supported Process name: %name% Class : %class% Title : %title% - ) + )", "Vim Ahk", "Iconi") }else{ - Msgbox, 0x10, Vim Ahk, - ( + MsgBox("( Not supported Process name: %name% Class : %class% Title : %title% - ) + )", "Vim Ahk", "Iconx") } } } diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 0fa9aa3..2ec9286 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -32,7 +32,12 @@ this.SetTooltip(this.Mode "`r`ng=" this.g "`r`nn=" this.n "`r`nLineCopy=" this.LineCopy, 4) } if(verbose >= 4){ - Msgbox, , Vim Ahk, % "Mode: " this.Mode "`nVim_g: " this.g "`nVim_n: " this.n "`nVimLineCopy: " this.LineCopy + MsgBox("( + Mode : %this.Mode% + Vim_g : %this.g% + Vim_n : %this.n% + VimLineCopy : %this.LineCopy% + )", "Vim Ahk") } } @@ -159,7 +164,12 @@ ) } }catch e{ - MsgBox % "Warning: " e.Message "`n" e.Extra "`n`n Called in " e.What " at line " e.Line + MsgBox("( + Warning: %e.Message% + %e.Extra% + + Called in %e.What% at line %e.Line% + )", "Vim Ahk") } } From f5f0aeb428774f03915f9c6963152f070275a924 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 14:05:30 +0900 Subject: [PATCH 24/75] fix: array Length function was replaced Length property (for v2) --- lib/vim_state.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 2ec9286..3058521 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -176,7 +176,7 @@ HasValue(haystack, needle, fullMatch:=true){ if(!isObject(haystack)){ return false - }else if(haystack.Length() == 0){ + }else if(haystack.Length == 0){ return false } for index, value in haystack{ From 60bcb0ab666498f27bbfcf955137df8e197eeaa4 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 14:09:45 +0900 Subject: [PATCH 25/75] fix: replace deprecated 'HasKey' method with 'Has' method (for v2) --- lib/vim_tooltip.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index 629b17c..e552209 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -12,7 +12,7 @@ class VimToolTip{ if(this.Vim.State.CurrControl != this.Vim.State.PrevControl){ this.Vim.State.PrevControl := this.Vim.State.CurrControl this.RemoveToolTip() - if(this.Vim.Info.HasKey(this.Vim.State.CurrControl)){ + if(this.Vim.Info.Has(this.Vim.State.CurrControl)){ display := this.DisplayToolTipObj SetTimer(display, -1000) } From cb5619862df748d16d3291022831a3f6dd4f51a2 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 14:12:01 +0900 Subject: [PATCH 26/75] fix: rename exception class to ValueError in vim_state (for v2) --- lib/vim_state.ahk | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 3058521..42980e2 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -153,17 +153,16 @@ Return } try{ - InOrBlank:= (not fullMatch) ? "in " : "" + InOrBlank := (not fullMatch) ? "in " : "" if not this.HasValue(this.PossibleVimModes, mode, fullMatch){ - throw Exception("Invalid mode specified",-2, - (Join - "'" Mode "' is not " InOrBlank " a valid mode as defined by the VimPossibleVimModes - array at the top of vim_state.ahk. This may be a typo. - Fix this error by using an existing mode, - or adding your mode to the array.") - ) + Throw ValueError("Invalid mode specified", -2, "( + '%Mode%' is not %InOrBlank%a valid mode as defined by the VimPossibleVimModes + array at the top of vim_state.ahk. This may be a typo. + Fix this error by using an existing mode, + or adding your mode to the array. + )") } - }catch e{ + }catch ValueError as e{ MsgBox("( Warning: %e.Message% %e.Extra% From e5d91e3ec98a341c539fee8dc5c847dca7bdafe6 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 15:15:15 +0900 Subject: [PATCH 27/75] fix: remove unnecessary "new" keyword when instantiating classes (for v2) --- lib/vim_ahk.ahk | 20 ++++++++++---------- vim.ahk | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 615679a..f672d64 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -33,16 +33,16 @@ class VimAhk{ ; Classes - this.About := new VimAbout(this) - this.Check := new VimCheck(this) - this.Icon := new VimIcon(this) - this.Caret := new VimCaret(this) - this.Ini := new VimIni(this) - this.VimMenu := new VimMenu(this) - this.Move := new VimMove(this) - this.Setting := new VimSetting(this) - this.State := new VimState(this) - this.VimToolTip := new VimToolTip(this) + this.About := VimAbout(this) + this.Check := VimCheck(this) + this.Icon := VimIcon(this) + this.Caret := VimCaret(this) + this.Ini := VimIni(this) + this.VimMenu := VimMenu(this) + this.Move := VimMove(this) + this.Setting := VimSetting(this) + this.State := VimState(this) + this.VimToolTip := VimToolTip(this) ; Group Settings this.GroupDel := "," diff --git a/vim.ahk b/vim.ahk index bb49099..efe26ed 100644 --- a/vim.ahk +++ b/vim.ahk @@ -2,7 +2,7 @@ ; Auto-execute section VimScriptPath := A_LineFile -Vim := new VimAhk() +Vim := VimAhk() Return #Include %A_LineFile%\..\lib\vim_ahk.ahk From 360bd572d904e7c54471d464acbf6b8a9f062d0b Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 15:34:09 +0900 Subject: [PATCH 28/75] fix: refactor GroupAdd usage to function syntax (for v2) --- lib/vim_ahk.ahk | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index f672d64..7d70468 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -52,40 +52,40 @@ class VimAhk{ DefaultGroup := this.SetDefaultActiveWindows() ; On following applications, Enter works as Enter at the normal mode. - GroupAdd, VimNonEditor, ahk_exe explorer.exe ; Explorer - GroupAdd, VimNonEditor, ahk_exe Explorer.exe ; Explorer, Explorer became also upper case, but lower case works for this - GroupAdd, VimNonEditor, ahk_exe Q-Dir_x64.exe ; Q-dir - GroupAdd, VimNonEditor, ahk_exe Q-Dir.exe ; Q-dir + GroupAdd("VimNonEditor", "ahk_exe explorer.exe") ; Explorer + GroupAdd("VimNonEditor", "ahk_exe Explorer.exe") ; Explorer, Explorer became also upper case, but lower case works for this + GroupAdd("VimNonEditor", "ahk_exe Q-Dir_x64.exe") ; Q-dir + GroupAdd("VimNonEditor", "ahk_exe Q-Dir.exe") ; Q-dir ; Following applications select the line break at Shift + End. - GroupAdd, VimLBSelectGroup, ahk_exe POWERPNT.exe ; PowerPoint - GroupAdd, VimLBSelectGroup, ahk_exe WINWORD.exe ; Word - GroupAdd, VimLBSelectGroup, ahk_exe wordpad.exe ; WordPad + GroupAdd("VimLBSelectGroup", "ahk_exe POWERPNT.exe") ; PowerPoint + GroupAdd("VimLBSelectGroup", "ahk_exe WINWORD.exe") ; Word + GroupAdd("VimLBSelectGroup", "ahk_exe wordpad.exe") ; WordPad ; Following applications do not copy the line break - GroupAdd, VimNoLBCopyGroup, ahk_exe Evernote.exe ; Evernote + GroupAdd("VimNoLBCopyGroup", "ahk_exe Evernote.exe") ; Evernote ; Need Ctrl for Up/Down - GroupAdd, VimCtrlUpDownGroup, ahk_exe onenote.exe ; OneNote Desktop, before Windows 10 + GroupAdd("VimCtrlUpDownGroup", "ahk_exe onenote.exe") ; OneNote Desktop, before Windows 10 ; Need Home twice - GroupAdd, VimDoubleHomeGroup, ahk_exe Code.exe ; Visual Studio Code + GroupAdd("VimDoubleHomeGroup", "ahk_exe Code.exe") ; Visual Studio Code ; Followings can emulate ^. For others, ^ works as same as 0 ; It does not work for NotePad at Windows 11 - ; GroupAdd, VimCaretMove, ahk_exe notepad.exe ; NotePad - ; GroupAdd, VimCaretMove, ahk_exe Notepad.exe ; NotePad + ; GroupAdd("VimCaretMove", "ahk_exe notepad.exe") ; NotePad + ; GroupAdd("VimCaretMove", "ahk_exe Notepad.exe") ; NotePad ; Followings start cursor from the same place after selection. ; Others start right/left (by cursor) point of the selection - GroupAdd, VimCursorSameAfterSelect, ahk_exe notepad.exe ; NotePad - GroupAdd, VimCursorSameAfterSelect, ahk_exe Notepad.exe ; NotePad - GroupAdd, VimCursorSameAfterSelect, ahk_exe explorer.exe ; Explorer - GroupAdd, VimCursorSameAfterSelect, ahk_exe Explorer.exe ; Explorer + GroupAdd("VimCursorSameAfterSelect", "ahk_exe notepad.exe") ; NotePad + GroupAdd("VimCursorSameAfterSelect", "ahk_exe Notepad.exe") ; NotePad + GroupAdd("VimCursorSameAfterSelect", "ahk_exe explorer.exe") ; Explorer + GroupAdd("VimCursorSameAfterSelect", "ahk_exe Explorer.exe") ; Explorer ; Q-Dir - GroupAdd, VimQdir, ahk_exe Q-Dir_x64.exe ; q-dir - GroupAdd, VimQdir, ahk_exe Q-Dir.exe ; q-dir + GroupAdd("VimQdir", "ahk_exe Q-Dir_x64.exe") ; q-dir + GroupAdd("VimQdir", "ahk_exe Q-Dir.exe") ; q-dir ; Configuration values for Read/Write ini ; setting, default, val, description, info @@ -185,7 +185,7 @@ class VimAhk{ this.GroupName := "VimGroup" this.GroupN Loop Parse, this.Conf["VimGroup"]["val"], this.GroupDel { if(A_LoopField != ""){ - GroupAdd, % this.GroupName, %A_LoopField% + GroupAdd(this.GroupName, A_LoopField) } } } From c47587df34667c86675b7ce692960653bba95f74 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 15:56:58 +0900 Subject: [PATCH 29/75] fix: replace object literals with Map() for configuration and tooltip info (for v2) --- lib/vim_ahk.ahk | 6 +++--- lib/vim_caret.ahk | 8 ++++---- lib/vim_icon.ahk | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 7d70468..c46c94e 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -89,7 +89,7 @@ class VimAhk{ ; Configuration values for Read/Write ini ; setting, default, val, description, info - this.Conf := {} + this.Conf := Map() this.AddToConf("VimEscNormal", 1, 1 , "ESC to enter the normal mode" , "Use ESC to enter the normal mode, long press ESC to send ESC.") @@ -148,7 +148,7 @@ class VimAhk{ this.CheckBoxes := ["VimEscNormal", "VimSendEscNormal", "VimLongEscNormal", "VimCtrlBracketToEsc", "VimCtrlBracketNormal", "VimSendCtrlBracketNormal", "VimLongCtrlBracketNormal", "VimRestoreIME", "VimJJ", "VimChangeCaretWidth"] ; ToolTip Information - this.Info := {} + this.Info := Map() for k, v in this.Conf { info := k ":`n" v["info"] this.Info[k] := info @@ -167,7 +167,7 @@ class VimAhk{ } AddToConf(setting, default, val, description, info){ - this.Conf[setting] := {"default": default, "val": val, "description": description, "info": info} + this.Conf[setting] := Map("default", default, "val", val, "description", description, "info", info) } SetExistValue(){ diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index febfd5a..6f0a8b0 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -2,10 +2,10 @@ class VimCaret{ __New(vim){ global VimScriptPath this.Vim := vim - this.caretwidths := {"Normal": 10 - , "Visual": 10 - , "Insert": 1 - , "Default": 1} + this.caretwidths := Map("Normal", 10 + , "Visual", 10 + , "Insert", 1 + , "Default", 1) } SetCaret(Mode:=""){ diff --git a/lib/vim_icon.ahk b/lib/vim_icon.ahk index 98fb3be..618b407 100644 --- a/lib/vim_icon.ahk +++ b/lib/vim_icon.ahk @@ -2,12 +2,12 @@ __New(vim){ global VimScriptPath this.Vim := vim - this.icons := {Normal: VimScriptPath "\..\vim_ahk_icons\normal.ico" - , Insert: VimScriptPath "\..\vim_ahk_icons\insert.ico" - , Visual: VimScriptPath "\..\vim_ahk_icons\visual.ico" - , Command: VimScriptPath "\..\vim_ahk_icons\command.ico" - , Disabled: VimScriptPath "\..\vim_ahk_icons\disabled.ico" - , Default: A_AhkPath} + this.icons := Map("Normal", this.Vim.ScriptPath "\..\vim_ahk_icons\normal.ico" + , "Insert", this.Vim.ScriptPath "\..\vim_ahk_icons\insert.ico" + , "Visual", this.Vim.ScriptPath "\..\vim_ahk_icons\visual.ico" + , "Command", this.Vim.ScriptPath "\..\vim_ahk_icons\command.ico" + , "Disabled", this.Vim.ScriptPath "\..\vim_ahk_icons\disabled.ico" + , "Default", A_AhkPath) } SetIcon(Mode:="", Interval:=0){ From b5ed89ac41e5dcc16a1703e93aaef8e5e16e1778 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:01:51 +0900 Subject: [PATCH 30/75] fix: correct parameter (A -> "A") in VIM_IME_GetConverting function call (for v2) --- lib/vim_state.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 42980e2..05c025b 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -76,7 +76,7 @@ SetNormal(){ this.LastIME := VIM_IME_Get() if(this.LastIME){ - if(VIM_IME_GetConverting(A)){ + if(VIM_IME_GetConverting("A")){ Send("{Esc}") Return }else{ From f3d792f4d30c7aca764b2160eb2e57f19c8ae376 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:22:56 +0900 Subject: [PATCH 31/75] fix: replace deprecated HotKey syntax with HotIf for conditional hotkey (for v2) --- lib/vim_ahk.ahk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index c46c94e..bd6dfdf 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -205,9 +205,9 @@ class VimAhk{ SetTwoLetterMap(key1, key2){ EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") Enabled := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") - HotKey If, % Enabled - HotKey, %key1% & %key2%, % EnterNormal - HotKey, %key2% & %key1%, % EnterNormal + HotIf(Enabled) + HotKey("%key1% & %key2%", EnterNormal) + HotKey("%key2% & %key1%", EnterNormal) } TwoLetterNormalMapsEnabled(){ From 7f1b356b6a10dae27b6978a0b453e8b1a4d43528 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:23:34 +0900 Subject: [PATCH 32/75] fix: use function syntax for SetTitleMatchMode calls (for v2) --- lib/util/vim_ime.ahk | 4 ++-- lib/vim_ahk.ahk | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index 5765e35..22dac3e 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -45,12 +45,12 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ WinGet, pid, PID,% "ahk_id " hwnd tmm := A_TitleMatchMode - SetTitleMatchMode, RegEx + SetTitleMatchMode("RegEx") ret := WinExist("ahk_class " . CandCls . " ahk_pid " pid) ? 2 : WinExist("ahk_class " . CandGCls ) ? 2 : WinExist("ahk_class " . ConvCls . " ahk_pid " pid) ? 1 : 0 - SetTitleMatchMode, %tmm% + SetTitleMatchMode(tmm) Return ret } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index bd6dfdf..b7d9d2e 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -220,8 +220,8 @@ class VimAhk{ } Setup(){ - SetTitleMatchMode, % this.Conf["VimSetTitleMatchMode"]["val"] - SetTitleMatchMode, % this.Conf["VimSetTitleMatchModeFS"]["val"] + SetTitleMatchMode(this.Conf["VimSetTitleMatchMode"]["val"]) + SetTitleMatchMode(this.Conf["VimSetTitleMatchModeFS"]["val"]) this.State.SetStatusCheck() this.SetGroup() this.LoadTwoLetterMaps() From a13af83aee044b244632e27c311e09b7eaaa8321 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:24:35 +0900 Subject: [PATCH 33/75] fix: update BlockInput usage to function call syntax (for v2) --- lib/vim_ahk.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index b7d9d2e..37f5b6b 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -282,7 +282,7 @@ class VimAhk{ ; Ref: https://www.reddit.com/r/AutoHotkey/comments/4ma5b8/identifying_end_of_line_when_typing_with_ahk_and/ CheckChr(key){ - BlockInput, Send + BlockInput("Send") ClipSaved := ClipboardAll() A_Clipboard := "" SendInput("{Shift Down}{Right}{Shift up}{Ctrl down}c{Ctrl Up}{Left}") @@ -293,7 +293,7 @@ class VimAhk{ } sleep(10) A_Clipboard := ClipSaved - BlockInput, off + BlockInput("Off") Return ret } } From 9118767195655185b825c5414c91bce093c0f599 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:33:07 +0900 Subject: [PATCH 34/75] fix: use function style WinGetPID in vim_ime.ahk (for v2) fix: use function style WinGetID in vim_caret.ahk (for v2) fix: replace WinGet commands with function style in vim_check.ahk (for v2) fix: use WinGetPos function style in vim_state.ahk (for v2) fix: replace variable name class -> win_class as class is reserved (for v2) --- lib/util/vim_ime.ahk | 2 +- lib/vim_caret.ahk | 2 +- lib/vim_check.ahk | 12 ++++++------ lib/vim_state.ahk | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index 22dac3e..6667c86 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -43,7 +43,7 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd } - WinGet, pid, PID,% "ahk_id " hwnd + pid := WinGetPID("ahk_id " hwnd) tmm := A_TitleMatchMode SetTitleMatchMode("RegEx") ret := WinExist("ahk_class " . CandCls . " ahk_pid " pid) ? 2 diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 6f0a8b0..813ebf4 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -39,7 +39,7 @@ class VimCaret{ SwitchToSameWindow(){ ; Get ID of active window - WinGet, hwnd, ID, A + hwnd := WinGetID("A") ; Activate desktop winActivate, ahk_class WorkerW WinActivate, ahk_id %hwnd% diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 2464a4f..09d323a 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -7,22 +7,22 @@ ; Additional message is necessary before checking current window. ; Otherwise process name cannot be retrieved...? MsgBox("Checking current window...", "Vim Ahk") - WinGet, process, PID, A - WinGet, name, ProcessName, ahk_pid %process% - WinGetClass, class, ahk_pid %process% - WinGetTitle, title, ahk_pid %process% + process := WinGetPID("A") + name := WinGetProcessName("ahk_pid " process) + win_class := WinGetClass("ahk_pid " process) + title := WinGetTitle("ahk_pid " process) if(this.Vim.IsVimGroup()){ MsgBox("( Supported Process name: %name% - Class : %class% + Class : %win_class% Title : %title% )", "Vim Ahk", "Iconi") }else{ MsgBox("( Not supported Process name: %name% - Class : %class% + Class : %win_class% Title : %title% )", "Vim Ahk", "Iconx") } diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 05c025b..fe642e1 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -42,7 +42,7 @@ } SetTooltip(Title, lines:=1){ - WinGetPos, , , W, H, A + WinGetPos(, , &W, &H, "A") ToolTip(Title, W - 110, H - 30 - (lines) * 20) this.Vim.VimToolTip.SetRemoveToolTip(1000) } From d26c5dfc20b30809336e38136f076b191f826f16 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:34:36 +0900 Subject: [PATCH 35/75] fix: initialize width variable to an empty string (for v2) --- lib/vim_caret.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 813ebf4..1170db4 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -12,7 +12,7 @@ class VimCaret{ if (this.Vim.Conf["VimChangeCaretWidth"]["val"] == 0){ return } - width := + width := "" if this.Vim.State.IsCurrentVimMode("Vim_Normal"){ width := this.caretwidths["Normal"] }else if this.Vim.State.StrIsInCurrentVimMode("Visual"){ From 0bf2c92a97a51efc2399a553234aaa9b8e1be30e Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:36:14 +0900 Subject: [PATCH 36/75] fix: replace StringUpper with StrUpper function for case conversion (for v2) --- lib/vim_ini.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index 6822650..9fe9ddd 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -43,8 +43,8 @@ } DeprecatedTwoLetter(l1, l2){ - StringUpper, ul1, l1 - StringUpper, ul2, l2 + ul1 := StrUpper(l1) + ul2 := StrUpper(l2) twoLetter := "Vim" ul1 ul2 IniRead, val, % this.Ini, % this.Section, % twoLetter, 0 if (val == 1){ From 5baff1b7b2a8636881237b965e9441990ed1328c Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:37:42 +0900 Subject: [PATCH 37/75] fix: replace legacy IniRead/IniWrite/IniDelete commands with function calls (for v2) --- lib/vim_ini.ahk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index 9fe9ddd..2fbda8b 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -26,9 +26,9 @@ for k, v in conf { current := v["val"] if(current != ""){ - IniRead, val, % this.Ini, % this.Section, % k, % current + val := IniRead(this.Ini, this.Section, k, current) }else{ - IniRead, val, % this.Ini, % this.Section, % k, % A_Space + val := IniRead(this.Ini, this.Section, k, A_Space) } %k% := val v["val"] := val @@ -46,7 +46,7 @@ ul1 := StrUpper(l1) ul2 := StrUpper(l2) twoLetter := "Vim" ul1 ul2 - IniRead, val, % this.Ini, % this.Section, % twoLetter, 0 + val := IniRead(this.Ini, this.Section, twoLetter, 0) if (val == 1){ if (this.Vim.Conf["VimTwoLetter"]["val"] == ""){ this.Vim.Conf["VimTwoLetter"]["val"] := l1 l2 @@ -54,7 +54,7 @@ this.Vim.Conf["VimTwoLetter"]["val"] := this.Vim.Conf["VimTwoLetter"]["val"] this.Vim.GroupDel l1 l2 } } - IniDelete, % this.Ini, % this.Section, % twoLetter + IniDelete(this.Ini, this.Section, twoLetter) } WriteIni(){ @@ -62,7 +62,7 @@ FileCreateDir, % this.IniDir for k, v in this.Vim.Conf { - IniWrite, % v["val"], % this.Ini, % this.Section, % k + IniWrite(v["val"], this.Ini, this.Section, k) } } } From 99c73defc5c845b66fe0b55949019425e42c6d1f Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:39:23 +0900 Subject: [PATCH 38/75] fix: replace deprecated `FileCreateDir` with `DirCreate` in WriteIni method (for v2) --- lib/vim_ini.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index 2fbda8b..dd93b82 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -58,8 +58,8 @@ } WriteIni(){ - IfNotExist, % this.IniDir - FileCreateDir, % this.IniDir + if not FileExist(this.IniDir) + DirCreate(this.IniDir) for k, v in this.Vim.Conf { IniWrite(v["val"], this.Ini, this.Section, k) From 1036a82c068e2c1d2eada723c60eadbcf6cc655d Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:44:26 +0900 Subject: [PATCH 39/75] fix: use ScriptPath in VimAhk class fix: remove unused arg setup in VimAhk.__New --- lib/vim_about.ahk | 4 ++-- lib/vim_ahk.ahk | 3 ++- lib/vim_caret.ahk | 1 - lib/vim_icon.ahk | 1 - vim.ahk | 3 +-- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index 31f59b0..51ffbb9 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -12,7 +12,7 @@ } MakeGui(){ - global VimHomepage, VimAboutOK, VimScriptPath + global VimHomepage, VimAboutOK Gui, % this.Hwnd ":-MinimizeBox" Gui, % this.Hwnd ":-Resize" Gui, % this.Hwnd ":Add", Text, , % "Vim Ahk (vim_ahk):`n" this.Description @@ -24,7 +24,7 @@ Gui, % this.Hwnd ":Add", Text, , % "Author: " this.Author Gui, % this.Hwnd ":Add", Text, , % "Version: " this.Version Gui, % this.Hwnd ":Add", Text, Y+0, % "Last update: " this.Date - Gui, % this.Hwnd ":Add", Text, , Script path:`n%VimScriptPath% + Gui, % this.Hwnd ":Add", Text, , Script path:`n%this.Vim.ScriptPath% Gui, % this.Hwnd ":Add", Text, , % "Setting file:`n" this.Vim.Ini.Ini Gui, % this.Hwnd ":Add", Button, +HwndOK X200 W100 Default vVimAboutOK, &OK this.HwndAll.Push(OK) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 37f5b6b..625a5a4 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -28,7 +28,8 @@ class VimAhk{ this.Info["VimHomepage"] := this.About.Homepage } - __New(setup=true){ + __New(ScriptPath){ + this.ScriptPath := ScriptPath this.Enabled := True diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 1170db4..0492367 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -1,6 +1,5 @@ class VimCaret{ __New(vim){ - global VimScriptPath this.Vim := vim this.caretwidths := Map("Normal", 10 , "Visual", 10 diff --git a/lib/vim_icon.ahk b/lib/vim_icon.ahk index 618b407..9d6accf 100644 --- a/lib/vim_icon.ahk +++ b/lib/vim_icon.ahk @@ -1,6 +1,5 @@ class VimIcon{ __New(vim){ - global VimScriptPath this.Vim := vim this.icons := Map("Normal", this.Vim.ScriptPath "\..\vim_ahk_icons\normal.ico" , "Insert", this.Vim.ScriptPath "\..\vim_ahk_icons\insert.ico" diff --git a/vim.ahk b/vim.ahk index efe26ed..aa0702a 100644 --- a/vim.ahk +++ b/vim.ahk @@ -1,8 +1,7 @@ #Requires AutoHotkey v1.1 ; Auto-execute section -VimScriptPath := A_LineFile -Vim := VimAhk() +Vim := VimAhk(A_LineFile) Return #Include %A_LineFile%\..\lib\vim_ahk.ahk From e8bd8daf1b55f047aed556c6d315babe7bd1d67a Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:54:03 +0900 Subject: [PATCH 40/75] fix: use function syntax for WinActivate (for v2) --- lib/vim_caret.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 0492367..05e1127 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -40,8 +40,8 @@ class VimCaret{ ; Get ID of active window hwnd := WinGetID("A") ; Activate desktop - winActivate, ahk_class WorkerW - WinActivate, ahk_id %hwnd% + WinActivate("ahk_class WorkerW") + WinActivate("ahk_id " hwnd) } } From fda4daa21eab55df59c418a71dc48fd2ba520598 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 16:58:52 +0900 Subject: [PATCH 41/75] fix: replace Menu commands with method-based menu structure in vim_menu (for v2) --- lib/vim_menu.ahk | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/vim_menu.ahk b/lib/vim_menu.ahk index e605ed1..6a61748 100644 --- a/lib/vim_menu.ahk +++ b/lib/vim_menu.ahk @@ -8,13 +8,13 @@ MenuVimCheck := ObjBindMethod(this.Vim.Check, "CheckMenu") MenuVimStatus := ObjBindMethod(this.Vim.State, "FullStatus") MenuVimAbout := ObjBindMethod(this.Vim.About, "ShowGui") - Menu, VimSubMenu, Add, Settings, % MenuVimSetting - Menu, VimSubMenu, Add - Menu, VimSubMenu, Add, Vim Check, % MenuVimCheck - Menu, VimSubMenu, Add, Status, % MenuVimStatus - Menu, VimSubMenu, Add, About vim_ahk, % MenuVimAbout - - Menu, Tray, Add - Menu, Tray, Add, VimMenu, :VimSubMenu + this.Vim.SubMenu := Menu() + this.Vim.SubMenu.Add("Settings", MenuVimSetting) + this.Vim.SubMenu.Add() + this.Vim.SubMenu.Add("Vim Check", MenuVimCheck) + this.Vim.SubMenu.Add("Status", MenuVimStatus) + this.Vim.SubMenu.Add("About vim_ahk", MenuVimAbout) + A_TrayMenu.Add() + A_TrayMenu.Add("VimMenu", this.Vim.SubMenu) } } From bf3a9f83a41c4ed0be372912bdf0adc0afef0170 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:00:39 +0900 Subject: [PATCH 42/75] fix: replace ControlGet with WinExist for hwnd retrieval (for v2) --- lib/util/vim_ime.ahk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index 6667c86..fcd0fe3 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -2,7 +2,7 @@ ; Get IME Status. 0: Off, 1: On VIM_IME_GET(WinTitle:="A"){ - ControlGet,hwnd,HWND,,,%WinTitle% + hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) @@ -34,7 +34,7 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ . "|SKKIME\d+\.*\d+UCand" ; SKKIME Unicode CandGCls := "GoogleJapaneseInputCandidateWindow" ; Google IME - ControlGet, hwnd, HWND, , , %WinTitle% + hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) @@ -56,7 +56,7 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ ; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success VIM_IME_SET(SetSts:=0, WinTitle:="A"){ - ControlGet, hwnd, HWND, , , %WinTitle% + hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) From d3476848a2b0cc07c17cf10ed5a14633d68419e4 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:01:24 +0900 Subject: [PATCH 43/75] fix: rename variable 'type' to 't_type' to avoid shadowing --- lib/vim_ahk.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 625a5a4..daa9e8d 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -153,8 +153,8 @@ class VimAhk{ for k, v in this.Conf { info := k ":`n" v["info"] this.Info[k] := info - for i, type in ["Text", "List", "Value", "Edit"] { - textKey := k type + for i, t_type in ["Text", "List", "Value", "Edit"] { + textKey := k t_type this.Info[textKey] := info } } From a5d19fabd2c58d2e1cce5f382082e2766c583672 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:04:14 +0900 Subject: [PATCH 44/75] fix: quote UInt, Int in DllCall arguments (for v2) refactor: Uint -> UInt --- lib/util/vim_ime.ahk | 22 +++++++++++----------- lib/vim_caret.ahk | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index fcd0fe3..e8025ed 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -7,15 +7,15 @@ VIM_IME_GET(WinTitle:="A"){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", Uint,0, Uint, &stGTI) + hwnd := DllCall("GetGUIThreadInfo", "Uint" , 0, "Uint", &stGTI) ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd } Return DllCall("SendMessage" - , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint, hwnd) - , UInt, 0x0283 ;Message : WM_IME_CONTROL - , Int, 0x0005 ;wParam : IMC_GETOPENSTATUS - , Int, 0) ;lParam : 0 + , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", hwnd) + , "UInt", 0x0283 ;Message : WM_IME_CONTROL + , "Int", 0x0005 ;wParam : IMC_GETOPENSTATUS + , "Int", 0) ;lParam : 0 } ; Get input status. 1: Converting, 2: Have converting window, 0: Others VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ @@ -39,7 +39,7 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", Uint, 0, Uint,&stGTI) + hwnd := DllCall("GetGUIThreadInfo", "Uint", 0, "Uint", &stGTI) ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd } @@ -61,13 +61,13 @@ VIM_IME_SET(SetSts:=0, WinTitle:="A"){ ptrSize := !A_PtrSize ? 4 : A_PtrSize VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", Uint, 0, Uint, &stGTI) + hwnd := DllCall("GetGUIThreadInfo", "Uint", 0, "Uint", &stGTI) ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd } Return DllCall("SendMessage" - , UInt, DllCall("imm32\ImmGetDefaultIMEWnd", Uint, hwnd) - , UInt, 0x0283 ;Message : WM_IME_CONTROL - , Int, 0x006 ;wParam : IMC_SETOPENSTATUS - , Int, SetSts) ;lParam : 0 or 1 + , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", hwnd) + , "UInt", 0x0283 ;Message : WM_IME_CONTROL + , "Int", 0x006 ;wParam : IMC_SETOPENSTATUS + , "Int", SetSts) ;lParam : 0 or 1 } diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 05e1127..8b3bf3f 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -32,7 +32,7 @@ class VimCaret{ SPIF_UPDATEINIFILE := 0x01 SPIF_SENDCHANGE := 0x02 fWinIni := SPIF_UPDATEINIFILE | SPIF_SENDCHANGE - DllCall("SystemParametersInfo", UInt,SPI_SETCARETWIDTH, UInt,0, UInt,CARETWIDTH, UInt,fWinIni) + DllCall("SystemParametersInfo", "UInt", SPI_SETCARETWIDTH, "UInt", 0, "UInt", CARETWIDTH, "UInt", fWinIni) this.SwitchToSameWindow() } From 86ac7522d8b36bd38b631e1b60b5f4d778e7e488 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:07:48 +0900 Subject: [PATCH 45/75] fix: replace VarSetCapacity with Buffer (for v2) --- lib/util/vim_ime.ahk | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index e8025ed..bfb615d 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -5,14 +5,15 @@ VIM_IME_GET(WinTitle:="A"){ hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) - NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", "Uint" , 0, "Uint", &stGTI) - ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd + cbSize := 4+4+(PtrSize*6)+16 + stGTI := Buffer(cbSize,0) + NumPut("DWORD", cbSize, stGTI.Ptr, 0) ; DWORD cbSize; + hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt", stGTI.Ptr) + ? NumGet(stGTI.Ptr, 8+PtrSize, "UInt") : hwnd } Return DllCall("SendMessage" - , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", hwnd) + , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", hwnd) , "UInt", 0x0283 ;Message : WM_IME_CONTROL , "Int", 0x0005 ;wParam : IMC_GETOPENSTATUS , "Int", 0) ;lParam : 0 @@ -37,10 +38,11 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) - NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", "Uint", 0, "Uint", &stGTI) - ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd + cbSize := 4+4+(PtrSize*6)+16 + stGTI := Buffer(cbSize,0) + NumPut("UInt", cbSize, stGTI.Ptr,0) ; DWORD cbSize; + hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "Ptr", stGTI.Ptr) + ? NumGet(stGTI.Ptr, 8+PtrSize, "UInt") : hwnd } pid := WinGetPID("ahk_id " hwnd) @@ -59,10 +61,10 @@ VIM_IME_SET(SetSts:=0, WinTitle:="A"){ hwnd := WinExist(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - VarSetCapacity(stGTI, cbSize:=4+4+(PtrSize*6)+16, 0) - NumPut(cbSize, stGTI, 0, "UInt") ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", "Uint", 0, "Uint", &stGTI) - ? NumGet(stGTI, 8+PtrSize, "UInt") : hwnd + cbSize := 4+4+(PtrSize*6)+16 + stGTI := Buffer(cbSize,0) + NumPut("UInt", cbSize, stGTI.Ptr,0) ; DWORD cbSize; + hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "Ptr", stGTI.Ptr) } Return DllCall("SendMessage" From 4ecb9b5b53103a7372bfa97988a2eac5c81cf756 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:20:39 +0900 Subject: [PATCH 46/75] fix: replace global variables with configuration object (for v2) --- lib/vim_state.ahk | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index fe642e1..a9eecc6 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -97,16 +97,15 @@ } HandleEsc(){ - global Vim, VimEscNormal, vimSendEscNormal, VimLongEscNormal - if (!VimEscNormal) { + if (!this.Vim.Conf["VimEscNormal"]["val"]) { Send("{Esc}") Return } ; The keywait waits for esc to be released. If it doesn't detect a release ; within the time limit, return 0, otherwise return 1. ShortPress := KeyWait("Esc", "T0.5") - SetNormal := VimLongEscNormal != ShortPress - if (!SetNormal or (VimSendEscNormal && this.IsCurrentVimMode("Vim_Normal"))) { + SetNormal := this.Vim.Conf["VimLongEscNormal"]["val"] != ShortPress + if (!SetNormal or (this.Vim.Conf["VimSendEscNormal"]["val"] && this.IsCurrentVimMode("Vim_Normal"))) { Send("{Esc}") } if (SetNormal) { @@ -120,14 +119,13 @@ } HandleCtrlBracket(){ - global Vim, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal - if (!VimCtrlBracketNormal) { + if (!this.Vim.Conf["VimCtrlBracketNormal"]["val"]) { Send("^[") Return } ShortPress := KeyWait("[", "T0.5") - SetNormal := VimLongCtrlBracketNormal != ShortPress - if (!SetNormal or (VimSendCtrlBracketNormal && this.IsCurrentVimMode("Vim_Normal"))) { + SetNormal := this.Vim.Conf["VimLongCtrlBracketNormal"]["val"] != ShortPress + if (!SetNormal or (this.Vim.Conf["VimSendCtrlBracketNormal"]["val"] && this.IsCurrentVimMode("Vim_Normal"))) { Send("^[") } if (SetNormal) { From 086df553348be382298764b1bb4c2a1dede08d01 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:23:51 +0900 Subject: [PATCH 47/75] fix: replace Menu icon commands with TraySetIcon and VimSubMenu.SetIcon (for v2) --- lib/vim_icon.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_icon.ahk b/lib/vim_icon.ahk index 9d6accf..be9fb49 100644 --- a/lib/vim_icon.ahk +++ b/lib/vim_icon.ahk @@ -25,9 +25,9 @@ icon := this.icons["Disabled"] } if FileExist(icon){ - Menu, Tray, Icon, % icon + TraySetIcon(icon) if(icon != this.icons["Default"]){ - Menu, VimSubMenu, Icon, Status, % icon + this.Vim.SubMenu.SetIcon("Status", icon) } } } From c17946a7ca7d4b464a8c2edacd523dc01ee1e9b7 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 17:45:52 +0900 Subject: [PATCH 48/75] fix: remove global variable for v-labels used in settings, instead use conf (for v2) feat: add GetVal class in settings --- lib/vim_ahk.ahk | 15 ++++---- lib/vim_ini.ahk | 1 - lib/vim_setting.ahk | 94 ++++++++++++++++++++++++++------------------- 3 files changed, 62 insertions(+), 48 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index daa9e8d..88c0957 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -172,13 +172,14 @@ class VimAhk{ } SetExistValue(){ - for k, v in this.Conf { - ; This ensures the variable exists, as a workaround since in AHK we cannot directly check whether it exists. - if(%k% != ""){ - this.Conf[k]["default"] := %k% - this.Conf[k]["val"] := %k% - } - } + ; Need some way to retrieve default values (v-label values are removed from vim_ahk for v2) + ;for k, v in this.Conf { + ; ; This ensures the variable exists, as a workaround since in AHK we cannot directly check whether it exists. + ; if(%k% != ""){ + ; this.Conf[k]["default"] := %k% + ; this.Conf[k]["val"] := %k% + ; } + ;} } SetGroup(){ diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index dd93b82..39f8b46 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -30,7 +30,6 @@ }else{ val := IniRead(this.Ini, this.Section, k, A_Space) } - %k% := val v["val"] := val } this.ReadDeprecatedSettings() diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index 2068984..8a0a674 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -5,9 +5,6 @@ class VimSetting Extends VimGui{ } MakeGui(){ - global VimRestoreIME, VimJJ, VimEscNormal, VimSendEscNormal, VimLongEscNormal, VimCtrlBracketToEsc, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal, VimChangeCaretWidth - global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimAppList, VimGroup, VimGroupList, VimTwoLetterList - global VimDisableUnusedText, VimSetTitleMatchModeText, VimIconCheckIntervalText, VimIconCheckIntervalEdit, VimVerboseText, VimAppListText, VimGroupText, VimHomepage, VimSettingOK, VimSettingReset, VimSettingCancel, VimTwoLetterText this.VimVal2V() Gui, % this.Hwnd ":-MinimizeBox" Gui, % this.Hwnd ":-Resize" @@ -30,19 +27,19 @@ class VimSetting Extends VimGui{ GuiControl, % this.Hwnd ":", % k, % %k% } Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".TwoLetterText vVimTwoLetterText", % this.Vim.Conf["VimTwoLetter"]["description"] - Gui, % this.Hwnd ":Add", Edit, XM+10 Y+5 R4 W100 Multi vVimTwoLetterList, % VimTwoLetterList + Gui, % this.Hwnd ":Add", Edit, XM+10 Y+5 R4 W100 Multi vVimTwoLetterList, % StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".DisableUnusedText vVimDisableUnusedText", % this.Vim.Conf["VimDisableUnused"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndDisableUnused X+5 Y+-16 W30 vVimDisableUnused Choose" VimDisableUnused, 1|2|3 + Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndDisableUnused X+5 Y+-16 W30 vVimDisableUnused Choose" this.GetVal("VimDisableUnused"), 1|2|3 this.HwndAll.Push(HwndDisableUnused) Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".SetTitleMatchModeText vVimSetTitleMatchModeText", % this.Vim.Conf["VimSetTitleMatchMode"]["description"] - if(VimSetTitleMatchMode == "RegEx"){ + if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ - matchmode := VimSetTitleMatchMode + matchmode := this.GetVal("VimSetTitleMatchMode") } Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndSetTitleMachMode X+5 Y+-16 W60 vVimSetTitleMatchMode Choose" matchmode, 1|2|3|RegEx this.HwndAll.Push(HwndSetTitleMachMode) - if(VimSetTitleMatchModeFS == "Fast"){ + if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 @@ -52,15 +49,15 @@ class VimSetting Extends VimGui{ Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".IconCheckIntervalText vVimIconCheckIntervalText", % this.Vim.Conf["VimIconCheckInterval"]["description"] Gui, % this.Hwnd ":Add", Edit, +HwndHwndIconCheckIntervalEdit X+5 Y+-16 W70 vVimIconCheckIntervalEdit this.HwndAll.Push(HwndIconCheckIntervalEdit) - Gui, % this.Hwnd ":Add", UpDown, +HwndHwndIconCheckInterval vVimIconCheckInterval Range0-1000000, % VimIconCheckInterval + Gui, % this.Hwnd ":Add", UpDown, +HwndHwndIconCheckInterval vVimIconCheckInterval Range0-1000000, % this.GetVal("VimIconCheckInterval") this.HwndAll.Push(HwndIconCheckInterval) Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".VerboseText vVimVerboseText", % this.Vim.Conf["VimVerbose"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndVerbose X+5 Y+-16 W30 vVimVerbose Choose"VimVerbose, 1|2|3|4 + Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndVerbose X+5 Y+-16 W30 vVimVerbose Choose"this.GetVal("VimVerbose"), 1|2|3|4 Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".AppListText vVimAppListText", % this.Vim.Conf["VimAppList"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndAppList X+5 Y+-16 W100 vVimAppList Choose"AppList, All|Allow List|Deny List + Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndAppList X+5 Y+-16 W100 vVimAppList Choose"this.GetVal("VimAppList"), All|Allow List|Deny List this.HwndAll.Push(HwndVerbose) Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+5 g" this.__Class ".GroupText vVimGroupText", % this.Vim.Conf["VimGroup"]["description"] - Gui, % this.Hwnd ":Add", Edit, +HwndHwndGroupList XM+10 Y+5 R10 W300 Multi vVimGroupList, % VimGroupList + Gui, % this.Hwnd ":Add", Edit, +HwndHwndGroupList XM+10 Y+5 R10 W300 Multi vVimGroupList, % StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) this.HwndAll.Push(HwndGroupList) Gui, % this.Hwnd ":Add", Text, XM+10 Y+10, Check Gui, % this.Hwnd ":Font", Underline @@ -87,34 +84,31 @@ class VimSetting Extends VimGui{ } UpdateGui(){ - this.VimVal2V() this.UpdateGuiValue() } UpdateGuiValue(){ - global VimRestoreIME, VimJJ, VimEscNormal, VimSendEscNormal, VimLongEscNormal, VimCtrlBracketToEsc, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal, VimChangeCaretWidth - global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimAppList, VimGroup, VimGroupList, VimTwoLetter, VimTwoLetterList for i, k in this.Vim.Checkboxes { - GuiControl, % this.Hwnd ":", % k, % %k% + GuiControl, % this.Hwnd ":", % k, % this.GetVal(k) } - GuiControl, % this.Hwnd ":", VimTwoLetterList, % VimTwoLetterList - GuiControl, % this.Hwnd ":Choose", VimDisableUnused, % VimDisableUnused - GuiControl, % this.Hwnd ":", VimIconCheckInterval, % VimIconCheckInterval - if(VimSetTitleMatchMode == "RegEx"){ + GuiControl, % this.Hwnd ":", VimTwoLetterList, % StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) + GuiControl, % this.Hwnd ":Choose", VimDisableUnused, % this.GetVal("VimDisableUnused") + GuiControl, % this.Hwnd ":", VimIconCheckInterval, % this.GetVal("VimIconCheckInterval") + if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ - matchmode := VimSetTitleMatchMode + matchmode := this.GetVal("VimSetTitleMatchMode") } GuiControl, % this.Hwnd ":Choose", VimSetTitleMatchMode, % matchmode - if(VimSetTitleMatchModeFS == "Fast"){ + if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } GuiControl, % this.Hwnd ":Choose", VimSetTitleMatchModeFS, % matchmodefs - GuiControl, % this.Hwnd ":Choose", VimVerbose, % VimVerbose - GuiControl, % this.Hwnd ":Choose", VimAppList, % VimAppList - GuiControl, % this.Hwnd ":", VimGroupList, % VimGroupList + GuiControl, % this.Hwnd ":Choose", VimVerbose, this.GetVal("VimVerbose") + GuiControl, % this.Hwnd ":Choose", VimAppList, this.GetVal("VimAppList") + GuiControl, % this.Hwnd ":", VimGroupList, this.GetVal("VimGroupList") } ; Dummy Labels, to enable tooltip over the text @@ -140,12 +134,28 @@ class VimSetting Extends VimGui{ } VimV2Conf(){ - global VimRestoreIME, VimJJ, VimEscNormal, VimSendEscNormal, VimLongEscNormal, VimCtrlBracketToEsc, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal, VimChangeCaretWidth - global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimAppList, VimGroup, VimGroupList, VimTwoLetter, VimTwoLetterList - VimGroup := this.VimParseList(VimGroupList) - VimTwoLetter := this.VimParseList(VimTwoLetterList) for k, v in this.Vim.Conf { - v["val"] := %k% + if(k == "VimGroup" || k == "VimTwoLetter"){ + v["val"] := this.VimParseList(this.Hwnd[k].Value) + }else if(k == "VimSetTitleMatchMode" && this.Hwnd[k].Value == 4){ + v["val"] := "RegEx" + }else if(k == "VimSetTitleMatchModeFS"){ + if(this.Hwnd[k].Value == 1){ + v["val"] := "Fast" + }else{ + v["val"] := "Slow" + } + }else if(k == "VimAppList"){ + if(this.Hwnd[k].Value == 1){ + v["val"] = "All" + }else if(this.Hwnd[k].Value == 2){ + v["val"] = "Allow List" + }else{ + v["val"] = "Deny List" + } + }else{ + v["val"] := this.Hwnd[k].Value + } } } @@ -165,22 +175,26 @@ class VimSetting Extends VimGui{ return result } - VimConf2V(vd){ - global VimRestoreIME, VimJJ, VimEscNormal, VimSendEscNormal, VimLongEscNormal, VimCtrlBracketToEsc, VimCtrlBracketNormal, VimSendCtrlBracketNormal, VimLongCtrlBracketNormal, VimChangeCaretWidth - global VimDisableUnused, VimSetTitleMatchMode, VimSetTitleMatchModeFS, VimIconCheckInterval, VimVerbose, VimAppList, VimGroup, VimGroupList, VimTwoLetterList - StringReplace, VimGroupList, % this.Vim.Conf["VimGroup"][vd], % this.Vim.GroupDel, `n, All - StringReplace, VimTwoLetterList, % this.Vim.Conf["VimTwoLetter"][vd], % this.Vim.GroupDel, `n, All + VimDefault2V(){ for k, v in this.Vim.Conf { - %k% := v[vd] + v["val"] := v["default"] } } - VimVal2V(){ - this.VimConf2V("val") + GetConf(name, key){ + return this.Vim.Conf[name][key] } - VimDefault2V(){ - this.VimConf2V("default") + GetVal(name){ + return this.GetConf(name, "val") + } + + GetDefault(name){ + return this.GetConf(name, "default") + } + + GetDescription(name){ + return this.GetConf(name, "description") } OK(){ From ddbbb2c3b81fe2db9a66930bba78fe9b4057f9d0 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 18:22:03 +0900 Subject: [PATCH 49/75] fix: move superclass constructor to the beginning of VimAbout.__New fix: simplify homepage button callback in MakeGui for VimAbout (for v2) fix: replace legacy GUI commands with modern methods in VimAbout (for v2) fix: streamline ShowGui and OK method for VimGui class (for v2) fix: introduce button event binding in MakeGui for VimSetting (for v2) fix: replace global Gui commands with modern AHK GUI methods in VimSetting (for v2) --- lib/vim_about.ahk | 39 +++++------ lib/vim_gui.ahk | 27 ++++---- lib/vim_setting.ahk | 163 ++++++++++++++++++++------------------------ 3 files changed, 104 insertions(+), 125 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index 51ffbb9..ac43a27 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -1,5 +1,7 @@ class VimAbout Extends VimGui{ __New(vim){ + super.__New(vim, "Vim Ahk") + this.Vim := vim this.Version := "" @@ -7,33 +9,26 @@ this.Author := "" this.Description := "" this.Homepage := "" - - super.__New(vim, "Vim Ahk") + this.OpenHomepageObj := ObjBindMethod(this, "OpenHomepage") } MakeGui(){ - global VimHomepage, VimAboutOK - Gui, % this.Hwnd ":-MinimizeBox" - Gui, % this.Hwnd ":-Resize" - Gui, % this.Hwnd ":Add", Text, , % "Vim Ahk (vim_ahk):`n" this.Description - Gui, % this.Hwnd ":Font", Underline - Gui, % this.Hwnd ":Add", Text, Y+0 cBlue vVimHomepage, Homepage - VimGuiAboutOpenHomepage := ObjBindMethod(this, "OpenHomepage") - GuiControl, +G, VimHomepage, % VimGuiAboutOpenHomepage - Gui, % this.Hwnd ":Font", Norm - Gui, % this.Hwnd ":Add", Text, , % "Author: " this.Author - Gui, % this.Hwnd ":Add", Text, , % "Version: " this.Version - Gui, % this.Hwnd ":Add", Text, Y+0, % "Last update: " this.Date - Gui, % this.Hwnd ":Add", Text, , Script path:`n%this.Vim.ScriptPath% - Gui, % this.Hwnd ":Add", Text, , % "Setting file:`n" this.Vim.Ini.Ini - Gui, % this.Hwnd ":Add", Button, +HwndOK X200 W100 Default vVimAboutOK, &OK - this.HwndAll.Push(OK) - ok := ObjBindMethod(this, "OK") - GuiControl, +G, VimAboutOK, % ok + this.Hwnd.Opt("-MinimizeBox -Resize") + this.Hwnd.AddText(, "Vim Ahk (vim_ahk):`n" this.Description) + this.Hwnd.SetFont("Underline") + this.Hwnd.AddText("Y+0 cBlue vVimHomepage", this.Homepage).OnEvent("Click", this.OpenHomepageObj) + this.Hwnd.SetFont("Norm") + this.Hwnd.AddText(, "Author: " this.Author) + this.Hwnd.AddText(, "Version: " this.Version) + this.Hwnd.AddText("Y+0", "Last update: " this.Date) + this.Hwnd.AddText(, "Script path:`n%this.Vim.ScriptPath%") + this.Hwnd.AddText(, "Setting file:`n" this.Vim.Ini.Ini) + this.Hwnd.AddButton("X200 W100 Default vVimAboutOK", "OK").OnEvent("Click", this.OKObj) + this.HwndAll.Push(this.Hwnd["VimAboutOK"]) } - OpenHomepage(){ + OpenHomepage(btn, info){ this.Vim.VimToolTip.RemoveToolTip() - Run % this.Homepage + Run(this.Homepage) } } diff --git a/lib/vim_gui.ahk b/lib/vim_gui.ahk index b3ac024..447613b 100644 --- a/lib/vim_gui.ahk +++ b/lib/vim_gui.ahk @@ -4,28 +4,25 @@ class VimGui{ this.Hwnd := 0 this.HwndAll := [] this.Title := title + this.OKObj := ObjBindMethod(this, "OK") } - ShowGui(){ - if(this.hwnd == 0){ - Gui, New, +HwndGuiHwnd - this.Hwnd := GuiHwnd - this.HwndAll.Push(GuiHwnd) + ShowGui(name, pos, mymenu){ + if(this.Hwnd == 0){ + this.Hwnd := Gui("", this.Title) + this.HwndAll.Push(this.Hwnd) this.MakeGui() - Gui, % this.Hwnd ":Show", , % this.Title OnMessage(0x112, ObjBindMethod(this, "OnClose")) OnMessage(0x100, ObjBindMethod(this, "OnEscape")) + }else{ + this.UpdateGui() } - this.UpdateGui() - Gui, % this.Hwnd ":Show", , % this.Title - Return + this.Hwnd.Show() } MakeGui(){ - Gui, % this.Hwnd ":Add", Button, +HwndOK X200 W100 Default, &OK - this.HwndAll.Push(OK) - ok := ObjBindMethod(this, "OK") - GuiControl, +G, % OK, % ok + this.Hwnd.AddButton("X200 W100 Default vGuiOK", "OK").OnEvent("Click", this.OKObj) + this.HwndAll.Push(this.Hwnd["GuiOK"]) } UpdateGui(){ @@ -33,10 +30,10 @@ class VimGui{ Hide(){ this.Vim.VimToolTip.RemoveToolTip() - Gui, % this.Hwnd ":Hide" + this.Hwnd.Hide() } - OK(){ + OK(btn, info){ this.Hide() } diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index 8a0a674..fe39165 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -1,13 +1,16 @@ class VimSetting Extends VimGui{ __New(vim){ - this.Vim := vim super.__New(vim, "Vim Ahk Settings") + + this.Vim := vim + + this.OKObj := ObjBindMethod(this, "OK") + this.ResetObj := ObjBindMethod(this, "Reset") + this.CancelObj := ObjBindMethod(this, "Cancel") } MakeGui(){ - this.VimVal2V() - Gui, % this.Hwnd ":-MinimizeBox" - Gui, % this.Hwnd ":-Resize" + this.Hwnd.Opt("-MinimizeBox -Resize") created := 0 for i, k in this.Vim.Checkboxes { if(created == 0){ @@ -20,67 +23,66 @@ class VimSetting Extends VimGui{ }else{ x := "10" } - Gui, % this.Hwnd ":Add", Checkbox, % "+HwndHwnd" k " XM+" x " " y " v" k, % this.Vim.Conf[k]["description"] - hwnd := "Hwnd" k - this.HwndAll.Push(%hwnd%) + this.Hwnd.AddCheckbox(k " XM+" x " " y " v" k, this.GetDescription(k)) + this.HwndAll.Push(this.Hwnd[k]) created := 1 - GuiControl, % this.Hwnd ":", % k, % %k% + this.Hwnd[k].Value := this.GetVal(k) } - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".TwoLetterText vVimTwoLetterText", % this.Vim.Conf["VimTwoLetter"]["description"] - Gui, % this.Hwnd ":Add", Edit, XM+10 Y+5 R4 W100 Multi vVimTwoLetterList, % StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".DisableUnusedText vVimDisableUnusedText", % this.Vim.Conf["VimDisableUnused"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndDisableUnused X+5 Y+-16 W30 vVimDisableUnused Choose" this.GetVal("VimDisableUnused"), 1|2|3 - this.HwndAll.Push(HwndDisableUnused) - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+15 g" this.__Class ".SetTitleMatchModeText vVimSetTitleMatchModeText", % this.Vim.Conf["VimSetTitleMatchMode"]["description"] + this.Hwnd.AddText("XM+10 Y+15 vVimTwoLetterText", this.GetDescription("VimTwoLetter")) + this.Hwnd.AddEdit("XM+10 Y+5 R4 W100 Multi vVimTwoLetter", StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1)) + this.Hwnd.AddText("XM+10 Y+15 vVimDisableUnusedText", this.GetDescription("VimDisableUnused")) + this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimDisableUnused Choose" this.GetVal("VimDisableUnused"), [1, 2, 3]) + this.HwndAll.Push(this.Hwnd["VimDisableUnused"]) + this.Hwnd.AddText("XM+10 Y+15 vVimSetTitleMatchModeText", this.GetDescription("VimSetTitleMatchMode")) if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ matchmode := this.GetVal("VimSetTitleMatchMode") } - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndSetTitleMachMode X+5 Y+-16 W60 vVimSetTitleMatchMode Choose" matchmode, 1|2|3|RegEx - this.HwndAll.Push(HwndSetTitleMachMode) + this.Hwnd.AddDDL("X+5 Y+-16 W60 vVimSetTitleMatchMode Choose" matchmode, [1, 2, 3, "RegEx"]) + this.HwndAll.Push(this.Hwnd["VimSetTitleMatchMode"]) if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndSetTitleMachModeFS X+5 Y+-20 W50 vVimSetTitleMatchModeFS Choose" matchmodefs, Fast|Slow - this.HwndAll.Push(HwndSetTitleMachModeFS) - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".IconCheckIntervalText vVimIconCheckIntervalText", % this.Vim.Conf["VimIconCheckInterval"]["description"] - Gui, % this.Hwnd ":Add", Edit, +HwndHwndIconCheckIntervalEdit X+5 Y+-16 W70 vVimIconCheckIntervalEdit - this.HwndAll.Push(HwndIconCheckIntervalEdit) - Gui, % this.Hwnd ":Add", UpDown, +HwndHwndIconCheckInterval vVimIconCheckInterval Range0-1000000, % this.GetVal("VimIconCheckInterval") - this.HwndAll.Push(HwndIconCheckInterval) - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".VerboseText vVimVerboseText", % this.Vim.Conf["VimVerbose"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndVerbose X+5 Y+-16 W30 vVimVerbose Choose"this.GetVal("VimVerbose"), 1|2|3|4 - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+10 g" this.__Class ".AppListText vVimAppListText", % this.Vim.Conf["VimAppList"]["description"] - Gui, % this.Hwnd ":Add", DropDownList, % "+HwndHwndAppList X+5 Y+-16 W100 vVimAppList Choose"this.GetVal("VimAppList"), All|Allow List|Deny List - this.HwndAll.Push(HwndVerbose) - Gui, % this.Hwnd ":Add", Text, % "XM+10 Y+5 g" this.__Class ".GroupText vVimGroupText", % this.Vim.Conf["VimGroup"]["description"] - Gui, % this.Hwnd ":Add", Edit, +HwndHwndGroupList XM+10 Y+5 R10 W300 Multi vVimGroupList, % StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) - this.HwndAll.Push(HwndGroupList) - Gui, % this.Hwnd ":Add", Text, XM+10 Y+10, Check - Gui, % this.Hwnd ":Font", Underline - Gui, % this.Hwnd ":Add", Text, X+5 cBlue vVimHomepage, HELP - homepage := ObjBindMethod(this.Vim.About, "OpenHomepage") - GuiControl, +G, VimHomepage, % homepage - Gui, % this.Hwnd ":Font", Norm - Gui, % this.Hwnd ":Add", Text, X+5, for further information. - - Gui, % this.Hwnd ":Add", Button, +HwndHwndOK vVimSettingOK X10 W100 Y+10 Default, &OK - this.HwndAll.Push(HwndOK) - ok := ObjBindMethod(this, "OK") - GuiControl, +G, VimSettingOK, % ok - - Gui, % this.Hwnd ":Add", Button, +HwndHwndReset vVimSettingReset W100 X+10, &Reset - this.HwndAll.Push(HwndReset) - reset := ObjBindMethod(this, "Reset") - GuiControl, +G, VimSettingReset, % reset - - Gui, % this.Hwnd ":Add", Button, +HwndHwndCancel vVimSettingCancel W100 X+10, &Cancel - this.HwndAll.Push(HwndCancel) - cancel := ObjBindMethod(this, "Cancel") - GuiControl, +G, VimSettingCancel, % cancel + this.Hwnd.AddDDL("X+5 Y+-20 W50 vVimSetTitleMatchModeFS Choose" matchmodefs, ["Fast", "Slow"]) + this.HwndAll.Push(this.Hwnd["VimSetTitleMatchModeFS"]) + this.Hwnd.AddText("XM+10 Y+10 vVimIconCheckIntervalText", this.GetDescription("VimIconCheckInterval")) + this.Hwnd.AddEdit("X+5 Y+-16 W70 vVimIconCheckIntervalEdit") + this.HwndAll.Push(this.Hwnd["VimIconCheckIntervalEdit"]) + this.Hwnd.AddUpDown("vVimIconCheckInterval Range0-1000000", this.GetVal("VimIconCheckInterval")) + this.HwndAll.Push(this.Hwnd["VimIconCheckInterval"]) + this.Hwnd.AddText("XM+10 Y+10 vVimVerboseText", this.GetDescription("VimVerbose")) + this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimVerbose Choose" this.GetVal("VimVerbose"), [1, 2, 3, 4]) + this.HwndAll.Push(this.Hwnd["VimVerbose"]) + this.Hwnd.AddText("XM+10 Y+10 vVimAppListText", this.GetDescription("VimAppList")) + if(this.GetVal("VimAppList") == "All"){ + matchapplist := 1 + }else if(this.GetVal("VimAppList") == "Allow List"){ + matchapplist := 2 + }else{ + matchapplist := 3 + } + this.Hwnd.AddDDL("X+5 Y+-16 W100 vVimAppList Choose" matchapplist, ["All", "Allow List", "Deny List"]) + this.HwndAll.Push(this.Hwnd["VimAppList"]) + this.Hwnd.AddText("XM+10 Y+5 vVimGroupText", this.GetDescription("VimGroup")) + this.Hwnd.AddEdit("XM+10 Y+5 R10 W300 Multi vVimGroup", StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1)) + this.HwndAll.Push(this.Hwnd["VimGroup"]) + this.Hwnd.AddText("XM+10 Y+10", "Check") + this.Hwnd.SetFont("Underline") + this.Hwnd.AddText("X+5 cBlue vVimHomepage", "HELP").OnEvent("Click", this.Vim.about.OpenHomepageObj) + this.Hwnd.SetFont("Norm") + this.Hwnd.AddText("X+5", "for further information.") + + this.Hwnd.AddButton("vVimSettingOK X10 W100 Y+10 Default", "OK").OnEvent("Click", this.OKObj) + this.HwndAll.Push(this.Hwnd["VimSettingOK"]) + + this.Hwnd.AddButton("vVimSettingReset W100 X+10", "Reset").OnEvent("Click", this.ResetObj) + this.HwndAll.Push(this.Hwnd["VimSettingReset"]) + + this.Hwnd.AddButton("vVimSettingCancel W100 X+10", "Cancel").OnEvent("Click", this.CancelObj) + this.HwndAll.Push(this.Hwnd["VimSettingCancel"]) } UpdateGui(){ @@ -89,48 +91,33 @@ class VimSetting Extends VimGui{ UpdateGuiValue(){ for i, k in this.Vim.Checkboxes { - GuiControl, % this.Hwnd ":", % k, % this.GetVal(k) + this.Hwnd[k].Value := this.GetVal(k) } - GuiControl, % this.Hwnd ":", VimTwoLetterList, % StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) - GuiControl, % this.Hwnd ":Choose", VimDisableUnused, % this.GetVal("VimDisableUnused") - GuiControl, % this.Hwnd ":", VimIconCheckInterval, % this.GetVal("VimIconCheckInterval") + this.Hwnd["VimTwoLetter"].Value := StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) + this.Hwnd["VimDisableUnused"].Value := this.GetVal("VimDisableUnused") + this.Hwnd["VimIconCheckInterval"].Value := this.GetVal("VimIconCheckInterval") if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ matchmode := this.GetVal("VimSetTitleMatchMode") } - GuiControl, % this.Hwnd ":Choose", VimSetTitleMatchMode, % matchmode + this.Hwnd["VimSetTitleMatchMode"].Value := matchmode if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } - GuiControl, % this.Hwnd ":Choose", VimSetTitleMatchModeFS, % matchmodefs - GuiControl, % this.Hwnd ":Choose", VimVerbose, this.GetVal("VimVerbose") - GuiControl, % this.Hwnd ":Choose", VimAppList, this.GetVal("VimAppList") - GuiControl, % this.Hwnd ":", VimGroupList, this.GetVal("VimGroupList") - } - - ; Dummy Labels, to enable tooltip over the text - DisableUnusedText(){ - } - - TwoLetterText(){ - } - - SetTitleMatchModeText(){ - } - - IconCheckIntervalText(){ - } - - VerboseText(){ - } - - AppListText(){ - } - - GroupText(){ + this.Hwnd["VimSetTitleMatchModeFS"].Value := matchmodefs + this.Hwnd["VimVerbose"].Value := this.GetVal("VimVerbose") + if(this.GetVal("VimAppList") == "All"){ + matchapplist := 1 + }else if(this.GetVal("VimAppList") == "Allow List"){ + matchapplist := 2 + }else{ + matchapplist := 3 + } + this.Hwnd["VimAppList"].Value := matchapplist + this.Hwnd["VimGroup"].Value := StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) } VimV2Conf(){ @@ -197,19 +184,19 @@ class VimSetting Extends VimGui{ return this.GetConf(name, "description") } - OK(){ - Gui, % this.Hwnd ":Submit" + OK(btn, info){ + this.Hwnd.Submit() this.VimV2Conf() this.Vim.Setup() this.vim.Ini.WriteIni() this.Hide() } - Cancel(){ + Cancel(btn, info){ this.Hide() } - Reset(){ + Reset(btn, info){ this.VimDefault2V() this.UpdateGuiValue() } From d21b8c0196e052d8bd9d98a2a065140214a86a5b Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 18:24:43 +0900 Subject: [PATCH 50/75] fix: add parameters to CheckMenu and FullStatus functions in vim_check and vim_state (for v2) --- lib/vim_check.ahk | 2 +- lib/vim_state.ahk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 09d323a..431699d 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -3,7 +3,7 @@ this.Vim := vim } - CheckMenu() { + CheckMenu(ItemName, ItemPos, MyMenu) { ; Additional message is necessary before checking current window. ; Otherwise process name cannot be retrieved...? MsgBox("Checking current window...", "Vim Ahk") diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index a9eecc6..f60abf0 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -47,7 +47,7 @@ this.Vim.VimToolTip.SetRemoveToolTip(1000) } - FullStatus(){ + FullStatus(ItemName, ItemPos, MyMenu){ this.CheckMode(4, , , , 1) } From 7a9346d2f49ea45729a08960f16785beb12d1dc9 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 18:27:30 +0900 Subject: [PATCH 51/75] refactor: move #Include directive for vim_gui.ahk to relevant files --- lib/vim_about.ahk | 5 ++++- lib/vim_ahk.ahk | 1 - lib/vim_setting.ahk | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index ac43a27..4ff5dca 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -1,4 +1,7 @@ -class VimAbout Extends VimGui{ +#Include %A_LineFile%\..\vim_gui.ahk + + +class VimAbout Extends VimGui{ __New(vim){ super.__New(vim, "Vim Ahk") diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 88c0957..632ff65 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -5,7 +5,6 @@ ; Classes, Functions #Include %A_LineFile%\..\vim_about.ahk #Include %A_LineFile%\..\vim_check.ahk -#Include %A_LineFile%\..\vim_gui.ahk #Include %A_LineFile%\..\vim_icon.ahk #Include %A_LineFile%\..\vim_caret.ahk #Include %A_LineFile%\..\vim_ini.ahk diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index fe39165..78d447c 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -1,3 +1,6 @@ +#Include %A_LineFile%\..\vim_gui.ahk + + class VimSetting Extends VimGui{ __New(vim){ super.__New(vim, "Vim Ahk Settings") From 02386faa7bcea78ad92d9e6b8dcc744a9020f58d Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 22:32:40 +0900 Subject: [PATCH 52/75] fix: remove #NoEnv (v2 default) (for v2) --- lib/util/vim_ahk_setting.ahk | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/util/vim_ahk_setting.ahk b/lib/util/vim_ahk_setting.ahk index 44c6878..a6573c7 100644 --- a/lib/util/vim_ahk_setting.ahk +++ b/lib/util/vim_ahk_setting.ahk @@ -1,4 +1,3 @@ -#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. #UseHook On ; Make it a bit slow, but can avoid infinitude loop ; Same as "$" for each hotkey #InstallKeybdHook ; For checking key history From 81506303205943b98616b9ccf861bcc5a1da62a2 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 22:34:26 +0900 Subject: [PATCH 53/75] fix: update settings (for v2) --- lib/util/vim_ahk_setting.ahk | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/util/vim_ahk_setting.ahk b/lib/util/vim_ahk_setting.ahk index a6573c7..bd32bbb 100644 --- a/lib/util/vim_ahk_setting.ahk +++ b/lib/util/vim_ahk_setting.ahk @@ -1,10 +1,7 @@ -#UseHook On ; Make it a bit slow, but can avoid infinitude loop - ; Same as "$" for each hotkey -#InstallKeybdHook ; For checking key history - ; Use ~500kB memory? -#HotkeyInterval 2000 ; Hotkey interval (default 2000 milliseconds). -#MaxHotkeysPerInterval 70 ; Max hotkeys per interval (default 50). - -; #Warn ; Enable warnings to assist with detecting common errors. - -SendMode Input ; Recommended for new scripts due to its superior speed and reliability. +#UseHook True ; Make it a bit slow, but can avoid infinitude loop + ; Same as "$" for each hotkey +InstallKeybdHook(true) ; For checking key history + ; Use ~500kB memory? +A_HotkeyInterval := 2000 ; Hotkey interval (default 2000 milliseconds). +A_MaxHotkeysPerInterval := 70 ; Max hotkeys per interval (default 50). +SendMode("Input") ; Recommended for new scripts due to its superior speed and reliability. From 836c5c35eba90fdcddeee7a3bd52791765a4668e Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Wed, 25 Sep 2024 23:04:02 +0900 Subject: [PATCH 54/75] fix: update script to require AutoHotkey v2.0 and remove Return (for v2) --- vim.ahk | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/vim.ahk b/vim.ahk index aa0702a..2cf0ca7 100644 --- a/vim.ahk +++ b/vim.ahk @@ -1,7 +1,4 @@ -#Requires AutoHotkey v1.1 - -; Auto-execute section -Vim := VimAhk(A_LineFile) -Return +#Requires AutoHotkey v2.0 #Include %A_LineFile%\..\lib\vim_ahk.ahk +Vim := VimAhk(A_LineFile) From b42a08a79b0b6b708645e8566d5cd83da84d2230 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Thu, 26 Sep 2024 00:47:49 +0900 Subject: [PATCH 55/75] fix: fix multiline in MsgBox --- lib/vim_check.ahk | 6 ++++-- lib/vim_state.ahk | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 431699d..44309df 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -12,14 +12,16 @@ win_class := WinGetClass("ahk_pid " process) title := WinGetTitle("ahk_pid " process) if(this.Vim.IsVimGroup()){ - MsgBox("( + MsgBox(" + ( Supported Process name: %name% Class : %win_class% Title : %title% )", "Vim Ahk", "Iconi") }else{ - MsgBox("( + MsgBox(" + ( Not supported Process name: %name% Class : %win_class% diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index f60abf0..8a4c110 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -32,7 +32,8 @@ this.SetTooltip(this.Mode "`r`ng=" this.g "`r`nn=" this.n "`r`nLineCopy=" this.LineCopy, 4) } if(verbose >= 4){ - MsgBox("( + MsgBox(" + ( Mode : %this.Mode% Vim_g : %this.g% Vim_n : %this.n% @@ -153,7 +154,8 @@ try{ InOrBlank := (not fullMatch) ? "in " : "" if not this.HasValue(this.PossibleVimModes, mode, fullMatch){ - Throw ValueError("Invalid mode specified", -2, "( + Throw ValueError("Invalid mode specified", -2, " + ( '%Mode%' is not %InOrBlank%a valid mode as defined by the VimPossibleVimModes array at the top of vim_state.ahk. This may be a typo. Fix this error by using an existing mode, @@ -161,7 +163,8 @@ )") } }catch ValueError as e{ - MsgBox("( + MsgBox(" + ( Warning: %e.Message% %e.Extra% From 4c0a8cacab34fd3c6ec6c97e8c9ef018aa2dd4de Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Thu, 26 Sep 2024 01:37:25 +0900 Subject: [PATCH 56/75] docs: Add note about AutoHotkey v1 and v2 compatibility --- README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 002fdd7..2210d9b 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,11 @@ This is vim emulation for Windows. If you are interested in the same settings for Mac, try Vim emulation for [Karabiner - Software for macOS](https://pqrs.org/osx/karabiner/): [Karabiner-Elements complex_modifications rules by rcmdnk](https://rcmdnk.com/KE-complex_modifications/). - ## AutoHotkey v1 or v2 -This script is for AutoHotkey v1. - -Currently, vim_ahk for AutoHotkey v2 is under development in the branch [ahk_v2](https://github.com/rcmdnk/vim_ahk/tree/ahk_v2). - -If you are using AutoHotkey v2, please try the script in [ahk_v2](https://github.com/rcmdnk/vim_ahk/tree/ahk_v2). +This script is for AutoHotkey v2. -Any feedback is welcome. +If you are using AutoHotkey v1, please use release [v0.13.1](https://github.com/rcmdnk/vim_ahk/tree/v0.13.1). ## Installation From 54dc4e89d15adecfe31258b194fe28ca50b9f4f0 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Thu, 26 Sep 2024 03:08:59 +0900 Subject: [PATCH 57/75] feat: bump version to v0.14.0 and update release date --- lib/vim_ahk.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 632ff65..43f8781 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -19,8 +19,8 @@ class VimAhk{ __About(){ - this.About.Version := "v0.13.1" - this.About.Date := "01/Mar/2024" + this.About.Version := "v0.14.0" + this.About.Date := "26/Sep/2024" this.About.Author := "rcmdnk" this.About.Description := "Vim emulation with AutoHotkey, everywhere in Windows." this.About.Homepage := "https://github.com/rcmdnk/vim_ahk" From c28b87041e7713b92bde2a97750c217c171fcd98 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 01:07:13 +0900 Subject: [PATCH 58/75] fix: correct DllCall parameter type and assignment logic --- lib/util/vim_ime.ahk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index bfb615d..3e08ad4 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -64,9 +64,9 @@ VIM_IME_SET(SetSts:=0, WinTitle:="A"){ cbSize := 4+4+(PtrSize*6)+16 stGTI := Buffer(cbSize,0) NumPut("UInt", cbSize, stGTI.Ptr,0) ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "Ptr", stGTI.Ptr) + hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt",stGTI.Ptr) + ? NumGet(stGTI.Ptr,8+PtrSize,"Uint") : hwnd } - Return DllCall("SendMessage" , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", hwnd) , "UInt", 0x0283 ;Message : WM_IME_CONTROL From 74717f5475909f48e61a9b38497102936f3aa98e Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 05:11:08 +0900 Subject: [PATCH 59/75] refactor: Replace WinExist with WinGetID for obtaining window handle refactor: Refactor buffer creation and structure size calculations refactor: Use simplified NumGet and NumPut syntax for buffer management --- lib/util/vim_ime.ahk | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/util/vim_ime.ahk b/lib/util/vim_ime.ahk index 3e08ad4..3dba89a 100644 --- a/lib/util/vim_ime.ahk +++ b/lib/util/vim_ime.ahk @@ -2,14 +2,14 @@ ; Get IME Status. 0: Off, 1: On VIM_IME_GET(WinTitle:="A"){ - hwnd := WinExist(WinTitle) + hwnd := WinGetID(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - cbSize := 4+4+(PtrSize*6)+16 - stGTI := Buffer(cbSize,0) - NumPut("DWORD", cbSize, stGTI.Ptr, 0) ; DWORD cbSize; + cbSize := 4 + 4 + (PtrSize * 6) + 16 + stGTI := Buffer(cbSize, 0) + NumPut("UInt", cbSize, stGTI, 0) ; DWORD cbSize; hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt", stGTI.Ptr) - ? NumGet(stGTI.Ptr, 8+PtrSize, "UInt") : hwnd + ? NumGet(stGTI, 8 + PtrSize, "UInt") : hwnd } Return DllCall("SendMessage" @@ -35,14 +35,14 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ . "|SKKIME\d+\.*\d+UCand" ; SKKIME Unicode CandGCls := "GoogleJapaneseInputCandidateWindow" ; Google IME - hwnd := WinExist(WinTitle) + hwnd := WinGetID(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - cbSize := 4+4+(PtrSize*6)+16 - stGTI := Buffer(cbSize,0) - NumPut("UInt", cbSize, stGTI.Ptr,0) ; DWORD cbSize; + cbSize := 4 + 4 + (PtrSize * 6) + 16 + stGTI := Buffer(cbSize, 0) + NumPut("UInt", cbSize, stGTI, 0) ; DWORD cbSize; hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "Ptr", stGTI.Ptr) - ? NumGet(stGTI.Ptr, 8+PtrSize, "UInt") : hwnd + ? NumGet(stGTI, 8 + PtrSize, "UInt") : hwnd } pid := WinGetPID("ahk_id " hwnd) @@ -58,14 +58,14 @@ VIM_IME_GetConverting(WinTitle:="A", ConvCls:="", CandCls:=""){ ; Set IME, SetSts=0: Off, 1: On, return 0 for success, others for non-success VIM_IME_SET(SetSts:=0, WinTitle:="A"){ - hwnd := WinExist(WinTitle) + hwnd := WinGetID(WinTitle) if(WinActive(WinTitle)){ ptrSize := !A_PtrSize ? 4 : A_PtrSize - cbSize := 4+4+(PtrSize*6)+16 - stGTI := Buffer(cbSize,0) - NumPut("UInt", cbSize, stGTI.Ptr,0) ; DWORD cbSize; - hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt",stGTI.Ptr) - ? NumGet(stGTI.Ptr,8+PtrSize,"Uint") : hwnd + cbSize := 4 + 4 + (PtrSize * 6) + 16 + stGTI := Buffer(cbSize, 0) + NumPut("UInt", cbSize, stGTI, 0) ; DWORD cbSize; + hwnd := DllCall("GetGUIThreadInfo", "UInt", 0, "UInt", stGTI.Ptr) + ? NumGet(stGTI, 8 + PtrSize, "Uint") : hwnd } Return DllCall("SendMessage" , "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", hwnd) From ff9ebf33998e1f4989bbe02ab46ed238f2269527 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 22:47:00 +0900 Subject: [PATCH 60/75] refactor: rename SwitchToSameWindow method to Refocus and adjust window handling logic fix: use ahk_class Progman instead of ahk_class WorkerW to get desktop (spy window shows Progman on Window11 (WorkerW in Wndow10?) --- lib/vim_caret.ahk | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 8b3bf3f..bf830ca 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -33,14 +33,18 @@ class VimCaret{ SPIF_SENDCHANGE := 0x02 fWinIni := SPIF_UPDATEINIFILE | SPIF_SENDCHANGE DllCall("SystemParametersInfo", "UInt", SPI_SETCARETWIDTH, "UInt", 0, "UInt", CARETWIDTH, "UInt", fWinIni) - this.SwitchToSameWindow() + ; Switch focus to another window and back to update caret width + this.Refocus() } - SwitchToSameWindow(){ - ; Get ID of active window + Refocus(){ + ; Get ID of current active window hwnd := WinGetID("A") ; Activate desktop - WinActivate("ahk_class WorkerW") + ;WinActivate("ahk_class WorkerW") + WinActivate("ahk_class Progman") + +; ; Re-activate current window WinActivate("ahk_id " hwnd) } } From 64727b38e5506589fb0945b417db7b6a17ba129d Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 22:54:48 +0900 Subject: [PATCH 61/75] refactor: improve error handling in Refocus method with try-catch blocks --- lib/vim_caret.ahk | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index bf830ca..07205c0 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -26,26 +26,33 @@ class VimCaret{ ; Expects argument "width" in hex SetCaretWidth(width){ - CARETWIDTH := width - ; SPI := SystemParametersInfo - SPI_SETCARETWIDTH := 0x2007 - SPIF_UPDATEINIFILE := 0x01 - SPIF_SENDCHANGE := 0x02 - fWinIni := SPIF_UPDATEINIFILE | SPIF_SENDCHANGE - DllCall("SystemParametersInfo", "UInt", SPI_SETCARETWIDTH, "UInt", 0, "UInt", CARETWIDTH, "UInt", fWinIni) - ; Switch focus to another window and back to update caret width - this.Refocus() + CARETWIDTH := width + ; SPI := SystemParametersInfo + SPI_SETCARETWIDTH := 0x2007 + SPIF_UPDATEINIFILE := 0x01 + SPIF_SENDCHANGE := 0x02 + fWinIni := SPIF_UPDATEINIFILE | SPIF_SENDCHANGE + DllCall("SystemParametersInfo", "UInt", SPI_SETCARETWIDTH, "UInt", 0, "UInt", CARETWIDTH, "UInt", fWinIni) + ; Switch focus to another window and back to update caret width + this.Refocus() } Refocus(){ - ; Get ID of current active window - hwnd := WinGetID("A") - ; Activate desktop - ;WinActivate("ahk_class WorkerW") + ; Get ID of current active window + hwnd := WinGetID("A") + + ; Activate desktop + try { WinActivate("ahk_class Progman") + } catch Error { + try { + WinActivate("ahk_class WorkerW") + } catch Error { + } + } -; ; Re-activate current window - WinActivate("ahk_id " hwnd) +; ; Re-activate current window + WinActivate("ahk_id " hwnd) } } From 8335333de5fe9a4300a98852682ceaf1ce380f84 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 23:29:37 +0900 Subject: [PATCH 62/75] fix: update SetTwoLetterMap to use SendSame method for key handling --- lib/vim_ahk.ahk | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 43f8781..2a4d728 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -204,19 +204,26 @@ class VimAhk{ } SetTwoLetterMap(key1, key2){ - EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") Enabled := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") + SendSame := ObjBindMethod(this, "SendSame") + EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") HotIf(Enabled) - HotKey("%key1% & %key2%", EnterNormal) - HotKey("%key2% & %key1%", EnterNormal) + HotKey(key1, SendSame) + HotKey(key2, SendSame) + HotKey(key1 " & " key2, EnterNormal) + HotKey(key2 " & " key1, EnterNormal) + HotIf() + } + + SendSame(HotkeyName){ + SendInput(HotkeyName) } - TwoLetterNormalMapsEnabled(){ + TwoLetterNormalMapsEnabled(*){ Return this.IsVimGroup() && (this.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet } - TwoLetterEnterNormal(){ - SendInput("{BackSpace 1}") + TwoLetterEnterNormal(*){ this.State.SetNormal() } From cb1fd2de1341d85b5713bf1ee70f2d6c9fae19b1 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 23:40:08 +0900 Subject: [PATCH 63/75] refactor: Rename variables to follow consistent camelCase convention --- lib/vim_about.ahk | 8 +++--- lib/vim_ahk.ahk | 14 +++++----- lib/vim_caret.ahk | 24 +++++++++--------- lib/vim_check.ahk | 6 ++--- lib/vim_gui.ahk | 22 ++++++++-------- lib/vim_icon.ahk | 4 +-- lib/vim_ini.ahk | 46 ++++++++++++++++----------------- lib/vim_menu.ahk | 4 +-- lib/vim_move.ahk | 62 ++++++++++++++++++++++----------------------- lib/vim_setting.ahk | 30 +++++++++++----------- lib/vim_state.ahk | 48 +++++++++++++++++------------------ lib/vim_tooltip.ahk | 12 ++++----- 12 files changed, 140 insertions(+), 140 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index 4ff5dca..f7be583 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -2,10 +2,10 @@ class VimAbout Extends VimGui{ - __New(vim){ - super.__New(vim, "Vim Ahk") + __New(Vim){ + super.__New(Vim, "Vim Ahk") - this.Vim := vim + this.Vim := Vim this.Version := "" this.Date := "" @@ -30,7 +30,7 @@ class VimAbout Extends VimGui{ this.HwndAll.Push(this.Hwnd["VimAboutOK"]) } - OpenHomepage(btn, info){ + OpenHomepage(*){ this.Vim.VimToolTip.RemoveToolTip() Run(this.Homepage) } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 2a4d728..bb21a49 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -203,15 +203,15 @@ class VimAhk{ } } - SetTwoLetterMap(key1, key2){ + SetTwoLetterMap(Key1, Key2){ Enabled := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") SendSame := ObjBindMethod(this, "SendSame") EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") HotIf(Enabled) - HotKey(key1, SendSame) - HotKey(key2, SendSame) - HotKey(key1 " & " key2, EnterNormal) - HotKey(key2 " & " key1, EnterNormal) + HotKey(Key1, SendSame) + HotKey(Key2, SendSame) + HotKey(Key1 " & " Key2, EnterNormal) + HotKey(Key2 " & " Key1, EnterNormal) HotIf() } @@ -289,14 +289,14 @@ class VimAhk{ } ; Ref: https://www.reddit.com/r/AutoHotkey/comments/4ma5b8/identifying_end_of_line_when_typing_with_ahk_and/ - CheckChr(key){ + CheckChr(Key){ BlockInput("Send") ClipSaved := ClipboardAll() A_Clipboard := "" SendInput("{Shift Down}{Right}{Shift up}{Ctrl down}c{Ctrl Up}{Left}") Sleep(10) ret := False - If (A_Clipboard ~= key){ + If (A_Clipboard ~= Key){ ret := True } sleep(10) diff --git a/lib/vim_caret.ahk b/lib/vim_caret.ahk index 07205c0..2da632d 100644 --- a/lib/vim_caret.ahk +++ b/lib/vim_caret.ahk @@ -1,6 +1,6 @@ class VimCaret{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim this.caretwidths := Map("Normal", 10 , "Visual", 10 , "Insert", 1 @@ -11,29 +11,29 @@ class VimCaret{ if (this.Vim.Conf["VimChangeCaretWidth"]["val"] == 0){ return } - width := "" + Width := "" if this.Vim.State.IsCurrentVimMode("Vim_Normal"){ - width := this.caretwidths["Normal"] + Width := this.caretwidths["Normal"] }else if this.Vim.State.StrIsInCurrentVimMode("Visual"){ - width := this.caretwidths["Visual"] + Width := this.caretwidths["Visual"] }else if this.Vim.State.IsCurrentVimMode("Insert"){ - width := this.caretwidths["Insert"] + Width := this.caretwidths["Insert"] }else{ - width := this.caretwidths["Default"] + Width := this.caretwidths["Default"] } - this.SetCaretWidth(width) + this.SetCaretWidth(Width) } - ; Expects argument "width" in hex - SetCaretWidth(width){ - CARETWIDTH := width + ; Expects argument "Width" in hex + SetCaretWidth(Width){ + CARETWIDTH := Width ; SPI := SystemParametersInfo SPI_SETCARETWIDTH := 0x2007 SPIF_UPDATEINIFILE := 0x01 SPIF_SENDCHANGE := 0x02 fWinIni := SPIF_UPDATEINIFILE | SPIF_SENDCHANGE DllCall("SystemParametersInfo", "UInt", SPI_SETCARETWIDTH, "UInt", 0, "UInt", CARETWIDTH, "UInt", fWinIni) - ; Switch focus to another window and back to update caret width + ; Switch focus to another window and back to update caret Width this.Refocus() } diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 44309df..9a84b10 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -1,9 +1,9 @@ class VimCheck{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim } - CheckMenu(ItemName, ItemPos, MyMenu) { + CheckMenu(*) { ; Additional message is necessary before checking current window. ; Otherwise process name cannot be retrieved...? MsgBox("Checking current window...", "Vim Ahk") diff --git a/lib/vim_gui.ahk b/lib/vim_gui.ahk index 447613b..83df447 100644 --- a/lib/vim_gui.ahk +++ b/lib/vim_gui.ahk @@ -1,13 +1,13 @@ class VimGui{ - __New(vim, title){ - this.Vim := vim + __New(Vim, Title){ + this.Vim := Vim this.Hwnd := 0 this.HwndAll := [] - this.Title := title + this.Title := Title this.OKObj := ObjBindMethod(this, "OK") } - ShowGui(name, pos, mymenu){ + ShowGui(*){ if(this.Hwnd == 0){ this.Hwnd := Gui("", this.Title) this.HwndAll.Push(this.Hwnd) @@ -33,27 +33,27 @@ class VimGui{ this.Hwnd.Hide() } - OK(btn, info){ + OK(*){ this.Hide() } - IsThisWindow(hwnd){ + IsThisWindow(Hwnd){ for i, h in this.HwndAll { - if(hwnd == h){ + if(Hwnd == h){ Return True } } Return False } - OnClose(wp, lp, msg, hwnd){ - if(wp == 0xF060 && hwnd == this.Hwnd){ + OnClose(Wp, Lp, Msg, Hwnd){ + if(Wp == 0xF060 && Hwnd == this.Hwnd){ this.Hide() } } - OnEscape(wp, lp, msg, hwnd){ - if(wp == 27 && this.IsThisWindow(hwnd)){ + OnEscape(Wp, Lp, Msg, Hwnd){ + if(Wp == 27 && this.IsThisWindow(Hwnd)){ this.Hide() } } diff --git a/lib/vim_icon.ahk b/lib/vim_icon.ahk index be9fb49..7dd6767 100644 --- a/lib/vim_icon.ahk +++ b/lib/vim_icon.ahk @@ -1,6 +1,6 @@ class VimIcon{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim this.icons := Map("Normal", this.Vim.ScriptPath "\..\vim_ahk_icons\normal.ico" , "Insert", this.Vim.ScriptPath "\..\vim_ahk_icons\insert.ico" , "Visual", this.Vim.ScriptPath "\..\vim_ahk_icons\visual.ico" diff --git a/lib/vim_ini.ahk b/lib/vim_ini.ahk index 39f8b46..69f37e5 100644 --- a/lib/vim_ini.ahk +++ b/lib/vim_ini.ahk @@ -3,30 +3,30 @@ static Ini_Default := "vim_ahk.ini" static Section_Default := "Vim Ahk Settings" - __New(vim, dir:="", ini:="", section:=""){ - this.Vim := vim - if(dir == ""){ - dir := VimIni.IniDir_Default + __New(Vim, Dir:="", Ini:="", Section:=""){ + this.Vim := Vim + if(Dir == ""){ + Dir := VimIni.IniDir_Default } - if(ini == ""){ - ini := VimIni.Ini_Default + if(Ini == ""){ + Ini := VimIni.Ini_Default } - if(section == ""){ - section := VimIni.Section_Default + if(Section == ""){ + Section := VimIni.Section_Default } - this.IniDir := dir - this.Ini := dir "\" ini - this.section := section + this.IniDir := Dir + this.Ini := Dir "\" Ini + this.section := Section } - ReadIni(conf:=""){ - if (conf == ""){ - conf := this.Vim.Conf + ReadIni(Conf:=""){ + if (Conf == ""){ + Conf := this.Vim.Conf } - for k, v in conf { - current := v["val"] - if(current != ""){ - val := IniRead(this.Ini, this.Section, k, current) + for k, v in Conf { + Current := v["val"] + if(Current != ""){ + val := IniRead(this.Ini, this.Section, k, Current) }else{ val := IniRead(this.Ini, this.Section, k, A_Space) } @@ -41,16 +41,16 @@ this.DeprecatedTwoLetter("j", "k") } - DeprecatedTwoLetter(l1, l2){ - ul1 := StrUpper(l1) - ul2 := StrUpper(l2) + DeprecatedTwoLetter(L1, L2){ + ul1 := StrUpper(L1) + ul2 := StrUpper(L2) twoLetter := "Vim" ul1 ul2 val := IniRead(this.Ini, this.Section, twoLetter, 0) if (val == 1){ if (this.Vim.Conf["VimTwoLetter"]["val"] == ""){ - this.Vim.Conf["VimTwoLetter"]["val"] := l1 l2 + this.Vim.Conf["VimTwoLetter"]["val"] := L1 L2 }else{ - this.Vim.Conf["VimTwoLetter"]["val"] := this.Vim.Conf["VimTwoLetter"]["val"] this.Vim.GroupDel l1 l2 + this.Vim.Conf["VimTwoLetter"]["val"] := this.Vim.Conf["VimTwoLetter"]["val"] this.Vim.GroupDel L1 L2 } } IniDelete(this.Ini, this.Section, twoLetter) diff --git a/lib/vim_menu.ahk b/lib/vim_menu.ahk index 6a61748..0d1af84 100644 --- a/lib/vim_menu.ahk +++ b/lib/vim_menu.ahk @@ -1,6 +1,6 @@ class VimMenu{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim } SetMenu(){ diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index c685cb6..827ace5 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -1,17 +1,17 @@ class VimMove{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim this.shift := 0 } - MoveInitialize(key:=""){ + MoveInitialize(Key:=""){ this.shift := 0 if(this.Vim.State.StrIsInCurrentVimMode("Visual") or this.Vim.State.StrIsInCurrentVimMode("ydc")){ this.shift := 1 Send("{Shift Down}") } - if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (key == "k" or key == "^u" or key == "^b" or key == "g"){ + if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (Key == "k" or Key == "^u" or Key == "^b" or Key == "g"){ Send("{Shift Up}{End}") this.Zero() Send("{Shift Down}") @@ -19,11 +19,11 @@ this.vim.state.setmode("Vim_VisualLine") } - if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (key == "j" or key == "^d" or key == "^f" or key == "+g"){ + if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (Key == "j" or Key == "^d" or Key == "^f" or Key == "+g"){ this.vim.state.setmode("Vim_VisualLine") } - if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (key == "k" or key == "^u" or key == "^b" or key == "g"){ + if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (Key == "k" or Key == "^u" or Key == "^b" or Key == "g"){ this.Vim.State.LineCopy := 1 Send("{Shift Up}") this.Zero() @@ -31,7 +31,7 @@ Send("{Shift Down}") this.Up() } - if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (key == "j" or key == "^d" or key == "^f" or key == "+g"){ + if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (Key == "j" or Key == "^d" or Key == "^f" or Key == "+g"){ this.Vim.State.LineCopy := 1 Send("{Shift Up}") this.Zero() @@ -96,8 +96,8 @@ } } - Move(key:="", repeat:=false){ - if(!repeat){ + Move(Key:="", Repeat:=false){ + if(!Repeat){ this.MoveInitialize(key) } @@ -108,14 +108,14 @@ ; For now, caret does not work even add + directly ; 1 character - if(key == "h"){ + if(Key == "h"){ if WinActive("ahk_group VimQdir"){ Send("{BackSpace down}{BackSpace up}") } else { Send("{Left}") } - }else if(key == "l"){ + }else if(Key == "l"){ if WinActive("ahk_group VimQdir"){ Send("{Enter}") } @@ -123,15 +123,15 @@ Send("{Right}") } ; Home/End - }else if(key == "0"){ + }else if(Key == "0"){ this.Zero() - }else if(key == "$"){ + }else if(Key == "$"){ if(this.shift == 1){ Send("+{End}") }else{ Send("{End}") } - }else if(key == "^"){ + }else if(Key == "^"){ if(this.shift == 1){ if WinActive("ahk_group VimCaretMove"){ Send("+{Home}") @@ -150,13 +150,13 @@ } } ; Words - }else if(key == "w"){ + }else if(Key == "w"){ if(this.shift == 1){ Send("+^{Right}") }else{ Send("^{Right}") } - }else if(key == "e"){ + }else if(Key == "e"){ if(this.shift == 1){ if(this.Vim.CheckChr(" ")){ Send("+^{Right}") @@ -168,7 +168,7 @@ } Send("^{Right}{Left}") } - }else if(key == "b"){ + }else if(Key == "b"){ if(this.shift == 1){ Send("+^{Left}") }else{ @@ -177,38 +177,38 @@ } } ; Up/Down 1 character - if(key == "j"){ + if(Key == "j"){ this.Down() - }else if(key="k"){ + }else if(Key="k"){ this.Up() ; Page Up/Down n := 10 - }else if(key == "^u"){ + }else if(Key == "^u"){ this.Up(10) - }else if(key == "^d"){ + }else if(Key == "^d"){ this.Down(10) - }else if(key == "^b"){ + }else if(Key == "^b"){ Send("{PgUp}") - }else if(key == "^f"){ + }else if(Key == "^f"){ Send("{PgDn}") - }else if(key == "g"){ + }else if(Key == "g"){ Send("^{Home}") - }else if(key == "+g"){ + }else if(Key == "+g"){ Send("^{End}{Home}") } - if(!repeat){ + if(!Repeat){ this.MoveFinalize() } } - Repeat(key:=""){ - this.MoveInitialize(key) + Repeat(Key:=""){ + this.MoveInitialize(Key) if(this.Vim.State.n == 0){ this.Vim.State.n := 1 } Loop this.Vim.State.n { - this.Move(key, true) + this.Move(Key, true) } this.MoveFinalize() } @@ -229,8 +229,8 @@ } } - Inner(key:=""){ - if(key == "w"){ + Inner(Key:=""){ + if(Key == "w"){ this.Move("b", true) this.Move("w", false) } diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index 78d447c..ae86b04 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -2,10 +2,10 @@ class VimSetting Extends VimGui{ - __New(vim){ - super.__New(vim, "Vim Ahk Settings") + __New(Vim){ + super.__New(Vim, "Vim Ahk Settings") - this.Vim := vim + this.Vim := Vim this.OKObj := ObjBindMethod(this, "OK") this.ResetObj := ObjBindMethod(this, "Reset") @@ -149,10 +149,10 @@ class VimSetting Extends VimGui{ } } - VimParseList(list){ + VimParseList(List){ result := "" tmpArray := [] - Loop Parse, list, "`n" { + Loop Parse, List, "`n" { if(! tmpArray.Has(A_LoopField)){ tmpArray.push(A_LoopField) if(result == ""){ @@ -171,23 +171,23 @@ class VimSetting Extends VimGui{ } } - GetConf(name, key){ - return this.Vim.Conf[name][key] + GetConf(Name, Key){ + return this.Vim.Conf[Name][Key] } - GetVal(name){ - return this.GetConf(name, "val") + GetVal(Name){ + return this.GetConf(Name, "val") } - GetDefault(name){ - return this.GetConf(name, "default") + GetDefault(Name){ + return this.GetConf(Name, "default") } GetDescription(name){ - return this.GetConf(name, "description") + return this.GetConf(Name, "description") } - OK(btn, info){ + OK(*){ this.Hwnd.Submit() this.VimV2Conf() this.Vim.Setup() @@ -195,11 +195,11 @@ class VimSetting Extends VimGui{ this.Hide() } - Cancel(btn, info){ + Cancel(*){ this.Hide() } - Reset(btn, info){ + Reset(*){ this.VimDefault2V() this.UpdateGuiValue() } diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 8a4c110..90da68b 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -1,6 +1,6 @@ class VimState{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim ; CheckModeValue does not get set for compiled scripts. ;@Ahk2Exe-IgnoreBegin @@ -23,15 +23,15 @@ this.StatusCheckObj := ObjBindMethod(this, "StatusCheck") } - CheckMode(verbose:=1, Mode:="", g:=0, n:=0, LineCopy:=-1, force:=0){ - if(force == 0) and ((verbose <= 1) or ((Mode == "") and (g == 0) and (n == 0) and (LineCopy == -1))){ + CheckMode(Verbose:=1, Mode:="", g:=0, n:=0, LineCopy:=-1, Force:=0){ + if(Force == 0) and ((Verbose <= 1) or ((Mode == "") and (g == 0) and (n == 0) and (LineCopy == -1))){ Return - }else if(verbose == 2){ + }else if(Verbose == 2){ this.SetTooltip(this.Mode, 1) - }else if(verbose == 3){ + }else if(Verbose == 3){ this.SetTooltip(this.Mode "`r`ng=" this.g "`r`nn=" this.n "`r`nLineCopy=" this.LineCopy, 4) } - if(verbose >= 4){ + if(Verbose >= 4){ MsgBox(" ( Mode : %this.Mode% @@ -42,13 +42,13 @@ } } - SetTooltip(Title, lines:=1){ + SetTooltip(Title, Lines:=1){ WinGetPos(, , &W, &H, "A") - ToolTip(Title, W - 110, H - 30 - (lines) * 20) + ToolTip(Title, W - 110, H - 30 - (Lines) * 20) this.Vim.VimToolTip.SetRemoveToolTip(1000) } - FullStatus(ItemName, ItemPos, MyMenu){ + FullStatus(*){ this.CheckMode(4, , , , 1) } @@ -137,23 +137,23 @@ } } - IsCurrentVimMode(mode){ - this.CheckValidMode(mode) + IsCurrentVimMode(Mode){ + this.CheckValidMode(Mode) Return (mode == this.Mode) } - StrIsInCurrentVimMode(mode){ - this.CheckValidMode(mode, false) - Return (inStr(this.Mode, mode)) + StrIsInCurrentVimMode(Mode){ + this.CheckValidMode(Mode, false) + Return (inStr(this.Mode, Mode)) } - CheckValidMode(mode, fullMatch:=true){ + CheckValidMode(Mode, FullMatch:=true){ if(this.CheckModeValue == false){ Return } try{ - InOrBlank := (not fullMatch) ? "in " : "" - if not this.HasValue(this.PossibleVimModes, mode, fullMatch){ + InOrBlank := (not FullMatch) ? "in " : "" + if not this.HasValue(this.PossibleVimModes, Mode, FullMatch){ Throw ValueError("Invalid mode specified", -2, " ( '%Mode%' is not %InOrBlank%a valid mode as defined by the VimPossibleVimModes @@ -173,19 +173,19 @@ } } - HasValue(haystack, needle, fullMatch:=true){ - if(!isObject(haystack)){ + HasValue(Haystack, Needle, FullMatch:=true){ + if(!isObject(Haystack)){ return false - }else if(haystack.Length == 0){ + }else if(Haystack.Length == 0){ return false } - for index, value in haystack{ + for index, value in Haystack{ if fullMatch{ - if (value == needle){ + if (value == Needle){ return true } }else{ - if (inStr(value, needle)){ + if (inStr(value, Needle)){ return true } } diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index e552209..6d8cd5c 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -1,14 +1,14 @@ class VimToolTip{ - __New(vim){ - this.Vim := vim + __New(Vim){ + this.Vim := Vim this.DisplayToolTipObj := ObjBindMethod(this, "DisplayToolTip") this.RemoveToolTipObj := ObjBindMethod(this, "RemoveToolTip") OnMessage(0x200, ObjBindMethod(this, "OnMouseMove")) } - OnMouseMove(wp, lp, msg, hwnd){ - this.Vim.State.CurrControl := hwnd + OnMouseMove(Wp, Lp, Msg, Hwnd){ + this.Vim.State.CurrControl := Hwnd if(this.Vim.State.CurrControl != this.Vim.State.PrevControl){ this.Vim.State.PrevControl := this.Vim.State.CurrControl this.RemoveToolTip() @@ -34,8 +34,8 @@ class VimToolTip{ ToolTip } - SetRemoveToolTip(time){ + SetRemoveToolTip(Time){ remove := this.RemoveToolTipObj - SetTimer(remove, "-" time) + SetTimer(remove, "-" Time) } } From e046354c0615da5d9e74bf01bc5d011ee0ffd33c Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sat, 28 Sep 2024 23:45:08 +0900 Subject: [PATCH 64/75] refactor: replace Send with SendInput for improved reliability in key input operations. refactor: remove `SendMode("Input")` setting as all Send was replaced by SendInput --- lib/bind/vim_command.ahk | 12 ++--- lib/bind/vim_enter_insert.ahk | 10 ++-- lib/bind/vim_normal.ahk | 26 +++++----- lib/bind/vim_replace.ahk | 8 +-- lib/bind/vim_search.ahk | 12 ++--- lib/bind/vim_visual.ahk | 22 ++++---- lib/bind/vim_ydcxp.ahk | 44 ++++++++-------- lib/util/vim_ahk_setting.ahk | 1 - lib/vim_move.ahk | 94 +++++++++++++++++------------------ lib/vim_state.ahk | 14 +++--- 10 files changed, 121 insertions(+), 122 deletions(-) diff --git a/lib/bind/vim_command.ahk b/lib/bind/vim_command.ahk index 47fc487..f1ce261 100644 --- a/lib/bind/vim_command.ahk +++ b/lib/bind/vim_command.ahk @@ -6,34 +6,34 @@ w::Vim.State.SetMode("Command_w") q::Vim.State.SetMode("Command_q") h:: { - Send("{F1}") + SendInput("{F1}") Vim.State.SetMode("Vim_Normal") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_w")) Enter:: { - Send("^s") + SendInput("^s") Vim.State.SetMode("Vim_Normal") } q:: { - Send("^s") - Send("!{F4}") + SendInput("^s") + SendInput("!{F4}") Vim.State.SetMode("Insert") } Space:: { - Send("!fa") + SendInput("!fa") Vim.State.SetMode("Insert") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Command_q")) Enter:: { - Send("!{F4}") + SendInput("!{F4}") Vim.State.SetMode("Insert") } diff --git a/lib/bind/vim_enter_insert.ahk b/lib/bind/vim_enter_insert.ahk index e136b89..d67a6ca 100644 --- a/lib/bind/vim_enter_insert.ahk +++ b/lib/bind/vim_enter_insert.ahk @@ -3,33 +3,33 @@ i::Vim.State.SetMode("Insert") +i:: { - Send("{Home}") + SendInput("{Home}") Vim.State.SetMode("Insert") } a:: { if(! Vim.CheckChr("`n")){ - Send("{Right}") + SendInput("{Right}") } Vim.State.SetMode("Insert") } +a:: { - Send("{End}") + SendInput("{End}") Vim.State.SetMode("Insert") } o:: { - Send("{End}{Enter}") + SendInput("{End}{Enter}") Vim.State.SetMode("Insert") } +o:: { - Send("{Home}{Enter}{Left}") + SendInput("{Home}{Enter}{Left}") Vim.State.SetMode("Insert") } diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index 2d22eb6..e6f6c5c 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -1,24 +1,24 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) ; Undo/Redo -u::Send("^z") -^r::Send("^y") +u::SendInput("^z") +^r::SendInput("^y") ; Combine lines -+j:: Send("{End}{Space}{Delete}") ++j:: SendInput("{End}{Space}{Delete}") ; Change case ~:: { ClipSaved := ClipboardAll() A_Clipboard := "" - Send("+{Right}^x") + SendInput("+{Right}^x") ClipWait(1) if(isLower(A_Clipboard)){ A_Clipboard := StrUpper(A_Clipboard) }else if(isUpper(A_Clipboard)){ A_Clipboard := StrLower(A_Clipboard) } - Send("^v") + SendInput("^v") A_Clipboard := ClipSaved } @@ -29,14 +29,14 @@ u::Send("^z") #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) +z:: { - Send("^s") - Send("!{F4}") + SendInput("^s") + SendInput("!{F4}") Vim.State.SetMode("Vim_Normal") } +q:: { - Send("!{F4}") + SendInput("!{F4}") Vim.State.SetMode("Vim_Normal") } @@ -45,12 +45,12 @@ u::Send("^z") ; For Q-dir, ^X mapping does not work, use !X instead. ; ^X does not work to be sent, too, use Down/Up ; switch to left top (1), right top (2), left bottom (3), right bottom (4) -!u::Send("{LControl Down}{1 Down}{1 Up}{LControl Up}") -!i::Send("{LControl Down}{2 Down}{2 Up}{LControl Up}") -!j::Send("{LControl Down}{3 Down}{3 Up}{LControl Up}") -!k::Send("{LControl Down}{4 Down}{4 Up}{LControl Up}") +!u::SendInput("{LControl Down}{1 Down}{1 Up}{LControl Up}") +!i::SendInput("{LControl Down}{2 Down}{2 Up}{LControl Up}") +!j::SendInput("{LControl Down}{3 Down}{3 Up}{LControl Up}") +!k::SendInput("{LControl Down}{4 Down}{4 Up}{LControl Up}") ; Ctrl+q, menu Quick-links -'::Send("{LControl Down}{q Down}{q Up}{LControl Up}") +'::SendInput("{LControl Down}{q Down}{q Up}{LControl Up}") ; Keep the e key in Normal mode, use the right button and then press the refresh (e) function, do nothing, return to the e key directly ~e:: {} diff --git a/lib/bind/vim_replace.ahk b/lib/bind/vim_replace.ahk index b8c68ee..d8365c9 100644 --- a/lib/bind/vim_replace.ahk +++ b/lib/bind/vim_replace.ahk @@ -96,13 +96,13 @@ r::Vim.State.SetMode("r_once") ~>:: ~Space:: { - Send("{Del}") + SendInput("{Del}") Vim.State.SetMode("Vim_Normal") } ::: ; ":" can't be used with "~"? { - Send("{:}{Del}") + SendInput("{:}{Del}") Vim.State.SetMode("Vim_Normal") } @@ -200,12 +200,12 @@ r::Vim.State.SetMode("r_once") ~>:: ~Space:: { - Send("{Del}") + SendInput("{Del}") } ::: { - Send("{:}{Del}") + SendInput("{:}{Del}") } #HotIf diff --git a/lib/bind/vim_search.ahk b/lib/bind/vim_search.ahk index e9ff475..bd1346d 100644 --- a/lib/bind/vim_search.ahk +++ b/lib/bind/vim_search.ahk @@ -1,7 +1,7 @@ #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) /:: { - Send("^f") + SendInput("^f") Vim.State.SetMode("Insert") } @@ -9,15 +9,15 @@ { ClipSaved := ClipboardAll() A_Clipboard := "" - Send("^{Left}+^{Right}^c") + SendInput("^{Left}+^{Right}^c") ClipWait(1) - Send("^f") - Send("^v!f") + SendInput("^f") + SendInput("^v!f") A_Clipboard := ClipSaved Vim.State.SetMode("Insert") } -n::Send("{F3}") -+n::Send("+{F3}") +n::SendInput("{F3}") ++n::SendInput("+{F3}") #HotIf diff --git a/lib/bind/vim_visual.ahk b/lib/bind/vim_visual.ahk index 98a3e95..02a4f66 100644 --- a/lib/bind/vim_visual.ahk +++ b/lib/bind/vim_visual.ahk @@ -3,14 +3,14 @@ v::Vim.State.SetMode("Vim_VisualChar") ^v:: { - Send("^b") + SendInput("^b") Vim.State.SetMode("Vim_VisualChar") } +v:: { Vim.State.SetMode("Vim_VisualLineFirst") - Send("{Home}+{Down}") + SendInput("{Home}+{Down}") } #HotIf Vim.IsVimGroup() and (Vim.State.StrIsInCurrentVimMode("Visual")) @@ -20,10 +20,10 @@ v::Vim.State.SetMode("Vim_Normal") y:: { A_Clipboard := "" - Send("^c") - Send("{Right}") + SendInput("^c") + SendInput("{Right}") if WinActive("ahk_group VimCursorSameAfterSelect"){ - Send("{Left}") + SendInput("{Left}") } ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ @@ -36,7 +36,7 @@ y:: d:: { A_Clipboard := "" - Send("^x") + SendInput("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) @@ -48,7 +48,7 @@ d:: x:: { A_Clipboard := "" - Send("^x") + SendInput("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Vim_Normal", 0, 0, 1) @@ -60,7 +60,7 @@ x:: c:: { A_Clipboard := "" - Send("^x") + SendInput("^x") ClipWait(1) if(Vim.State.StrIsInCurrentVimMode("Line")){ Vim.State.SetMode("Insert", 0, 0, 1) @@ -73,10 +73,10 @@ c:: { ClipSaved := ClipboardAll() A_Clipboard := "" - Send("^c") + SendInput("^c") ClipWait(1) - Send("^f") - Send("^v!f") + SendInput("^f") + SendInput("^v!f") A_Clipboard := ClipSaved Vim.State.SetMode("Vim_Normal") } diff --git a/lib/bind/vim_ydcxp.ahk b/lib/bind/vim_ydcxp.ahk index c8799f5..0ad016e 100644 --- a/lib/bind/vim_ydcxp.ahk +++ b/lib/bind/vim_ydcxp.ahk @@ -7,15 +7,15 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) Vim.State.SetMode("Vim_ydc_y", 0, 0, 1) Sleep(150) ; Need to wait (For variable change?) if WinActive("ahk_group VimDoubleHomeGroup"){ - Send("{Home}") + SendInput("{Home}") } - Send("{Home}+{End}") + SendInput("{Home}+{End}") if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("l") }else{ Vim.Move.Move("") } - Send("{Left}{Home}") + SendInput("{Left}{Home}") } +d:: @@ -24,7 +24,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") }else{ - Send("{Shift Down}{End}{Left}") + SendInput("{Shift Down}{End}{Left}") Vim.Move.Move("") } } @@ -35,7 +35,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) if not WinActive("ahk_group VimLBSelectGroup"){ Vim.Move.Move("$") }else{ - Send("{Shift Down}{End}{Left}") + SendInput("{Shift Down}{End}{Left}") Vim.Move.Move("") } } @@ -44,7 +44,7 @@ c::Vim.State.SetMode("Vim_ydc_c", 0, -1, 0) y:: { Vim.Move.YDCMove() - Send("{Left}{Home}") + SendInput("{Left}{Home}") } #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_ydc_d")) @@ -54,26 +54,26 @@ d::Vim.Move.YDCMove() c::Vim.Move.YDCMove() #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) -x::Send("{Delete}") -+x::Send("{BS}") +x::SendInput("{Delete}") ++x::SendInput("{BS}") ; Paste #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Vim_Normal")) p:: { ;i:=0 - ;;Send("{p Up}") + ;;SendInput("{p Up}") ;Loop { ; if !GetKeyState("p", "P"){ ; break ; } ; if(Vim.State.LineCopy == 1){ - ; Send("{End}{Enter}^v{BS}{Home}") + ; SendInput("{End}{Enter}^v{BS}{Home}") ; }else{ - ; Send("{Right}") - ; Send("^v") + ; SendInput("{Right}") + ; SendInput("^v") ; ;Sleep(1000) - ; Send("^{Left}") + ; SendInput("^{Left}") ; } ; ;TrayTip,i,%i%, ; if(i == 0){ @@ -89,16 +89,16 @@ p:: ;} if(Vim.State.LineCopy == 1){ if WinActive("ahk_group VimNoLBCopyGroup"){ - Send("{End}{Enter}^v{Home}") + SendInput("{End}{Enter}^v{Home}") }else{ - Send("{End}{Enter}^v{BS}{Home}") + SendInput("{End}{Enter}^v{BS}{Home}") } }else{ - Send("{Right}") - Send("^v") + SendInput("{Right}") + SendInput("^v") ;Sleep(1000) - Send("{Left}") - ;;Send("^{Left}") + SendInput("{Left}") + ;;SendInput("^{Left}") } KeyWait("p") ; To avoid repeat, somehow it calls , print... } @@ -106,10 +106,10 @@ p:: +p:: { if(Vim.State.LineCopy == 1){ - Send("{Up}{End}{Enter}^v{BS}{Home}") + SendInput("{Up}{End}{Enter}^v{BS}{Home}") }else{ - Send("^v") - ;Send("^{Left}") + SendInput("^v") + ;SendInput("^{Left}") } KeyWait("p") } diff --git a/lib/util/vim_ahk_setting.ahk b/lib/util/vim_ahk_setting.ahk index bd32bbb..c07bd3a 100644 --- a/lib/util/vim_ahk_setting.ahk +++ b/lib/util/vim_ahk_setting.ahk @@ -4,4 +4,3 @@ InstallKeybdHook(true) ; For checking key history ; Use ~500kB memory? A_HotkeyInterval := 2000 ; Hotkey interval (default 2000 milliseconds). A_MaxHotkeysPerInterval := 70 ; Max hotkeys per interval (default 50). -SendMode("Input") ; Recommended for new scripts due to its superior speed and reliability. diff --git a/lib/vim_move.ahk b/lib/vim_move.ahk index 827ace5..59d2f71 100644 --- a/lib/vim_move.ahk +++ b/lib/vim_move.ahk @@ -8,13 +8,13 @@ this.shift := 0 if(this.Vim.State.StrIsInCurrentVimMode("Visual") or this.Vim.State.StrIsInCurrentVimMode("ydc")){ this.shift := 1 - Send("{Shift Down}") + SendInput("{Shift Down}") } if(this.Vim.State.IsCurrentVimMode("Vim_VisualLineFirst")) and (Key == "k" or Key == "^u" or Key == "^b" or Key == "g"){ - Send("{Shift Up}{End}") + SendInput("{Shift Up}{End}") this.Zero() - Send("{Shift Down}") + SendInput("{Shift Down}") this.Up() this.vim.state.setmode("Vim_VisualLine") } @@ -25,63 +25,63 @@ if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (Key == "k" or Key == "^u" or Key == "^b" or Key == "g"){ this.Vim.State.LineCopy := 1 - Send("{Shift Up}") + SendInput("{Shift Up}") this.Zero() this.Down() - Send("{Shift Down}") + SendInput("{Shift Down}") this.Up() } if(this.Vim.State.StrIsInCurrentVimMode("Vim_ydc")) and (Key == "j" or Key == "^d" or Key == "^f" or Key == "+g"){ this.Vim.State.LineCopy := 1 - Send("{Shift Up}") + SendInput("{Shift Up}") this.Zero() - Send("{Shift Down}") + SendInput("{Shift Down}") this.Down() } } MoveFinalize(){ - Send("{Shift Up}") + SendInput("{Shift Up}") ydc_y := false if(this.Vim.State.StrIsInCurrentVimMode("ydc_y")){ A_Clipboard := "" - Send("^c") + SendInput("^c") ClipWait(1) this.Vim.State.SetMode("Vim_Normal") ydc_y := true }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_d")){ A_Clipboard := "" - Send("^x") + SendInput("^x") ClipWait(1) this.Vim.State.SetMode("Vim_Normal") }else if(this.Vim.State.StrIsInCurrentVimMode("ydc_c")){ A_Clipboard := "" - Send("^x") + SendInput("^x") ClipWait(1) this.Vim.State.SetMode("Insert") } this.Vim.State.SetMode("", 0, 0) if(ydc_y){ - Send("{Left}{Right}") + SendInput("{Left}{Right}") } ; Sometimes, when using `c`, the control key would be stuck down afterwards. ; This forces it to be up again afterwards. - send("{Ctrl Up}") + SendInput("{Ctrl Up}") } Zero(){ if WinActive("ahk_group VimDoubleHomeGroup"){ - Send("{Home}") + SendInput("{Home}") } - Send("{Home}") + SendInput("{Home}") } Up(n:=1){ Loop n { if WinActive("ahk_group VimCtrlUpDownGroup"){ - Send("^{Up}") + SendInput("^{Up}") } else { - Send("{Up}") + SendInput("{Up}") } } } @@ -89,9 +89,9 @@ Down(n:=1){ Loop n { if WinActive("ahk_group VimCtrlUpDownGroup"){ - Send("^{Down}") + SendInput("^{Down}") } else { - Send("{Down}") + SendInput("{Down}") } } } @@ -110,69 +110,69 @@ ; 1 character if(Key == "h"){ if WinActive("ahk_group VimQdir"){ - Send("{BackSpace down}{BackSpace up}") + SendInput("{BackSpace down}{BackSpace up}") } else { - Send("{Left}") + SendInput("{Left}") } }else if(Key == "l"){ if WinActive("ahk_group VimQdir"){ - Send("{Enter}") + SendInput("{Enter}") } else { - Send("{Right}") + SendInput("{Right}") } ; Home/End }else if(Key == "0"){ this.Zero() }else if(Key == "$"){ if(this.shift == 1){ - Send("+{End}") + SendInput("+{End}") }else{ - Send("{End}") + SendInput("{End}") } }else if(Key == "^"){ if(this.shift == 1){ if WinActive("ahk_group VimCaretMove"){ - Send("+{Home}") - Send("+^{Right}") - Send("+^{Left}") + SendInput("+{Home}") + SendInput("+^{Right}") + SendInput("+^{Left}") }else{ - Send("+{Home}") + SendInput("+{Home}") } }else{ if WinActive("ahk_group VimCaretMove"){ - Send("{Home}") - Send("^{Right}") - Send("^{Left}") + SendInput("{Home}") + SendInput("^{Right}") + SendInput("^{Left}") }else{ - Send("{Home}") + SendInput("{Home}") } } ; Words }else if(Key == "w"){ if(this.shift == 1){ - Send("+^{Right}") + SendInput("+^{Right}") }else{ - Send("^{Right}") + SendInput("^{Right}") } }else if(Key == "e"){ if(this.shift == 1){ if(this.Vim.CheckChr(" ")){ - Send("+^{Right}") + SendInput("+^{Right}") } - Send("+^{Right}+{Left}") + SendInput("+^{Right}+{Left}") }else{ if(this.Vim.CheckChr(" ")){ - Send("^{Right}") + SendInput("^{Right}") } - Send("^{Right}{Left}") + SendInput("^{Right}{Left}") } }else if(Key == "b"){ if(this.shift == 1){ - Send("+^{Left}") + SendInput("+^{Left}") }else{ - Send("^{Left}") + SendInput("^{Left}") } } } @@ -188,13 +188,13 @@ }else if(Key == "^d"){ this.Down(10) }else if(Key == "^b"){ - Send("{PgUp}") + SendInput("{PgUp}") }else if(Key == "^f"){ - Send("{PgDn}") + SendInput("{PgDn}") }else if(Key == "g"){ - Send("^{Home}") + SendInput("^{Home}") }else if(Key == "+g"){ - Send("^{End}{Home}") + SendInput("^{End}{Home}") } if(!Repeat){ @@ -216,12 +216,12 @@ YDCMove(){ this.Vim.State.LineCopy := 1 this.Zero() - Send("{Shift Down}") + SendInput("{Shift Down}") if(this.Vim.State.n == 0){ this.Vim.State.n := 1 } this.Down(this.Vim.State.n - 1) - Send("{End}") + SendInput("{End}") if not WinActive("ahk_group VimLBSelectGroup"){ this.Move("l") }else{ diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index 90da68b..cc0cbc1 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -78,16 +78,16 @@ this.LastIME := VIM_IME_Get() if(this.LastIME){ if(VIM_IME_GetConverting("A")){ - Send("{Esc}") + SendInput("{Esc}") Return }else{ VIM_IME_SET() } } if(this.StrIsInCurrentVimMode("Visual") or this.StrIsInCurrentVimMode("ydc")){ - Send("{Right}") + SendInput("{Right}") if WinActive("ahk_group VimCursorSameAfterSelect"){ - Send("{Left}") + SendInput("{Left}") } } this.SetMode("Vim_Normal") @@ -99,7 +99,7 @@ HandleEsc(){ if (!this.Vim.Conf["VimEscNormal"]["val"]) { - Send("{Esc}") + SendInput("{Esc}") Return } ; The keywait waits for esc to be released. If it doesn't detect a release @@ -107,7 +107,7 @@ ShortPress := KeyWait("Esc", "T0.5") SetNormal := this.Vim.Conf["VimLongEscNormal"]["val"] != ShortPress if (!SetNormal or (this.Vim.Conf["VimSendEscNormal"]["val"] && this.IsCurrentVimMode("Vim_Normal"))) { - Send("{Esc}") + SendInput("{Esc}") } if (SetNormal) { this.SetNormal() @@ -121,13 +121,13 @@ HandleCtrlBracket(){ if (!this.Vim.Conf["VimCtrlBracketNormal"]["val"]) { - Send("^[") + SendInput("^[") Return } ShortPress := KeyWait("[", "T0.5") SetNormal := this.Vim.Conf["VimLongCtrlBracketNormal"]["val"] != ShortPress if (!SetNormal or (this.Vim.Conf["VimSendCtrlBracketNormal"]["val"] && this.IsCurrentVimMode("Vim_Normal"))) { - Send("^[") + SendInput("^[") } if (SetNormal) { this.SetNormal() From 425e8c50d61b00abec54ca4a85b73dea9f98cfa1 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 00:09:43 +0900 Subject: [PATCH 65/75] feat: add new bindings for period, ZZ, and ZQ in Vim mode --- lib/bind/vim_normal.ahk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/bind/vim_normal.ahk b/lib/bind/vim_normal.ahk index e6f6c5c..43a2807 100644 --- a/lib/bind/vim_normal.ahk +++ b/lib/bind/vim_normal.ahk @@ -23,10 +23,13 @@ u::SendInput("^z") } ; period -.::Send, +^{Right}{BS}^v +.::SendInput("+^{Right}{BS}^v") +; Z mode +z::Vim.State.SetMode("Z") #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Z")) + +; ZZ +z:: { SendInput("^s") @@ -34,6 +37,7 @@ u::SendInput("^z") Vim.State.SetMode("Vim_Normal") } +; ZQ +q:: { SendInput("!{F4}") From f13e64d07590f9e5d3d5732762f3303fcfa83a14 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 01:46:24 +0900 Subject: [PATCH 66/75] refactor: update OpenHomepage method to accept Btn and Info parameters refactor: reorder TwoLetterNormalMapsEnabled method and update parameter refactor: update CheckMenu method to accept ItemName, ItemPos, and MyMenu parameters refactor: simplify supported window message in CheckMenu method refactor: update ShowGui method to use additional parameters fix: missing closing parentheses in OK method of VimGui class refactor: update OK method to accept Btn and Info parameters in VimSetting refactor: update Cancel and Reset methods to accept Btn and Info parameters refactor: simplify verbose status display message in VimState class refactor: update FullStatus method to use additional parameters --- lib/vim_about.ahk | 2 +- lib/vim_ahk.ahk | 10 +++++----- lib/vim_check.ahk | 18 +++--------------- lib/vim_gui.ahk | 4 ++-- lib/vim_setting.ahk | 6 +++--- lib/vim_state.ahk | 10 ++-------- 6 files changed, 16 insertions(+), 34 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index f7be583..d91b837 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -30,7 +30,7 @@ class VimAbout Extends VimGui{ this.HwndAll.Push(this.Hwnd["VimAboutOK"]) } - OpenHomepage(*){ + OpenHomepage(Btn, Info){ this.Vim.VimToolTip.RemoveToolTip() Run(this.Homepage) } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index bb21a49..ef688f5 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -215,15 +215,15 @@ class VimAhk{ HotIf() } - SendSame(HotkeyName){ - SendInput(HotkeyName) + TwoLetterNormalMapsEnabled(HotkeyName){ + Return this.IsVimGroup() && (this.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet } - TwoLetterNormalMapsEnabled(*){ - Return this.IsVimGroup() && (this.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet + SendSame(HotkeyName){ + SendInput(HotkeyName) } - TwoLetterEnterNormal(*){ + TwoLetterEnterNormal(HotkeyName){ this.State.SetNormal() } diff --git a/lib/vim_check.ahk b/lib/vim_check.ahk index 9a84b10..790c568 100644 --- a/lib/vim_check.ahk +++ b/lib/vim_check.ahk @@ -3,7 +3,7 @@ this.Vim := Vim } - CheckMenu(*) { + CheckMenu(ItemName, ItemPos, MyMenu) { ; Additional message is necessary before checking current window. ; Otherwise process name cannot be retrieved...? MsgBox("Checking current window...", "Vim Ahk") @@ -12,21 +12,9 @@ win_class := WinGetClass("ahk_pid " process) title := WinGetTitle("ahk_pid " process) if(this.Vim.IsVimGroup()){ - MsgBox(" - ( - Supported - Process name: %name% - Class : %win_class% - Title : %title% - )", "Vim Ahk", "Iconi") + MsgBox("Supported`nProcess name: " name "`nClass : " win_class "`nTitle : " title, "Vim Ahk", "Iconi") }else{ - MsgBox(" - ( - Not supported - Process name: %name% - Class : %win_class% - Title : %title% - )", "Vim Ahk", "Iconx") + MsgBox("Not supported`nProcess name: " name "`nClass : " win_class "`nTitle : " title, "Vim Ahk", "Iconx") } } } diff --git a/lib/vim_gui.ahk b/lib/vim_gui.ahk index 83df447..ac3c1dd 100644 --- a/lib/vim_gui.ahk +++ b/lib/vim_gui.ahk @@ -7,7 +7,7 @@ class VimGui{ this.OKObj := ObjBindMethod(this, "OK") } - ShowGui(*){ + ShowGui(ItemName, ItemPos, MyMenu){ if(this.Hwnd == 0){ this.Hwnd := Gui("", this.Title) this.HwndAll.Push(this.Hwnd) @@ -33,7 +33,7 @@ class VimGui{ this.Hwnd.Hide() } - OK(*){ + OK(Btn, Info){ this.Hide() } diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index ae86b04..b211165 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -187,7 +187,7 @@ class VimSetting Extends VimGui{ return this.GetConf(Name, "description") } - OK(*){ + OK(Btn, Info){ this.Hwnd.Submit() this.VimV2Conf() this.Vim.Setup() @@ -195,11 +195,11 @@ class VimSetting Extends VimGui{ this.Hide() } - Cancel(*){ + Cancel(Btn, Info){ this.Hide() } - Reset(*){ + Reset(Btn, Info){ this.VimDefault2V() this.UpdateGuiValue() } diff --git a/lib/vim_state.ahk b/lib/vim_state.ahk index cc0cbc1..c7297b9 100644 --- a/lib/vim_state.ahk +++ b/lib/vim_state.ahk @@ -32,13 +32,7 @@ this.SetTooltip(this.Mode "`r`ng=" this.g "`r`nn=" this.n "`r`nLineCopy=" this.LineCopy, 4) } if(Verbose >= 4){ - MsgBox(" - ( - Mode : %this.Mode% - Vim_g : %this.g% - Vim_n : %this.n% - VimLineCopy : %this.LineCopy% - )", "Vim Ahk") + MsgBox("Mode : " this.Mode "`nVim_g : " this.g "`nVim_n : " this.n "`nVimLineCopy : " this.LineCopy, "Vim Ahk") } } @@ -48,7 +42,7 @@ this.Vim.VimToolTip.SetRemoveToolTip(1000) } - FullStatus(*){ + FullStatus(ItemName, ItemPos, MyMenu){ this.CheckMode(4, , , , 1) } From f9df00f821a3e78128706ed6ee9580e311319eaf Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 02:13:42 +0900 Subject: [PATCH 67/75] fix: jj --- lib/bind/vim_enter_normal.ahk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/bind/vim_enter_normal.ahk b/lib/bind/vim_enter_normal.ahk index 33c0a78..576c451 100644 --- a/lib/bind/vim_enter_normal.ahk +++ b/lib/bind/vim_enter_normal.ahk @@ -5,10 +5,10 @@ Esc::Vim.State.HandleEsc() #HotIf Vim.IsVimGroup() and (Vim.State.IsCurrentVimMode("Insert")) and (Vim.Conf["VimJJ"]["val"] == 1) ~j up:: ; jj: go to Normal mode. { - jout := InputHook("jout, I T0.1 V L1", "j") + jout := InputHook("I T0.1 V L1", "j") jout.Start() - jout.Wait() - if(jout.Input == "EndKey:J"){ + EndReason := jout.Wait() + if(EndReason == "EndKey"){ SendInput("{BackSpace 2}") Vim.State.SetNormal() } From 49a9085f3883243d70ea27999351d141660bdcf2 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 21:10:54 +0900 Subject: [PATCH 68/75] feat: add two-letter normal mode feature and corresponding configurations --- lib/vim_ahk.ahk | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index ef688f5..ecabfcc 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -51,6 +51,11 @@ class VimAhk{ DefaultGroup := this.SetDefaultActiveWindows() + ; Two-letter normal mode + this.TwoLetterNormalIsSet := False + this.TwoLetterNormalArray := Array() + this.TwoLetterNormalMapsEnabledObj := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") + ; On following applications, Enter works as Enter at the normal mode. GroupAdd("VimNonEditor", "ahk_exe explorer.exe") ; Explorer GroupAdd("VimNonEditor", "ahk_exe Explorer.exe") ; Explorer, Explorer became also upper case, but lower case works for this @@ -192,39 +197,51 @@ class VimAhk{ } LoadTwoLetterMaps() { + HotIf(this.TwoLetterNormalMapsEnabledObj) this.TwoLetterNormalIsSet := False + for value in this.TwoLetterNormalArray { + HotKey(value, "Off") + } + this.TwoLetterNormalArray := Array() + Loop Parse, this.Conf["VimTwoLetter"]["val"], this.GroupDel { if(A_LoopField != ""){ + if(StrLen(A_LoopField) != 2){ + MsgBox("Two-letter should be exactly two letters: " A_LoopField) + Continue + } this.TwoLetterNormalIsSet := True key1 := SubStr(A_LoopField, 1, 1) key2 := SubStr(A_LoopField, 2, 1) this.SetTwoLetterMap(key1, key2) } } + HotIf() } SetTwoLetterMap(Key1, Key2){ - Enabled := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") SendSame := ObjBindMethod(this, "SendSame") EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") - HotIf(Enabled) - HotKey(Key1, SendSame) - HotKey(Key2, SendSame) - HotKey(Key1 " & " Key2, EnterNormal) - HotKey(Key2 " & " Key1, EnterNormal) - HotIf() + EnterNormal1 := EnterNormal.Bind(Key2) + EnterNormal2 := EnterNormal.Bind(Key1) + HotKey("~" Key1, EnterNormal1) + HotKey("~" Key2, EnterNormal2) + this.TwoLetterNormalArray.Push(key1) + this.TwoLetterNormalArray.Push(key2) } TwoLetterNormalMapsEnabled(HotkeyName){ Return this.IsVimGroup() && (this.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet } - SendSame(HotkeyName){ - SendInput(HotkeyName) - } - - TwoLetterEnterNormal(HotkeyName){ - this.State.SetNormal() + TwoLetterEnterNormal(EndKey, HotkeyName){ + Out := InputHook("I T0.1 V L1", EndKey) + Out.Start() + EndReason := Out.Wait() + if(EndReason == "EndKey"){ + SendInput("{BackSpace 2}") + Vim.State.SetNormal() + } } Setup(){ From adb12f92da805e004d0972aed75721bb7367d3e6 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 21:46:07 +0900 Subject: [PATCH 69/75] chore: update actions/checkout to use tag v4 in GitHub actions --- .github/workflows/build_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 434154f..7918448 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -8,7 +8,7 @@ jobs: runs-on: windows-latest steps: - name: Checkout code - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + uses: actions/checkout@v4 - name: Install AutoHotkey with Chocolatey uses: crazy-max/ghaction-chocolatey@v3 with: From 2689573d6e83af0d499c50f4eb6909fe4be9bbec Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Sun, 29 Sep 2024 21:50:12 +0900 Subject: [PATCH 70/75] chore: update AHKPath to point to AutoHotkey v2 --- build.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.bat b/build.bat index 6b26d4f..5e72aa0 100644 --- a/build.bat +++ b/build.bat @@ -1,5 +1,5 @@ @echo off -SET AHKPath=C:\Program Files\AutoHotkey +SET AHKPath=C:\Program Files\AutoHotkey\v2 REM Takes a simple optional command parameter, /t, which starts testing before build. SET Param1=%1 From b6c5adfcccb4a0471d8fd592a49e1bdcebba369a Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Mon, 30 Sep 2024 00:06:06 +0900 Subject: [PATCH 71/75] doc: Add warning and notes for two-letter hotkey usage in README refactor: Extract two-letter normal mode logic to a new Vimkey class --- README.md | 24 ++++++++++++------- lib/vim_ahk.ahk | 57 +++------------------------------------------ lib/vim_key.ahk | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 63 deletions(-) create mode 100644 lib/vim_key.ahk diff --git a/README.md b/README.md index 2210d9b..1e32332 100644 --- a/README.md +++ b/README.md @@ -88,13 +88,14 @@ Example line: Multiple applications can be written by a comma-separated. -Note: This will overwrite the default applications. If you want to **add** -these applications to the default applications, add following applications -after your applications: - - ahk_exe notepad.exe,ahk_exe explorer.exe,ahk_exe wordpad.exe,ahk_exe TeraPad.exe,作成,Write:,ahk_exe POWERPNT.exe,ahk_exe WINWORD.exe,ahk_exe Evernote.exe,ahk_exe Code.exe,ahk_exe onenote.exe,OneNote,ahk_exe texworks.exe,ahk_exe texstudio.exe - -Or you can use GUI option setting menu described below. +> [!NOTE] +> This will overwrite the default applications. If you want to **add** +> these applications to the default applications, add following applications +> after your applications: +> +> ahk_exe notepad.exe,ahk_exe explorer.exe,ahk_exe wordpad.exe,ahk_exe TeraPad.exe,作成,Write:,ahk_exe POWERPNT.exe,ahk_exe WINWORD.exe,ahk_exe Evernote.exe,ahk_exe Code.exe,ahk_exe onenote.exe,OneNote,ahk_exe texworks.exe,ahk_exe texstudio.exe +> +> Or you can use GUI option setting menu described below. The default setting of `VimSetTitleMatchMode` is 2, which makes matching methods as `Contain`. @@ -103,7 +104,7 @@ If you set `OneNote`, all windows with a title containing `OneNote` (e.g. `XXX's OneNote`) will be included. If you set `VimSetTitleMatchMode` as 3, only the exact title of `OneNote` will be included. -Note: It may not work on OneNote. OneNote may have a window name like +It may not work on OneNote. OneNote may have a window name like **User's Notebook - OneNote**, instead of **OneNote**. In that case, you need to check OneNote's window title with Window spy. @@ -254,6 +255,10 @@ and a long press will change the mode to the normal mode. If using a custom two-letter hotkey to enter the normal mode, the two letters must be different. +> [!WARNING] +> A character can be used only for one two-letter hotkey. If you specify `ab` and `bc`, `ba` (push `b` first and then `a`) does not work. If you push `a` first, then `ab` will work, though. + + ## Available commands in the normal mode ### Mode Change @@ -281,7 +286,8 @@ If using a custom two-letter hotkey to enter the normal mode, the two letters mu |Space| Right.| |Enter| Move to the beginning of the next line.| -Note: Enter works only for editor applications (for other than Explorer, Q-dir, it works as Enter even in the normal mode). +> [!NOTE] +> Enter works only for editor applications (for other than Explorer, Q-dir, it works as Enter even in the normal mode). In addition, `Repeat` is also available for some commands. diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index ecabfcc..6d0cc47 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -8,6 +8,7 @@ #Include %A_LineFile%\..\vim_icon.ahk #Include %A_LineFile%\..\vim_caret.ahk #Include %A_LineFile%\..\vim_ini.ahk +#Include %A_LineFile%\..\vim_key.ahk #Include %A_LineFile%\..\vim_menu.ahk #Include %A_LineFile%\..\vim_move.ahk #Include %A_LineFile%\..\vim_setting.ahk @@ -38,6 +39,7 @@ class VimAhk{ this.Icon := VimIcon(this) this.Caret := VimCaret(this) this.Ini := VimIni(this) + this.key := Vimkey(this) this.VimMenu := VimMenu(this) this.Move := VimMove(this) this.Setting := VimSetting(this) @@ -51,11 +53,6 @@ class VimAhk{ DefaultGroup := this.SetDefaultActiveWindows() - ; Two-letter normal mode - this.TwoLetterNormalIsSet := False - this.TwoLetterNormalArray := Array() - this.TwoLetterNormalMapsEnabledObj := ObjBindMethod(this, "TwoLetterNormalMapsEnabled") - ; On following applications, Enter works as Enter at the normal mode. GroupAdd("VimNonEditor", "ahk_exe explorer.exe") ; Explorer GroupAdd("VimNonEditor", "ahk_exe Explorer.exe") ; Explorer, Explorer became also upper case, but lower case works for this @@ -196,60 +193,12 @@ class VimAhk{ } } - LoadTwoLetterMaps() { - HotIf(this.TwoLetterNormalMapsEnabledObj) - this.TwoLetterNormalIsSet := False - for value in this.TwoLetterNormalArray { - HotKey(value, "Off") - } - this.TwoLetterNormalArray := Array() - - Loop Parse, this.Conf["VimTwoLetter"]["val"], this.GroupDel { - if(A_LoopField != ""){ - if(StrLen(A_LoopField) != 2){ - MsgBox("Two-letter should be exactly two letters: " A_LoopField) - Continue - } - this.TwoLetterNormalIsSet := True - key1 := SubStr(A_LoopField, 1, 1) - key2 := SubStr(A_LoopField, 2, 1) - this.SetTwoLetterMap(key1, key2) - } - } - HotIf() - } - - SetTwoLetterMap(Key1, Key2){ - SendSame := ObjBindMethod(this, "SendSame") - EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") - EnterNormal1 := EnterNormal.Bind(Key2) - EnterNormal2 := EnterNormal.Bind(Key1) - HotKey("~" Key1, EnterNormal1) - HotKey("~" Key2, EnterNormal2) - this.TwoLetterNormalArray.Push(key1) - this.TwoLetterNormalArray.Push(key2) - } - - TwoLetterNormalMapsEnabled(HotkeyName){ - Return this.IsVimGroup() && (this.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet - } - - TwoLetterEnterNormal(EndKey, HotkeyName){ - Out := InputHook("I T0.1 V L1", EndKey) - Out.Start() - EndReason := Out.Wait() - if(EndReason == "EndKey"){ - SendInput("{BackSpace 2}") - Vim.State.SetNormal() - } - } - Setup(){ SetTitleMatchMode(this.Conf["VimSetTitleMatchMode"]["val"]) SetTitleMatchMode(this.Conf["VimSetTitleMatchModeFS"]["val"]) this.State.SetStatusCheck() this.SetGroup() - this.LoadTwoLetterMaps() + this.Key.Set() } Initialize(){ diff --git a/lib/vim_key.ahk b/lib/vim_key.ahk new file mode 100644 index 0000000..bbd22d6 --- /dev/null +++ b/lib/vim_key.ahk @@ -0,0 +1,62 @@ +class Vimkey{ + __New(Vim){ + this.Vim := Vim + + ; Two-letter normal mode + this.TwoLetterNormalIsSet := False + this.TwoLetterNormalArray := Array() + this.TwoLetterNormalEnabledObj := ObjBindMethod(this, "TwoLetterNormalEnabled") + } + + TwoLetterNormalEnabled(HotkeyName){ + Return this.Vim.IsVimGroup() && (this.Vim.State.StrIsInCurrentVimMode("Insert")) && this.TwoLetterNormalIsSet + } + + TwoLetterEnterNormal(EndKey, HotkeyName){ + Out := InputHook("I T0.1 V L1", EndKey) + Out.Start() + EndReason := Out.Wait() + if(EndReason == "EndKey"){ + SendInput("{BackSpace 2}") + Vim.State.SetNormal() + } + } + + SetTwoLetterMap(Key1, Key2){ + SendSame := ObjBindMethod(this, "SendSame") + EnterNormal := ObjBindMethod(this, "TwoLetterEnterNormal") + EnterNormal1 := EnterNormal.Bind(Key2) + EnterNormal2 := EnterNormal.Bind(Key1) + HotKey("~" Key1, EnterNormal1) + HotKey("~" Key2, EnterNormal2) + this.TwoLetterNormalArray.Push(key1) + this.TwoLetterNormalArray.Push(key2) + } + + SetTwoLetterMaps() { + HotIf(this.TwoLetterNormalEnabledObj) + this.TwoLetterNormalIsSet := False + for value in this.TwoLetterNormalArray { + HotKey(value, "Off") + } + this.TwoLetterNormalArray := Array() + + Loop Parse, this.Vim.Conf["VimTwoLetter"]["val"], this.Vim.GroupDel { + if(A_LoopField != ""){ + if(StrLen(A_LoopField) != 2){ + MsgBox("Two-letter should be exactly two letters: " A_LoopField) + Continue + } + this.TwoLetterNormalIsSet := True + key1 := SubStr(A_LoopField, 1, 1) + key2 := SubStr(A_LoopField, 2, 1) + this.SetTwoLetterMap(key1, key2) + } + } + HotIf() + } + + Set(){ + this.SetTwoLetterMaps() + } +} From fddc97540fd1c28066d6122d678c394a269f42b8 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Mon, 30 Sep 2024 00:22:08 +0900 Subject: [PATCH 72/75] refactor: rename Vimkey class to VimHotkey feat: add SetConfDefault method for setting default configuration values refactor: replace direct Conf access with GetConf for configuration retrieval refactor: switch to using GetVal and GetDescription in VimSetting fix: update Setup to use VimHotkey instead of removed Vimkey refactor: update variable assignment in IsVimGroup method to use GetVal fix: replace VimDefault2V with SetConfDefault in Reset method of VimSetting --- lib/vim_ahk.ahk | 38 ++++++++++--- lib/{vim_key.ahk => vim_hotkey.ahk} | 2 +- lib/vim_setting.ahk | 84 +++++++++++------------------ 3 files changed, 62 insertions(+), 62 deletions(-) rename lib/{vim_key.ahk => vim_hotkey.ahk} (99%) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 6d0cc47..3432bb5 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -7,8 +7,8 @@ #Include %A_LineFile%\..\vim_check.ahk #Include %A_LineFile%\..\vim_icon.ahk #Include %A_LineFile%\..\vim_caret.ahk +#Include %A_LineFile%\..\vim_hotkey.ahk #Include %A_LineFile%\..\vim_ini.ahk -#Include %A_LineFile%\..\vim_key.ahk #Include %A_LineFile%\..\vim_menu.ahk #Include %A_LineFile%\..\vim_move.ahk #Include %A_LineFile%\..\vim_setting.ahk @@ -38,8 +38,8 @@ class VimAhk{ this.Check := VimCheck(this) this.Icon := VimIcon(this) this.Caret := VimCaret(this) + this.VimHotkey := VimHotkey(this) this.Ini := VimIni(this) - this.key := Vimkey(this) this.VimMenu := VimMenu(this) this.Move := VimMove(this) this.Setting := VimSetting(this) @@ -172,6 +172,12 @@ class VimAhk{ this.Conf[setting] := Map("default", default, "val", val, "description", description, "info", info) } + SetConfDefault(){ + for k, v in this.Conf { + v["val"] := v["default"] + } + } + SetExistValue(){ ; Need some way to retrieve default values (v-label values are removed from vim_ahk for v2) ;for k, v in this.Conf { @@ -183,10 +189,26 @@ class VimAhk{ ;} } + GetConf(Name, Key){ + return this.Conf[Name][Key] + } + + GetVal(Name){ + return this.GetConf(Name, "val") + } + + GetDefault(Name){ + return this.GetConf(Name, "default") + } + + GetDescription(name){ + return this.GetConf(Name, "description") + } + SetGroup(){ this.GroupN++ this.GroupName := "VimGroup" this.GroupN - Loop Parse, this.Conf["VimGroup"]["val"], this.GroupDel { + Loop Parse, this.GetConf("VimGroup", "val"), this.GroupDel { if(A_LoopField != ""){ GroupAdd(this.GroupName, A_LoopField) } @@ -194,11 +216,11 @@ class VimAhk{ } Setup(){ - SetTitleMatchMode(this.Conf["VimSetTitleMatchMode"]["val"]) - SetTitleMatchMode(this.Conf["VimSetTitleMatchModeFS"]["val"]) + SetTitleMatchMode(this.GetVal("VimSetTitleMatchMode")) + SetTitleMatchMode(this.GetVal("VimSetTitleMatchModeFS")) this.State.SetStatusCheck() this.SetGroup() - this.Key.Set() + this.VimHotkey.Set() } Initialize(){ @@ -246,9 +268,9 @@ class VimAhk{ IsVimGroup(){ if(not this.Enabled){ Return False - }else if(this.Conf["VimAppList"]["val"] == "Allow List"){ + }else if(this.GetVal("VimAppList") == "Allow List"){ Return WinActive("ahk_group " . this.GroupName) - }else if(this.Conf["VimAppList"]["val"] == "Deny List"){ + }else if(this.GetVal("VimAppList") == "Deny List"){ Return !WinActive("ahk_group " . this.GroupName) } Return True diff --git a/lib/vim_key.ahk b/lib/vim_hotkey.ahk similarity index 99% rename from lib/vim_key.ahk rename to lib/vim_hotkey.ahk index bbd22d6..0cf324f 100644 --- a/lib/vim_key.ahk +++ b/lib/vim_hotkey.ahk @@ -1,4 +1,4 @@ -class Vimkey{ +class VimHotkey{ __New(Vim){ this.Vim := Vim diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index b211165..be29d9d 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -26,51 +26,51 @@ class VimSetting Extends VimGui{ }else{ x := "10" } - this.Hwnd.AddCheckbox(k " XM+" x " " y " v" k, this.GetDescription(k)) + this.Hwnd.AddCheckbox(k " XM+" x " " y " v" k, this.Vim.GetDescription(k)) this.HwndAll.Push(this.Hwnd[k]) created := 1 - this.Hwnd[k].Value := this.GetVal(k) + this.Hwnd[k].Value := this.Vim.GetVal(k) } - this.Hwnd.AddText("XM+10 Y+15 vVimTwoLetterText", this.GetDescription("VimTwoLetter")) - this.Hwnd.AddEdit("XM+10 Y+5 R4 W100 Multi vVimTwoLetter", StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1)) - this.Hwnd.AddText("XM+10 Y+15 vVimDisableUnusedText", this.GetDescription("VimDisableUnused")) - this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimDisableUnused Choose" this.GetVal("VimDisableUnused"), [1, 2, 3]) + this.Hwnd.AddText("XM+10 Y+15 vVimTwoLetterText", this.Vim.GetDescription("VimTwoLetter")) + this.Hwnd.AddEdit("XM+10 Y+5 R4 W100 Multi vVimTwoLetter", StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1)) + this.Hwnd.AddText("XM+10 Y+15 vVimDisableUnusedText", this.Vim.GetDescription("VimDisableUnused")) + this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimDisableUnused Choose" this.Vim.GetVal("VimDisableUnused"), [1, 2, 3]) this.HwndAll.Push(this.Hwnd["VimDisableUnused"]) - this.Hwnd.AddText("XM+10 Y+15 vVimSetTitleMatchModeText", this.GetDescription("VimSetTitleMatchMode")) - if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ + this.Hwnd.AddText("XM+10 Y+15 vVimSetTitleMatchModeText", this.Vim.GetDescription("VimSetTitleMatchMode")) + if(this.Vim.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ - matchmode := this.GetVal("VimSetTitleMatchMode") + matchmode := this.Vim.GetVal("VimSetTitleMatchMode") } this.Hwnd.AddDDL("X+5 Y+-16 W60 vVimSetTitleMatchMode Choose" matchmode, [1, 2, 3, "RegEx"]) this.HwndAll.Push(this.Hwnd["VimSetTitleMatchMode"]) - if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ + if(this.Vim.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } this.Hwnd.AddDDL("X+5 Y+-20 W50 vVimSetTitleMatchModeFS Choose" matchmodefs, ["Fast", "Slow"]) this.HwndAll.Push(this.Hwnd["VimSetTitleMatchModeFS"]) - this.Hwnd.AddText("XM+10 Y+10 vVimIconCheckIntervalText", this.GetDescription("VimIconCheckInterval")) + this.Hwnd.AddText("XM+10 Y+10 vVimIconCheckIntervalText", this.Vim.GetDescription("VimIconCheckInterval")) this.Hwnd.AddEdit("X+5 Y+-16 W70 vVimIconCheckIntervalEdit") this.HwndAll.Push(this.Hwnd["VimIconCheckIntervalEdit"]) - this.Hwnd.AddUpDown("vVimIconCheckInterval Range0-1000000", this.GetVal("VimIconCheckInterval")) + this.Hwnd.AddUpDown("vVimIconCheckInterval Range0-1000000", this.Vim.GetVal("VimIconCheckInterval")) this.HwndAll.Push(this.Hwnd["VimIconCheckInterval"]) - this.Hwnd.AddText("XM+10 Y+10 vVimVerboseText", this.GetDescription("VimVerbose")) - this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimVerbose Choose" this.GetVal("VimVerbose"), [1, 2, 3, 4]) + this.Hwnd.AddText("XM+10 Y+10 vVimVerboseText", this.Vim.GetDescription("VimVerbose")) + this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimVerbose Choose" this.Vim.GetVal("VimVerbose"), [1, 2, 3, 4]) this.HwndAll.Push(this.Hwnd["VimVerbose"]) - this.Hwnd.AddText("XM+10 Y+10 vVimAppListText", this.GetDescription("VimAppList")) - if(this.GetVal("VimAppList") == "All"){ + this.Hwnd.AddText("XM+10 Y+10 vVimAppListText", this.Vim.GetDescription("VimAppList")) + if(this.Vim.GetVal("VimAppList") == "All"){ matchapplist := 1 - }else if(this.GetVal("VimAppList") == "Allow List"){ + }else if(this.Vim.GetVal("VimAppList") == "Allow List"){ matchapplist := 2 }else{ matchapplist := 3 } this.Hwnd.AddDDL("X+5 Y+-16 W100 vVimAppList Choose" matchapplist, ["All", "Allow List", "Deny List"]) this.HwndAll.Push(this.Hwnd["VimAppList"]) - this.Hwnd.AddText("XM+10 Y+5 vVimGroupText", this.GetDescription("VimGroup")) - this.Hwnd.AddEdit("XM+10 Y+5 R10 W300 Multi vVimGroup", StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1)) + this.Hwnd.AddText("XM+10 Y+5 vVimGroupText", this.Vim.GetDescription("VimGroup")) + this.Hwnd.AddEdit("XM+10 Y+5 R10 W300 Multi vVimGroup", StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1)) this.HwndAll.Push(this.Hwnd["VimGroup"]) this.Hwnd.AddText("XM+10 Y+10", "Check") this.Hwnd.SetFont("Underline") @@ -94,33 +94,33 @@ class VimSetting Extends VimGui{ UpdateGuiValue(){ for i, k in this.Vim.Checkboxes { - this.Hwnd[k].Value := this.GetVal(k) + this.Hwnd[k].Value := this.Vim.GetVal(k) } - this.Hwnd["VimTwoLetter"].Value := StrReplace(this.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) - this.Hwnd["VimDisableUnused"].Value := this.GetVal("VimDisableUnused") - this.Hwnd["VimIconCheckInterval"].Value := this.GetVal("VimIconCheckInterval") - if(this.GetVal("VimSetTitleMatchMode") == "RegEx"){ + this.Hwnd["VimTwoLetter"].Value := StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) + this.Hwnd["VimDisableUnused"].Value := this.Vim.GetVal("VimDisableUnused") + this.Hwnd["VimIconCheckInterval"].Value := this.Vim.GetVal("VimIconCheckInterval") + if(this.Vim.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ - matchmode := this.GetVal("VimSetTitleMatchMode") + matchmode := this.Vim.GetVal("VimSetTitleMatchMode") } this.Hwnd["VimSetTitleMatchMode"].Value := matchmode - if(this.GetVal("VimSetTitleMatchModeFS") == "Fast"){ + if(this.Vim.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } this.Hwnd["VimSetTitleMatchModeFS"].Value := matchmodefs - this.Hwnd["VimVerbose"].Value := this.GetVal("VimVerbose") - if(this.GetVal("VimAppList") == "All"){ + this.Hwnd["VimVerbose"].Value := this.Vim.GetVal("VimVerbose") + if(this.Vim.GetVal("VimAppList") == "All"){ matchapplist := 1 - }else if(this.GetVal("VimAppList") == "Allow List"){ + }else if(this.Vim.GetVal("VimAppList") == "Allow List"){ matchapplist := 2 }else{ matchapplist := 3 } this.Hwnd["VimAppList"].Value := matchapplist - this.Hwnd["VimGroup"].Value := StrReplace(this.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) + this.Hwnd["VimGroup"].Value := StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) } VimV2Conf(){ @@ -165,28 +165,6 @@ class VimSetting Extends VimGui{ return result } - VimDefault2V(){ - for k, v in this.Vim.Conf { - v["val"] := v["default"] - } - } - - GetConf(Name, Key){ - return this.Vim.Conf[Name][Key] - } - - GetVal(Name){ - return this.GetConf(Name, "val") - } - - GetDefault(Name){ - return this.GetConf(Name, "default") - } - - GetDescription(name){ - return this.GetConf(Name, "description") - } - OK(Btn, Info){ this.Hwnd.Submit() this.VimV2Conf() @@ -200,7 +178,7 @@ class VimSetting Extends VimGui{ } Reset(Btn, Info){ - this.VimDefault2V() + this.Vim.SetConfDefault() this.UpdateGuiValue() } } From 55cdbf9cef33912979d5c2d31fc991b6271febec Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Mon, 30 Sep 2024 06:26:55 +0900 Subject: [PATCH 73/75] fix: tooltip --- lib/vim_about.ahk | 27 ++++----- lib/vim_ahk.ahk | 40 ++++++------- lib/vim_gui.ahk | 64 +++++++++------------ lib/vim_setting.ahk | 133 ++++++++++++++++++++++---------------------- lib/vim_tooltip.ahk | 5 +- 5 files changed, 123 insertions(+), 146 deletions(-) diff --git a/lib/vim_about.ahk b/lib/vim_about.ahk index d91b837..55bf134 100644 --- a/lib/vim_about.ahk +++ b/lib/vim_about.ahk @@ -5,8 +5,6 @@ class VimAbout Extends VimGui{ __New(Vim){ super.__New(Vim, "Vim Ahk") - this.Vim := Vim - this.Version := "" this.Date := "" this.Author := "" @@ -16,21 +14,20 @@ class VimAbout Extends VimGui{ } MakeGui(){ - this.Hwnd.Opt("-MinimizeBox -Resize") - this.Hwnd.AddText(, "Vim Ahk (vim_ahk):`n" this.Description) - this.Hwnd.SetFont("Underline") - this.Hwnd.AddText("Y+0 cBlue vVimHomepage", this.Homepage).OnEvent("Click", this.OpenHomepageObj) - this.Hwnd.SetFont("Norm") - this.Hwnd.AddText(, "Author: " this.Author) - this.Hwnd.AddText(, "Version: " this.Version) - this.Hwnd.AddText("Y+0", "Last update: " this.Date) - this.Hwnd.AddText(, "Script path:`n%this.Vim.ScriptPath%") - this.Hwnd.AddText(, "Setting file:`n" this.Vim.Ini.Ini) - this.Hwnd.AddButton("X200 W100 Default vVimAboutOK", "OK").OnEvent("Click", this.OKObj) - this.HwndAll.Push(this.Hwnd["VimAboutOK"]) + this.Obj.Opt("-MinimizeBox -Resize") + this.Obj.AddText(, "Vim Ahk (vim_ahk):`n" this.Description) + this.Obj.SetFont("Underline") + this.AddClick("Text", "Y+0 cBlue", this.Homepage, this.Vim.about.OpenHomepageObj, this.Homepage) + this.Obj.SetFont("Norm") + this.Obj.AddText(, "Author: " this.Author) + this.Obj.AddText(, "Version: " this.Version) + this.Obj.AddText("Y+0", "Last update: " this.Date) + this.Obj.AddText(, "Script path:`n%this.Vim.ScriptPath%") + this.Obj.AddText(, "Setting file:`n" this.Vim.Ini.Ini) + this.AddClick("Button", "X200 W100 Default", "OK", this.OKObj) } - OpenHomepage(Btn, Info){ + OpenHomepage(Obj, Info){ this.Vim.VimToolTip.RemoveToolTip() Run(this.Homepage) } diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index 3432bb5..a6d09f3 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -25,7 +25,6 @@ class VimAhk{ this.About.Author := "rcmdnk" this.About.Description := "Vim emulation with AutoHotkey, everywhere in Windows." this.About.Homepage := "https://github.com/rcmdnk/vim_ahk" - this.Info["VimHomepage"] := this.About.Homepage } __New(ScriptPath){ @@ -149,21 +148,6 @@ class VimAhk{ this.CheckBoxes := ["VimEscNormal", "VimSendEscNormal", "VimLongEscNormal", "VimCtrlBracketToEsc", "VimCtrlBracketNormal", "VimSendCtrlBracketNormal", "VimLongCtrlBracketNormal", "VimRestoreIME", "VimJJ", "VimChangeCaretWidth"] - ; ToolTip Information - this.Info := Map() - for k, v in this.Conf { - info := k ":`n" v["info"] - this.Info[k] := info - for i, t_type in ["Text", "List", "Value", "Edit"] { - textKey := k t_type - this.Info[textKey] := info - } - } - - this.Info["VimSettingOK"] := "Reflect changes and exit" - this.Info["VimSettingReset"] := "Reset to the default values" - this.Info["VimSettingCancel"] := "Don't change and exit" - ; Initialize this.Initialize() } @@ -189,20 +173,24 @@ class VimAhk{ ;} } - GetConf(Name, Key){ - return this.Conf[Name][Key] + GetConf(Key, Data){ + return this.Conf[Key][Data] } - GetVal(Name){ - return this.GetConf(Name, "val") + GetVal(Key){ + return this.GetConf(Key, "val") } - GetDefault(Name){ - return this.GetConf(Name, "default") + GetDefault(Key){ + return this.GetConf(Key, "default") } - GetDescription(name){ - return this.GetConf(Name, "description") + GetDescription(Key){ + return this.GetConf(Key, "description") + } + + GetInfo(Key){ + return this.GetConf(Key, "info") } SetGroup(){ @@ -292,4 +280,8 @@ class VimAhk{ BlockInput("Off") Return ret } + + AddToolTip(Hwnd, Text){ + this.VimToolTip.Info[Hwnd] := Text + } } diff --git a/lib/vim_gui.ahk b/lib/vim_gui.ahk index ac3c1dd..16a2206 100644 --- a/lib/vim_gui.ahk +++ b/lib/vim_gui.ahk @@ -1,60 +1,46 @@ class VimGui{ __New(Vim, Title){ this.Vim := Vim - this.Hwnd := 0 - this.HwndAll := [] + this.Obj := 0 this.Title := Title + this.HideObj := ObjBindMethod(this, "Hide") this.OKObj := ObjBindMethod(this, "OK") } - ShowGui(ItemName, ItemPos, MyMenu){ - if(this.Hwnd == 0){ - this.Hwnd := Gui("", this.Title) - this.HwndAll.Push(this.Hwnd) - this.MakeGui() - OnMessage(0x112, ObjBindMethod(this, "OnClose")) - OnMessage(0x100, ObjBindMethod(this, "OnEscape")) - }else{ - this.UpdateGui() - } - this.Hwnd.Show() - } - - MakeGui(){ - this.Hwnd.AddButton("X200 W100 Default vGuiOK", "OK").OnEvent("Click", this.OKObj) - this.HwndAll.Push(this.Hwnd["GuiOK"]) + Hide(Obj){ + this.Vim.VimToolTip.RemoveToolTip() + this.Obj.Hide() } - UpdateGui(){ + OK(Obj, Info){ + this.Hide(Obj) } - Hide(){ - this.Vim.VimToolTip.RemoveToolTip() - this.Hwnd.Hide() + AddClick(ControlType, Option, Text, Callback, ToolTipText:=""){ + Obj := this.Obj.Add(ControlType, Option, Text) + Obj.OnEvent("Click", Callback) + if(ToolTipText != ""){ + this.Vim.AddToolTip(Obj.Hwnd, ToolTipText) + } } - OK(Btn, Info){ - this.Hide() + MakeGui(){ + this.AddClick("Button", "X200 W100 Default", "OK", this.OKObj) } - IsThisWindow(Hwnd){ - for i, h in this.HwndAll { - if(Hwnd == h){ - Return True - } - } - Return False + UpdateGui(){ } - OnClose(Wp, Lp, Msg, Hwnd){ - if(Wp == 0xF060 && Hwnd == this.Hwnd){ - this.Hide() + ShowGui(ItemName, ItemPos, MyMenu){ + if(this.Obj == 0){ + this.Obj := Gui("", this.Title) + this.MakeGui() + this.Obj.OnEvent("Close", this.HideObj) + this.Obj.OnEvent("Escape", this.HideObj) + }else{ + this.UpdateGui() } + this.Obj.Show() } - OnEscape(Wp, Lp, Msg, Hwnd){ - if(Wp == 27 && this.IsThisWindow(Hwnd)){ - this.Hide() - } - } } diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index be29d9d..7eb4302 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -1,23 +1,39 @@ #Include %A_LineFile%\..\vim_gui.ahk +DoNothing(Obj, Info){ +} + class VimSetting Extends VimGui{ __New(Vim){ super.__New(Vim, "Vim Ahk Settings") - this.Vim := Vim - - this.OKObj := ObjBindMethod(this, "OK") this.ResetObj := ObjBindMethod(this, "Reset") this.CancelObj := ObjBindMethod(this, "Cancel") } + AddConf(ControlType, Key, Options, Text:="", V:=False){ + if(ControlType == "Text"){ + Text := this.Vim.GetDescription(Key) + } + if(V){ + Options := Options " v" Key + } + Obj := this.Obj.Add(ControlType, Options, Text) + if(ControlType == "Text"){ + ; Pseudo click event to show tooltop + Obj.OnEvent("Click", DoNothing) + } + this.Vim.AddToolTip(Obj.Hwnd, this.Vim.GetInfo(Key)) + } + MakeGui(){ - this.Hwnd.Opt("-MinimizeBox -Resize") + this.Obj.Opt("-MinimizeBox -Resize") created := 0 for i, k in this.Vim.Checkboxes { if(created == 0){ y := "YM" + created := 1 }else{ y := "Y+10" } @@ -26,40 +42,32 @@ class VimSetting Extends VimGui{ }else{ x := "10" } - this.Hwnd.AddCheckbox(k " XM+" x " " y " v" k, this.Vim.GetDescription(k)) - this.HwndAll.Push(this.Hwnd[k]) - created := 1 - this.Hwnd[k].Value := this.Vim.GetVal(k) + this.AddConf("Checkbox", k, "XM+" x " " y, this.Vim.GetDescription(k), True) + this.Obj[k].Value := this.Vim.GetVal(k) } - this.Hwnd.AddText("XM+10 Y+15 vVimTwoLetterText", this.Vim.GetDescription("VimTwoLetter")) - this.Hwnd.AddEdit("XM+10 Y+5 R4 W100 Multi vVimTwoLetter", StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1)) - this.Hwnd.AddText("XM+10 Y+15 vVimDisableUnusedText", this.Vim.GetDescription("VimDisableUnused")) - this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimDisableUnused Choose" this.Vim.GetVal("VimDisableUnused"), [1, 2, 3]) - this.HwndAll.Push(this.Hwnd["VimDisableUnused"]) - this.Hwnd.AddText("XM+10 Y+15 vVimSetTitleMatchModeText", this.Vim.GetDescription("VimSetTitleMatchMode")) + this.AddConf("Text", "VimTwoLetter", "XM+10 Y+15") + this.AddConf("Edit", "VimTwoLetter", "XM+10 Y+5 R4 W100 Multi", StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1), True) + this.AddConf("Text", "VimDisableUnused", "XM+10 Y+15") + this.AddConf("DDL", "VimDisableUnused", "X+5 Y+-16 W30 Choose" this.Vim.GetVal("VimDisableUnused"), [1, 2, 3], True) + this.AddConf("Text", "VimSetTitleMatchMode", "XM+10 Y+15") if(this.Vim.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ matchmode := this.Vim.GetVal("VimSetTitleMatchMode") } - this.Hwnd.AddDDL("X+5 Y+-16 W60 vVimSetTitleMatchMode Choose" matchmode, [1, 2, 3, "RegEx"]) - this.HwndAll.Push(this.Hwnd["VimSetTitleMatchMode"]) + this.AddConf("DDL","VimSetTitleMatchMode", "X+5 Y+-16 W60 Choose" matchmode, [1, 2, 3, "RegEx"], True) if(this.Vim.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } - this.Hwnd.AddDDL("X+5 Y+-20 W50 vVimSetTitleMatchModeFS Choose" matchmodefs, ["Fast", "Slow"]) - this.HwndAll.Push(this.Hwnd["VimSetTitleMatchModeFS"]) - this.Hwnd.AddText("XM+10 Y+10 vVimIconCheckIntervalText", this.Vim.GetDescription("VimIconCheckInterval")) - this.Hwnd.AddEdit("X+5 Y+-16 W70 vVimIconCheckIntervalEdit") - this.HwndAll.Push(this.Hwnd["VimIconCheckIntervalEdit"]) - this.Hwnd.AddUpDown("vVimIconCheckInterval Range0-1000000", this.Vim.GetVal("VimIconCheckInterval")) - this.HwndAll.Push(this.Hwnd["VimIconCheckInterval"]) - this.Hwnd.AddText("XM+10 Y+10 vVimVerboseText", this.Vim.GetDescription("VimVerbose")) - this.Hwnd.AddDDL("X+5 Y+-16 W30 vVimVerbose Choose" this.Vim.GetVal("VimVerbose"), [1, 2, 3, 4]) - this.HwndAll.Push(this.Hwnd["VimVerbose"]) - this.Hwnd.AddText("XM+10 Y+10 vVimAppListText", this.Vim.GetDescription("VimAppList")) + this.AddConf("DDL", "VimSetTitleMatchModeFS", "X+5 Y+-20 W50 Choose" matchmodefs, ["Fast", "Slow"], True) + this.AddConf("Text", "VimIconCheckInterval", "XM+10 Y+10") + this.AddConf("Edit", "VimIconCheckInterval", "X+5 Y+-16 W70") + this.AddConf("UpDown", "VimIconCheckInterval", "Range0-1000000", this.Vim.GetVal("VimIconCheckInterval"), True) + this.AddConf("Text", "VimVerbose", "XM+10 Y+10") + this.AddConf("DDL", "VimVerbose", "X+5 Y+-16 W30 Choose" this.Vim.GetVal("VimVerbose"), [1, 2, 3, 4], True) + this.AddConf("Text", "VimAppList", "XM+10 Y+10") if(this.Vim.GetVal("VimAppList") == "All"){ matchapplist := 1 }else if(this.Vim.GetVal("VimAppList") == "Allow List"){ @@ -67,25 +75,18 @@ class VimSetting Extends VimGui{ }else{ matchapplist := 3 } - this.Hwnd.AddDDL("X+5 Y+-16 W100 vVimAppList Choose" matchapplist, ["All", "Allow List", "Deny List"]) - this.HwndAll.Push(this.Hwnd["VimAppList"]) - this.Hwnd.AddText("XM+10 Y+5 vVimGroupText", this.Vim.GetDescription("VimGroup")) - this.Hwnd.AddEdit("XM+10 Y+5 R10 W300 Multi vVimGroup", StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1)) - this.HwndAll.Push(this.Hwnd["VimGroup"]) - this.Hwnd.AddText("XM+10 Y+10", "Check") - this.Hwnd.SetFont("Underline") - this.Hwnd.AddText("X+5 cBlue vVimHomepage", "HELP").OnEvent("Click", this.Vim.about.OpenHomepageObj) - this.Hwnd.SetFont("Norm") - this.Hwnd.AddText("X+5", "for further information.") - - this.Hwnd.AddButton("vVimSettingOK X10 W100 Y+10 Default", "OK").OnEvent("Click", this.OKObj) - this.HwndAll.Push(this.Hwnd["VimSettingOK"]) - - this.Hwnd.AddButton("vVimSettingReset W100 X+10", "Reset").OnEvent("Click", this.ResetObj) - this.HwndAll.Push(this.Hwnd["VimSettingReset"]) + this.AddConf("DDL", "VimAppList", "X+5 Y+-16 W100 Choose" matchapplist, ["All", "Allow List", "Deny List"], True) + this.AddConf("Text", "VimGroup", "XM+10 Y+5") + this.AddConf("Edit", "VimGroup", "XM+10 Y+5 R10 W300 Multi", StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1), True) + this.Obj.AddText("XM+10 Y+10", "Check") + this.Obj.SetFont("Underline") + this.AddClick("Text", "X+5 cBlue", "HELP", this.Vim.about.OpenHomepageObj, this.Vim.About.Homepage) + this.Obj.SetFont("Norm") + this.Obj.AddText("X+5", "for further information.") - this.Hwnd.AddButton("vVimSettingCancel W100 X+10", "Cancel").OnEvent("Click", this.CancelObj) - this.HwndAll.Push(this.Hwnd["VimSettingCancel"]) + this.AddClick("Button", "X10 W100 Y+10 Default", "OK", this.OKObj, "Reflect changes and exit") + this.AddClick("Button", "X+10 W100", "Reset", this.ResetObj, "Reset to the default values") + this.AddClick("Button", "X+10 W100", "Cancel", this.CancelObj, "Don't change and exit") } UpdateGui(){ @@ -94,24 +95,24 @@ class VimSetting Extends VimGui{ UpdateGuiValue(){ for i, k in this.Vim.Checkboxes { - this.Hwnd[k].Value := this.Vim.GetVal(k) + this.Obj[k].Value := this.Vim.GetVal(k) } - this.Hwnd["VimTwoLetter"].Value := StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) - this.Hwnd["VimDisableUnused"].Value := this.Vim.GetVal("VimDisableUnused") - this.Hwnd["VimIconCheckInterval"].Value := this.Vim.GetVal("VimIconCheckInterval") + this.Obj["VimTwoLetter"].Value := StrReplace(this.Vim.GetVal("VimTwoLetter"), this.Vim.GroupDel, "`n", 0, , -1) + this.Obj["VimDisableUnused"].Value := this.Vim.GetVal("VimDisableUnused") + this.Obj["VimIconCheckInterval"].Value := this.Vim.GetVal("VimIconCheckInterval") if(this.Vim.GetVal("VimSetTitleMatchMode") == "RegEx"){ matchmode := 4 }else{ matchmode := this.Vim.GetVal("VimSetTitleMatchMode") } - this.Hwnd["VimSetTitleMatchMode"].Value := matchmode + this.Obj["VimSetTitleMatchMode"].Value := matchmode if(this.Vim.GetVal("VimSetTitleMatchModeFS") == "Fast"){ matchmodefs := 1 }else{ matchmodefs := 2 } - this.Hwnd["VimSetTitleMatchModeFS"].Value := matchmodefs - this.Hwnd["VimVerbose"].Value := this.Vim.GetVal("VimVerbose") + this.Obj["VimSetTitleMatchModeFS"].Value := matchmodefs + this.Obj["VimVerbose"].Value := this.Vim.GetVal("VimVerbose") if(this.Vim.GetVal("VimAppList") == "All"){ matchapplist := 1 }else if(this.Vim.GetVal("VimAppList") == "Allow List"){ @@ -119,32 +120,32 @@ class VimSetting Extends VimGui{ }else{ matchapplist := 3 } - this.Hwnd["VimAppList"].Value := matchapplist - this.Hwnd["VimGroup"].Value := StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) + this.Obj["VimAppList"].Value := matchapplist + this.Obj["VimGroup"].Value := StrReplace(this.Vim.GetVal("VimGroup"), this.Vim.GroupDel, "`n", 0, , -1) } VimV2Conf(){ for k, v in this.Vim.Conf { if(k == "VimGroup" || k == "VimTwoLetter"){ - v["val"] := this.VimParseList(this.Hwnd[k].Value) - }else if(k == "VimSetTitleMatchMode" && this.Hwnd[k].Value == 4){ + v["val"] := this.VimParseList(this.Obj[k].Value) + }else if(k == "VimSetTitleMatchMode" && this.Obj[k].Value == 4){ v["val"] := "RegEx" }else if(k == "VimSetTitleMatchModeFS"){ - if(this.Hwnd[k].Value == 1){ + if(this.Obj[k].Value == 1){ v["val"] := "Fast" }else{ v["val"] := "Slow" } }else if(k == "VimAppList"){ - if(this.Hwnd[k].Value == 1){ + if(this.Obj[k].Value == 1){ v["val"] = "All" - }else if(this.Hwnd[k].Value == 2){ + }else if(this.Obj[k].Value == 2){ v["val"] = "Allow List" }else{ v["val"] = "Deny List" } }else{ - v["val"] := this.Hwnd[k].Value + v["val"] := this.Obj[k].Value } } } @@ -165,19 +166,19 @@ class VimSetting Extends VimGui{ return result } - OK(Btn, Info){ - this.Hwnd.Submit() + OK(Obj, Info){ + this.Obj.Submit() this.VimV2Conf() this.Vim.Setup() this.vim.Ini.WriteIni() - this.Hide() + this.Hide(Obj) } - Cancel(Btn, Info){ - this.Hide() + Cancel(Obj, Info){ + this.Hide(Obj) } - Reset(Btn, Info){ + Reset(Obj, Info){ this.Vim.SetConfDefault() this.UpdateGuiValue() } diff --git a/lib/vim_tooltip.ahk b/lib/vim_tooltip.ahk index 6d8cd5c..8463bb9 100644 --- a/lib/vim_tooltip.ahk +++ b/lib/vim_tooltip.ahk @@ -1,6 +1,7 @@ class VimToolTip{ __New(Vim){ this.Vim := Vim + this.Info := Map() this.DisplayToolTipObj := ObjBindMethod(this, "DisplayToolTip") this.RemoveToolTipObj := ObjBindMethod(this, "RemoveToolTip") @@ -12,7 +13,7 @@ class VimToolTip{ if(this.Vim.State.CurrControl != this.Vim.State.PrevControl){ this.Vim.State.PrevControl := this.Vim.State.CurrControl this.RemoveToolTip() - if(this.Vim.Info.Has(this.Vim.State.CurrControl)){ + if(this.Info.Has(this.Vim.State.CurrControl)){ display := this.DisplayToolTipObj SetTimer(display, -1000) } @@ -22,7 +23,7 @@ class VimToolTip{ DisplayToolTip(){ display := this.DisplayToolTipObj SetTimer(display, 0) - ToolTip(this.Vim.Info[this.Vim.State.CurrControl]) + ToolTip(this.Info[this.Vim.State.CurrControl]) this.SetRemoveToolTip(60000) } From 9680a7dd3f7926af9341e07787cdf9dcf5c3eca7 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Mon, 30 Sep 2024 06:44:55 +0900 Subject: [PATCH 74/75] fix: check pre-defined values --- lib/vim_ahk.ahk | 14 ++++++-------- lib/vim_setting.ahk | 5 +---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/vim_ahk.ahk b/lib/vim_ahk.ahk index a6d09f3..d4c2d00 100644 --- a/lib/vim_ahk.ahk +++ b/lib/vim_ahk.ahk @@ -163,14 +163,12 @@ class VimAhk{ } SetExistValue(){ - ; Need some way to retrieve default values (v-label values are removed from vim_ahk for v2) - ;for k, v in this.Conf { - ; ; This ensures the variable exists, as a workaround since in AHK we cannot directly check whether it exists. - ; if(%k% != ""){ - ; this.Conf[k]["default"] := %k% - ; this.Conf[k]["val"] := %k% - ; } - ;} + for k, v in this.Conf { + if(IsSet(%k%)){ + v["default"] := %k% + v["val"] := %k% + } + } } GetConf(Key, Data){ diff --git a/lib/vim_setting.ahk b/lib/vim_setting.ahk index 7eb4302..c249f4e 100644 --- a/lib/vim_setting.ahk +++ b/lib/vim_setting.ahk @@ -1,9 +1,6 @@ #Include %A_LineFile%\..\vim_gui.ahk -DoNothing(Obj, Info){ -} - class VimSetting Extends VimGui{ __New(Vim){ super.__New(Vim, "Vim Ahk Settings") @@ -22,7 +19,7 @@ class VimSetting Extends VimGui{ Obj := this.Obj.Add(ControlType, Options, Text) if(ControlType == "Text"){ ; Pseudo click event to show tooltop - Obj.OnEvent("Click", DoNothing) + Obj.OnEvent("Click", DoNothing(Obj, Info) => "") } this.Vim.AddToolTip(Obj.Hwnd, this.Vim.GetInfo(Key)) } From 3cae41c8039765b2c9308e42b67be82dce8997b6 Mon Sep 17 00:00:00 2001 From: rcmdnk Date: Mon, 30 Sep 2024 06:50:47 +0900 Subject: [PATCH 75/75] docs: add note about Vim variable behavior and reset option in README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1e32332..c9e339f 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,12 @@ in the auto execute section like: If you want to change them directly in the vim.ahk script, add these variable before `Vim := new VimAhk()`. +> [!NOTE] +> These Vim variables will overwrite the default values and initial values. +> After checking these variables, the configuration file is read. +> If you have already run vim_ahk, the configuration file was created and all the settings were saved. +> To reflect the new settings, try `Reset` in the GUI option setting window. + > [!NOTE] > VimIconCheckInterval example >