Page 1 of 2
Good News! Fuzzy Completion!
Posted: Fri Apr 05, 2024 7:35 am
by Piero
I had to hack a bit because of IDE 6.10 "selection" problems… anyway here's version 0.0001a1!
See links for needed support stuff (e.g. fzf, if you cannot use brew…)
I plan to add completion of entire lines (procedures etc.) and more, must be easy now; just some regex here and there, and mostly on stuff already inside PureBasic.app… but I better wait until the IDE will be a bit more "stable"……
Apropos, did you ppl see what TextMate can do? Try "Edit Bundles"!
Anyway, I also made a 18-hours video explaining the basics of my creation… Enjoy!
Video (dedicated to Idle)
PB Text File
fzf silicon from brew install
New VIDEO dedicated to pf shadoko
READ POSTS BELOW FOR UPDATES!
AppleScript IDE tool:
Code: Select all
set pargr to "" -- Mac IDE Tool (no parameters needed) for Fuzzy Autocomplete!!!
try
tell application "PureBasic" to activate
tell application "System Events"
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 ¬
of splitter group 1 of splitter group 1 of window 1 of application process "PureBasic"
repeat 16 times -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using shift down
end repeat
delay 0.1
tell scint to set sel to value of attribute "AXSelectedText"
set nc to count last word of sel
tell application process "PureBasic" to key code 124
repeat nc times
tell application process "PureBasic" to key code 123 using shift down
end repeat -- END of HACK… 10 lines instead of 1… grrr…
set src to words of ((value of scint) as string)
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set src to src as text
set AppleScript's text item delimiters to ASTID
set src to quoted form of src
tell scint to set sel to value of attribute "AXSelectedText" -- Paths to support file and app below…
set pargr to paragraphs 2 thru -1 of (do shell script ¬
"echo " & src & " | cat - ~/bin/pb.txt | sort -u | /opt/homebrew/bin/fzf -i -f " & sel)
tell application "PureBasic" to set pargr to choose from list pargr default items {item 1 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end tell
end try
Huh?
Posted: Fri Apr 05, 2024 5:58 pm
by Piero
No comments?
I think it's better this way: I don't really wanna sell my old Macs; I Love them
Re: Good News! Fuzzy Completion!
Posted: Sat Apr 06, 2024 10:01 am
by Fred
Good idea, I use this a lot in VS/Resharper IDE
Re: Good News! Fuzzy Completion!
Posted: Sun Apr 07, 2024 12:58 am
by idle
Piero wrote: Fri Apr 05, 2024 7:35 am
Anyway, I also made a 18-hours video explaining the basics of my creation… Enjoy!
Video (dedicated to Idle)
Pineapple Pizza on the menu and I'll try one of those Scottish delicacies a Deep fried Mars bar.

Re: Good News! Fuzzy Completion!
Posted: Sun Apr 07, 2024 11:01 am
by Piero
"Regex PB words" version 0.0001a2
Note: you may need to launch it (as IDE tool) with its binary path:
Fuzzy.app/Contents/MacOS/applet
Anyway, you can also run it with a global launcher…
Code: Select all
-- Mac IDE Tool (no parameters needed) for Fuzzy Autocomplete!!! - Paths to support stuff on line below
property exp : " | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?' | cat - ~/bin/pb.txt | sort -u | /opt/homebrew/bin/fzf -i -f "
try
tell application "PureBasic" to activate
tell application "System Events"
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 ¬
of splitter group 1 of splitter group 1 of window 1 of application process "PureBasic"
set src to ((value of scint) as string)
repeat 16 times -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using shift down
end repeat
delay 0.1
tell scint to set sel to value of attribute "AXSelectedText"
set nc to count last word of sel
tell application process "PureBasic" to key code 124
repeat nc times
tell application process "PureBasic" to key code 123 using shift down
end repeat -- END of HACK… 10 lines instead of 1… grrr…
tell scint to set sel to value of attribute "AXSelectedText"
copy paragraphs 2 thru -1 of (do shell script "echo " & quoted form of src & exp & sel) to pargr
tell application "PureBasic" to set pargr to choose from list pargr default items {item 1 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end tell
end try
Update!
Posted: Tue Apr 09, 2024 10:54 am
by Piero
Version 0.0001a3
Added all the "function prototypes" of PB help to the
Support File
Added procedures completion (the regex I used needs
Homebrew's
ggrep: it can be very useful!)
Enjoy!
Code: Select all
-- AppleScript PB IDE Tool (no parameters needed) for Fuzzy Autocomplete!
property exp : " | cat - ~/bin/pb.txt | sort -u | /opt/homebrew/bin/fzf -i -f " -- paths to support stuff here
property ggrep : " | /opt/homebrew/bin/ggrep " -- gnu grep path ; it will be called ggrep
tell application "PureBasic" to activate -- just in case (needed only for app launchers/debug)
tell application "System Events"
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 of application process "PureBasic" -- in this case, only for better code readability…
repeat 16 times -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using shift down
end repeat
delay 0.1
tell scint to set sel to ((value of attribute "AXSelectedText") as string)
set nc to count last word of sel
tell application process "PureBasic" to key code 124
repeat nc times
tell application process "PureBasic" to key code 123 using shift down
end repeat -- END of HACK… 10 lines instead of 1… grrr…
tell scint to set sel to value of attribute "AXSelectedText"
delay 0.1
tell application process "PureBasic" to key code 51 -- delete (exclude from source)
set src to quoted form of ((value of scint) as string) -- source
set fsrc to (do shell script "echo " & src & " | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?'") & "\n" -- extract PB "words"
set fsrc to fsrc & (do shell script "echo " & src & ggrep & "-Poi '[^;]*procedure\\w*\\s+\\K.*\\)'") & "\n" -- add source procedures
copy {sel} & paragraphs of (do shell script "echo " & quoted form of fsrc & exp & quoted form of sel) to pargr
try
tell application "PureBasic" to set pargr to choose from list pargr default items {item 2 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end try
end tell
Edit/PS:
Code: Select all
tell application process "PureBasic" to key code 53 -- press esc
It took less than 2 minutes to extract "function prototypes" from PB help, with TextMate

Re: Good News! Fuzzy Completion!
Posted: Thu Apr 11, 2024 10:34 am
by Piero
Version 0.0001a5
Trapped possible errors, also bugfixing the "no procedures" error (remember: it needs homebrew ggrep)
Added some cocoa to detect option key up (my shortcut is ⌥Z)
Added esc in case of PB autocomplete open
Fixed sort
Code: Select all
-- AppleScript PB IDE Tool (no parameters needed) for Fuzzy Autocomplete!
property exp : " | cat - ~/bin/pb.txt | /opt/homebrew/bin/fzf -i -f " -- paths to support stuff here
property ggrep : " | /opt/homebrew/bin/ggrep " -- gnu grep path; it will be called ggrep
use AppleScript version "2.3" -- Mavericks (10.9) or later
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSEvent
tell application "PureBasic" to activate -- just in case (needed only for app launchers/debug)
tell application "System Events"
repeat -- wait for option key up (PB shortcut)
if not (((current application's NSEvent's modifierFlags()) div (current application's NSAlternateKeyMask as integer)) mod 2) > 0 then exit repeat
delay 0.3
end repeat
tell application process "PureBasic" to key code 53 -- press esc
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 of application process "PureBasic" -- in this case, only for better code readability…
repeat 16 times -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using shift down
end repeat
delay 0.1
tell scint to set sel to ((value of attribute "AXSelectedText") as string)
set nc to count last word of ("Error " & sel)
tell application process "PureBasic" to key code 124
repeat nc times
tell application process "PureBasic" to key code 123 using shift down
end repeat -- END of HACK… 10 lines instead of 1… grrr…
tell scint to set sel to value of attribute "AXSelectedText"
delay 0.1
tell application process "PureBasic" to key code 51 -- delete (exclude from source)
set src to quoted form of ((value of scint) as string) -- source
set fsrc to (do shell script "(echo " & src & " | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?' | sort -u ) || echo Debug") & "\n" -- extract PB "words"
set fsrc to fsrc & (do shell script "(echo " & src & ggrep & "-Poi '[^;]*procedure\\w*\\s+\\K.*\\)' | sort -u ) || echo Debug") & "\n" -- add source procedures
if sel is not "" then copy {sel} & paragraphs of (do shell script "(echo " & quoted form of fsrc & exp & quoted form of sel & ") || echo Debug") to pargr
try
tell application "PureBasic" to set pargr to choose from list pargr default items {item 2 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end try
end tell
Re: Good News! Fuzzy Completion!
Posted: Thu Apr 11, 2024 2:00 pm
by Piero
I imagine the Gurus of this Forum seeing "delay 0.3"… it must feel like I would feel eating pineapple pizza with ketchup
Update
Posted: Fri Apr 12, 2024 5:24 pm
by Piero
Small update to script above because sort -u pipe wasn't working as expected
Finally! Fuzzy Autocomplete!
Posted: Sat Apr 13, 2024 6:01 am
by Piero
I found what the problem was! Hint:
\r!!!
Now works very well! (at least on Monterey M1)
Version 0.0001b1
Optimized the delays (for my Mac…)
Put a minimum of 3 characters needed (max is 16, see the hack…)
Updated procedure regex
See
VIDEO!
Needs:
Support Text File (updated Apr 09, 2024)
Homebrew's
fzf
Homebrew's
ggrep
Enjoy!
Code: Select all
-- AppleScript PB IDE Tool (no parameters needed) for Fuzzy Autocomplete!
property exp : " | cat - ~/bin/pb.txt | tr '\r' '\n' | sort -u | /opt/homebrew/bin/fzf -i -f " -- paths to support stuff here
property ggrep : " | /opt/homebrew/bin/ggrep " -- homebrew gnu grep path; it will be called ggrep
use AppleScript version "2.3" -- Mavericks (10.9) or later
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSEvent
tell application "PureBasic" to activate -- just in case (needed only for app launchers/debug)
tell application "System Events"
repeat -- wait for option key up (PB shortcut)
if not (((current application's NSEvent's modifierFlags()) div (current application's NSAlternateKeyMask as integer)) mod 2) > 0 then exit repeat
delay 0.1
end repeat
tell application process "PureBasic" to key code 53 -- press esc
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of window 1 of application process "PureBasic" -- in this case, only for better code readability…
repeat 16 times -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using shift down
end repeat
delay 0.1
tell scint to set sel to ((value of attribute "AXSelectedText") as string)
set nc to count last word of ("Error " & sel)
tell application process "PureBasic" to key code 124
repeat nc times
tell application process "PureBasic" to key code 123 using shift down
end repeat -- END of HACK… 10 lines instead of 1… grrr…
tell scint to set sel to value of attribute "AXSelectedText"
set src to quoted form of ((value of scint) as string) -- source
set fsrc to (do shell script "(echo " & src & " | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?' ) || echo Debug") & "\n" -- extract PB "words"
set fsrc to fsrc & (do shell script "(echo " & src & ggrep & "-Poi '[^;]*procedure[.]?\\w*\\s+\\K.*\\)' ) || echo Debug") & "\n" -- add source procedures
if (count words of sel) > 0 and (count sel) > 2 then copy paragraphs of (do shell script "(echo " & quoted form of fsrc & exp & quoted form of sel & ") || echo Debug") to pargr
try
tell application "PureBasic" to set pargr to choose from list pargr default items {item 2 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end try
end tell
Video
Posted: Sat Apr 13, 2024 3:15 pm
by Piero
Have Fun!
Posted: Mon Apr 15, 2024 6:08 am
by Piero
Version 0.0001b2
Hacked my own hack

(found I could reliably read cursor position, so I used ⌥←)
Removed "option key wait" (
better use a simple shortcut like ⌥Z)
Added Macros (definition) so now you can "clearly" see how to add patterns
Needs:
Support Text File (updated Apr 09, 2024)
Homebrew's
fzf
Homebrew's
ggrep
Have Fun!
Piero
Code: Select all
-- AppleScript PB IDE Tool (no parameters needed) for Fuzzy Autocomplete!
property exp : " | cat - ~/bin/pb.txt | tr '\r' '\n' | sort -u | /opt/homebrew/bin/fzf -i -f " -- paths to support stuff here
property ggrep : " | /opt/homebrew/bin/ggrep " -- homebrew gnu grep path; it will be called ggrep
tell application "PureBasic" to activate -- just in case (needed only for app launchers/debug)
tell application "System Events"
tell application process "PureBasic" to key code 53 -- press esc
set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of item 1 of (windows of application process "PureBasic" whose name begins with "PureBasic") -- in this case, only for better code readability…
tell scint to set c1 to item 2 of (value of attribute "AXSelectedTextRange" as list) -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…
tell application process "PureBasic" to key code 123 using option down
tell scint to set c2 to item 2 of (value of attribute "AXSelectedTextRange" as list)
repeat c1 - c2 times
tell application process "PureBasic" to key code 124 using shift down
end repeat -- END HACK
delay 0.1
tell scint to set sel to value of attribute "AXSelectedText"
set src to quoted form of ((value of scint) as string) -- source
set fsrc to (do shell script "(echo " & src & " | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?' ) || echo Debug" without altering line endings) -- extract PB "words"
set fsrc to fsrc & (do shell script "(echo " & src & ggrep & "-Poi '[^;]*procedure[.]?\\w*\\s+\\K.*\\)' ) || echo Debug" without altering line endings) -- add source procedures
set fsrc to fsrc & (do shell script "(echo " & src & ggrep & "-Poi '[^;]*macro\\s+\\K\\w+\\s*(\\(.*\\))' ) || echo Debug" without altering line endings) -- add source macros
if (count words of sel) > 0 and (count sel) > 2 then copy paragraphs of (do shell script "(echo " & quoted form of fsrc & exp & quoted form of sel & ") || echo Debug") to pargr
try
tell application "PureBasic" to set pargr to choose from list pargr default items {item 2 of pargr}
tell application process "PureBasic" to keystroke {item 1 of pargr}
end try
end tell
Small edit: used "without altering line endings", but left "| tr '\r' '\n' |" (in case of "bad editing" of the support file…)
Edit: now also works with debugger open
PB Version!
Posted: Tue Apr 16, 2024 10:07 am
by Piero
Here's the PB version
It will parse all your (saved + open) source files
Enjoy!
Piero
Code: Select all
; PB IDE Tool (no parameters needed) for Fuzzy Autocomplete!
Procedure simpleShell(ShellCommand$)
Protected shell
shell = RunProgram("/bin/sh","","", #PB_Program_Open|#PB_Program_Write)
If shell
WriteProgramStringN(shell,ShellCommand$)
WriteProgramData(shell,#PB_Program_Eof,0)
CloseProgram(shell)
EndIf
EndProcedure
ExamineEnvironmentVariables()
PBSOURCES.s = GetEnvironmentVariable("PB_TOOL_FileList")
AScr.s = ~"osascript\n"+
~"set src to \"\"\n"+
~"repeat with i in paragraphs of \"" + PBSOURCES + ~"\"\n"+
~"set src to src & (do shell script \"cat \" & quoted form of i without altering line endings) & \"\\n\"\n"+
~"end repeat\n"+
~"set src to quoted form of src -- sources\n"+
~"property exp : \" | cat - ~/bin/pb.txt | tr '\\r' '\\n' | sort -u | /opt/homebrew/bin/fzf -i -f \" -- paths to support stuff here\n"+
~"property ggrep : \" | /opt/homebrew/bin/ggrep \" -- homebrew gnu grep path; it will be called ggrep\n"+
~"tell application \"PureBasic\" to activate -- just in case (needed only for app launchers/debug)\n"+
~"tell application \"System Events\"\n"+
~"tell application process \"PureBasic\" to key code 53 -- press esc\n"+
~"set scint to a reference to text area 1 of scroll area 1 of group 1 of group 1 of splitter group 1 of splitter group 1 of item 1 of (windows of application process \"PureBasic\" whose name begins with \"PureBasic\") -- in this case, only for better code readability…\n"+
~"tell scint to set c1 to item 2 of (value of attribute \"AXSelectedTextRange\" as list) -- HACK to bypass PB 6.10 IDE bug; ⌥← works, but ⌥⇧← does not…\n"+
~"tell application process \"PureBasic\" to key code 123 using option down\n"+
~"tell scint to set c2 to item 2 of (value of attribute \"AXSelectedTextRange\" as list)\n"+
~"repeat c1 - c2 times\n"+
~"tell application process \"PureBasic\" to key code 124 using shift down\n"+
~"end repeat -- END HACK\n"+
~"delay 0.1\n"+
~"tell scint to set sel to value of attribute \"AXSelectedText\"\n"+
~"set fsrc to (do shell script \"(echo \" & src & \" | grep -o -E '[*@#!]?[_a-zA-Z]+[0-9_a-zA-Z]*[$]?' ) || echo Debug\" without altering line endings) -- extract PB \"words\"\n"+
~"set fsrc to fsrc & (do shell script \"(echo \" & src & ggrep & \"-Poi '[^;]*procedure[.]?\\\\w*\\\\s+\\\\K.*\\\\)' ) || echo Debug\" without altering line endings) -- add source procedures\n"+
~"set fsrc to fsrc & (do shell script \"(echo \" & src & ggrep & \"-Poi '[^;]*macro\\\\s+\\\\K\\\\w+\\\\s*(\\\\(.*\\\\))' ) || echo Debug\" without altering line endings) -- add source macros\n"+
~"if (count words of sel) > 0 and (count sel) > 2 then copy paragraphs of (do shell script \"(echo \" & quoted form of fsrc & exp & quoted form of sel & \") || echo Debug\") to pargr\n"+
~"try\n"+
~"tell application \"PureBasic\" to set pargr to choose from list {sel} & pargr default items {item 1 of pargr}\n"+
~"tell application process \"PureBasic\" to keystroke {item 1 of pargr}\n"+
~"end try\n"+
~"end tell"
simpleShell(AScr)
Edit (18 Apr 2024): small tweak to default selection (only for this PB version).
Also Note: fzf was updated 4 days ago; now it's even faster!
Re: Good News! Fuzzy Completion!
Posted: Wed Apr 17, 2024 9:11 am
by pf shadoko
a video for me, great!
(after viewing, I'm a bit disappointed, I was thinking of a documentary on my life and work

)
since v6, the list of authorized constants is displayed for function Arguments, too bad it requires typing "#pb_" (especially for beginners)
Re: Good News! Fuzzy Completion!
Posted: Wed Apr 17, 2024 11:41 am
by Piero
pf shadoko wrote: Wed Apr 17, 2024 9:11 amsince v6, the list of authorized constants is displayed for function Arguments, too bad it requires typing "#pb_" (especially for beginners)
Yep, that's why I think fuzzy completion can be useful; it just takes some tries to learn how to type good "abbreviations"…
Dedicated to you for your amazing paysage work (that I also used to test this thing)
Thanks!