U:RDoc::AnyMethod[iI"completion_proc=:ETI"Readline::completion_proc=;TT: publico:RDoc::Markup::Document: @parts[o:RDoc::Markup::Paragraph; [I"JSpecifies a Proc object +proc+ to determine completion behavior. It ;TI"Kshould take input string and return an array of completion candidates.;To:RDoc::Markup::BlankLineo; ; [I"5The default completion is used if +proc+ is nil.;T@o; ; [ I":The String that is passed to the Proc depends on the ;TI"MReadline.completer_word_break_characters property. By default the word ;TI"Punder the cursor is passed to the Proc. For example, if the input is "foo ;TI"Abar" then only "bar" would be passed to the completion Proc.;T@o; ; [I"QUpon successful completion the Readline.completion_append_character will be ;TI"Pappended to the input so the user can start working on their next argument.;T@S:RDoc::Markup::Heading: leveli: textI" Examples;T@S; ; i;I"!Completion for a Static List;T@o:RDoc::Markup::Verbatim; [I"require 'readline' ;TI" ;TI"LIST = [ ;TI"% 'search', 'download', 'open', ;TI"" 'help', 'history', 'quit', ;TI" 'url', 'next', 'clear', ;TI" 'prev', 'past' ;TI" ].sort ;TI" ;TI";comp = proc { |s| LIST.grep(/^#{Regexp.escape(s)}/) } ;TI" ;TI"0Readline.completion_append_character = " " ;TI"%Readline.completion_proc = comp ;TI" ;TI"0while line = Readline.readline('> ', true) ;TI" p line ;TI" end ;T: @format0S; ; i;I"&Completion For Directory Contents;T@o;; [I"require 'readline' ;TI" ;TI"0Readline.completion_append_character = " " ;TI"2Readline.completion_proc = Proc.new do |str| ;TI"3 Dir[str+'*'].grep(/^#{Regexp.escape(str)}/) ;TI" end ;TI" ;TI"0while line = Readline.readline('> ', true) ;TI" p line ;TI" end ;T;0S; ; i;I"Autocomplete strategies;T@o; ; [ I"OWhen working with auto-complete there are some strategies that work well. ;TI"2To get some ideas you can take a look at the ;TI"Tcompletion.rb[http://svn.ruby-lang.org/repos/ruby/trunk/lib/irb/completion.rb] ;TI"file for irb.;T@o; ; [ I"QThe common strategy is to take a list of possible completions and filter it ;TI"Mdown to those completions that start with the user input. In the above ;TI"Oexamples Enumerator.grep is used. The input is escaped to prevent Regexp ;TI";special characters from interfering with the matching.;T@o; ; [I"NIt may also be helpful to use the Abbrev library to generate completions.;T@o; ; [I"HRaises ArgumentError if +proc+ does not respond to the call method.;T: @fileI"ext/readline/readline.c;T:0@omit_headings_from_table_of_contents_below0I"%Readline.completion_proc = proc ;T0[I" (p1);T@VFI" Readline;TcRDoc::NormalModule00