Skip to content

Instantly share code, notes, and snippets.

@llinfeng
Created November 4, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinfeng/5e6ba65c0278d7380aa064f250e00c06 to your computer and use it in GitHub Desktop.
Save llinfeng/5e6ba65c0278d7380aa064f250e00c06 to your computer and use it in GitHub Desktop.
Use AutoHotKey + Google for spell-checking: in Normal text editors
; How it works? Well, when you type a single word with erranous spellings to Google, it way "Did you mean ...".
; This AHK script grab that piece of Google Suggestion and pass it back to the clipboard.
; Purpose: select the world to the left of the cursor, and correct using Google:
; Credits: AutoHotkey Community (Linfeng is not able to find the original source.)
; Please comment if you are able to find the source of those fantastic regex expressions
;; Usage: use Ctrl + Alt + Shift + H, to select the word to the left of your active cursor,
;; and replace it with whatever Google corrects it to be.
;; Warning: only work best for very-close, but wrong, spellings.
^+!h::
send {CTRLDOWN}{SHIFTDOWN}{LEFT}{CTRLUP}{SHIFTUP}
clipback := ClipboardAll
clipboard=
Send ^c
ClipWait, 0
UrlDownloadToFile % "https://www.google.com/search?q=" . clipboard, temp
FileRead, contents, temp
FileDelete temp
if (RegExMatch(contents, "(Showing results for|Did you mean:)</span>.*?>(.*?)</a>", match)) {
StringReplace, clipboard, match2, <b><i>,, All
StringReplace, clipboard, clipboard, </i></b>,, All
clipboard := RegExReplace(clipboard, "&#39;", "'")
clipboard := RegExReplace(clipboard, "&amp;", "&")
}
Send ^v
Sleep 500
clipboard := clipback
; MsgBox You are right ; As something new, and inline comment is admissible.
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment