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.9k
楽してコードを書くためのエディタ活用術/golang on emacs
できるだけ手を動かさず、頭も使わずにコードを書くための機能の紹介です。
題材としてEmacsを使っていますが、他のエディタでも設定次第で同じような機能が利用できるはず。
NAGATA Hiroaki
January 20, 2018
Tweet
Share
More Decks by NAGATA Hiroaki
See All by NAGATA Hiroaki
ボードゲーム × 専用収納 〜3Dプリントで埋めるニッチな隙間〜 / Board Games × Custom Storage
handlename
0
180
生成AIとの上手な付き合い方【公開版】/ How to Get Along Well with Generative AI (Public Version)
handlename
0
960
Other Decks in Programming
See All in Programming
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
Grafana:建立系統全知視角的捷徑
blueswen
0
330
dchart: charts from deck markup
ajstarks
3
1k
高速開発のためのコード整理術
sutetotanuki
1
410
Oxlintはいいぞ
yug1224
5
1.3k
CSC307 Lecture 03
javiergs
PRO
1
490
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
130
ぼくの開発環境2026
yuzneri
0
240
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
200
Claude Codeと2つの巻き戻し戦略 / Two Rewind Strategies with Claude Code
fruitriin
0
140
Data-Centric Kaggle
isax1015
2
780
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
740
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Music & Morning Musume
bryan
47
7.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.9k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
Ruling the World: When Life Gets Gamed
codingconduct
0
140
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
Docker and Python
trallard
47
3.7k
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 を調べたり まだ使いこなせていない