Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
楽してコードを書くためのエディタ活用術/golang on emacs
Search
NAGATA Hiroaki
January 20, 2018
Programming
0
2.8k
楽してコードを書くためのエディタ活用術/golang on emacs
できるだけ手を動かさず、頭も使わずにコードを書くための機能の紹介です。
題材としてEmacsを使っていますが、他のエディタでも設定次第で同じような機能が利用できるはず。
NAGATA Hiroaki
January 20, 2018
Tweet
Share
More Decks by NAGATA Hiroaki
See All by NAGATA Hiroaki
生成AIとの上手な付き合い方【公開版】/ How to Get Along Well with Generative AI (Public Version)
handlename
0
490
Other Decks in Programming
See All in Programming
初学者でも今すぐできる、Claude Codeの生産性を10倍上げるTips
s4yuba
16
11k
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
650
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
250
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
0
140
効率的な開発手段として VRTを活用する
ishkawa
0
130
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
290
PipeCDのプラグイン化で目指すところ
warashi
1
270
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
210
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
52
33k
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
550
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
1
4.9k
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
329
21k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Rails Girls Zürich Keynote
gr2m
95
14k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Site-Speed That Sticks
csswizardry
10
680
Faster Mobile Websites
deanohume
307
31k
Done Done
chrislema
184
16k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Transcript
楽してコードを書くための テキストエディタ活用術 20 January 2018 NAGATA Hiroaki KAYAC Inc.
Presenter 長田洸明 (@handlename) KAYAC Inc. Lobi 事業部 サーバーサイドエンジニア Perl, Go
Emacs 歴は8 年くらい エディタは色々触っているけど結局Emacs に戻ってきました。 Emacs -> Vim -> Emacs -> SublimeText2 -> Emacs -> Atom -> Emacs
Text Editors
Text Editors 機能拡張 できるエディタが広く使われている。 Atom Emacs Vim Visual Studio Code
etc. ※アルファベット順です
Text Editors なぜエディタの機能を拡張するのかというと・・・ 楽をしたい できるだけ操作したくない できるだけ頭を使いたくない エディタに仕事をさせましょう。
Emacs
Emacs www.gnu.org/software/emacs/ (https://www.gnu.org/software/emacs/) 1972 年にリリースされたテキストエディタ 現在もバージョンアップが続いている Emacs Lisp で機能拡張
go-mode.el github.com/dominikh/go-mode.el (https://github.com/dominikh/go-mode.el) Emacs でGo を書くためのmajor mode Emacs でGo を書くならとりあえず入れておくべし
Spacemacs spacemacs.org/ (http://spacemacs.org/) A community-driven Emacs distribution - The best
editor is neither Emacs nor Vim, it's Emacs *and* Vim! Emacs のための設定集 ドキュメントが充実している 自分でEmacs Lisp を( ほとんど) 書かなくていい! 設定ファイルに一行追加すればgo-mode.el とその他便利機能が有効になる ;; .spacemacs (defun dotspacemacs/layers () (setq-default ;; ... dotspacemacs-configuration-layers '( ;; ... go ; 足 )))
Topics Code Writing Code Reading Build & Run Code
Code Writing
Code Writing Code Format Add/Delete Import Code Completion Syntax Check
Rename
Code Format M-x gofmt Go を書く上でのマナー インデントや空白文字の自動整形 gofmt (https://golang.org/cmd/gofmt) を利用している
ファイル保存時に自動実行するのが吉(spacemacs のデフォルト設定)
Add/Delete Import コード内で利用しているpackage を特定して import に自動追加 goimports (https://golang.org/x/tools/cmd/goimports) を利用している 同時にコードフォーマットしてくれるのでgofmt
代わりにも go-mode.el ではgofmt と入れ替える方法が紹介されている (go :variables gofmt-command "goimports"
Code Completion 定義済み関数・変数の入力補完 関数なら引数リストまで補完される struct はメンバまで補完される gocode (https://github.com/nsf/gocode) を利用している
Syntax Check 構文エラーをエディタ上に表示 go build する前に気付ける ycheck が各種linter( go vet
(https://golang.org/cmd/vet/) とか golint (https://github.com/golang/lint) とか) を呼び出し gometalinter (https://github.com/alecthomas/gometalinter) を利用することもできる (go :variables go-use-gometalinter t)
Rename M-x go-rename 変数名・関数名をリネーム 機械的な置換ではなく、同一定義のものだけをリネーム 別のファイルに書かれているものもリネーム gorename (https://golang.org/x/tools/cmd/gorename) を利用 構文エラーがあると実行できないので注意
Code Reading
Code Reading Reference De nition Reference GoDoc Jump to De
nition
Reference De nition 関数のインターフェイス・変数の型をさっと確認 いちいちgodoc を引くのはちょっと・・・ カーソルを合わせるとモードラインに自動で表示される コードリーディングの時にお世話になる
Reference GoDoc M-x go-doc-at-point 関数・変数のgodoc を引く さっと確認するには便利 Dash との使い分け
Jump to De nition M-x godef-jump 変数・関数の定義元にジャンプ godef (https://github.com/rogpeppe/godef) を利用
コードリーディングのお供
Build & Run Code
Build & Run Code Run Test Quickrun Post to Playground
Run Test M-x spacemacs/go-run-package-tests M-x spacemacs/go-run-test-current-function 開いているファイルに関連するテストを実行する プロジェクト全体/ ファイル内/ テストケース単体
を実行できる Spacemacs の独自関数 go test に -v オプションをを付けたいので手を加えている (advice-add 'spacemacs/go-run-tests :filter-args (lambda (args) (list (concat "-v " (car args)))))
Quickrun M-x quickrun 現在開いているファイルor 選択している範囲をその場で実行 quickrun.el (https://github.com/syohex/emacs-quickrun) を利用 quickrun.vim (https://github.com/thinca/vim-quickrun)
が元ネタ Go に限らず複数の言語に対応
Post to Playground M-x go-play-region M-x go-play-buffer 今書いているコードを paly.golang.org に投稿
投稿結果のURL が kill-ring にコピーされる
Conclusion Go はエディタから独立した開発支援ツールが充実している 好きなエディタ/IDE を使いましょう NO MORE WAR! エディタに仕事をさせて快適なコーディングライフを
Appendix
Environment OSX v10.13.2 Emacs v25.3.1 Spacemacs v0.200.10
Environment Variables Emacs 上ではPATH が通っていなくて外部コマンドが呼び出せない問題 .zshrc でEmacs 用の環境変数設定ファイルを生成している 環境変数の不一致でハマることがないので良い perl
$HOME/src/github.com/handlename/spacemacs-private/scripts/init_shellenv.pl \ > $HOME/src/github.com/handlename/spacemacs-private/ondemand/shellenv.el #!/usr/bin/env perl use strict; use warnings; for my $name (sort keys %ENV) { next if ! exists $ENV{$name}; my $value = $ENV{$name}; $value =~ s/\\/\\\\/g; printf qq{(setenv "%s" "%s")\n}, $name, $value; } (setenv "PATH" "/Users/nagata-hiroaki/.anyenv/envs/plenv/versions/5.26.1/bin:/Users/nagata-hiroaki/.anye (setenv "GOPATH" "/Users/nagata-hiroaki")
Guru godoc.org/golang.org/x/tools/cmd/guru (https://godoc.org/golang.org/x/tools/cmd/guru) よりIDE っぽいことができる 変数の呼び出し箇所を調べたり callstack を調べたり まだ使いこなせていない