Upgrade to Pro — share decks privately, control downloads, hide ads and more …

reply.vim

Linda_pp
February 18, 2019

 reply.vim

@ gorilla.vim #1

Linda_pp

February 18, 2019
Tweet

More Decks by Linda_pp

Other Decks in Technology

Transcript

  1. Reply.vim
    at gorilla.vim #1

    View full-size slide

  2. About Me
    @Linda_pp
    @rhysd


    View full-size slide

  3. REPL (Read Eval Print Loop)
    ࢖ͬͯ·͔͢ʁ
    node, python, ghci, swift -repl, bash, iex, irb,
    clojure,...
    API ΍ݴޠػೳΛͪΐͬͱ֬ೝ͢Δ࣌ʹͨ͠
    ͍ͱ͖ʹศར


    View full-size slide

  4. ୺຤ Vim + Tmux Ͱ REPL Λ࢖ͬ
    ͍ͯͨ࣌ͷ໰୊఺
    • Vim ͰฤूதͷίʔυΛ෦෼తʹ REPL Ͱ࠶
    ར༻͍ͨ࣌͠ɼ෦෼͝ͱʹ Vim ͔Β REPL ʹ
    ίϐʔ͠ͳ͍ͱ͍͚ͳ͍
    • REPL Ͱࢼͨ͠ޙʹ Vim ʹ໭͖ͬͯͨ࣌ʹίʔ
    υΛଧͪ௚͞ͳ͍ͱ͍͚ͳ͍
    • gVim Λ࢖ͬͯΔ࣌ʹࠔΔ


    View full-size slide

  5. reply.vim
    https://github.com/rhysd/reply.vim

    View full-size slide

  6. reply.vim
    https://github.com/rhysd/reply.vim
    Vim ͱ REPL ͷΠϯλϥΫγϣϯΛվળ͢Δϓ
    ϥάΠϯʢVim 8+ ͱ Neovim ྆ରԠʣ
    ϨϓϦʔͱಡΈ·͢


    View full-size slide

  7. reply.vim
    • :[range]Repl [{name} [{args...}]
    • {name} Ͱࢦఆͨ͠ REPL Λىಈʢࢦఆ͠ͳ͍ͱ
    filetype ͔Βࣗಈ൑ผʣɽ{args} ΛίϚϯυ࣮ߦʹ௥
    ՃͰ͖Δɽ[range] ͷίʔυΛ REPL ։࢝࣌ʹૹ৴
    • :ReplStop
    • REPL Λऴྃ͢Δ
    • :ReplList
    • :Repl ͷ {name} Ͱ࢖͑Δ REPL ͷҰཡ
    • Ϛοϐϯά͸σϑΥϧτͰ͸ແ͠


    View full-size slide

  8. :Repl Ͱىಈ͠ɼ:ReplSend ͰςΩετΛςΩετόοϑΝ͔Β REPL ʹ
    ૹΔ

    View full-size slide

  9. REPL Ͱ࣮ߦͨ͠ίʔυΛ Vim ͷςΩετόοϑΝʹ :ReplRecv Ͱॻ͖
    ग़͢

    View full-size slide

  10. :ReplAuto ͰςΩετόοϑΝͰฤूதͷίʔυΛࣗಈͰ REPL ʹૹ࣮ͬͯߦ͢Δ
    ʢexperimentalʣ

    View full-size slide

  11. reply.vim
    • REPL ࣗମ͸ :terminal Ͱಈ͔͢ͷͰɼREPL ͷ
    ิ׬΍ίʔυϋΠϥΠτ͸ͦͷ··࢖͑Δ
    • σϑΥϧτͰ30Ҏ্ͷݴޠɼ40Ҏ্ͷ REPL
    ʹରԠ
    • ࣗલͷ REPL Λ௥Ճ͢Δ͜ͱ΋Ͱ͖Δ
    • vim-themis Ͱ୯ମςετ


    View full-size slide

  12. REPL ͷΧελϚΠζ
    filetype ͝ͱʹىಈ͢Δ REPL ͷΧελϚΠζ͕Ͱ͖
    ΔɽREPL ໊Ͱ͸ͳ͘ Funcref Λ༩͑Δͱɼࣗલͷ REPL
    ΛఆٛͰ͖Δ
    let g:reply_repls = {
    \ 'python': ['python3'],
    \ 'scheme': ['mit_scheme', 'gauche'],
    \ 'javascript': ['ts_node'],
    \ 'text': [
    \ {-> reply#repl#base('mycalc', {
    \ 'prompt_start' : '^calc> ',
    \ 'prompt_continue' : v:null,
    \ })}
    \ ],
    \ }
    ྫɿ 'calc> ' ͱ͍͏ϓϩϯϓτΛग़͢ mycalc ͱ͍͏ REPL ίϚϯυͷ௥Ճ


    View full-size slide

  13. Vim ͱ Neovim ͷλʔϛφϧ
    ػೳͷࡉ͔͍ҧ͍

    View full-size slide

  14. Vim ͱ Neovim ͷ :terminal ͸جຊతʹಉ͡
    Α͏ʹ࢖͑ɼ࣮૷΋ͲͪΒ΋ libvterm ϕʔε
    ͕ͩɼ࣮૷ࣗମ͸ผ෺ͷͨΊࡉ͔͍ͱ͜Ζ͕
    ҧ͏


    View full-size slide

  15. ΢Οϯυ΢ͷ։͖ํ͕ҧ͏
    Vim → ΢Οϯυ΢Λ෼ׂͯ͠৽͍͠λʔϛφϧΛ։
    ͘ɽterm_start() ͷҾ਺ʹ౉ࣙ͢ॻͷ term_opencmd
    Ͱ։͖ํ͕ࢦఆͰ͖Δʢྫɿ'botright sbuffer %d'ʣ
    Neovim → ΢Οϯυ΢Λ෼ׂͤͣ։͘ɽ෼ׂ͍ͨ͠
    ৔߹͸ࣄલʹ޷͖ͳํ๏Ͱ෼ׂ͔ͯ͠Β։͘
    ʢྫɿ:vsplit | termʣ


    View full-size slide

  16. :terminal ͷҾ਺ͷΫΥʔτ
    Vim → γϯάϧΫΥʔτ͸ͦͷ··λʔϛφϧ
    ʹ౉ͯ͠͠·͏ɽྫ͑͹ɼ:term echo "foo" ͸
    foo ͱදࣔ͞ΕΔ͕ɼ:term echo 'foo' ͸ 'foo' ͱ
    දࣔ͞ΕΔ
    Neovim → γϯάϧΫΥʔτͰ΋μϒϧΫΥʔ
    τͰ΋ OK


    View full-size slide

  17. λʔϛφϧ΁ͷจࣈྻૹ৴
    Vim → γઐ༻ͷؔ਺ term_sendkeys() Λ࢖͏ɽ୺຤δϣϒϞʔ
    υͰͳ͍ͱಈ͔ͳ͍ͷͰ஫ҙ
    Neovim → ୺຤όοϑΝͷ &l:channel Φϓγϣϯʹ channel ID
    ͕ೖ͍ͬͯΔͷͰɼͦΕΛ࢖ͬͯ jobsend() Ͱૹ৴͢Δ
    " ·ͣ͸୺຤΢Οϯυ΢ʹҠಈ
    1wincmd
    " ୺຤δϣϒϞʔυʹೖΔ
    normal! i
    " จࣈྻૹ৴
    call term_sendkeys(bufnr, "echo hello\n")
    call jobsend(getbufvar(bufnr, '&channel'), ["echo hello\n"])


    View full-size slide

  18. ຤ඌͷۭനߦͷඳըͷ࢓ํ͕
    ҧ͏
    Vim → getline(1, '$') ͢Δͱ ['echo foo', '', '', '',
    '', ..., ''] ͱ2ߦ໨Ҏ߱ͷۭനߦ΋ೖͬͯ͘Δ
    Neovim → γ getline(1, '$') ͢Δͱ ['echo foo']
    ͷΈͰ຤ඌͷۭനߦ͸ೖͬͯ͜ͳ͍
    > echo foo


    View full-size slide

  19. ऄ଍ɿ୯ମςετͰ Vim ͱ Neovim ͷλʔϛ
    φϧύϑΥʔϚϯεൺֱ
    > time ./vim-themis/bin/themis test/ >/dev/null 2>&1
    ./vim-themis/bin/themis test/ > /dev/null 2>&1 0.97s user 0.24s system
    12% cpu 9.330 total
    > time THEMIS_VIM=nvim ./vim-themis/bin/themis test/ >/dev/null 2>&1
    THEMIS_VIM=nvim ./vim-themis/bin/themis test/ > /dev/null 2>&1 2.17s user
    0.04s system 82% cpu 2.662 total
    • iMac 2015 Late (core i7)
    • Vim 8.1 873
    • Neovim 0.3.4


    View full-size slide