Posted By

gtcaz on 01/29/07


Tagged

command ruby snippet e wxCocoaDialog Speller Bundle


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

adam_dc
Firanide
vali29
webstic


Super Simple Speller v3


 / Published in: Ruby
 

Requires aspell and wxCocoaDialog.

Now checks all of your selection for misspellings.

Known issues: * e doesn't see contractions as a "word", so you must select things like can't, won't, etc. or the command won't see the whole word.

  • Duplicate misspelled words are not handled well. Replacements are done globally, yet you'll be asked for each occurrence.

Place in the Text bundle I named the command: Spell check word/selection Save: Nothing Input: Selected Text or Word Output: Replace Selected Text Key Equivalent: Ctrl-; Scope Selector: {Blank}

  1. #!/usr/bin/env ruby -w
  2. # By Geoff Cheshire <[email protected]>
  3. require ENV['TM_SUPPORT_PATH'] + "/lib/exit_codes.rb"
  4. COCOA_DIALOG = "#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog"
  5. selection = STDIN.read
  6. IO.popen("aspell -a", 'w+') do |aspell|
  7. aspell.puts(selection)
  8. aspell.close_write
  9. aspell.each do |check|
  10. if check =~ /^\&/
  11. data, raw_suggestions = check.split(":")
  12. signal, original, count, offset = data.split
  13. suggestions = ""
  14. raw_suggestions.split(', ').each { |s| suggestions += "\"#{s.chomp}\" " }
  15. choice=%x("#{COCOA_DIALOG}" dropdown \
  16. --title "Misspelled Word" \
  17. --text "There are #{count} suggestions for '#{original}':" \
  18. --string-output \
  19. --items #{suggestions} \
  20. --button1 "Replace" --button2 "Skip" --button3 "Add to dictionary") # No room for a "Cancel" button
  21. button, replacement = choice.split(" ", 2)
  22. replacement.chomp!
  23. case button
  24. when "Replace"
  25. selection.gsub!(/#{original}/, replacement) # Replace done globally; all instances of original replaced
  26. when "Add"
  27. `echo -e "*#{original}\n#" | aspell -a`
  28. `"#{COCOA_DIALOG}" ok-msgbox \
  29. --text "Added '#{original}' to your personal dictionary." \
  30. --no-cancel --timeout 2`
  31. end
  32. end
  33. end
  34. end
  35. print selection

Report this snippet  

You need to login to post a comment.