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
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
170
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
610
Node-RED を(HTTP で)つなげる MCP サーバーを作ってみた
highu
0
120
PicoRuby on Rails
makicamel
2
130
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
800
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
350
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
2
630
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
520
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
12
3.4k
効率的な開発手段として VRTを活用する
ishkawa
0
130
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
550
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
290
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
270
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.4k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
31
1.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
What's in a price? How to price your products and services
michaelherold
246
12k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
It's Worth the Effort
3n
185
28k
Building an army of robots
kneath
306
45k
Why Our Code Smells
bkeepers
PRO
337
57k
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 を調べたり まだ使いこなせていない