Skip to content

Instantly share code, notes, and snippets.

@killme2008
Created August 7, 2012 10:57
Show Gist options
  • Save killme2008/3284540 to your computer and use it in GitHub Desktop.
Save killme2008/3284540 to your computer and use it in GitHub Desktop.
dot.emacs
;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(add-to-list 'load-path "~/.emacs.d/marmalade")
(require 'package)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
';;使用缩写模式
(setq-default abbrev-mode t)
(read-abbrev-file "~/.emacs.d/.abbrev-defs")
(setq save-abbrevs t)
;;设置语言环境
;; For my language code setting (UTF-8)
(setq current-language-environment "UTF-8")
;;(setq default-input-method "chinese-py")
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;;启动自动最大化
(setq initial-frame-alist '((top . 0)(left . 0)(width . 200)(height . 60)))
;; 打开就启用 text 模式
(setq default-major-mode 'text-mode)
;; 禁用启动信息
(setq inhibit-startup-message t)
;; 语法高亮
(global-font-lock-mode t)
;; 设置字体为微软雅黑
(set-default-font "-apple-Microsoft_YaHei-medium-normal-normal-*-14-*-*-*-p-0-iso10646-1")
;; 打开图片显示功能
(auto-image-file-mode t)
;; 以 y/n 替代 yes/no
(fset 'yes-or-no-p 'y-or-n-p)
;; 显示行列号
(column-number-mode t)
;; 显示括号匹配
(show-paren-mode t)
(setq show-paren-style 'parentheses)
;; 显示时间,格式如下
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
;; 光标靠近鼠标指针时,让鼠标指针自动让开
(mouse-avoidance-mode 'animate)
;; 不要在鼠标光标出插入
(setq mouse-yank-at-point t)
;; 高亮显示选中的区域
(transient-mark-mode t)
;; 支持emacs和外部程序的拷贝粘贴
(setq x-select-enable-clipboard t)
;; 在标题栏提示当前位置
(setq frame-title-format "dennis@%b")
;; 显示80列就换行
(setq default-fill-column 80)
;; 禁止终端响铃
(setq visible-bell t)
;; 设置tab为4个空格的宽度
(setq default-tab-width 4)
;; 代码折叠
(load-library "hideshow")
(add-hook 'java-mode-hook 'hs-minor-mode)
(add-hook 'perl-mode-hook 'hs-minor-mode)
(add-hook 'clojure-mode-hook 'hs-minor-mode)
(add-hook 'erlang-mode-hook 'hs-minor-mode)
(add-hook 'ruby-mode-hook 'hs-minor-mode)
(add-hook 'php-mode-hook 'hs-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
;; Auto complete
(require 'auto-complete-config)
(eval-after-load "auto-complete"
'(progn
(define-key ac-complete-mode-map "\C-n" 'ac-next)
(define-key ac-complete-mode-map "\C-i" 'ac-stop)
(define-key ac-complete-mode-map "\C-p" 'ac-previous)
(define-key ac-complete-mode-map "\C-j" 'ac-complete)
(setq ac-auto-start 2
ac-menu-height 20
ac-delay 0.5
ac-completion-face "lightgray"
ac-selection-face "steelblue"
ac-candidate-face "darkgray")))
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.4/dict")
(ac-config-default)
(add-to-list 'ac-modes 'slime-repl-mode)
;; configure auto complete to work in slime
(require 'ac-slime)
(add-hook 'slime-mode-hook 'set-up-slime-ac)
(add-hook 'slime-repl-mode-hook 'set-up-slime-ac)
;; redraw的时候不暂停响应输入
(setq redisplay-dont-pause t)
;; 设置个人信息
(setq user-full-name "dennis zhuang")
(setq user-mail-address "killme2008@gmail.com")
;; 显示标签
;;(load-file "~/.emacs.d/tabbar.el")
;;(require 'tabbar)
(tabbar-mode)
;; mark-multi.el
(setq load-path (cons "~/.emacs.d/mark-multiple.el" load-path))
(require 'inline-string-rectangle)
(global-set-key (kbd "C-x r t") 'inline-string-rectangle)
(require 'mark-more-like-this)
(global-set-key (kbd "C-<") 'mark-previous-like-this)
(global-set-key (kbd "C->") 'mark-next-like-this)
(global-set-key (kbd "C-M-m") 'mark-more-like-this) ; like the other two, but takes an argument (negative is previous)
(global-set-key (kbd "C-*") 'mark-all-like-this)
;; 所有的备份文件转移到~/emacs_backup目录下
(setq backup-directory-alist (quote (("." . "~/emacs_backup"))))
(setq version-control t)
(setq kept-old-versions 2)
(setq kept-new-versions 3)
(setq delete-old-versions t)
(setq backup-directory-alist '(("." . "~/emacs_backup")))
(setq backup-by-copying t)
;;环境变量
(setenv "PATH" (concat (getenv "PATH") ":/opt/local/bin/"))
(setq exec-path (append exec-path '("/opt/local/bin/")))
;;设置加载路径
(setq load-path (cons "~/.emacs.d" load-path))
;;加载配色方案
;;(setq load-path (cons "~/.emacs.d/color-theme" load-path))
;;(load-file "~/.emacs.d/color-theme/.emacs-color-theme")
(require 'color-theme)
(load-file "~/.emacs.d/my-color-theme.el")
;;(color-theme-initialize)
;;(color-theme-tango)
(dark-clojure-1)
;;(my-color-theme)
;;(color-theme-dark-laptop)
;;(color-theme-deep-blue)
;;加载psvn
(setq load-path (cons "~/.emacs.d/svn" load-path))
(require 'psvn)
;;左侧显示行号
(set-scroll-bar-mode nil) ; no scroll bar, even in x-window system (recommended)
;;(require 'wb-line-number)
;;(wb-line-number-toggle)
;;加载html-helper-mode
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;;是否禁止菜单栏和工具栏
;;(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
;;(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;;(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;;shell mode配置
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on t)
;;windows setting
;;C c 左箭头,回到上一次窗口设置
(when (fboundp 'winner-mode)
(winner-mode)
(windmove-default-keybindings))
;;产生四窗口界面
(defun split-window-4()
"Splite window into 4 sub-window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-vertically)
(split-window-horizontally)
(other-window 2)
(split-window-horizontally))))
(global-set-key (kbd "C-x 4 4") (quote split-window-4))
;;产生三窗口界面
(defun split-window-4-3()
"Split window into 3 sub-window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-vertically)
(other-window 1)
(split-window-horizontally))))
(global-set-key (kbd "C-x 4 3") 'split-window-4-3)
;;在两种三窗口模型中切换
(defun change-split-type-3 ()
"Change 3 window style from horizontal to vertical and vice-versa"
(interactive)
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stBuf (window-buffer (car winList)))
(2ndBuf (window-buffer (car (cdr winList))))
(3rdBuf (window-buffer (car (cdr (cdr winList)))))
(split-3
(lambda(1stBuf 2ndBuf 3rdBuf split-1 split-2)
"change 3 window from horizontal to vertical and vice-versa"
(message "%s %s %s" 1stBuf 2ndBuf 3rdBuf)
(delete-other-windows)
(funcall split-1)
(set-window-buffer nil 2ndBuf)
(funcall split-2)
(set-window-buffer (next-window) 3rdBuf)
(other-window 2)
(set-window-buffer nil 1stBuf)))
(split-type-1 nil)
(split-type-2 nil)
)
(if (= (window-width) (frame-width))
(setq split-type-1 'split-window-horizontally
split-type-2 'split-window-vertically)
(setq split-type-1 'split-window-vertically
split-type-2 'split-window-horizontally))
(funcall split-3 1stBuf 2ndBuf 3rdBuf split-type-1 split-type-2)
))))
(global-set-key (kbd "C-x 4 c") (quote change-split-type-3))
;;产生等分三窗口
(defun split-2-windows-horizontally-evenly ()
(interactive)
(command-execute 'split-window-horizontally)
(command-execute 'split-window-horizontally)
(command-execute 'balance-windows)
)
(global-set-key (kbd "C-x 4") 'split-2-windows-horizontally-evenly)
;;outline mode entry switcher
(defun switch-entry ()
(interactive)
(if (outline-invisible-p)
(show-entry)
(hide-entry)))
;;让三窗口旋转
(defun roll-v-3 (&optional arg)
"Rolling 3 window buffers (anti-)clockwise"
(interactive "P")
(select-window (get-largest-window))
(if (= 3 (length (window-list)))
(let ((winList (window-list)))
(let ((1stWin (car winList))
(2ndWin (car (cdr winList)))
(3rdWin (car (last winList))))
(let ((1stBuf (window-buffer 1stWin))
(2ndBuf (window-buffer 2ndWin))
(3rdBuf (window-buffer 3rdWin)))
(if arg (progn
; anti-clockwise
(set-window-buffer 1stWin 3rdBuf)
(set-window-buffer 2ndWin 1stBuf)
(set-window-buffer 3rdWin 2ndBuf))
(progn ; clockwise
(set-window-buffer 1stWin 2ndBuf)
(set-window-buffer 2ndWin 3rdBuf)
(set-window-buffer 3rdWin 1stBuf))
))))
(switch-entry)))
(global-set-key (kbd "C-c 4 r") (quote roll-v-3))
;;config destrel
;; This is needed for Erlang mode setup
(setq erlang-root-dir "/usr/local/Cellar/erlang/R15B01/lib/erlang")
(setq load-path (cons "/usr/local/Cellar/erlang/R15B01/lib/erlang/lib/tools-2.6.7/emacs" load-path))
(setq exec-path (cons "/usr/local/Cellar/erlang/R15B01/lib/erlang/bin" exec-path))
(require 'erlang-start)
;; This is needed for Distel setup
(let ((distel-dir "/Users/apple/programming/erlang/distel/elisp"))
(unless (member distel-dir load-path)
;; Add distel-dir to the end of load-path
(setq load-path (append load-path (list distel-dir)))))
(require 'distel)
(distel-setup)
;; Some Erlang customizations
(add-hook 'erlang-mode-hook
(lambda ()
;; when starting an Erlang shell in Emacs, default in the node name
(setq inferior-erlang-machine-options '("-sname" "emacs"))
;; add Erlang functions to an imenu menu
(imenu-add-to-menubar "imenu")))
;; A number of the erlang-extended-mode key bindings are useful in the shell too
(defconst distel-shell-keys
'(("\C-\M-i" erl-complete)
("\M-?" erl-complete)
("\M-." erl-find-source-under-point)
("\M-," erl-find-source-unwind)
("\M-*" erl-find-source-unwind)
)
"Additional keys to bind when in Erlang shell.")
(add-hook 'erlang-shell-mode-hook
(lambda ()
;; add some Distel bindings to the Erlang shell
(dolist (spec distel-shell-keys)
(define-key erlang-shell-mode-map (car spec) (cadr spec)))))
;;ruby
;;svn co http://svn.ruby-lang.org/repos/ruby/trunk/misc ruby-mode
(setq load-path (cons "/usr/share/emacs/site-lisp/ruby-mode" load-path))
(require 'ruby-mode)
(require 'ruby-end)
(require 'ruby-block)
(ruby-block-mode t)
;; display to minibuffer and do overlay
(setq ruby-block-highlight-toggle t)
(setq auto-mode-alist (cons '("\\.rb$" . ruby-mode) auto-mode-alist))
(server-start)
;;lua
;;(require 'lua-mode)
(setq auto-mode-alist (cons '("\\.lua$" . lua-mode) auto-mode-alist))
;;markdown mode
(require 'markdown-mode)
(setq auto-mode-alist (cons '("\\.markdown$" . markdown-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.md$" . markdown-mode) auto-mode-alist))
;;RST
(require 'rst)
(setq auto-mode-alist
(append '(("\\.rst$" . rst-mode)
("\\.rest$" . rst-mode)) auto-mode-alist))
;;clojure-mode
;;(add-to-list 'load-path "~/.emacs.d/clojure/clojure-mode")
;;(add-to-list 'load-path "~/.emacs.d/clojure/slime")
;;(require 'clojure-test-mode)
(add-hook 'slime-repl-mode-hook
(defun clojure-mode-slime-font-lock ()
(require 'clojure-mode)
(let (font-lock-mode)
(clojure-mode-font-lock-setup))))
(defun paredit-mode-enable () (paredit-mode 1))
(add-hook 'clojure-mode-hook 'paredit-mode-enable)
(add-hook 'clojure-test-mode-hook 'paredit-mode-enable)
(eval-after-load "slime"
'(progn
(slime-setup '(slime-repl slime-fuzzy))
;;(setq slime-truncate-lines t)
(setq swank:*globally-redirect-io* t)
;; (setq slime-complete-symbol-function ' slime-fuzzy-complete-symbol)
(setq slime-net-coding-system 'utf-8-unix)))
(eval-after-load "clojure-mode"
'(progn
(require 'slime)
(require 'clojure-mode)
(define-key clojure-mode-map (kbd "M-/") (quote slime-complete-symbol))
(define-key clojure-mode-map (kbd "C-c s") (quote slime-selector))
(unless (slime-connected-p)
(save-excursion (clojure-jack-in)))))
(setq auto-mode-alist (cons '("\\.clj$" . clojure-mode) auto-mode-alist))
;;clojure-project-mode
(require 'clojure-project-mode)
(project-load-all)
(project-mode 1)
;;yaml mode
;;(add-to-list 'load-path "~/.emacs.d/others/yaml-mode")
;;(require 'yaml-mode)
(setq auto-mode-alist
(append '(("\\.yml$" . yaml-mode)
("\\.yaml$" . yaml-mode)) auto-mode-alist))
(add-hook 'yaml-mode-hook
'(lambda ()
(define-key yaml-mode-map "\C-m" 'newline-and-indent)))
;;禁用箭头
(defvar no-easy-keys-minor-mode-map (make-keymap)
"no-easy-keys-minor-mode keymap.")
(let ((f (lambda (m)
`(lambda () (interactive)
(message (concat "No! use " ,m " instead."))))))
(dolist (l '(("<left>" . "C-b") ("<right>" . "C-f") ("<up>" . "C-p")
("<down>" . "C-n")
("<C-left>" . "M-f") ("<C-right>" . "M-b") ("<C-up>" . "M-{")
("<C-down>" . "M-}")
("<M-left>" . "M-f") ("<M-right>" . "M-b") ("<M-up>" . "M-{")
("<M-down>" . "M-}")
("<delete>" . "C-d") ("<C-delete>" . "M-d")
("<M-delete>" . "M-d") ("<next>" . "C-v") ("<C-next>" . "M-x <")
("<prior>" . "M-v") ("<C-prior>" . "M-x >")
("<home>" . "C-a") ("<C-home>" . "M->")
("<C-home>" . "M-<") ("<end>" . "C-e") ("<C-end>" . "M->")))
(define-key no-easy-keys-minor-mode-map
(read-kbd-macro (car l)) (funcall f (cdr l)))))
(define-minor-mode no-easy-keys-minor-mode
"A minor mode that disables the arrow-keys, pg-up/down, delete
and backspace." t " no-easy-keys"
'no-easy-keys-minor-mode-map :global t)
(no-easy-keys-minor-mode 1)
;;其他
(setq transient-mark-mode t) ; highlight text selection
(setq delete-selection-mode t) ; delete seleted text when typing
;;mac系统的案件设置,command设置为meta
;;; I prefer cmd key for meta
(setq mac-option-key-is-meta nil
mac-command-key-is-meta t
mac-command-modifier 'meta
mac-option-modifier 'none)
;; read in PATH from .bashrc
(if (not (getenv "TERM_PROGRAM"))
(setenv "PATH"
(shell-command-to-string "source $HOME/.bash_profile && printf $PATH")))
;;自定义函数和钩子
;;格式化
(defun indent-buffer ()
"Indent whole buffer"
(interactive)
(indent-region (point-min) (point-max))
(message "format successfully"))
(defun indent-file (file)
"prompt for a file and indent it according to its major mode"
(interactive "Which file do you want to indent: ")
(find-file file)
(indent-buffer))
(defun indent-file-when-save ()
"indent file when save."
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook
(lambda ()
(if (buffer-file-name)
(indent-buffer))
(save-buffer))))
;;当文件保存的时候自动格式化
(add-hook 'emacs-lisp-mode-hook 'indent-file-when-save)
;;(add-hook 'text-mode-hook 'indent-file-when-save)
;;(add-hook 'clojure-mode-hook 'indent-file-when-save)
(add-hook 'erlang-mode-hook 'indent-file-when-save)
;;缓冲区一键切
(defun switch-recent-buffer ()
"Switch to buffer used recently"
(interactive)
(switch-to-buffer (other-buffer)))
;;统计单词
(defun count-words (start end)
"Print number of words in the region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(message (number-to-string (count-matches "\\sw+"))))))
(defalias 'word-count 'count-words)
;;ssh登陆的适合自动更改shell命名
(defun rename-buffer-in-ssh-login (cmd)
"Rename buffer to the destination hostname in ssh login"
(if (string-match "ssh [-_a-z0-9A-Z]+@[-_a-z0-9A-Z.]+[ ]*[^-_a-z0-9-A-Z]*$" cmd)
(let (( host (nth 2 (split-string cmd "[ @\n]" t) )))
(rename-buffer (concat "*" host))
;(add-to-list 'shell-buffer-name-list (concat "*" host))
;(message "%s" shell-buffer-name-list)
)))
(add-hook 'comint-input-filter-functions 'rename-buffer-in-ssh-login)
;;退出shell关闭进程
(defun kill-shell-buffer(process event)
"The one actually kill shell buffer when exit. "
(kill-buffer (process-buffer process)))
(defun kill-shell-buffer-after-exit()
"kill shell buffer when exit."
(set-process-sentinel (get-buffer-process (current-buffer))
#'kill-shell-buffer))
(add-hook 'shell-mode-hook 'kill-shell-buffer-after-exit t)
;;outline mode设置,不同mode设置不同的regexp
(defun set-outline-minor-mode-regexp ()
""
(let ((find-regexp
(lambda
(lst mode)
""
(let
((innerList
(car lst)))
(if innerList
(if
(string=
(car innerList)
mode)
(car
(cdr innerList))
(progn
(pop lst)
(funcall find-regexp lst mode))))))))
(outline-minor-mode 1)
(make-local-variable 'outline-regexp)
(setq outline-regexp (funcall find-regexp outline-minor-mode-list major-mode))))
(add-hook 'shell-mode-hook 'set-outline-minor-mode-regexp t )
(add-hook 'sh-mode-hook 'set-outline-minor-mode-regexp t )
(add-hook 'emacs-lisp-mode-hook 'set-outline-minor-mode-regexp t )
(add-hook 'java-mode-hook 'set-outline-minor-mode-regexp t )
(add-hook 'clojure-mode-hook 'set-outline-minor-mode-regexp t )
(add-hook 'erlang-mode-hook 'set-outline-minor-mode-regexp t )
;;设置各个mode下的outline regexp
(setq outline-minor-mode-list
(list '(emacs-lisp-mode "(defun")
'(shell-mode ".*[bB]ash.*[#\$]")
'(sh-mode "function .*{")
'(javascript-mode "function .*{")
'(ruby-mode "def")
'(clojure-mode "(def.*")))
(add-hook 'shell-mode-hook 'outline-minor-mod
e)
(add-hook 'clojure-mode-hook 'outline-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
(add-hook 'ruby-mode-hook 'outline-minor-mode)
(add-hook 'sh-mode-hook 'outline-minor-mode)
(add-hook 'javascript-mode-hook 'outline-minor-mode)
;;emacs-jabber
(add-to-list 'load-path "~/.emacs.d/emacs-jabber")
(require 'hexrgb)
(require 'jabber-autoloads)
;;gtalk
(setq jabber-account-list '(
("killme2008@gmail.com"
;; (:password nnil)
(:network-server . "talk.google.com")
(:port . 443)
(:connection-type . ssl))))
;;Chat on new frame
(setq
special-display-regexps
'(("jabber-chat"
(width . 80)
(scroll-bar-width . 16)
(height . 15)
(tool-bar-lines . 0)
(menu-bar-lines 0)
(font . "-GURSoutline-Courier New-normal-r-normal-normal-11-82-96-96-c-70-iso8859-1")
(left . 80))))
;;Control message history (which stored in ~/.emacs-jabber dir)
(setq
jabber-history-enabled t
jabber-use-global-history nil
jabber-backlog-number 40
jabber-backlog-days 30
)
;;Redefine standard binding for sending message form RET to C-RET:
;;(define-key jabber-chat-mode-map (kbd "RET") 'newline)
;;(define-key jabber-chat-mode-map [C-return] 'jabber-chat-buffer-send)
;;Change prompt format:
(setq my-chat-prompt "[%t] %n>\n")
(when (featurep 'jabber)
(setq
jabber-chat-foreign-prompt-format my-chat-prompt
jabber-chat-local-prompt-format my-chat-prompt
jabber-groupchat-prompt-format my-chat-prompt
jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n"))
;;Automatically highlight URLs
(add-hook 'jabber-chat-mode-hook 'goto-address)
;;w3m配置
(add-to-list 'load-path "~/.emacs.d/w3m")
(require 'w3m-load)
;;enable cookie
(setq w3m-use-cookies t)
;;首页
(setq w3m-home-page "http://www.google.com")
;;图片
(setq w3m-display-inline-image t)
;;使用工具包
(setq w3m-use-toolbar t)
;;ut-8
(setq w3m-coding-system 'utf-8
w3m-file-coding-system 'utf-8
w3m-file-name-coding-system 'utf-8
w3m-input-coding-system 'utf-8
w3m-output-coding-system 'utf-8
w3m-terminal-coding-system 'utf-8)
;;键设置
(global-set-key [f2] 'tabbar-backward)
(global-set-key [f3] 'tabbar-forward)
(global-set-key [f4] 'roll-v-3)
(global-set-key [f5] 'shell)
(global-set-key [f6] 'clojure-jack-in)
(global-set-key [f7] 'indent-buffer)
(global-set-key [f8] 'change-split-type-3)
;;用control+m为mark-set键,留出ctrl+space热键作为输入法
(global-set-key (kbd "C-`") 'set-mark-command)
;;用control+tab作为切换窗口键
(global-set-key [(control tab)] 'other-window)
;;use M-/ to complete code for clojure
;;(setq slime-description-autofocus nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment