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

Emacsとその周辺 / Emacs and CLI tools

Emacsとその周辺 / Emacs and CLI tools

社内勉強会の資料です

FUJIWARA Shunichiro

June 16, 2017
Tweet

More Decks by FUJIWARA Shunichiro

Other Decks in Technology

Transcript

  1. Emacsͱͦͷपล
    2017.06.09 @fujiwara

    View Slide

  2. ͳͥ Emacs Λ࢖͍ͬͯΔͷ͔
    1. େֶͰ࠷ॳʹ࢖Θ͞Εͨͷ͕ Mule ͩͬͨ(1994೥)
    Emacs → Nemacs(೔ຊޠԽ) → Mule(ଟݴޠԽ)
    → ຊମʹ੒ՌऔΓࠐΈ(Emacs 20,21)
    2. ͦͷޙ JED Λ Emacs ΩʔόΠϯυͰ࢖ͬͯͨ(2000೥)
    www.jedsoft.org/jed/
    3. Emacs ʹ໭͖ͬͯͨ (200?೥)

    View Slide

  3. Vim ΋࢖͍·͢
    .vimrc 1ߦ
    syntax on
    • Ͳ͜ͷαʔόͰ΋࡞ۀ͢ΔͨΊ
    • ઃఆϑΝΠϧ͸ͳΜͱͳ͘ vim Ͱ͍͡Δ͜ͱ͕ଟ͍

    View Slide

  4. screen
    .screenrc ̍ߦ
    escape ^z^z
    • Ͳ͜ͷαʔόͰ΋࡞ۀ͢ΔͨΊ
    • Ctrl-A ͩͱਏ͍
    $ echo "escape ^z^z" > ~/.screenrc
    ιϥͰଧͯΔ

    View Slide

  5. emacsclient
    ىಈ͍ͯ͠Δ Emacs ʹରͯ͠ϑΝΠϧΛ։͔ͤΔίϚϯυ
    ;; .emacs
    (server-start)
    # .zshrc
    alias ec='emacsclient -n'
    $ ec ϑΝΠϧ໊
    Ͱىಈ͍ͯ͠Δ Emacs ͰϑΝΠϧΛ։͚Δ

    View Slide

  6. emacsclient
    -n Φϓγϣϯ: block͠ͳ͍
    EmacsʹϑΝΠϧΛ։͔ͤͨΒ໭ͬͯ͘Δ
    (σϑΥϧτ͸ϑΝΠϧΛด͡Δ·Ͱ଴ͭ)
    ීஈ͸͜ΕΛ࢖͏

    View Slide

  7. EDITOR=emacsclient
    # .zshrc
    export EDITOR=$HOME/local/bin/emacsclient
    git commit ͨ͠ͱ͖ʹ Emacs ͰίϛοτϩάΛฤूͰ͖Δ
    (͜ͷ৔߹ -n Λ෇͚ͯ͸͍͚ͳ͍)

    View Slide

  8. peco
    github.com/peco/peco
    Ctrl-R ͰώετϦΛ peco ͰḷΔ
    # .zshrc
    function peco_select_history() {
    BUFFER=$(fc -l -n 1 | gtac | peco --query "$LBUFFER")
    CURSOR=$#BUFFER # move cursor
    zle -R -c # refresh
    }
    zle -N peco_select_history
    bindkey '^R' peco_select_history

    View Slide

  9. ghq + peco
    github.com/motemen/ghq
    GoͷϦϙδτϦϨΠΞ΢τͰશͯͷ git repo Λ഑ஔ͢Δౕ
    peco Ͱબ୒ͯ͠ cd ͢Δ
    function peco-src () {
    local selected_dir=$(ghq list | peco --query "$LBUFFER")
    if [ -n "$selected_dir" ]; then
    BUFFER="cd $HOME/src/${selected_dir}"
    zle accept-line
    fi
    zle clear-screen
    }
    zle -N peco-src
    bindkey '^]' peco-src

    View Slide

  10. direnv
    github.com/direnv/direnv
    # .envrc
    export AWS_PROFILE=someproject-assumerole
    export AWS_REGION=ap-northeast-1
    $ cd /Users/fujiwara/src/github.com/fujiwara/someproject
    direnv: loading .envrc
    direnv: export +AWS_PROFILE +AWS_REGION
    ϓϩδΣΫτʹԠͨ͡؀ڥม਺Λઃఆ

    View Slide

  11. gh-open
    github.com/typester/gh-open
    $ gh-open ~/path/to/repo
    GitHubͷϖʔδΛϒϥ΢βͰ։͍ͯ͘ΕΔ

    View Slide

  12. ag + peco + ec
    github.com/ggreer/the_silver_searcher/
    ཁ͢Δʹ͍͢͝ grep
    # .zshrc
    agec () {
    emacsclient -n $(ag $@ | peco --query "$LBUFFER" | awk -F: '{print "+" $2, $1}')
    }
    ag Ͱ grep ͨ݁͠ՌΛ peco Ͱબ୒
    "ϑΝΠϧ໊:ߦ൪߸:ߦͷ಺༰" → awk Ͱ "+ߦ൪߸ ϑΝΠϧ໊"
    emacsclient -n +10 foo.txt
    (foo.txt Λ Emacs Ͱ։͍ͯ10ߦ໨ʹҠಈ)

    View Slide