completion_proc and history
-
Upload
nobuhiro-imai -
Category
Technology
-
view
405 -
download
0
Transcript of completion_proc and history
![Page 1: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/1.jpg)
completion_proc
no6v (Nobuhiro IMAI)RubyKansai
Sat, 21 Jul 2012
![Page 2: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/2.jpg)
require "readline"line edit (←→)
history (↑↓)
completion (Tab)
01 14
![Page 3: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/3.jpg)
line edit
Readline.readline("⚡ ")
⚡ ←→
02 14
![Page 4: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/4.jpg)
history
Readline.readline("⚡ ", true)
⚡ Readline::HISTORY.clear⚡ Readline::HISTORY << "a"⚡ Readline::HISTORY << "b"⚡ ↑↓
03 14
![Page 5: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/5.jpg)
completion
Readline.completion_procReadline.completion_proc = ->(word){%w[word1 word2 ...]}
04 14
![Page 6: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/6.jpg)
demodemo
![Page 7: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/7.jpg)
memo of demogithub.com/jugyo/earthquake
github.com/no6v/rubykansai55/blob/master/completion_proc.rb
06 14
![Page 8: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/8.jpg)
fat man in readline
puts Readline. methods(false). grep(->m{/[=?]$/!~m}). sort_by(&:size). reverse# refs hp12c http://bit.ly/QnKcDS
07 14
![Page 9: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/9.jpg)
GJ! Thanks!! http://bit.ly/QnFG8r
08 14
![Page 10: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/10.jpg)
breakbreak
![Page 11: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/11.jpg)
Array-like object
Readline::HISTORY.class # => ObjectReadline::HISTORY.singleton_methods(false) # =>[:to_s, :[], :[]=, :<<, :push, :pop,
:shift, :each, :length, :size, :empty?, :delete_at, :clear]Enumerable === Readline::HISTORY # => true
10 14
![Page 12: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/12.jpg)
but, somethings lack...unshift(*obj)
lastfirst(n)/last(n)
delete_if{|x| ... }
11 14
![Page 13: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/13.jpg)
HISTORY.delete_if
require "readline"
class << Readline::HISTORY def delete_if(&block) return enum_for(__method__) unless block raise SecurityError if $SAFE == 4 i = 0 while (size > i) do break unless entry = self[i] if block.call(entry) delete_at(i) else i += 1 end end return self endend
12 14
![Page 14: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/14.jpg)
hist_delete_if
static VALUEhist_delete_if(VALUE self){ HIST_ENTRY *entry; int i = 0;
RETURN_ENUMERATOR(self, 0, 0);
rb_secure(4); while (history_length > i) { entry = history_get(history_get_offset_func(i)); if (entry == NULL) break; if (RTEST(rb_yield(rb_locale_str_new_cstr(entry->line)))) rb_remove_history(i); else i++; } return self;}
13 14
![Page 15: completion_proc and history](https://reader033.fdocuments.net/reader033/viewer/2022052910/559a2da01a28abea758b47aa/html5/thumbnails/15.jpg)
Thanks & Q?Thanks & Q?