completion_proc and history

Nobuhiro IMAI
Nobuhiro IMAISoftware Developer at home!
completion_proc
no6v (Nobuhiro IMAI)
   RubyKansai
  Sat, 21 Jul 2012
require "readline"
     line edit (←→)
     history (↑↓)
     completion (Tab)



01                      14
line edit
     Readline.readline("⚡ ")

     ⚡ ←→



02                             14
history
     Readline.readline("⚡ ", true)

     ⚡   Readline::HISTORY.clear
     ⚡   Readline::HISTORY << "a"
     ⚡   Readline::HISTORY << "b"
     ⚡   ↑↓


03                                   14
completion
     Readline.completion_proc
     Readline.completion_proc =
       ->(word){%w[word1 word2 ...]}




04                                     14
demo
demo
memo of demo
     github.com/jugyo/earthquake
     github.com/no6v/
     rubykansai55/blob/master/
     completion_proc.rb


06                                 14
fat man in readline
     puts Readline.
       methods(false).
       grep(->m{/[=?]$/!~m}).
       sort_by(&:size).
       reverse
     # refs hp12c http://bit.ly/QnKcDS



07                                       14
GJ! Thanks!! http://bit.ly/QnFG8r


08                               14
break
break
Array-like object
     Readline::HISTORY.class # => Object
     Readline::HISTORY.singleton_methods(false) # =>
      [:to_s, :[], :[]=, :<<, :push, :pop,
       :shift, :each, :length, :size, :empty?,
       :delete_at, :clear]
     Enumerable === Readline::HISTORY # => true




10                                                     14
but, somethings lack...
     unshift(*obj)
     last
      first(n)/last(n)

     delete_if{|x| ... }


11                         14
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
       end
     end



12                                                  14
hist_delete_if
     static VALUE
     hist_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
Thanks & Q?
Thanks & Q?
1 of 15

Recommended

JavaScript - Agora nervoso by
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
114 views23 slides
Groovy by
GroovyGroovy
GroovyPascal Nsue Engonga
484 views27 slides
JavaSE7 Launch Event: Java7xGroovy by
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyYasuharu Nakano
1.4K views24 slides
Composition in JavaScript by
Composition in JavaScriptComposition in JavaScript
Composition in JavaScriptJosh Mock
1.5K views35 slides
From Javascript To Haskell by
From Javascript To HaskellFrom Javascript To Haskell
From Javascript To Haskellujihisa
2.1K views39 slides
Taking Inspiration From The Functional World by
Taking Inspiration From The Functional WorldTaking Inspiration From The Functional World
Taking Inspiration From The Functional WorldPiotr Solnica
878 views70 slides

More Related Content

What's hot

Duralexsedregex by
DuralexsedregexDuralexsedregex
DuralexsedregexWairton Abreu
535 views22 slides
Vcs23 by
Vcs23Vcs23
Vcs23Malikireddy Bramhananda Reddy
302 views15 slides
Chat code by
Chat codeChat code
Chat codemanish bhandare
132 views2 slides
プログラム実行の話と
OSとメモリの挙動の話 by
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話tatsunori ishikawa
226 views65 slides
Funcd by
FuncdFuncd
FuncdJulio Gonzalez-Saenz
175 views2 slides
HailDB: A NoSQL API Direct to InnoDB by
HailDB: A NoSQL API Direct to InnoDBHailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDBstewartsmith
2.2K views98 slides

What's hot(20)

