module Bond::Search

Contains search methods used to filter possible completions given what the user has typed for that completion. For a search method to be used by Bond#complete it must end in '_search' and take two arguments: the Input string and an array of possible completions.

Creating a search method

Say you want to create a custom search which ignores completions containing '-'. In a completion file under Rc namespace, define this method:

def ignore_hyphen_search(input, list)
  normal_search(input, list.select {|e| e !~ /-/ })
end

Now you can pass this custom search to any complete() as :search => :ignore_hyphen

Attributes

Public Instance Methods

incremental_filter(input, list, delim) click to toggle source

Used by #files_search and modules_search.

# File lib/bond/search.rb, line 66
def incremental_filter(input, list, delim)
  i = 0; input.gsub(delim) {|e| i+= 1 }
  delim_chars = delim.split('').uniq.join('')
  current_matches, future_matches = default_search(input, list).partition {|e|
    e[/^[^#{delim_chars}]*(#{delim}[^#{delim_chars}]+){0,#{i}}$/] }
  (current_matches + future_matches.map {|e| e[/^(([^#{delim_chars}]*#{delim}){0,#{i+1}})/, 1] }).uniq
end