読者です 読者をやめる 読者になる 読者になる

(define -ayalog '())

括弧に魅せられて道を外した名前のないプログラマ

Emacsの設定をやり直した!

昨日、 @ さんに Emacs の使い方教えようとして、とりあえず anything とか入れてあげたんだけど設定してあげているうちに Emacs 24 になってから Package.el が使える分、設定の仕方が少し変わったりしていることに気付いたので自分のもこの機会に少し変えてみようと思って最初からいじり直してみた。

メジャーどころで入れているのは anything, auto-complete, auto-install あたり。
それ以外には e2wm や inertial-scroll を入れている。

RubyGauche が書ける最小構成を目指していた気がするけど、気が付いたら半日経過していたあたり Emacs の設定は沼だと思う。
Ruby 書く設定は今までと少し趣を変えて RSense を導入したりしてみた。 RSense, ruby-end-mode, rcodetools を導入した。 inf-ruby が少し気になったけど、 RSense と競合してしまってどうしようもなかったので諦めた。

今回一番感動したのは anything-filelist+ だったりする。これ入れて少し人生変わった感じある(大げさ
階層をあまり意識しないで済むので非常に良い。 anything 的なパターンマッチでファイル名の検索が出来るのも点数高い。Emacs使うときはだいたいプログラミングするときなので、 filelist はプログラム書くときに使っているディレクトリ以下のファイルだけにした。これのお陰で重くないし凄く快適です。

以下は今回の設定で出来上がった init.el です。最近だとファイルを分けたり、ディレクトリを分けたりするみたいだけど、まぁそんなに行数が多いわけじゃないのでとりあえずいっかなーとか思ってたり。ちなみに一番最後に今回参考にしたとこをリンクしてます。

;; package
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)

(require 'cl)
(defvar installing-package-list
  '(
    anything
    anything-complete
    anything-config
    anything-match-plugin
    anything-obsolete
    anything-show-completion
    auto-complete
    auto-install
    e2wm
    popup
    ruby-end
    ruby-mode
    window-layout
    color-theme-solarized
    ))
(let ((not-installed (loop for x in installing-package-list
                            when (not (package-installed-p x))
                            collect x)))
  (when not-installed
    (package-refresh-contents)
    (dolist (pkg not-installed)
        (package-install pkg))))

;; load path
;; (require 'auto-install)
(add-to-list 'load-path "~/.emacs.d/elisp")
(add-to-list 'load-path "~/.emacs.d/auto-install")

;; mozc
(when (require 'mozc nil t)
  (setq default-input-method "japanese-mozc")
  (setq mozc-candidate-style 'overlay)
  ;; faces
  (set-face-attribute 'mozc-cand-overlay-even-face 'nil
                      :background "aquamarine" :foreground "black")
  (set-face-attribute 'mozc-cand-overlay-odd-face 'nil
                      :background "aquamarine" :foreground "black"))

;; anything
(setq anything-c-filelist-file-name "/tmp/programming.filelist")
(setq anything-grep-candidates-fast-directory-regexp "^/tmp")

;; auto-complete
(require 'auto-complete)
(global-auto-complete-mode t)
(add-hook 'auto-complete-mode-hook
          (lambda ()
            (define-key ac-completing-map (kbd "C-n") 'ac-next)
            (define-key ac-completing-map (kbd "C-p") 'ac-previous)))

;; ruby
(add-to-list 'auto-mode-alist
	     '("Rakefile$" . ruby-mode))

(require 'ruby-end)

;; Rsense
(setq rsense-home (expand-file-name "~/.emacs.d/opt/rsense-0.3"))
(add-to-list 'load-path (concat rsense-home "/etc"))

(require 'rsense)
(add-hook 'ruby-mode-hook
	  (lambda ()
	    (ruby-end-mode)
	    (add-to-list 'ac-sources 'ac-source-rsense-method)
	    (add-to-list 'ac-sources 'ac-source-rsense-constant)))

(require 'rcodetools)
(setq rct-find-tag-if-available nil)
(defun ruby-mode-hook-rcodetools ()
  (define-key ruby-mode-map "\C-c\C-t" 'ruby-toggle-buffer)
  (define-key ruby-mode-map "\C-c\C-d" 'xmp))
(add-hook 'ruby-mode-hook 'ruby-mode-hook-rcodetools)

;; gauche
(setq process-coding-system-alist
      (cons '("gosh" utf-8 . utf-8) process-coding-system-alist))

(setq gosh-program-name "/usr/local/bin/gosh -i")

(autoload 'scheme-mode "cmuscheme" "Major mode for Scheme." t)
(autoload 'run-scheme "cmuscheme" "Run an inferior Scheme process." t)

(defun scheme-other-window ()
  "Run scheme on other window"
  (interactive)
  (split-window-horizontally (/ (frame-width) 2))
  (switch-to-buffer-other-window
   (get-buffer-create "*scheme*"))
  (run-scheme gosh-program-name))
(define-key global-map
  "\C-cS" 'scheme-other-window)

(put 'and-let* 'scheme-indent-function 1)
(put 'begin0 'scheme-indent-function 0)
(put 'call-with-client-socket 'scheme-indent-function 1)
(put 'call-with-input-conversion 'scheme-indent-function 1)
(put 'call-with-input-file 'scheme-indent-function 1)
(put 'call-with-input-process 'scheme-indent-function 1)
(put 'call-with-input-string 'scheme-indent-function 1)
(put 'call-with-iterator 'scheme-indent-function 1)
(put 'call-with-output-conversion 'scheme-indent-function 1)
(put 'call-with-output-file 'scheme-indent-function 1)
(put 'call-with-output-string 'scheme-indent-function 0)
(put 'call-with-temporary-file 'scheme-indent-function 1)
(put 'call-with-values 'scheme-indent-function 1)
(put 'dolist 'scheme-indent-function 1)
(put 'dotimes 'scheme-indent-function 1)
(put 'if-match 'scheme-indent-function 2)
(put 'let*-values 'scheme-indent-function 1)
(put 'let-args 'scheme-indent-function 2)
(put 'let-keywords* 'scheme-indent-function 2)
(put 'let-match 'scheme-indent-function 2)
(put 'let-optionals* 'scheme-indent-function 2)
(put 'let-syntax 'scheme-indent-function 1)
(put 'let-values 'scheme-indent-function 1)
(put 'let/cc 'scheme-indent-function 1)
(put 'let1 'scheme-indent-function 2)
(put 'letrec-syntax 'scheme-indent-function 1)
(put 'make 'scheme-indent-function 1)
(put 'multiple-value-bind 'scheme-indent-function 2)
(put 'match 'scheme-indent-function 1)
(put 'parameterize 'scheme-indent-function 1)
(put 'parse-options 'scheme-indent-function 1)
(put 'receive 'scheme-indent-function 2)
(put 'rxmatch-case 'scheme-indent-function 1)
(put 'rxmatch-cond 'scheme-indent-function 0)
(put 'rxmatch-if  'scheme-indent-function 2)
(put 'rxmatch-let 'scheme-indent-function 2)
(put 'syntax-rules 'scheme-indent-function 1)
(put 'unless 'scheme-indent-function 1)
(put 'until 'scheme-indent-function 1)
(put 'when 'scheme-indent-function 1)
(put 'while 'scheme-indent-function 1)
(put 'with-builder 'scheme-indent-function 1)
(put 'with-error-handler 'scheme-indent-function 0)
(put 'with-error-to-port 'scheme-indent-function 1)
(put 'with-input-conversion 'scheme-indent-function 1)
(put 'with-input-from-port 'scheme-indent-function 1)
(put 'with-input-from-process 'scheme-indent-function 1)
(put 'with-input-from-string 'scheme-indent-function 1)
(put 'with-iterator 'scheme-indent-function 1)
(put 'with-module 'scheme-indent-function 1)
(put 'with-output-conversion 'scheme-indent-function 1)
(put 'with-output-to-port 'scheme-indent-function 1)
(put 'with-output-to-process 'scheme-indent-function 1)
(put 'with-output-to-string 'scheme-indent-function 1)
(put 'with-port-locking 'scheme-indent-function 1)
(put 'with-string-io 'scheme-indent-function 1)
(put 'with-time-counter 'scheme-indent-function 1)
(put 'with-signal-handlers 'scheme-indent-function 1)
(put 'with-locking-mutex 'scheme-indent-function 1)
(put 'guard 'scheme-indent-function 1)

;; uniq
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)

;; whitespace
(setq whitespace-style '(face tabs tab-mark spaces space-mark trailing space-before-tab space-after-tab::space))
(setq whitespace-space-regexp "\\(\x3000+\\)")
(setq whitespace-display-mappings
      '((space-mark ?\x3000 [?\□])
        (tab-mark   ?\t   [?\xBB ?\t])
        ))

(global-whitespace-mode t)
(set-face-attribute 'whitespace-trailing nil
                    :foreground "DeepPink"
                    :underline t)
(set-face-attribute 'whitespace-tab nil
                    :foreground "LightSkyBlue"
                    :underline t)
(set-face-attribute 'whitespace-space nil
                    :foreground "GreenYellow"
                    :weight 'bold)

;; emacs style
;; 起動画面を非表示
(setq inhibit-startup-message t)
;; ツールバー非表示
(tool-bar-mode -1)
;; 現在行をハイライト
(global-hl-line-mode)
;; バックアップを作成しない
(setq backup-inhibited t)
(setq delete-auto-save-files t)
;; 括弧の強調表示
(show-paren-mode t)
;; 括弧の自動入力
(electric-pair-mode t)
(global-font-lock-mode t)
;; 補完時に大文字小文字を区別しない
(setq completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
;; solarized
(load-theme 'solarized-light t)
;; line number
(global-linum-mode t)
(setq linum-format "%4d: ")
;; fullscreen
(defun toggle-fullscreen ()
  (interactive)
  (set-frame-parameter nil 'fullscreen
		       (if (frame-parameter nil 'fullscreen)
					   nil 'fullboth)))
(global-set-key
 [f11] 'toggle-fullscreen)
;;font
(set-default-font "Inconsolata-12")
(set-face-font 'variable-pitch "Inconsolata-12")
(set-fontset-font (frame-parameter nil 'font)
                  'japanese-jisx0208
                  '("Takaoゴシック" . "unicode-bmp"))
;; inertial-scroll
(require 'inertial-scroll)
(setq inertias-global-minor-mode-map 
      (inertias-define-keymap
       '(
         ("<next>"  . inertias-up)
         ("<prior>" . inertias-down)
         ("C-v"     . inertias-up)
         ("M-v"     . inertias-down)
         ) inertias-prefix-key))
(inertias-global-minor-mode 1)

;; e2wm
(require 'e2wm)
(global-set-key (kbd "M-+") 'e2wm:start-management)

(e2wm:add-keymap
 e2wm:pst-minor-mode-keymap
 '(("<M-left>" . e2wm:dp-code) ; codeへ変更
   ("<M-right>"  . e2wm:dp-two)  ; twoへ変更
   ("<M-up>"    . e2wm:dp-doc)  ; docへ変更
   ("<M-down>"  . e2wm:dp-dashboard) ; dashboardへ変更
   ("C-."       . e2wm:pst-history-forward-command) ; 履歴を進む
   ("C-,"       . e2wm:pst-history-back-command) ; 履歴をもどる
   ("prefix L"  . ielm)
   ("M-m"       . e2wm:pst-window-select-main-command)
   ) e2wm:prefix-key)

;; key config
(global-set-key (kbd "C-x b") 'anything-for-files)
(global-set-key (kbd "M-y") 'anything-show-kill-ring)
(global-set-key (kbd "C-c C-f") 'anything-filelist+)
(global-set-key (kbd "\C-h") 'delete-backward-char)