/ 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
Installation requirements:
Save: Nothing
Input: Entire Document
Output: Insert as Text
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env ruby SUPPORT = ENV['TM_SUPPORT_PATH'] DIALOG = SUPPORT + '/bin/CocoaDialog.exe' selected_word = ENV['TM_CURRENT_WORD'] x = "--xpos #{ENV['TM_CARET_XPOS']} " y = "--ypos #{ENV['TM_CARET_YPOS']} " if selected_word != nil menu = [] all_words = STDIN.read.split(/\b/) all_words.each do |word| if word != selected_word if word.index(selected_word) == 0 menu << word + " " end end end menu.uniq! if menu.length < 1 abort elsif menu.length == 1 print menu[0].sub(selected_word, '').strip else selected = %x`"#{DIALOG}" menu --items #{menu} #{x} #{y}`.to_i - 1 print menu[selected].sub(selected_word, '').strip end end