Skip to content

Instantly share code, notes, and snippets.

@handlename
Created February 23, 2010 12:11
Show Gist options
  • Save handlename/312119 to your computer and use it in GitHub Desktop.
Save handlename/312119 to your computer and use it in GitHub Desktop.
;;; .emacs written by NAGATA Hiroaki (handlename.net)
(add-to-list 'load-path "~/.emacs.d/site-lisp/")
(require 'cl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; general settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; suppress opening new window
(setq ns-pop-up-frames nil)
;;
;; meta key
;;__________________________________________________________
(setq ns-command-modifier (quote meta))
(setq ns-alternate-modifier (quote super))
;;
;; for carbon emacs
;;__________________________________________________________
(if window-system (progn
(set-background-color "Black")
(set-foreground-color "LightGray")
(set-cursor-color "Red")
(set-frame-parameter nil 'alpha 80)
(set-face-attribute 'default nil
:family "M+2VM+IPAG circle"
:height 110)
(tool-bar-mode nil)
(setq initial-frame-alist
(append
'((top . 0) ; フレームの Y 位置(ピクセル数)
(left . 1) ; フレームの X 位置(ピクセル数)
(width . 180) ; フレーム幅(文字数)
(height . 50) ; フレーム高(文字数)
) initial-frame-alist))
; (ns-toggle-fullscreen)
(set-scroll-bar-mode nil)
(setq line-spacing 0.2)
))
;;
;; for cocoa emacs
;;__________________________________________________________
(when (>= emacs-major-version 23)
(tool-bar-mode nil)
(set-face-attribute 'default nil
:family "M+2VM+IPAG circle"
:height 140)
(set-fontset-font
(frame-parameter nil 'font)
'japanese-jisx0208
'("M+2VM+IPAG circle" . "iso10646-1"))
(set-fontset-font
(frame-parameter nil 'font)
'japanese-jisx0212
'("M+2VM+IPAG circle" . "iso10646-1"))
(set-fontset-font
(frame-parameter nil 'font)
'mule-unicode-0100-24ff
'("M+2VM+IPAG circle" . "iso10646-1"))
(setq face-font-rescale-alist
'(("^-apple-hiragino.*" . 1.3)
(".*osaka-bold.*" . 1.2)
(".*osaka-medium.*" . 1.2)
(".*courier-bold-.*-mac-roman" . 1.0)
(".*monaco cy-bold-.*-mac-cyrillic" . 0.9)
(".*monaco-bold-.*-mac-roman" . 0.9)
("-cdac$" . 1.3))))
;;
;; window setting
;;__________________________________________________________
(setq scroll-step 1)
(setq truncate-partial-width-windows nil)
;(setq wb-line-number-scroll-bar t)
;;
;; silent
;;__________________________________________________________
(setq visible-bell t)
;;
;; encoding
;;__________________________________________________________
(set-language-environment "Japanese")
(prefer-coding-system 'utf-8-unix)
(setq default-buffer-file-coding-system 'utf-8)
(set-buffer-file-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
;;
;; general key bind
;;__________________________________________________________
(global-set-key (kbd "C-h") 'backward-delete-char)
(global-set-key (kbd "C-/") 'undo)
(global-set-key (kbd "C-t") 'next-multiframe-window)
(global-set-key (kbd "C-M-t") 'previous-multiframe-window)
(global-set-key (kbd "M-r") 'replace-string)
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key (kbd "C-m") 'newline-and-indent)
(global-set-key (kbd "M-<RET>") 'ns-toggle-fullscreen)
(global-set-key (kbd "C-c C-e") 'eval-last-sexp)
(global-set-key (kbd "C-c e") 'eval-region)
(global-set-key (kbd "C-S-i") 'indent-region)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; additional functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; anything
;;__________________________________________________________
(require 'anything-config)
(define-key anything-map (kbd "C-M-n") 'anything-next-source)
(define-key anything-map (kbd "C-M-p") 'anything-previous-source)
;; 履歴を残さない(残すと読み込みエラーになるので)
(remove-hook 'kill-emacs-hook 'anything-c-adaptive-save-history)
(ad-disable-advice 'anything-exit-minibuffer 'before 'anything-c-adaptive-exit-minibuffer)
(ad-disable-advice 'anything-select-action 'before 'anything-c-adaptive-select-action)
(setq anything-c-adaptive-history-length 0)
;; バッファ内検索
(defun anything-for-occur ()
"Search current buffer in anything"
(interactive)
(anything '(anything-c-source-occur)))
(define-key global-map (kbd "C-s") 'anything-for-occur)
;; バッファ一覧+バッファ履歴+カレントディレクトリのファイル
(defun anything-for-buffers ()
"Open buffer list in anything"
(interactive)
(anything '(anything-c-source-buffers
anything-c-source-file-name-history
anything-c-source-files-in-current-dir)))
(define-key global-map (kbd "C-x b") 'anything-for-buffers)
;; 電卓
(defun anything-for-calc ()
"Calculate in anything"
(interactive)
(anything '(anything-c-source-calculation-result)))
(define-key global-map (kbd "C-M-c") 'anything-for-calc)
;; kill ring 履歴
(define-key global-map (kbd "C-M-y") 'anything-show-kill-ring)
;; emacs コマンド
(defun anything-for-emacs-commands ()
"Execute emacs commands in anything"
(interactive)
(anything '(anything-c-source-emacs-commands)))
(define-key global-map (kbd "M-x") 'anything-for-emacs-commands)
;; semantics
(defun anything-for-semantics ()
"semantics in anything"
(interactive)
(anything '(anything-c-source-semantic)))
(define-key global-map (kbd "C-M-f") 'anything-for-semantics)
;; tag jump
(require 'anything-etags)
(require 'anything-gtags)
(defun anything-etags-and-gtags-select ()
"Tag jump using etags, gtags and `anything'."
(interactive)
(let* ((initial-pattern (regexp-quote (or (thing-at-point 'symbol) ""))))
(anything (list anything-c-source-gtags-select
anything-c-source-etags-select))
"Find Tag: " nil))
(define-key global-map (kbd "C-x t") 'anything-etags-and-gtags-select)
;; ;; color-moccur in anything
;; http://d.hatena.ne.jp/IMAKADO/20080724/1216882563
;; (require 'color-moccur)
;; (setq moccur-split-word t)
;; (when (require 'migemo nil t)
;; (setq moccur-use-migemo t))
;; (require 'anything-c-moccur)
;; (setq anything-c-moccur-anything-idle-delay 0.2
;; anything-c-moccur-higligt-info-line-flag t
;; anything-c-moccur-enable-auto-look-flag t
;; anything-c-moccur-enable-initial-pattern t)
;; (global-set-key (kbd "C-s") 'anything-c-moccur-occur-by-moccur)
;; (global-set-key (kbd "C-M-s") 'anything-c-moccur-dmoccur)
;; (add-hook 'dired-mode-hook
;; '(lambda ()
;; (local-set-key (kbd "O") 'anything-c-moccur-dired-do-moccur-by-moccur)))
;;
;; highlight
;;__________________________________________________________
;; highlight current line
(require 'highlight-current-line)
(highlight-current-line-on t)
(set-face-background 'highlight-current-line-face "#101015")
;; hilight paren
(show-paren-mode 1)
;; highlight reagion
(setq transient-mark-mode t)
;; highlight branks
(defface my-face-b-1 '((t (:background "bisque"))) nil)
(defvar my-face-b-1 'my-face-b-1)
(defadvice font-lock-mode (before my-font-lock-mode ())
(font-lock-add-keywords
major-mode
'((" " 0 my-face-b-1 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
;; highlight current buffer
;; http://ksugita.blog62.fc2.com/blog-entry-8.html
(load-file "~/.emacs.d/site-lisp/hiwin.el")
;;
;; indent
;;__________________________________________________________
(setq-default tab-width 4 indent-tabs-mode t)
;;
;; sense-region
;; http://taiyaki.org/elisp/sense-region/
;;__________________________________________________________
(autoload 'sense-region-on "sense-region"
"System to toggle region and rectangle." t nil)
(sense-region-on)
;;
;; align
;;__________________________________________________________
(require 'align)
(global-set-key (kbd "C-c a") 'align)
(global-set-key (kbd "C-c M-a") 'align-regexp)
;; php-mode でも align
;; http://d.hatena.ne.jp/Tetsujin/20070614/1181757931
(add-to-list 'align-rules-list
'(php-assignment
(regexp . "[^-=!^&*+<>/.| \t\n]\\(\\s-*[.-=!^&*+<>/|]*\\)=>?\\(\\s-*\\)\\([^= \t\n]\\|$\\)")
(justify . t)
(tab-stop . nil)
(modes . '(php-mode))))
(add-to-list 'align-dq-string-modes 'php-mode)
(add-to-list 'align-sq-string-modes 'php-mode)
(add-to-list 'align-open-comment-modes 'php-mode)
(setq align-region-separate (concat "\\(^\\s-*$\\)\\|"
"\\([({}\\(/\*\\)]$\\)\\|"
"\\(^\\s-*[)}\\(\*/\\)][,;]?$\\)\\|"
"\\(^\\s-*\\(}\\|for\\|while\\|if\\|else\\|"
"switch\\|case\\|break\\|continue\\|do\\)[ ;]\\)"
))
;;
;; backup file
;;__________________________________________________________
(defun make-backup-file-name (filename)
(expand-file-name
(concat "~/.backup/" (file-name-nondirectory filename) "~")
(file-name-directory filename)))
;;
;; kill-all-buffers
;;__________________________________________________________
(require 'cl)
(defun kill-all-buffers ()
(interactive)
(loop for buffer being the buffers
do (kill-buffer buffer)))
;;
;; miscellaneous
;;__________________________________________________________
(column-number-mode t) ; 列番号表示
(global-linum-mode) ; 行番号表示
(setq-default fill-column 80) ; 詰め込み行設定
;; (setq truncate-lines t)
;; (setq truncate-partial-width-windows t)
;; インデント
(setq-default c-basic-offset 4)
(setq-default tab-width 4)
(setq cua-auto-tabify-rectangles nil)
(defadvice align (around smart-tabs activate)
(let ((indent-tabs-mode nil)) ad-do-it))
(defadvice align-regexp (around smart-tabs activate)
(let ((indent-tabs-mode nil)) ad-do-it))
(defadvice indent-relative (around smart-tabs activate)
(let ((indent-tabs-mode nil)) ad-do-it))
(defadvice indent-according-to-mode (around smart-tabs activate)
(let ((indent-tabs-mode indent-tabs-mode))
(if (memq indent-line-function
'(indent-relative
indent-relative-maybe))
(setq indent-tabs-mode nil))
ad-do-it))
(defmacro smart-tabs-advice (function offset)
(defvaralias offset 'tab-width)
`(defadvice ,function (around smart-tabs activate)
(cond
(indent-tabs-mode
(save-excursion
(beginning-of-line)
(while (looking-at "\t*\\( +\\)\t+")
(replace-match "" nil nil nil 1)))
(setq tab-width tab-width)
(let ((tab-width fill-column)
(,offset fill-column))
ad-do-it))
(t
ad-do-it))))
(smart-tabs-advice c-indent-line c-basic-offset)
(smart-tabs-advice c-indent-region c-basic-offset)
;;
;; speedbar
;;__________________________________________________________
(defun my-speedbar-expand-line ()
(interactive)
(if (= (point-max) (progn (speedbar-expand-line) (point-max)))
(save-current-buffer
(speedbar-edit-line))))
(when (locate-library "speedbar")
(require 'speedbar)
;; "a" で無視ファイル表示/非表示のトグル
(define-key speedbar-file-key-map "a" 'speedbar-toggle-show-all-files)
;; ← や → でもディレクトリを開閉 ;;デフォルト: "=" "+", "-"
(define-key speedbar-file-key-map [right] 'my-speedbar-expand-line)
(define-key speedbar-file-key-map "\C-f" 'my-speedbar-expand-line)
(define-key speedbar-file-key-map [left] 'speedbar-contract-line)
(define-key speedbar-file-key-map "\C-b" 'speedbar-contract-line)
;; BS でも上位ディレクトリへ ;;デフォルト: "U"
(define-key speedbar-file-key-map [backspace] 'speedbar-up-directory)
(define-key speedbar-file-key-map "\C-h" 'speedbar-up-directory)
;; 起動位置を直接指定する
(setq speedbar-frame-parameters
(append (list '(top . 0)
'(left . 0)
'(width . 25))
speedbar-frame-parameters))
;; Speedbar で表示するファイルタイプ
(setq speedbar-supported-extension-expressions
(append '(".el" ".[ch]\\(pp\\|\\+\\+\\)?" ".java" ".tex\\(i\\(nfo\\)?\\)?"
".s?html?" ".xml" ".dtd" ".css" ".js" ".txt"
".gif" ".jpe?g" ".png")))
) ;; end of speedbar
;; F5 で Speedbar
(global-set-key [f5] 'speedbar-get-focus)
;;
;; wb-line-number
;;__________________________________________________________
;; (require 'wb-line-number)
;; (wb-line-number-toggle)
;; (setq wb-line-number-scroll-bar t)
;; ;; for use with yatex
;; (eval-after-load "yatexlib"
;; '(progn
;; (defadvice YaTeX-window-list
;; (after wb-line-number-adv-aft-YaTeX-window-list)
;; (let ((l ad-return-value))
;; (while l
;; (and (window-dedicated-p (car l))
;; (setq ad-return-value (delete (car l) ad-return-value)))
;; (setq l (cdr l)))))
;; (ad-enable-regexp "^wb-line-number-adv-aft-YaTeX-window-list")
;; (ad-activate-regexp "^wb-line-number-adv-aft-YaTeX-window-list")))
;;
;; tabber
;;__________________________________________________________
;; (when (require 'tabbar nil t)
;; (setq tabbar-buffer-groups-function
;; (lambda (b) (list "All Buffers")))
;; (setq tabbar-buffer-list-function
;; (lambda ()
;; (remove-if
;; (lambda(buffer)
;; (find (aref (buffer-name buffer) 0) " *"))
;; (buffer-list))))
;; (tabbar-mode))
;; ;; 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)
;; ;; 外観変更
;; (set-face-attribute
;; 'tabbar-default-face nil
;; :background "gray60")
;; (set-face-attribute
;; 'tabbar-unselected-face nil
;; :background "gray85"
;; :foreground "gray30"
;; :box nil)
;; (set-face-attribute
;; 'tabbar-selected-face nil
;; :background "#f2f2f6"
;; :foreground "black"
;; :box nil)
;; (set-face-attribute
;; 'tabbar-button-face nil
;; :box '(:line-width 1 :color "gray72" :style released-button))
;; (set-face-attribute
;; 'tabbar-separator-face nil
;; :height 0.7)
;; ;; F4 で tabbar-mode
;; (global-set-key [f4] 'tabbar-mode)
;;
;; revive
;;__________________________________________________________
(autoload 'save-current-configuration "revive" "Save status" t)
(autoload 'resume "revive" "Resume Emacs" t)
(autoload 'wipe "revive" "Wipe emacs" t)
(define-key ctl-x-map "S" 'save-current-configuration) ; C-x S で状態保存
(define-key ctl-x-map "F" 'resume) ; C-x F で復元
(add-hook 'kill-emacs-hook 'save-current-configuration) ; 終了時に状態保存
;;
;; lispxmp
;;__________________________________________________________
(require 'lispxmp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; major mode settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; shell-mode
;;__________________________________________________________
(autoload 'ansi-color-for-comint-mode-on "ansi-color"
"Set `ansi-color-for-comint-mode' to t." t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(add-hook 'shell-mode-hook
(function (lambda ()
(define-key shell-mode-map [up] 'comint-previous-input)
(define-key shell-mode-map [down] 'comint-next-input))))
;;
;; gdb
;;__________________________________________________________
(add-hook 'gdb-mode-hook '(lambda () (gud-tooltip-mode t)))
;;
;; c++-mode
;;__________________________________________________________
(setenv "CPLUS_INCLUDE_PATH" "/opt/local/include")
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(add-hook 'c++-mode-hook
'(lambda ()
(define-key mode-specific-map "c" 'compile)
(c-set-style "cc-mode")))
;;
;; php-mode
;;__________________________________________________________
(autoload 'php-mode "php-mode")
(setq auto-mode-alist
(cons '("\\.php\\'" . php-mode) auto-mode-alist))
(setq php-mode-force-pear)
(add-hook 'php-mode-hook
'(lambda ()
(setq php-manual-path "/usr/share/doc/php/html")
(setq php-search-url "http://www.phppro.jp/")
(setq php-manual-url "http://www.phppro.jp/phpmanual")))
(add-hook 'php-mode-hook
'(lambda ()
(setq tab-width 4)
(setq c-basic-offset 4)))
;;
;; Js2-mode
;;__________________________________________________________
(add-hook 'ruby-mode-hook
'(lambda ()
(setq tab-width 4)
(setq c-basic-offset 4)))
;;
;; Js2-mode
;;__________________________________________________________
(autoload 'js2-mode "js2" nil t)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
;; (add-hook 'js2-mode-hook
;; '(lambda ()
;; (setq tab-width 4)
;; (setq js2-basic-offset 4)))
;; (when (load "js2" t)
;; (defun indent-and-back-to-indentation ()
;; (interactive)
;; (indent-for-tab-command)
;; (let ((point-of-indentation
;; (save-excursion
;; (back-to-indentation)
;; (point))))
;; (skip-chars-forward "\s " point-of-indentation)))
;; (define-key js2-mode-map "\C-i" 'indent-and-back-to-indentation)
;; (define-key js2-mode-map "\C-m" nil))
;;
;; objc-mode
;;__________________________________________________________
(add-hook 'objc-mode-hook
'(lambda ()
(setq tab-width 4)
(setq c-basic-offset 4)))
;;
;; lisp-mode
;;__________________________________________________________
(add-hook 'lisp-mode
'(lambda ()
(setq indent-tabs-mode nil)))
;;
;; emacs-lisp-mode
;;__________________________________________________________
(add-hook 'emacs-lisp-mode
'(lambda ()
(setq indent-tabs-mode nil)))
;;
;; smarty-mode
;;__________________________________________________________
;; (setq load-path (append (list "/usr/local/share/lisp/") load-path))
;; (autoload 'smarty-mode "smarty-mode" "Smarty Mode" t)
;;
;; yaml-mode
;;__________________________________________________________
;; (require 'yaml-mode)
;; (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
;;
;; yatex-mode
;;__________________________________________________________
(add-to-list 'load-path "~/.emacs.d/site-lisp/yatex/")
(setq auto-mode-alist (cons (cons "\\.tex$" 'yatex-mode) auto-mode-alist))
(autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t)
(setq tex-command "/opt/local/bin/platex")
(setq dvi2-command "/opt/local/bin/xdvi")
(setq YaTeX-kanji-code 4) ;; utf-8
(add-hook 'yatex-mode-hook'(lambda ()(setq auto-fill-function nil)))
;;
;; yahtml-mode
;;__________________________________________________________
(setq auto-mode-alist
(cons (cons "\\.html$" 'yahtml-mode) auto-mode-alist))
(autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t)
(add-hook 'yahtml-mode-hook #'(lambda () (auto-fill-mode -1))) ; no indent
;;
;; org-mode
;;__________________________________________________________
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
;; (define-key global-map "\C-cl" 'org-store-link)
;; (define-key global-map "\C-ca" 'org-agenda)
(add-hook 'org-mode-hook 'turn-on-font-lock)
;;
;; dsvn-mode
;;__________________________________________________________
(autoload 'svn-status "dsvn" "Run `svn status'." t)
(autoload 'svn-update "dsvn" "Run `svn update'." t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; minor mode settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; auto complete
;;__________________________________________________________
(require 'auto-complete)
(append '(yahtml-mode) ac-modes)
(global-auto-complete-mode t)
(define-key ac-complete-mode-map "\M-n" 'ac-next)
(define-key ac-complete-mode-map "\M-p" 'ac-previous)
;; ac-my-completion for auto-complete
(defun ac-my-completion-list-in-files (files &optional keywords-variable)
"create completion list for auto-complete"
(let ((ksymbol keywords-variable) keywords)
(cond
((stringp files)
(setq files (list files)))
((stringp keywords-variable)
(setq ksymbol (intern keywords-variable))))
(if (not (boundp ksymbol))
(progn
(dolist (file files)
(let ((buffer (find-file-noselect file)) filename)
(setq filename (file-name-nondirectory file))
(with-current-buffer buffer
(rename-buffer
(concat " *" filename "*") t)
(if (< (buffer-size) 131072) ; 128Kb
(save-excursion
(goto-char (point-min))
(while (re-search-forward "^[^;]\\(\\s_\\|\\sw\\)+\\b$" nil t)
(let ((candidate (match-string-no-properties 0)))
(if (not (member candidate keywords))
(push candidate keywords))))
(setq keywords (nreverse keywords)))))))
;; (sort keywords #'(lambda (a b) (> (length a) (length b))))
(if ksymbol
(set-default ksymbol keywords))
(message (concat "Building ac-source keywords(" (symbol-name ksymbol) ")...done."))
keywords))))
(defun ac-my-completion-files (files mode-name &optional set-hook)
"set completion list to mode-variable for auto-complete"
(lexical-let
((--ac-source (intern (concat "ac-source-" mode-name)))
(--ac-source-keywords (intern (concat "ac-source-" mode-name "-keywords")))
(--mode-hook (intern (concat mode-name "-mode-hook")))
(--files files))
(set-default --ac-source
(list (cons 'candidates
(lambda ()
(all-completions ac-prefix (symbol-value --ac-source-keywords))))))
(if set-hook
(add-hook --mode-hook
(lambda()
(ac-my-completion-list-in-files --files --ac-source-keywords)
(make-local-variable 'ac-sources)
(setq ac-sources (append ac-sources (list --ac-source)))))
(ac-my-completion-list-in-files --files --ac-source-keywords))))
;; 以下をモード毎に設定
(ac-my-completion-files "~/.emacs.d/completions/javascript+DOM" "javascript" t)
(ac-my-completion-files "~/.emacs.d/completions/C" "c" t)
(ac-my-completion-files "~/.emacs.d/completions/C++" "c++" t)
(ac-my-completion-files "~/.emacs.d/completions/PHP" "php" t)
(ac-my-completion-files "~/.emacs.d/completions/TeX" "yatex" t)
(ac-my-completion-files "~/.emacs.d/completions/HTML" "yahtml" t)
(ac-my-completion-files "~/.emacs.d/completions/elisp" "emacs-lisp" t)
;; auto-complete-etags
(require 'auto-complete-etags)
;;
;; mmm-mode
;;_________________________________________________________
(require 'mmm-mode)
(setq mmm-global-mode 'maybe)
(set-face-background 'mmm-default-submode-face "navy")
;; html + css
(mmm-add-classes
'((embedded-css
:submode css-mode
:front "<style[^>]*>"
:back "</style>")))
(mmm-add-mode-ext-class nil "\\.html?\\'" 'embedded-css)
;; html + php
(mmm-add-classes
'((html-php
:submode php-mode
:front "<\\?\\(php\\)?"
:back "\\?>")))
(mmm-add-mode-ext-class nil "\\.php?\\'" 'html-php)
;;
;; hs-minor-mode
;;__________________________________________________________
;; http://www.emacswiki.org/emacs/HideShow
;; (defun toggle-selective-display (column)
;; (interactive "P")
;; (set-selective-display
;; (or column
;; (unless selective-display
;; (1+ (current-column))))))
;; (defun toggle-hiding (column)
;; (interactive "P")
;; (if hs-minor-mode
;; (if (condition-case nil
;; (hs-toggle-hiding)
;; (error t))
;; (hs-show-all))
;; (toggle-selective-display column)))
;; (global-set-key (kbd "C-=") 'toggle-hiding)
;; (global-set-key (kbd "C-\\") 'toggle-selective-display)
;; (add-hook 'c-mode-common-hook 'hs-minor-mode)
;; (add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
;; (add-hook 'java-mode-hook 'hs-minor-mode)
;; (add-hook 'lisp-mode-hook 'hs-minor-mode)
;; (add-hook 'perl-mode-hook 'hs-minor-mode)
;; (add-hook 'sh-mode-hook 'hs-minor-mode)
;;
;; outline-miner-mode
;;__________________________________________________________
(make-variable-buffer-local 'outline-level)
(setq-default outline-level 'outline-level)
(setq outline-minor-mode-prefix "\C-c\C-o")
;; for yatex-mode
(defun latex-outline-level ()
(save-excursion
(looking-at outline-regexp)
(let ((title (buffer-substring (match-beginning 1) (match-end 1))))
(cond ((equal (substring title 0 4) "docu") 15)
((equal (substring title 0 4) "chap") 0)
((equal (substring title 0 4) "appe") 0)
(t (length title))))))
(add-hook 'yatex-mode-hook
(function
(lambda ()
(progn
(setq outline-level 'latex-outline-level)
(setq outline-regexp
(concat "[ \t]*\\\\\\(documentstyle\\|documentclass\\|"
"chapter\\|section\\|subsection\\|subsubsection\\)"
"\\*?[ \t]*[[{]"))))))
;;
;; Flymake
;;__________________________________________________________
(require 'flymake)
;; set-perl5lib
;; 開いたスクリプトのパスに応じて、@INCにlibを追加してくれる
;; 以下からダウンロードする必要あり
;; http://svn.coderepos.org/share/lang/elisp/set-perl5lib/set-perl5lib.el
(require 'set-perl5lib)
;; エラー、ワーニング時のフェイス
(set-face-background 'flymake-errline "red4")
(set-face-foreground 'flymake-errline "white")
(set-face-background 'flymake-warnline "yellow")
(set-face-foreground 'flymake-warnline "black")
;; エラーをミニバッファに表示
;; http://d.hatena.ne.jp/xcezx/20080314/1205475020
(defun flymake-display-err-minibuf ()
"Displays the error/warning for the current line in the minibuffer"
(interactive)
(let* ((line-no (flymake-current-line-no))
(line-err-info-list (nth 0 (flymake-find-err-info
flymake-err-info line-no)))
(count (length line-err-info-list)))
(while (> count 0)
(when line-err-info-list
(let* ((file (flymake-ler-file
(nth (1- count) line-err-info-list)))
(full-file (flymake-ler-full-file
(nth (1- count) line-err-info-list)))
(text (flymake-ler-text
(nth (1- count) line-err-info-list)))
(line (flymake-ler-line
(nth (1- count) line-err-info-list))))
(message "[%s] %s" line text)))
(setq count (1- count)))))
(global-set-key "\C-cd" 'flymake-display-err-minibuf)
;; C++用設定
;; http://d.hatena.ne.jp/suztomo/20080905/1220633281
(defun flymake-cc-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 "g++" (list "-Wall" "-Wextra" "-fsyntax-only" local-file))))
(defun flymake-cch-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 "g++"
(list "-Wall" "-Wextra" "-fsyntax-only" "-x c++-header" local-file))))
(push '("\\.h$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.cpp$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.hpp$" flymake-cch-init) flymake-allowed-file-name-masks)
(add-hook 'c++-mode-hook
'(lambda ()
(flymake-mode t)))
;; 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 '("\\.h$" flymake-cc-init) flymake-allowed-file-name-masks)
(push '("\\.c$" flymake-cc-init) flymake-allowed-file-name-masks)
(add-hook 'c-mode-hook
'(lambda ()
(flymake-mode t)))
;; Perl用設定
;; http://unknownplace.org/memo/2007/12/21#e001
(defvar flymake-perl-err-line-patterns
'(("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]" 2 3 nil 1)))
(defconst flymake-allowed-perl-file-name-masks
'(("\\.pl$" flymake-perl-init)
("\\.pm$" flymake-perl-init)
("\\.t$" flymake-perl-init)))
(defun flymake-perl-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 "perl" (list "-wc" local-file))))
(defun flymake-perl-load ()
(interactive)
(defadvice flymake-post-syntax-check (before flymake-force-check-was-interrupted)
(setq flymake-check-was-interrupted t))
(ad-activate 'flymake-post-syntax-check)
(setq flymake-allowed-file-name-masks
(append flymake-allowed-file-name-masks flymake-allowed-perl-file-name-masks))
(setq flymake-err-line-patterns flymake-perl-err-line-patterns)
(set-perl5lib)
(flymake-mode t))
(add-hook 'cperl-mode-hook 'flymake-perl-load)
;; PHP用設定
;; http://openlab.dino.co.jp/2008/08/05/223548324.html
(when (require 'flymake nil t)
(when (not (fboundp 'flymake-php-init))
;; flymake-php-initが未定義のバージョンだったら、自分で定義する
(defun flymake-php-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 "php" (list "-f" local-file "-l"))))
(setq flymake-allowed-file-name-masks
(append
flymake-allowed-file-name-masks
'(("\\.php[345]?$" flymake-php-init))))
(setq flymake-err-line-patterns
(cons
'("\\(\\(?:Parse error\\|Fatal error\\|Warning\\): .*\\) in \\(.*\\) on line \\([0-9]+\\)" 2 3 nil 1)
flymake-err-line-patterns))))
;;
;; hatenahelper-mode
;;__________________________________________________________
(require 'hatenahelper-mode)
;(add-hook 'hatena-mode-hook 'hatenahelper-mode) ; 本当はこう
(add-hook 'hatena-mode-hook
'(lambda ()
; other hooks must be wrote here!
(hatenahelper-mode 1)))
(put 'narrow-to-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment