経緯
社会人になったころエディタは何を使えば?って話でEmacsがいいよってことで、Emacsを使い始めました。半べそかきながら、鬼軍曹.elとか入れて頑張ってたんだけど、SublimeTextがリリースされた時についに耐えられなくなって乗り換え。
マルチカーソルや洒落た見た目が気に入って即ライセンスも買った。今でも使ったりはするけど、やっぱりShift-jisに対応していないのは致命的だなって思います(仕事ではshift-jisが避けられない状況が多い。renesasのCS+もshift-jisのみ)。saveonbuildでgccなんか走らせようものならドサクサに紛れてファイルがutf-8で保存されてるなんてことが多々あってうんざりしてました。本体も開発してんの?って感じだし、21世紀のエディタAtomを入れてみました。
AtomはublimeTextの影響を受けており、拡張がcoffeeで書けるってことで最高だ!って思ったんだけど、自分の環境では超もっさり。Ctrl+kでの行削除に0.5秒くらいかかってる印象。Emacsパッケージはなんか微妙な出来だし、会社のネットワークではS3へのアクセスが遮断されててプラグインやテーマもパッケージマネージャからインストールできないのも追い打ちをかけました。
どうしよかなーってことで考えた結果、Emacsに再入門してみることにしました。結果から言うと最高でした。もっと早くもどってくればよかった。
以下は昔の記憶と新たに調べて再入門した記録です。書きなぐりです。ご容赦ください。あと、以下はwndowsを想定してます。適宜自分の環境に置き換えてください。
windowsでいい感じに使えるようになったら自宅のmacにも設定予定。
基本的な設定
基本以下の記事を参考にさせていただいております。 フォントやメニュー非表示など細かいとこは変更しておりますが、基本は同じです。 詳細は以下の記事を参照してください。
うわっ...私のEmacs、使いにくすぎ?だったら...カスタマイズシヤッセー!!ダァダァシエリイェッスッシェーショーヘイヘイ!!! - 三等兵
windowsのフォントはMeiryoKe_Gothicを使用。 ここを参照。
Windowsで文字表示をなめらかにするための各種設定 - すたらブログ
; -*- Mode: Emacs-Lisp ; Coding: utf-8 -*- ;; ------------------------------------------------------------------------ ;; @ load-path ;; load-pathの追加関数 (defun add-to-load-path (&rest paths) (let (path) (dolist (path paths paths) (let ((default-directory (expand-file-name (concat user-emacs-directory path)))) (add-to-list 'load-path default-directory) (if (fboundp 'normal-top-level-add-subdirs-to-load-path) (normal-top-level-add-subdirs-to-load-path)))))) ;; load-pathに追加するフォルダ ;; 2つ以上フォルダを指定する場合の引数 => (add-to-load-path "elisp" "xxx" "xxx") (add-to-load-path "elisp") ;; ------------------------------------------------------------------------ ;; @ general ;; common lisp (require 'cl) ;; 文字コード (set-language-environment "Japanese") (let ((ws window-system)) (cond ((eq ws 'w32) (prefer-coding-system 'utf-8-unix) (set-default-coding-systems 'utf-8-unix) (setq file-name-coding-system 'sjis) (setq locale-coding-system 'utf-8)) ((eq ws 'ns) (require 'ucs-normalize) (prefer-coding-system 'utf-8-hfs) (setq file-name-coding-system 'utf-8-hfs) (setq locale-coding-system 'utf-8-hfs)))) ;; Windowsで英数と日本語にMeiryoを指定 ;; Macで英数と日本語にRictyを指定 (let ((ws window-system)) (cond ((eq ws 'w32) (set-face-attribute 'default nil :family "MeiryoKe_Gothic" ;; 英数 :height 100) (set-fontset-font nil 'japanese-jisx0208 (font-spec :family "MeiryoKe_Gothic"))) ;; 日本語 ((eq ws 'ns) (set-face-attribute 'default nil :family "Ricty" ;; 英数 :height 140) (set-fontset-font nil 'japanese-jisx0208 (font-spec :family "Ricty"))))) ;; 日本語 ;; スタートアップ非表示 (setq inhibit-startup-screen t) ;; scratchの初期メッセージ消去 (setq initial-scratch-message "") ;; ツールバー非表示 (tool-bar-mode -1) ;; メニューバーを非表示 (menu-bar-mode -1) ;; スクロールバー非表示 (set-scroll-bar-mode nil) ;; タイトルバーにファイルのフルパス表示 (setq frame-title-format (format "%%f - Emacs@%s" (system-name))) ;; 行番号表示 (global-linum-mode t) (set-face-attribute 'linum nil :foreground "#bf616a" :height 0.9) ;; 行番号フォーマット (setq linum-format "%4d") ;; 括弧の範囲内を強調表示 (show-paren-mode t) (setq show-paren-delay 0) (setq show-paren-style 'expression) ;; 括弧の範囲色 (set-face-background 'show-paren-match-face "#1ABC9C") ;; 選択領域の色 (set-face-background 'region "#555") ;; 行末の空白を強調表示 (setq-default show-trailing-whitespace t) (set-face-background 'trailing-whitespace "#b14770") ;; タブをスペースで扱う (setq-default indent-tabs-mode nil) ;; タブ幅 (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(custom-safe-themes (quote ("11dd7fb48f2c0360f79e80a694c9e919a86dce32e5605018e9862e1e6287e3cb" default))) '(tab-width 4)) ;; yes or noをy or n (fset 'yes-or-no-p 'y-or-n-p) ;; 最近使ったファイルの表示数 (setq recentf-max-menu-items 10) ;; 最近開いたファイルの保存数を増やす (setq recentf-max-saved-items 3000) ;; ミニバッファの履歴を保存する (savehist-mode 1) ;; ミニバッファの履歴の保存数を増やす (setq history-length 3000) ;; バックアップを残さない (setq make-backup-files nil) ;; 行間 (setq-default line-spacing 0) ;; 1行ずつスクロール (setq scroll-conservatively 35 scroll-margin 0 scroll-step 1) (setq comint-scroll-show-maximum-output t) ;; shell-mode ;; フレームの透明度 (set-frame-parameter (selected-frame) 'alpha '(0.95))
モードラインの設定
これもまんまこちらから。
うわっ...私のEmacs、使いにくすぎ?だったら...カスタマイズシヤッセー!!ダァダァシエリイェッスッシェーショーヘイヘイ!!! - 三等兵
;; モードラインに行番号表示 (line-number-mode t) ;; モードラインに列番号表示 (column-number-mode t) ;; ------------------------------------------------------------------------ ;; @ modeline ;; モードラインの割合表示を総行数表示 (defvar my-lines-page-mode t) (defvar my-mode-line-format) (when my-lines-page-mode (setq my-mode-line-format "%d") (if size-indication-mode (setq my-mode-line-format (concat my-mode-line-format " of %%I"))) (cond ((and (eq line-number-mode t) (eq column-number-mode t)) (setq my-mode-line-format (concat my-mode-line-format " (%%l,%%c)"))) ((eq line-number-mode t) (setq my-mode-line-format (concat my-mode-line-format " L%%l"))) ((eq column-number-mode t) (setq my-mode-line-format (concat my-mode-line-format " C%%c")))) (setq mode-line-position '(:eval (format my-mode-line-format (count-lines (point-max) (point-min))))))
テーマの設定
MetroWind/emacs-flatui-theme · GitHubをカスタマイズしています。 面倒くさかったので色をベタに上書きしてやりました。 色はsublimetextのテーマ『SpaceGray』の『Base16 Ocean Dark color scheme』から引っ張ってきました。
MetroWind/emacs-flatui-theme · GitHub
・背景色
(defvar fui-bg "#2b303b")
・コード色
`(font-lock-builtin-face ((t (:foreground ,"#ab7967")))) `(font-lock-comment-face ((t (:slant italic :foreground ,"#65737e")))) `(font-lock-constant-face ((t (:slant italic :foreground ,"#d08770")))) `(font-lock-function-name-face ((t (:foreground ,"#8fa1b3")))) `(font-lock-keyword-face ((t (:foreground ,"#c0c5ce")))) `(font-lock-string-face ((t (:foreground ,"#a3be8c")))) `(font-lock-type-face ((t (:foreground ,"#ebcb8b")))) `(font-lock-variable-name-face ((t (:foreground ,"#bf616a"))))
テーマのロード
;; ------------------------------------------------------------------------ ;; カスタムテーマのロード (setq custom-theme-directory "~/.emacs.d/themes/") (load-theme 'FlatUI t)
こんなんなりました。
しかしこの記事書いてるときに見つけた以下のテーマもいけてる。 機を見て使ってみる。
nishikawasasaki/ns-milk-theme · GitHub
空白の設定
全角スペースを強調。赤くなる。
;; ------------------------------------------------------------------------- ;; @ whitespace (global-whitespace-mode 1) (setq whitespace-space-regexp "\\(\u3000\\)") (setq whitespace-style '(face tabs tab-mark spaces space-mark)) (setq whitespace-display-mappings ()) (set-face-foreground 'whitespace-tab "#F1C40F") (set-face-background 'whitespace-space "#E74C3C")
C - hをバックスペースに設定
C
-h
でバックスペース。
;; ------------------------------------------------------------------------- (global-set-key "\C-h" 'delete-backward-char)
C + x fで最近開いたファイルからファイルを開く
C
-x
f
で最近開いたファイルからファイルを開く
;; ------------------------------------------------------------------------- (global-set-key "\C-xf" 'recentf-open-files)
package.elの設定
Emacs24からパッケージシステムが標準添付となったらしい。 最初こいつの存在を知らずにauto-install.elでパッケージいれてた。
;; ------------------------------------------------------------------------- ;;; package.el (require 'package) ;; MELPAを追加 (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/")) ;; Marmaladeを追加 (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/")) ;; 初期化 (package-initialize)
auto-complete.elの設定
以下の記事を参照
C
-n
、C
-p
で前後の候補を選択C
-m
で決定するよう設定
「Emacsのトラノマキ」連載第09回「auto-completeを使おう」(松山智大) | ありえるえりあ
;; ------------------------------------------------------------------------ ;; @ autocomplete.el (require 'auto-complete) (require 'auto-complete-config) (global-auto-complete-mode t) (define-key ac-completing-map (kbd "C-n") 'ac-next) (define-key ac-completing-map (kbd "C-p") 'ac-previous) (define-key ac-completing-map (kbd "C-m") 'ac-complete)
auto-install.elの設定
これも以下の記事を参照。
うわっ...私のEmacs、使いにくすぎ?だったら...カスタマイズシヤッセー!!ダァダァシエリイェッスッシェーショーヘイヘイ!!! - 三等兵
このとき、package.elの存在を知らず、後になって不要だったのか・・。って思ったけど、るびきちさん曰く
とはいえ、必ずしもパッケージに登録されているとは限りません。 URL指定やEmacsWikiからもインストールできるようにしておくと楽です。
とのこと。
;; ------------------------------------------------------------------------ ;; @ auto-install.el ;; パッケージのインストールを自動化 ;; http://www.emacswiki.org/emacs/auto-install.el (when (require 'auto-install nil t) (setq auto-install-directory "~/.emacs.d/elisp/") (auto-install-update-emacswiki-package-name t) (auto-install-compatibility-setup)) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. )
redo.elの設定
こちらも以下の記事を参考に。
C
-_
でredo。
うわっ...私のEmacs、使いにくすぎ?だったら...カスタマイズシヤッセー!!ダァダァシエリイェッスッシェーショーヘイヘイ!!! - 三等兵
;; ------------------------------------------------------------------------ ;; @ redo+.el ;; redoできるようにする ;; http://www.emacswiki.org/emacs/redo+.el (when (require 'redo+ nil t) (define-key global-map (kbd "C-_") 'redo))
tabbar.elの設定
以下の記事を参考に不要な部分を削除し、タブの色をテーマに合わせました。
C
-tab
、C
-Shift
-Tab
でタブを行き来。
elscreen 改め tabbar のインストールログ - テクノ組曲
;; ------------------------------------------------------------------------- ;; ;; tabbar ;; (install-elisp "http://www.emacswiki.org/emacs/download/tabbar.el") ;; (require 'tabbar) (tabbar-mode 1) ;; タブ上でマウスホイール操作無効 (tabbar-mwheel-mode -1) ;; グループ化しない (setq tabbar-buffer-groups-function nil) ;; 左に表示されるボタンを無効化 (dolist (btn '(tabbar-buffer-home-button tabbar-scroll-left-button tabbar-scroll-right-button)) (set btn (cons (cons "" nil) (cons "" nil)))) ;; タブの長さ (setq tabbar-separator '(2.2)) ;; 外観変更 (set-face-attribute 'tabbar-default nil :family "MeiryoKe_Gothic" :background "#34495E" :foreground "#EEEEEE" :height 0.95 ) (set-face-attribute 'tabbar-unselected nil :background "#34495E" :foreground "#EEEEEE" :box nil ) (set-face-attribute 'tabbar-modified nil :background "#E67E22" :foreground "#EEEEEE" :box nil ) (set-face-attribute 'tabbar-selected nil :background "#E74C3C" :foreground "#EEEEEE" :box nil) (set-face-attribute 'tabbar-button nil :box nil) (set-face-attribute 'tabbar-separator nil :height 2.0) ;; タブに表示させるバッファの設定 (defvar my-tabbar-displayed-buffers '("*scratch*" "*Messages*" "*Backtrace*" "*Colors*" "*Faces*" "*vc-") "*Regexps matches buffer names always included tabs.") (defun my-tabbar-buffer-list () "Return the list of buffers to show in tabs. Exclude buffers whose name starts with a space or an asterisk. The current buffer and buffers matches `my-tabbar-displayed-buffers' are always included." (let* ((hides (list ?\ ?\*)) (re (regexp-opt my-tabbar-displayed-buffers)) (cur-buf (current-buffer)) (tabs (delq nil (mapcar (lambda (buf) (let ((name (buffer-name buf))) (when (or (string-match re name) (not (memq (aref name 0) hides))) buf))) (buffer-list))))) ;; Always include the current buffer. (if (memq cur-buf tabs) tabs (cons cur-buf tabs)))) (setq tabbar-buffer-list-function 'my-tabbar-buffer-list) ;; Ctrl-Tab, Ctrl-Shift-Tab でタブを切り替える (dolist (func '(tabbar-mode tabbar-forward-tab tabbar-forward-group tabbar-backward-tab tabbar-backward-group)) (autoload func "tabbar" "Tabs at the top of buffers and easy control-tab navigation")) (defmacro defun-prefix-alt (name on-no-prefix on-prefix &optional do-always) `(defun ,name (arg) (interactive "P") ,do-always (if (equal nil arg) ,on-no-prefix ,on-prefix))) (defun-prefix-alt shk-tabbar-next (tabbar-forward-tab) (tabbar-forward-group) (tabbar-mode 1)) (defun-prefix-alt shk-tabbar-prev (tabbar-backward-tab) (tabbar-backward-group) (tabbar-mode 1)) (global-set-key [(control tab)] 'shk-tabbar-next) (global-set-key [(control shift tab)] 'shk-tabbar-prev)
こんなんなりました。 オレンジは変更があるバッファ、赤は選択されたバッファです。
google-c-style.elの設定
googleの規約にそってスタイルを整形してくれるっぽい。
;; ------------------------------------------------------------------------- ;; @ google-c-style (require 'google-c-style) (add-hook 'c-mode-common-hook 'google-set-c-style) (add-hook 'c-mode-common-hook 'google-make-newline-indent)
その他C言語用の設定
Cの場合自動改行とかインデントとか。
;; 自動改行+インデント (add-hook 'c-mode-common-hook '(lambda () ;; センテンスの終了である ';' を入力したら、自動改行+インデント (c-toggle-auto-hungry-state 1) ;; RET キーで自動改行+インデント (define-key c-mode-base-map "\C-m" 'newline-and-indent) ))
minimap.elの設定
SublimeTextでおなじみ。デフォルトはきってあります。
この右側に表示されたコード全体を俯瞰できるやつです。
M
-x
minimap-mode
で有効になる。
;; ------------------------------------------------------------------------- ;; @ minimap (require 'minimap)
右端のやつ。
anzuの設定
おすすめと聞いて。 以下を参考。
自分が入れたEmacs便利拡張・設定集 (2013年版) - $shibayu36->blog;
できることとして検索中に現在位置が何番目のwordか知る 置換結果をpreviewしながら置換できる もちろん$1とか使っても出来る
;; ------------------------------------------------------------------------ ;; @anzu (require 'anzu) (global-anzu-mode +1) (setq anzu-use-migemo t) (setq anzu-search-threshold 1000) (setq anzu-minimum-input-length 3) (global-set-key (kbd "C-c r") 'anzu-query-replace) (global-set-key (kbd "C-c R") 'anzu-query-replace-regexp)
helmの設定
anythingの後継らしい。必須。
;; ------------------------------------------------------------------------- ;; helm (require 'helm-config) (helm-mode 1)
browse-kill-ringの設定
以下の記事を参考に。
M
-y
でkill-ringの一覧を表示する。
helm や anything.el でも同等の機能が存在するので、 無理してインストールする必要はありません
あれ?不要?この辺よくわかってない。
;; ------------------------------------------------------------------------ ;; @ browse-kill-ring.el (global-set-key (kbd "M-y") 'browse-kill-ring)
coffee-modeの設定
オートコンパイルモードも持っていて優秀なんだけど、自分のwindows7環境では動かなかったのでコンパイルはflymakeで行っている。
;; ------------------------------------------------------------------------- ;; @coffee-mode.el (require 'coffee-mode) (add-to-list 'auto-mode-alist '("\.coffee$" . coffee-mode)) (add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode)) ;; coffeescript (custom-set-variables '(coffee-tab-width 2))
expand-region.elの設定
以下の記事を参考にさせていただきました。
以下の設定の場合、C
-@
でリージョンが広がっていき、C
-M
-@
でリージョンが狭くなっていきます。
自分が入れたEmacs便利拡張・設定集 (2013年版) - $shibayu36->blog;
;; ------------------------------------------------------------------------- ;; @expand region (require 'expandp-region) (global-set-key (kbd "C-@") 'er/expand-region) (global-set-key (kbd "C-M-@") 'er/contract-region) ;; リージョンを狭める ;; transient-mark-modeが nilでは動作しませんので注意 (transient-mark-mode t)
リージョンの内容でisearchする設定
expand-region->isearchが便利。 これも以下の記事を参考に。いっぱい参考にさせていただきました、ありがとうございます。
自分が入れたEmacs便利拡張・設定集 (2013年版) - $shibayu36->blog;
;; ------------------------------------------------------------------------- ;;; 選択範囲をisearch (defadvice isearch-mode (around isearch-mode-default-string (forward &optional regexp op-fun recursive-edit word-p) activate) (if (and transient-mark-mode mark-active (not (eq (mark) (point)))) (progn (isearch-update-ring (buffer-substring-no-properties (mark) (point))) (deactivate-mark) ad-do-it (if (not forward) (isearch-repeat-backward) (goto-char (mark)) (isearch-repeat-forward))) ad-do-it))
cmigeoの設定
ローマ字で日本語検索。 この記事を参考に。
mieki256's diary - NTEmacsを23.4から24.3に変更してみたり
C/Migemo — KaoriYa からWindowsバイナリをダウンロードしパスを通す。 なかなか動かなかったけどひとまずこれで動いた。
(require 'migemo) (setq migemo-command "cmigemo") (setq migemo-options '("-q" "--emacs" "-i" "\g")) ;; migemo-dict のパスを指定 (setq migemo-dictionary (expand-file-name "~/.emacs.d/cmigemo-default-win32/dict/utf-8/migemo-dict")) (setq migemo-user-dictionary nil) (setq migemo-regex-dictionary nil) ;; 辞書の文字コードを指定. (setq migemo-coding-system 'utf-8-unix) ;; キャッシュ機能を利用する (setq migemo-use-pattern-alist t) (setq migemo-use-frequent-pattern-alist t) (setq migemo-pattern-alist-length 1024) (load-library "migemo") ;; 起動時に初期化も行う (migemo-init)
helm-migeo/helm-swoop/ace-isearchの設定
『日刊Emacs』でおすすめされたhelm-swoop.elを入れてみます。 これ最高!
これを一言で言うと、 helm インターフェースを使って バッファ内・全バッファを 絞り込み検索 するものです。 M-x helm-occur 、 M-x helm-multi-occur の超強化版です。 『かゆいところに手が届く』helm-occur+αです。
設定はそのままです。
;; ------------------------------------------------------------------------- ;; @helm-swoop ;;; この前にmigemoの設定が必要 (require 'helm-migemo) ;;; この修正が必要 (eval-after-load "helm-migemo" '(defun helm-compile-source--candidates-in-buffer (source) (helm-aif (assoc 'candidates-in-buffer source) (append source `((candidates . ,(or (cdr it) (lambda () ;; Do not use `source' because other plugins ;; (such as helm-migemo) may change it (helm-candidates-in-buffer (helm-get-current-source))))) (volatile) (match identity))) source))) (require 'helm-swoop) ;;; isearchからの連携を考えるとC-r/C-sにも割り当て推奨 (define-key helm-swoop-map (kbd "C-r") 'helm-previous-line) (define-key helm-swoop-map (kbd "C-s") 'helm-next-line) ;;; 検索結果をcycleしない、お好みで (setq helm-swoop-move-to-line-cycle nil) (cl-defun helm-swoop-nomigemo (&key $query ($multiline current-prefix-arg)) "シンボル検索用Migemo無効版helm-swoop" (interactive) (let ((helm-swoop-pre-input-function (lambda () (format "\\_<%s\\_> " (thing-at-point 'symbol))))) (helm-swoop :$source (delete '(migemo) (copy-sequence (helm-c-source-swoop))) :$query $query :$multiline $multiline))) ;;; C-M-:に割り当て (global-set-key (kbd "C-M-:") 'helm-swoop-nomigemo) ;;; [2014-11-25 Tue] (when (featurep 'helm-anything) (defadvice helm-resume (around helm-swoop-resume activate) "helm-anything-resumeで復元できないのでその場合に限定して無効化" ad-do-it)) ;;; ace-isearch (global-ace-isearch-mode 1)
highlight-symbolの設定
以下の記事を参考にさせていただきました。
以下の設定の場合、C
-S
-h
でカーソルのある位置のsymbolをハイライト、C
-S
-M
-h
でハイライトの消去。
自分が入れたEmacs便利拡張・設定集 (2013年版) - $shibayu36->blog;
;; ------------------------------------------------------------------------- ;; highlight-symbol (require 'highlight-symbol) (setq highlight-symbol-colors '("DarkOrange" "DodgerBlue1" "DeepPink1")) ;; 使いたい色を設定、repeatしてくれる。 ;; 適宜keybindの設定 (global-set-key (kbd "C-S-h") 'highlight-symbol-at-point) (global-set-key (kbd "C-S-M-h") 'highlight-symbol-remove-all)
markdown-modeの設定
インストールのみ。
markdownのハイライトに。
C
-c
C
-c
m
でコンパイル、C
-c
C
-c
p
でプレビューできる?
multiple-cursorsの設定
以下の記事を参考にさせていただきました。 SublimeTextではデフォルトの機能です。 個人的にこいつは必須です。
multiple-cursors.el を使おう - あじーん-0.0.2-SNAPSHOT
;; ------------------------------------------------------------------------- ;; @multiple-cursors.el ;; (require 'multiple-cursors) (global-set-key (kbd "C->") 'mc/mark-next-like-this) (global-set-key (kbd "C-M->") 'mc/skip-to-next-like-this) (global-set-key (kbd "C-<") 'mc/mark-previous-like-this) (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
リージョンが存在しない場合はC
->
で下に新たなカーソルを、C
-M
->
で上に新たなカーソルを生成します。
こんなことができます。
リージョン状態の場合は、C
->
、C
-M
->
でリージョンと同じ内容の位置にカーソルを追加していきます。
quickrunの設定
名前の通り本来コード実行用のパッケージですが、coffeeのコンパイル後のJSを見るのに設定しました。
"quickrun-compile-onl"をC
-c
c
に割り当てました。
;; ------------------------------------------------------------------------- ;; @quickrun.el (require 'quickrun) (global-set-key "\C-cc" 'quickrun-compile-only)
yasnippetの設定
スニペット展開プラグイン。 以下の記事を参考に基本設定。
emacs 最強スニペット展開プラグイン yasnippet.elのインストール! - プログラミングのメモ
;; @yasnippet ;;自分用のスニペットフォルダと,拾ってきたスニペットフォルダの2つを作っておきます. (require 'yasnippet) (setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet/mySnippets" "~/.emacs.d/elpa/yasnippet/snippets" )) ;; yas起動 (yas-global-mode 1) ;; 既存スニペットを挿入する (define-key yas-minor-mode-map (kbd "C-x i i") 'yas-insert-snippet) ;; 新規スニペットを作成するバッファを用意する (define-key yas-minor-mode-map (kbd "C-x i n") 'yas-new-snippet) ;; 既存スニペットを閲覧・編集する (define-key yas-minor-mode-map (kbd "C-x i v") 'yas-visit-snippet-file)
helm対応を以下の記事を参考に設定。anythingの部分をhelmに変更するだけで動いた。
yasnippetの見直しをした - $shibayu36->blog;
;; helm interface (eval-after-load "helm-config" '(progn (defun my-yas/prompt (prompt choices &optional display-fn) (let* ((names (loop for choice in choices collect (or (and display-fn (funcall display-fn choice)) choice))) (selected (helm-other-buffer `(((name . ,(format "%s" prompt)) (candidates . names) (action . (("Insert snippet" . (lambda (arg) arg)))))) "*helm yas/prompt*"))) (if selected (let ((n (position selected names :test 'equal))) (nth n choices)) (signal 'quit "user quit!")))) (custom-set-variables '(yas/prompt-functions '(my-yas/prompt)))))
AutoCompleteとの連携はこれから設定する
wgrepの設定
grep で絞り込んだ行を、そのバッファ内で直接編集することが出来るやつ。 以下を参考に。
wgrep.el が便利 - amari3のはてなダイアリー
使い方 M-x grepやrgrepで得た検索結果(grepバッファ)で編集する C-c C-p 編集を開始する C-x C-s/C-c C-c/C-c C-e 編集内容を確定 C-c C-k 編集した内容を破棄してwgrepを終了する C-x C-q wgrepを終了する
;; ------------------------------------------------------------------------ ;; @ wgrep.el (require 'wgrep nil t)
flymakeの設定
ひとまず、Cの文法チェックとcoffeeのコンパイル兼文法チェックに設定 以下の記事を参考に。
flymake (いままでこれ無しでどうやってプログラム書いてたんだろう) - にゃあさんの戯言日記
;; ------------------------------------------------------------------------ ;; @ flymake.el (require 'flymake) ;; 色設定 (set-face-background 'flymake-errline "#E74C3C") (set-face-foreground 'flymake-errline "white")
あと以下を設定しておかないとエラー時に終了してしまったりいろいろ問題がでる。 以下を参考に設定。
flymakeでエラーになり、またバッファーを開こうとするとEmacsが固まるときの対処 - Qiita
;; チェック後にエラーしても終了しないようにする (defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted) (setq flymake-check-was-interrupted t)) (ad-activate 'flymake-post-syntax-check)
C言語用
;; c (defun flymake-c-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "gcc" (list "-Wall" "-Wextra" "-fsyntax-only" local-file)))) (push '("\\.c$" flymake-c-init) flymake-allowed-file-name-masks) (add-hook 'c-mode-hook '(lambda () (flymake-mode t)))
cppcheckもかけたいので要調査。
CoffeeScript用
よく理解してないけどこれでコンパイルされるようになった。
;; coffee (defun flymake-coffee-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name (buffer-file-name)))) (list "coffee" (list "-c" local-file)))) (push '(".+\\.coffee$" flymake-coffee-init) flymake-allowed-file-name-masks) (add-hook 'coffee-mode-hook '(lambda () (flymake-mode t)))
magitの設定
これまでcygwinのgitを使用していたんですが、さまざまなエラーに見舞われたのでmsysgitに乗り換えました。 以下の記事を参考にさせていただきました。 使用方法はこれから勉強。
Emacs Magitメモ | magiccircuit.com
C
-c
m
にmagit-statusを割り当て。
しかし遅いです。magit-statusで10秒くらいかかる。 以下を参考にしてみましたが、改善せず。ぐむむ。
;; ------------------------------------------------------------------------ ;; @ magit.el (require 'magit) (setq magit-git-executable "C:/Program Files/Git/cmd/git.exe") (global-set-key "\C-cm" 'magit-status)
web-modeの設定
以下を参考に。html書くよう。 これに相当するパッケージってSublimeTextでありますか?
Emacsでhtml書いてる人、必見 web-mode.el - Web学び
;; ------------------------------------------------------------------------ ;; @ web-mode.el (require 'web-mode) (add-to-list 'auto-mode-alist '("\\.phtml$" . web-mode)) (add-to-list 'auto-mode-alist '("\\.tpl\\.php$" . web-mode)) (add-to-list 'auto-mode-alist '("\\.jsp$" . web-mode)) (add-to-list 'auto-mode-alist '("\\.as[cp]x$" . web-mode)) (add-to-list 'auto-mode-alist '("\\.erb$" . web-mode)) (add-to-list 'auto-mode-alist '("\\.html?$" . web-mode)) ;;; インデント数 (defun web-mode-hook () "Hooks for Web mode." (setq web-mode-html-offset 2) (setq web-mode-css-offset 2) (setq web-mode-script-offset 2) (setq web-mode-php-offset 2) (setq web-mode-java-offset 2) (setq web-mode-asp-offset 2)) (add-hook 'web-mode-hook 'web-mode-hook)
emmet-modeの設定
ここを参考に。
Emacsの便利な設定 - Catcher in the tech
emmetはずっと入門できずにいたのでこの機会に。
;; ------------------------------------------------------------------------ ;; @ emmet-mode.el ;; http://catcher-in-the-tech.net/55/ (require 'emmet-mode) (add-hook 'sgml-mode-hook 'emmet-mode) (add-hook 'php-mode-hook 'emmet-mode) (add-hook 'emmet-mode-hook (lambda () (setq emmet-indentation 2))) (define-key emmet-mode-keymap (kbd "C-c C-j") 'emmet-expand-line)
git-gutter+の設定
git-gutterよりgit-gutter+のほうが早いらしい。
デフォルトは切っておいてC
-x
G
で有効にする。
デフォルトで有効にしておくとなぜか行番号がずれる。
nonsequitur/git-gutter-plus · GitHub
;; ------------------------------------------------------------------------ ;; @ git-gutter+.el (global-set-key (kbd "C-x g") 'git-gutter+-mode) ; Turn on/off in the current buffer (global-set-key (kbd "C-x G") 'global-git-gutter+-mode) ; Turn on/off globally (eval-after-load 'git-gutter+ '(progn ;;; Jump between hunks (define-key git-gutter+-mode-map (kbd "C-x n") 'git-gutter+-next-hunk) (define-key git-gutter+-mode-map (kbd "C-x p") 'git-gutter+-previous-hunk) ;;; Act on hunks (define-key git-gutter+-mode-map (kbd "C-x v =") 'git-gutter+-show-hunk) (define-key git-gutter+-mode-map (kbd "C-x r") 'git-gutter+-revert-hunks) ;; Stage hunk at point. ;; If region is active, stage all hunk lines within the region. (define-key git-gutter+-mode-map (kbd "C-x t") 'git-gutter+-stage-hunks) (define-key git-gutter+-mode-map (kbd "C-x c") 'git-gutter+-commit) (define-key git-gutter+-mode-map (kbd "C-x C") 'git-gutter+-stage-and-commit) (define-key git-gutter+-mode-map (kbd "C-x C-y") 'git-gutter+-stage-and-commit-whole-buffer) (define-key git-gutter+-mode-map (kbd "C-x U") 'git-gutter+-unstage-whole-buffer)))
これから
verilog-modeとかsass-modeとか、jadeとかいろいろ入れる。 スニペットを充実させたり、細かいところのチューニングする。
雑感
まだ使いこなせてないけど、helm-swoopとかmagitとか最高だった。興奮した。SublimeTextで同じくらい快適な環境が用意できる気がいまのところしないです。あとで初心者らしく自分用のチートシートを作ろう。

Emacs実践入門 ?思考を直感的にコード化し、開発を加速する (WEB+DB PRESS plus)
- 作者: 大竹智也
- 出版社/メーカー: 技術評論社
- 発売日: 2012/03/07
- メディア: 単行本(ソフトカバー)
- 購入: 22人 クリック: 396回
- この商品を含むブログ (1件) を見る

Emacsテクニックバイブル ?作業効率をカイゼンする200の技?
- 作者: るびきち
- 出版社/メーカー: 技術評論社
- 発売日: 2010/08/03
- メディア: 単行本(ソフトカバー)
- 購入: 27人 クリック: 1,039回
- この商品を含むブログ (68件) を見る

- 作者: るびきち
- 出版社/メーカー: 技術評論社
- 発売日: 2011/11/26
- メディア: 単行本(ソフトカバー)
- 購入: 5人 クリック: 220回
- この商品を含むブログを見る