プログラム実行の話と
OSとメモリの挙動の話 by tatsunori ishikawa
プログラム実行の話と
OSとメモリの挙動の話プログラム実行の話と
OSとメモリの挙動の話
プログラム実行の話と
OSとメモリの挙動の話
tatsunori ishikawa226 views
HailDB: A NoSQL API Direct to InnoDB by stewartsmith
HailDB: A NoSQL API Direct to InnoDBHailDB: A NoSQL API Direct to InnoDB
HailDB: A NoSQL API Direct to InnoDB
stewartsmith2.2K views
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86) by Masashi Shibata
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
システムコールトレーサーの動作原理と実装 (Writing system call tracer for Linux/x86)
Masashi Shibata783 views
Thread介紹 by Jack Chen
Thread介紹Thread介紹
Thread介紹
Jack Chen573 views
What is python by EU Edge
What is pythonWhat is python
What is python
EU Edge466 views
为什么 rust-lang 吸引我? by 勇浩 赖
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
勇浩 赖2.7K views
Azure Durable Funkiness - .NET Oxford June 2018 by Stuart Leeks
Azure Durable Funkiness - .NET Oxford June 2018Azure Durable Funkiness - .NET Oxford June 2018
Azure Durable Funkiness - .NET Oxford June 2018
Stuart Leeks309 views
JavaScript Code Formatting With Prettier by Christopher Chedeau by React London 2017
JavaScript Code Formatting With Prettier by Christopher ChedeauJavaScript Code Formatting With Prettier by Christopher Chedeau
JavaScript Code Formatting With Prettier by Christopher Chedeau
React London 2017772 views

Viewers also liked

Collecting user input by
Collecting user inputCollecting user input
Collecting user inputPeter Andrews
227 views2 slides
Proyecto 1: Aprendiendo sobre las TIC's by
Proyecto 1: Aprendiendo sobre las TIC'sProyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC'sAndrés Tortós
383 views12 slides
Opencomic by
OpencomicOpencomic
OpencomicDiki Andeas
1.2K views21 slides
BBV Theme Project + SVN Tutorial by
BBV Theme Project + SVN TutorialBBV Theme Project + SVN Tutorial
BBV Theme Project + SVN TutorialDiki Andeas
435 views28 slides
Digital Divide & Generation Y by
Digital Divide & Generation YDigital Divide & Generation Y
Digital Divide & Generation YDiki Andeas
427 views25 slides
Introduction to Ruby on Rails by
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsDiki Andeas
1.3K views45 slides

Viewers also liked(12)

Proyecto 1: Aprendiendo sobre las TIC's by Andrés Tortós
Proyecto 1: Aprendiendo sobre las TIC'sProyecto 1: Aprendiendo sobre las TIC's
Proyecto 1: Aprendiendo sobre las TIC's
Andrés Tortós383 views
BBV Theme Project + SVN Tutorial by Diki Andeas
BBV Theme Project + SVN TutorialBBV Theme Project + SVN Tutorial
BBV Theme Project + SVN Tutorial
Diki Andeas435 views
Digital Divide & Generation Y by Diki Andeas
Digital Divide & Generation YDigital Divide & Generation Y
Digital Divide & Generation Y
Diki Andeas427 views
Introduction to Ruby on Rails by Diki Andeas
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Diki Andeas1.3K views
Bilmeyenler icin eskrim by johnaydin
Bilmeyenler icin eskrimBilmeyenler icin eskrim
Bilmeyenler icin eskrim
johnaydin9.1K views
DevLOVE ターミナル勉強会 zsh + screen by Yozo SATO
DevLOVE ターミナル勉強会 zsh + screenDevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screen
Yozo SATO3.2K views
zshと仮想端末マネージャで快適ターミナル生活 by Nobutoshi Ogata
zshと仮想端末マネージャで快適ターミナル生活zshと仮想端末マネージャで快適ターミナル生活
zshと仮想端末マネージャで快適ターミナル生活
Nobutoshi Ogata2.6K views
Pengenalan Android by Diki Andeas
Pengenalan AndroidPengenalan Android
Pengenalan Android
Diki Andeas970 views
earthquake.gem or readline.so by Nobuhiro IMAI
earthquake.gem or readline.soearthquake.gem or readline.so
earthquake.gem or readline.so
Nobuhiro IMAI413 views

Similar to completion_proc and history

