dotfiles / dot.emacs

Full commit
; ~/.emacs

;; global setting ----
(setq load-path (cons "~/.emacs.d/lisp" load-path))

(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-m" 'newline-and-indent)

(setq inhibit-startup-message t)
(setq visible-bell t)
(setq scroll-step 1)
(setq frame-title-format "%b - emacs")
(setq make-backup-files nil)
(auto-compression-mode t)
(setq-default require-final-newline t)
(setq completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(temp-buffer-resize-mode 1)
(setq backward-delete-char-untabify-method 'hungry)
;(autoload 'nuke-trailing-whitespace "whitespace" nil t)
;(add-hook 'write-file-hooks 'nuke-trailing-whitespace)

; delete region by C-d
(delete-selection-mode t)

(set-language-environment "Japanese")
(if (equal (getenv "LANG") "ja_JP.eucJP")
    (prefer-coding-system 'euc-jp-unix)
  (prefer-coding-system 'utf-8-unix))
(setq ispell-dictionary "english")

(when (require 'migemo nil t)
  (if (and (not (executable-find "cmigemo"))
           (executable-find "ruby1.8"))
      (setq migemo-command "ruby1.8")))

(when (locate-library "anything-startup")
  ; anything-config depends on image-load-path, which may be missing
  (if (not (boundp 'image-load-path))
      (setq image-load-path '()))
  (require 'anything-startup)
  (if (getenv "SUDO_USER")
      ; allow to shutdown emacs even if permission denied
      (remove-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)))

(setq-default indent-tabs-mode nil)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60))

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

(when (require 'color-theme nil t)
  (if (fboundp 'color-theme-initialize) (color-theme-initialize))

  (defun choose-color-theme-by-window-system ()
    "Select color-theme by window-system or tty"
    (let ((color-theme-is-global nil))
      (if window-system


  (add-hook 'after-make-frame-functions
            '(lambda (frame)
               (select-frame frame)

(when (require 'linum nil t)
  (setq linum-format "%4d "))

(require 'show-wspace nil t)

(when (require 'highlight-symbol nil t)
  (setq-default highlight-symbol-idle-delay 0.8))

(when (require 'auto-complete-config nil t)

(when (require 'dtrt-indent nil t)
  (dtrt-indent-mode 1))

(setq x-alt-keysym 'meta)
(setq x-super-keysym 'meta)

; sync with X' clipboard
(setq x-select-enable-clipboard t)

(defvar after-make-window-system-frame-functions '()
  "Functions to run after creating a new window-system frame")
(add-hook 'after-make-frame-functions
          '(lambda (frame)
             (with-selected-frame frame
               (if (window-system)
                   (run-hooks 'after-make-window-system-frame-functions)))))

(add-hook 'after-make-window-system-frame-functions
          '(lambda ()
             (set-default-font "DejaVu Sans Mono-6.4") ; see also ~/.Xresources
             (set-fontset-font (frame-parameter nil 'font)
                               (font-spec :family "KonatuTohaba" :size 12))))

; configured by ~/.Xresources
;(setq default-frame-alist
;      (append '((width . 110) (height . 52)) default-frame-alist))

; for Chrome "Edit with Emacs" extension
(when (and (daemonp)
           (executable-find "chromium")
           (not (getenv "SUDO_USER"))
           (require 'edit-server nil t))
  (setq edit-server-new-frame nil)

; WORKAROUND for vc-hg's problem
(setenv "HGPLAIN" "")

; WORKAROUND for vc-find-file-hook to detect symlinks correctly
(defadvice vc-backend (before vc-backend-fix-abbrev-name activate)
  "Fixes vc-backend to expand abbreviated buffer-file-truename"
  (if (stringp (ad-get-arg 0))
      (ad-set-arg 0 (expand-file-name (ad-get-arg 0)))))

(setq vc-follow-symlinks t)

(require 'monky)

(when (require 'hi-lock nil t)
  (defun highlight-fixmes ()
    "Highlight FIXME, TODO and XXX"
    (highlight-regexp "\\(FIXME\\|TODO\\|XXX\\)" 'hi-red-b)))

(defun common-highlights ()
  "Highlighting used by most modes"
  (if (featurep 'highlight-symbol) (highlight-symbol-mode))
  (when (featurep 'show-wspace)
  (if (featurep 'hi-lock) (highlight-fixmes)))

;; c/c++ mode ----
(add-hook 'c-mode-common-hook
          '(lambda ()
             (setq c-default-style "k&r")
             (setq c-basic-offset 4)
             (setq c-argdecl-indent 0)
             (setq c-label-offset -2)
             (c-set-offset 'innamespace 0)
(defun my-cc-mode-hook ()
  (require 'xcscope nil t)
  (when (require 'auto-complete-clang nil t)
    (setq ac-sources (append '(ac-source-clang ac-source-yasnippet)
    (setq ac-delay 0.8))  ; clang completion is slow
(add-hook 'c-mode-hook 'my-cc-mode-hook)
(add-hook 'c++-mode-hook 'my-cc-mode-hook)

;; cmake mode ----
(add-hook 'cmake-mode-hook
          '(lambda ()

;; conf modes ----
(if (featurep 'dvc-autoloads)
    (progn (autoload 'hgrc-mode "xhg" "Major mode for hgrc" t)
           (add-to-list 'auto-mode-alist '("[./]hgrc\\'" . hgrc-mode)))
  (add-to-list 'auto-mode-alist '("[./]hgrc\\'" . conf-unix-mode)))

;; css mode ----
(add-hook 'css-mode-hook
          '(lambda ()

;; emacs lisp mode ----
(add-hook 'emacs-lisp-mode-hook
          '(lambda ()

;; gas (GNU as) mode ----
(autoload 'gas-mode "gas-mode"
  "Major mode for editing GNU assembler code" t)
(add-to-list 'auto-mode-alist '("\\.[sS]\\'" . gas-mode))
(add-hook 'gas-mode-hook
          '(lambda ()
             (setq gas-opcode-column 12)

;; html mode ----
(add-hook 'html-mode-hook
          '(lambda ()
             (set (make-local-variable 'sgml-basic-offset) 2)

;; makefile mode ----
(add-hook 'makefile-mode-hook
          '(lambda ()

;; markdown mode ----
(when (fboundp 'markdown-mode)
  (add-to-list 'auto-mode-alist '("\\.\\(markdown\\|md\\)\\'" . markdown-mode)))

;; moinmoin mode ----
(autoload 'moinmoin-mode "moinmoin-mode"
  "Major mode for editing MoinMoin mark-up text" t)
(add-hook 'moinmoin-mode-hook
          '(lambda ()

;; python mode ----
;(setq pymacs-load-path '("~/.emacs.d/pymacs"))
;(eval-after-load 'python-mode
;  '(progn
;     (require 'auto-complete-python)
;     (add-hook 'python-mode-hook 'setup-ropemacs)
;     (add-hook 'python-mode-hook 'ac-python-mode-setup)
;     (define-key python-mode-map (kbd ".") 'ac-self-insert-and-complete)))
(add-hook 'python-mode-hook
          '(lambda ()
(when (executable-find "ipython")
  (autoload 'py-shell "ipython" "IPython as Python interpreter" t))

;; po mode ----
; see
(defun po-wrap ()
  "Filter current po-mode buffer through `msgcat' tool to wrap all lines."
  (if (eq major-mode 'po-mode)
      (let ((tmp-file (make-temp-file "po-wrap."))
            (tmp-buf (generate-new-buffer "*temp*")))
              (write-region (point-min) (point-max) tmp-file nil 1)
              (if (zerop
                    "msgcat" nil tmp-buf t (shell-quote-argument tmp-file)))
                  (let ((saved (point))
                        (inhibit-read-only t))
                    (delete-region (point-min) (point-max))
                    (insert-buffer tmp-buf)
                    (goto-char (min saved (point-max))))
                (with-current-buffer tmp-buf
                  (error (buffer-string)))))
          (kill-buffer tmp-buf)
          (delete-file tmp-file)))))
(when (fboundp 'po-mode)
  (add-hook 'po-mode-hook
            '(lambda ()
               (define-key po-mode-map "P" 'po-wrap))))

;; rd (rdoc)  mode ----
(when (fboundp 'rd-mode)
  (add-to-list 'auto-mode-alist '("\\.rd\\(oc\\)?\\'" . rd-mode)))

;; ruby mode ----
(when (fboundp 'ruby-mode)
  (add-to-list 'auto-mode-alist '("\\bRakefile\\'" . ruby-mode))
  (add-to-list 'auto-mode-alist '("\\.rake\\'" . ruby-mode))
  (add-hook 'ruby-mode-hook
            '(lambda ()
               ; never insert -*- coding -*- automatically
               (remove-hook 'before-save-hook 'ruby-mode-set-encoding 'local)
               (define-key ruby-mode-map "\C-m" 'reindent-then-newline-and-indent)

;; sgml mode (for html, xml, etc.) ----
(add-hook 'sgml-mode-hook
          '(lambda ()

;; text-mode ---
(add-to-list 'auto-mode-alist
             '("NOTE" . text-mode)
             '("README" . text-mode))
(add-hook 'text-mode-hook
          '(lambda ()
             (flyspell-mode 1)))

;; textile mode ----
(autoload 'textile-mode "textile-mode"
  "Major mode for editing Textile mark-up text" t)
(add-to-list 'auto-mode-alist '("\\.textile\\'" . textile-mode))

;; wikicreole mode ----
(autoload 'wikicreole-mode "wikicreole-mode"
  "Major mode for editing WikiCreole text" t)
(add-to-list 'auto-mode-alist '("\\.wiki\\'" . wikicreole-mode))

  ;; 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.
 '(blink-cursor-mode nil)
 '(column-number-mode t)
 '(indicate-empty-lines t)
 '(scroll-bar-mode (quote right))
 '(show-paren-mode t)
 '(size-indication-mode t)
 '(tool-bar-mode nil))