Posted By

charlesroper on 03/18/07


Tagged

commands e-texteditor bundles


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

gtcaz
maxkks
copyleft
sergeizen
webstic


Auto-complete with menu


 / Published in: Ruby
 

Auto-complete command for E-TextEditor. Will popup a menu if there are multiple possibilities.

Installation requirements: Save: Nothing Input: Entire Document Output: Insert as Text

  1. #!/usr/bin/env ruby
  2.  
  3. SUPPORT = ENV['TM_SUPPORT_PATH']
  4. DIALOG = SUPPORT + '/bin/CocoaDialog.exe'
  5. selected_word = ENV['TM_CURRENT_WORD']
  6. x = "--xpos #{ENV['TM_CARET_XPOS']} "
  7. y = "--ypos #{ENV['TM_CARET_YPOS']} "
  8.  
  9. if selected_word != nil
  10. menu = []
  11. all_words = STDIN.read.split(/\b/)
  12. all_words.each do |word|
  13. if word != selected_word
  14. if word.index(selected_word) == 0
  15. menu << word + " "
  16. end
  17. end
  18. end
  19.  
  20. menu.uniq!
  21. if menu.length < 1
  22. abort
  23. elsif menu.length == 1
  24. print menu[0].sub(selected_word, '').strip
  25. else
  26. selected = %x`"#{DIALOG}" menu --items #{menu} #{x} #{y}`.to_i - 1
  27. print menu[selected].sub(selected_word, '').strip
  28. end
  29. end

Report this snippet  

You need to login to post a comment.