Python 1 liners by
Python 1 linersPython 1 liners
Python 1 linersNattawut Phetmak
728 views18 slides
3 by
33
3Marat Vyshegorodtsev
549 views36 slides
Marat-Slides by
Marat-SlidesMarat-Slides
Marat-SlidesMarat Vyshegorodtsev
585 views36 slides
Message in a bottle by
Message in a bottleMessage in a bottle
Message in a bottleKonstantin Haase
2.9K views56 slides
Kotlin by
KotlinKotlin
KotlinBoKaiRuan
231 views63 slides
What's New In C# 7 by
What's New In C# 7What's New In C# 7
What's New In C# 7Paulo Morgado
1K views23 slides

Recently uploaded

Understanding GenAI/LLM and What is Google Offering - Felix Goh by
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix GohNUS-ISS
41 views33 slides
Empathic Computing: Delivering the Potential of the Metaverse by
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the MetaverseMark Billinghurst
470 views80 slides
The Importance of Cybersecurity for Digital Transformation by
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital TransformationNUS-ISS
27 views26 slides
Business Analyst Series 2023 - Week 3 Session 5 by
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5DianaGray10
209 views20 slides
Top 10 Strategic Technologies in 2024: AI and Automation by
Top 10 Strategic Technologies in 2024: AI and AutomationTop 10 Strategic Technologies in 2024: AI and Automation
Top 10 Strategic Technologies in 2024: AI and AutomationAutomationEdge Technologies
14 views14 slides
Roadmap to Become Experts.pptx by
Roadmap to Become Experts.pptxRoadmap to Become Experts.pptx
Roadmap to Become Experts.pptxdscwidyatamanew
11 views45 slides

Recently uploaded(20)

Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
Empathic Computing: Delivering the Potential of the Metaverse by Mark Billinghurst
Empathic Computing: Delivering  the Potential of the MetaverseEmpathic Computing: Delivering  the Potential of the Metaverse
Empathic Computing: Delivering the Potential of the Metaverse
Mark Billinghurst470 views
The Importance of Cybersecurity for Digital Transformation by NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS27 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10209 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica... by NUS-ISS
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
Emerging & Future Technology - How to Prepare for the Next 10 Years of Radica...
NUS-ISS16 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
Black and White Modern Science Presentation.pptx by maryamkhalid2916
Black and White Modern Science Presentation.pptxBlack and White Modern Science Presentation.pptx
Black and White Modern Science Presentation.pptx
maryamkhalid291614 views
Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views

completion_proc and history

  • 1. completion_proc no6v (Nobuhiro IMAI) RubyKansai Sat, 21 Jul 2012
  • 2. require "readline" line edit (←→) history (↑↓) completion (Tab) 01 14
  • 3. line edit Readline.readline("⚡ ") ⚡ ←→ 02 14
  • 4. history Readline.readline("⚡ ", true) ⚡ Readline::HISTORY.clear ⚡ Readline::HISTORY << "a" ⚡ Readline::HISTORY << "b" ⚡ ↑↓ 03 14
  • 5. completion Readline.completion_proc Readline.completion_proc = ->(word){%w[word1 word2 ...]} 04 14
  • 7. memo of demo github.com/jugyo/earthquake github.com/no6v/ rubykansai55/blob/master/ completion_proc.rb 06 14
  • 8. fat man in readline puts Readline. methods(false). grep(->m{/[=?]$/!~m}). sort_by(&:size). reverse # refs hp12c http://bit.ly/QnKcDS 07 14
  • 11. Array-like object Readline::HISTORY.class # => Object Readline::HISTORY.singleton_methods(false) # => [:to_s, :[], :[]=, :<<, :push, :pop, :shift, :each, :length, :size, :empty?, :delete_at, :clear] Enumerable === Readline::HISTORY # => true 10 14
  • 12. but, somethings lack... unshift(*obj) last first(n)/last(n) delete_if{|x| ... } 11 14
  • 13. 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 end end 12 14
  • 14. hist_delete_if static VALUE hist_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