Emacs設定

init_loaderを使って設定毎にファイルを分ける方針

# init.el

```
(let ((default-directory (expand-file-name "~/.emacs.d/site-lisp")))
  (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)))

(require 'init-loader)
(setq init-loader-show-log-after-init nil)
(init-loader-load "~/.emacs.d/inits")
```
# 00-base.el

```
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Basic config
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;BS->backspace
(keyboard-translate ?\C-h ?\C-?)

;;don't show menu-bar
(menu-bar-mode -1)

;;Auto Save off
(setq auto-save-default nil)
(setq auto-save-list-file-name nil)
(setq auto-save-list-file-prefix nil)
(setq make-backup-files nil)

;;Display column number
(column-number-mode 1)

;;hilight paren
(show-paren-mode 1)

;;indent
(setq-default tab-width 4 indent-tabs-mode nil)

;;C-x p move windows reverce
(global-set-key "\C-xp" (lambda () (interactive) (other-window -1)))

;;add execute authority
(add-hook 'after-save-hook
      'executable-make-buffer-file-executable-if-script-p)

;;Display file path at mode-line
(set-default 'mode-line-buffer-identification
         '(buffer-file-name ("%f") ("%b")))

;;scroll number
(setq scroll-step 1)

;;ido-mode
(require 'ido)
(ido-mode t)

;;record last place
(require 'saveplace)
(setq-default save-place t)

;;enable ungry deletion
(setq c-hungry-delete-key t)

;;display
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
```

# 01-keybinds.el
```
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;keybind
;;;;;;;;;;;;;;;;;;;;;;;;;;;

(global-unset-key "\C-\\")

(global-set-key "\C-m" 'newline-and-indent)
(global-set-key "\C-c\C-c" 'comment-dwim)
(global-set-key "\C-j" 'newline)

(global-set-key "\C-c\C-g" 'grep)
(global-set-key "\C-c\C-f" 'find-grep)
(global-set-key "\C-c\C-l" 'goto-line)

(global-set-key "\C-c\C-v" 'set-mark-command)

(global-set-key "\C-c\C-e" 'execute-extended-command)

;;hexl-mode
(defun hexl-mode-hooks ()
  (define-key hexl-mode-map (kbd "C-c i") 'hexl-insert-hex-string))

(add-hook 'hexl-mode-hook 'hexl-mode-hooks)
```

# 04-package.el
起動時にパッケージがインストールされていない場合自動的にインストールする。
インストールしたいパッケージは、installing-package-list 変数で定義

応用としては Ruby 用の el ファイルでインストールしたいパッケージを変数で定義して install-package 関数を呼ぶと Ruby で必要なパッケージを起動時にインストールしたりも可能
が、起動時にパッケージをチェックするので起動が遅くなっている気がする

```
;;package.el
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "https://melpa.milkbox.net/packages/")))

;; proxy setting
(setq url-proxy-service
      '(("http" . "*****:8080")
        ("https" . "****:8080")))

;; basic package list
(defvar package-list '(multi-term
                                  auto-complete
                                  helm
                                  helm-gtags))

(package-initialize)

;; install basic package
(require 'cl)
(defun install-package (pacakage-list)
  (let ((not-installed (loop for x in package-list
                             when (not (package-installed-p x))
                             collect x)))
    (when not-installed
      (package-refresh-contents)
      (dolist (pkg not-installed)
        (package-install pkg)))))



;; install package
(install-package package-list)
```

# 05-helm.el

```
;; helm
(require 'helm-config)
(require 'helm-gtags)
(helm-mode 1)

(global-set-key "\C-xb" 'helm-for-files)
(global-set-key "\M-y" 'helm-show-kill-ring)
```

# 05-multi-term.el
色々試したけど、multi-term が一番しっくりきたので

```
(require 'multi-term)

(defun toggle-term-mode()
  "Toggles term mode(line <--> char)"
  (interactive)
  (if (term-in-line-mode)
      (term-char-mode)
    (term-line-mode)))

(setq multi-term-program shell-file-name)

(global-set-key "\C-c\C-t" 'multi-term)

;; keybinds for multi-term
(defun term-mode-hooks ()
  ;term-char
  (define-key term-raw-map (kbd "C-c C-p") 'multi-term-prev)
  (define-key term-raw-map (kbd "C-c C-n") 'multi-term-next)
  (define-key term-raw-map (kbd "C-c C-j") 'toggle-term-mode)

  (define-key term-raw-map (kbd "C-p") 'term-send-up)
  (define-key term-raw-map (kbd "C-n") 'term-send-down)

  ;term-line
  (define-key term-mode-map (kbd "C-c C-p") 'multi-term-prev)
  (define-key term-mode-map (kbd "C-c C-n") 'multi-term-next)
  (define-key term-mode-map (kbd "C-c C-j") 'toggle-term-mode))

(add-hook 'term-mode-hook 'term-mode-hooks)
```

だれか、コメント、アンコメントを切り替えられる設定教えてください。(comment-region と uncomment-region を C-c C-m で切り替えるようなもの、、)