オーストラリアで勉強してきたMLデザイナーの口語自由詩

主に、データ分析・機械学習・ベイズ・統計について自由に書く。

emacsに入信した

f:id:yukinagae:20171208103359p:plain

今更ながらspacemacs(=emacsの宗派の一つ)に入信した。普通にemacsを使おうとすると、気持ちよく動かせるまでに多くの設定ファイル(秘伝のタレ)が必要になるが、spacemacsだとデフォルトで既にイケてる感じで動く。カスタマイズももちろん色々できるが、だいたい1行から数行設定ファイルに書くだけでいいのでストレスがない。

The best editor is neither Emacs nor Vim, it's Emacs and Vim!

上記に書いてあるとおり、Vimキーバインドも動作する(らしい)。ただ、正直言うとガチのvimmerは普通にvim使うと思う。

理由

既に知られているように、「どのエディタ/IDEを使用するか」という問題は 宗教戦争 と呼ばれている。

以下主要なエディタは多くあるが、いずれか一つが主権を握ったことはない。

理性的に考えれば、ケースバイケースで適切なツールを選択していけばよい。しかしこの単純なツール選択の問題が宗教戦争と呼ばれるものを引き起こす背景には、エディタがただのツール以上に使用者の感覚や思考方法を制限するからではないか(同じようなことはプログラミング言語の選択でも起きている)。

であればどのエディタを使用するかというのは、衝動的および感情的に選択されるべきではないか。


元々vscode + vimキーバインドを使っていたが、MacBook Proのtouch barのescキーが押しづらいことに天啓を受け、emacsへの入信を決意した。

この点は、聖パウロがダマスカスでの奇跡によりキリスト教に転向したことに近い(要出典)

環境

導入手順

だいたい以下のgithubに書いてあります。

brewで色々インストールする。

$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus
$ brew linkapps emacs-plus

brew linkapps emacs-plus で以下のwarningが出て、 brew cask を使うことを検討するように言ってくるが、一旦動作に問題ないので無視。

Warning: `brew linkapps` has been deprecated and will eventually be removed!
Unfortunately `brew linkapps` cannot behave nicely with e.g. Spotlight using
either aliases or symlinks and Homebrew formulae do not build "proper" `.app`
bundles that can be relocated. Instead, please consider using `brew cask` and
migrate formulae using `.app`s to casks.

spacemacsの .emacs.d ディレクトリをcloneする(既に既存ディレクトリがある場合は上書きする前に一旦バックアップを取った方がよい)

$ git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

初期設定は /.spacemacs に設定が記載されているが、gitで管理しずらいの ~/.spacemacs.d/init.el にrenameしてディレクトリごと管理するようにする。

$ mkdir ~/.spacemacs.d
$ mv ~/.spacemacs ~/.spacemacs.d/init.el

設定

主に使う設定とおすすめを少し記載する。自分の設定は以下のgithubにある(随時更新)。

GitHub: yukinagae/.spacemacs.d

  • 基本パッケージ

使いたいパッケージをコメントアウトしただけ。

   dotspacemacs-configuration-layers
   '(
     ;; ----------------------------------------------------------------
     ;; Example of useful layers you may want to use right away.
     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
     ;; <M-m f e R> (Emacs style) to install them.
     ;; ----------------------------------------------------------------
     helm
     auto-completion
     better-defaults
     emacs-lisp
     git
     markdown
     ;; org
     ;; (shell :variables
     ;;        shell-default-height 30
     ;;        shell-default-position 'bottom)
     spell-checking
     syntax-checking
     version-control
     )
  • 追加パッケージ

追加で入れたいものを追記。

   dotspacemacs-additional-packages '(
                                      all-the-icons ;; フォルダツリーのアイコンを綺麗なのにする。
                                      quickrun      ;; コードの実行などができる
                                      )
  • 文字

好きなフォントなどを指定(もしフォントがなければ別途ダウンロードしてください。)。

   dotspacemacs-default-font '("Fira Code"  ;; プログラマ向けのフォント。別途インストールが必要
                               :size 14
                               :weight normal
                               :width normal
                               :powerline-scale 1.1)
  • テーマ
   dotspacemacs-themes '(
                         monokai ;; だいたいmonokaiがベスト
                         spacemacs-dark
                         spacemacs-light
                         )
  • 行番号の表示/非表示
   dotspacemacs-line-numbers t ;; `t`が表示、`nil`が非表示
  • カスタマイズいろいろ
(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."

  ;; settings for icon
  (require 'all-the-icons)
  (setq all-the-icons-color-icons t)
  (setq all-the-icons-for-buffer t)

  )
  • all-the-icons

以下のコマンドでアイコン等をインストールしないと適用されないので注意!

M-x all-the-icons-install-fonts

see Youtube: Emacs Tutorial | Changing Theme of Neo Tree To Devicons

M-x customize

search "neo theme"

change "Value Menu" to "icons" => "Apply and Save"

M-m f e R

type "g" in the neo tree directory view

コード整形や自動インポートの設定

GO layer

go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v golang.org/x/tools/cmd/goimports

user-config に以下を追記

(setq gofmt-command "goimports")

コマンド

設定を確認(編集)

M-m f e d

設定を再起動

M-m f e R

emacsを再起動

M-m q R

終わりに

emacsに終わりはない。