Skip to content

Instantly share code, notes, and snippets.

@stattrak-dragonlore
Created April 2, 2010 02:43
Show Gist options
  • Save stattrak-dragonlore/352674 to your computer and use it in GitHub Desktop.
Save stattrak-dragonlore/352674 to your computer and use it in GitHub Desktop.
(add-to-list 'load-path "~/.emacs.d")
(add-to-list 'load-path "~/.emacs.d/muse/lisp")
(add-to-list 'load-path "~/.emacs.d/vendor")
(progn (cd "~/.emacs.d/vendor")
(normal-top-level-add-subdirs-to-load-path))
(progn (cd "~"))
;; start emacs-server
(server-start)
;; User interface
(setq inhibit-startup-message t)
(setq initial-scratch-message "Hey, How are you\n")
(setq visible-bell t)
(setq line-number-mode t) ;;;;显示行号
(setq column-number-mode t) ;;;;显示列号
(setq-default indent-tabs-mode t)
(setq default-tab-width 8)
;(setq scroll-step 1)
(setq scroll-margin 3
scroll-conservatively 10000)
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(setq frame-title-format "%b@Emacs")
(setq default-major-mode 'text-mode);一打开就起用 text 模式。
(global-font-lock-mode t);语法高亮
(auto-image-file-mode t);打开图片显示功能
(display-time-mode 1);显示时间,格式如下
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(tool-bar-mode -1);去掉工具栏
(menu-bar-mode -1);去掉菜单栏
(scroll-bar-mode -1);去掉滚动条
(mouse-avoidance-mode 'jump);光标靠近鼠标指针时,让鼠标指针自动让开
(setq mouse-yank-at-point t);支持中键粘贴
(setq x-select-enable-clipboard t);支持emacs和外部程序的粘贴
(setq default-fill-column 80);默认显示 80列就换行
;; no trailing whitespace:
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(require 'linum)
;;左侧显示行号, linum.el
;(linum-mode 1)
;; color-theme
(require 'color-theme)
(color-theme-gray30)
;(require 'smart-operator)
;;窗口最大化
(require 'maxframe)
(add-hook 'window-setup-hook 'maximize-frame t)
;font
(set-default-font "Bitstream Vera Sans Mono-13")
(custom-set-variables
;; 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.
'(c-basic-offset 8)
'(c-default-style "K&R")
'(c-echo-syntactic-information-p t)
'(c-report-syntactic-errors t)
'(c-tab-always-indent nil)
'(kill-whole-line t)
'(muse-colors-autogen-headings (quote outline))
'(muse-colors-inline-image-method (quote muse-colors-use-publishing-directory))
'(muse-colors-inline-images nil)
'(muse-file-extension "muse")
'(muse-file-regexp "[/?]
\\|\\.\\(html?\\|pdf\\|mp3\\|el\\|zip\\|org\\|txt\\|tar\\)\\(\\.\\(gz\\|bz2\\)
\\)?\\'")
'(muse-html-charset-default "utf-8")
'(muse-html-encoding-default (quote utf-8))
'(muse-html-markup-functions (quote ((anchor . muse-html-markup-anchor) (table . muse-html-markup-table) (footnote . muse-html-markup-footnote))))
'(muse-html-meta-content-encoding (quote utf-8))
'(muse-html-style-sheet "<link rel=\"stylesheet\" type=\"text/css\"
charset=\"utf-8\" media=\"all\" href=\"css/muse.css\" />")
'(muse-publish-desc-transforms (quote (muse-wiki-publish-pretty-title muse-wiki-publish-pretty-interwiki muse-publish-escape-specials-in-string)))
'(muse-wiki-publish-small-title-words (quote ("the" "and" "at" "on" "of" "for" "in" "an" "a" "page" "anime")))
'(uniquify-buffer-name-style (quote post-forward) nil (uniquify)))
(custom-set-faces
;; custom-set-faces 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.
)
;;My keys binding
;;Genral purpose
(global-set-key [(meta g)] 'goto-line)
(global-set-key [(f4)] 'shell)
;;ANSI Color for Shell
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(setq ansi-color-for-comint-mode t)
;;global
(autoload 'gtags-mode "gtags" "" t)
(setq gtags-mode-hook
'(lambda ()
(define-key gtags-mode-map "\eh" 'gtags-display-browser)
(define-key gtags-mode-map "\C-]" 'gtags-find-tag-from-here)
(define-key gtags-mode-map "\C-t" 'gtags-pop-stack)
;; (define-key gtags-mode-map "\el" 'gtags-find-file)
;; (define-key gtags-mode-map "\eg" 'gtags-find-with-grep)
;; (define-key gtags-mode-map "\eI" 'gtags-find-with-idutils)
;; (define-key gtags-mode-map "\es" 'gtags-find-symbol)
;; (define-key gtags-mode-map "\er" 'gtags-find-rtag)
;; (define-key gtags-mode-map "\et" 'gtags-find-tag)
;; (define-key gtags-mode-map "\ev" 'gtags-visit-rootdir)
))
(global-set-key (kbd "M-[") 'grep)
;;Help System
(global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))
;;region indent
(global-set-key (kbd "C-M-=") 'indent-region)
;;Window control
;(global-set-key [(control o)] 'other-window) ;After all, it's a "Classical one"
(global-set-key [(control insert)] 'split-window-vertically)
(global-set-key [(control delete)] 'delete-other-windows)
(global-set-key [(control end)] 'delete-window)
(global-set-key [(control next)] 'other-window)
(global-set-key [(control prior)] 'other-window)
;;BookMark
;(global-set-key [(ctrl f2)] 'bookmark-set)
;(global-set-key [(ctrl f3)] 'bookmark-jump)
;(global-set-key [(f12)] 'list-bookmarks)
;(setq bookmark-save-flag 1);;Force it to save bookmark whenever it changes
;;Registers: a simple bookmark
;;(global-set-key (kbd "M-'") 'point-to-register)
;;(global-set-key (kbd "M-l") 'jump-to-register)
; Solve Chinese fill problem
(put-charset-property 'chinese-cns11643-5 'nospace-between-words t)
(put-charset-property 'chinese-cns11643-6 'nospace-between-words t)
(put-charset-property 'chinese-cns11643-7 'nospace-between-words t)
(defalias 'yes-or-no-p 'y-or-n-p)
(global-set-key [(f5)] 'buffer-action-compile)
(global-set-key [(f6)] 'buffer-action-run)
;(setq truncate-partial-width-windows nil)
;(require 'wb-line-number)
;(wb-line-number-toggle)
;;;;自动补齐策略
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "\\>")
(hippie-expand nil)
(indent-for-tab-command))
)
(global-set-key [(control tab)] 'my-indent-or-complete)
(setq hippie-expand-try-functions-list
'(
try-expand-dabbrev ; 搜索当前 buffer
try-expand-dabbrev-visible ; 搜索当前可见窗口
try-expand-dabbrev-all-buffers ; 搜索所有 buffer
try-expand-dabbrev-from-kill ; 从 kill-ring 中搜索
try-complete-file-name-partially ; 文件名部分匹配
try-complete-file-name ; 文件名匹配
try-expand-all-abbrevs ; 匹配所有缩写词
try-expand-list ; 补全一个列表
try-expand-line ; 补全当前行
try-expand-whole-kill
try-complete-lisp-symbol-partially ; 部分补全 elisp symbol
try-complete-lisp-symbol)) ; 补全 lisp
;(require 'cedet)
;; C/C++/Java mode
(defun my-c-mode-hook()
(interactive)
(define-key c-mode-map [return] 'newline-and-indent)
;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
(c-toggle-auto-state)
(c-semi&comma-no-newlines-before-nonblanks)
;; 此模式下,当按Backspace时会删除最多的空格
(c-toggle-hungry-state)
;; 在菜单中加入当前Buffer的函数索引
(imenu-add-menubar-index)
;; 在状态条上显示当前光标在哪个函数体内部
(which-function-mode t)
;; gtags mode
(gtags-mode 1)
;(smart-operator-mode 1)
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq comment-column 48)
(setq abbrev-mode t)
;; ThisIsSubWord
(c-subword-mode 1)
;;左侧显示行号, linum.el
(linum-mode 1)
)
(defun my-c++-mode-hook()
(interactive)
;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
(c-toggle-auto-state)
(c-semi&comma-no-newlines-before-nonblanks)
;; 此模式下,当按Backspace时会删除最多的空格
(c-toggle-hungry-state)
;; 在菜单中加入当前Buffer的函数索引
(imenu-add-menubar-index)
;; 在状态条上显示当前光标在哪个函数体内部
(which-function-mode)
;; gtags mode
(gtags-mode 1)
;(smart-operator-mode 1)
(setq hs-minor-mode t)
(setq comment-column 48)
(setq abbrev-mode t)
;; ThisIsSubWord
(c-subword-mode 1)
;;左侧显示行号, linum.el
(linum-mode 1)
(define-key c++-mode-map [return] 'newline-and-indent)
)
(defun my-java-mode()
(interactive)
(define-key java-mode-map [return] 'newline-and-indent)
(c-set-style "java")
(c-toggle-auto-state)
(c-toggle-hungry-state)
(imenu-add-menubar-index)
(which-function-mode)
(gtags-mode 1)
;; ThisIsSubWord
(c-subword-mode 1)
(setq comment-column 48)
)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
(add-hook 'java-mode-hook 'my-java-mode)
(defun my-scheme-mode()
(interactive)
(define-key scheme-mode-map [return] 'newline-and-indent)
)
(add-hook 'scheme-mode-hook 'my-scheme-mode)
; return a backup file path of a give file path
; with full directory mirroring from a root dir
; non-existant dir will be created
(defun my-backup-file-name (fpath)
"Return a new file path of a given file path.
If the new path's directories does not exist, create them."
(let (backup-root bpath)
(setq backup-root "~/backup")
(setq bpath (concat backup-root fpath "~"))
(make-directory (file-name-directory bpath) bpath)
bpath
)
)
(setq make-backup-file-name-function 'my-backup-file-name)
;; copy one line is mark not active
(global-set-key (kbd "M-w") 'huangq-save-line-dwim)
(defun huangq-save-one-line (&optional arg)
"save one line. If ARG, save one line from first non-white."
(interactive "P")
(save-excursion
(if arg
(progn
(back-to-indentation)
(kill-ring-save (point) (line-end-position)))
(kill-ring-save (line-beginning-position) (line-end-position)))))
;;;###autoload
(defun huangq-kill-ring-save (&optional n)
"If region is active, copy region. Otherwise, copy line."
(interactive "p")
(if (and mark-active transient-mark-mode)
(kill-ring-save (region-beginning) (region-end))
(if (> n 0)
(kill-ring-save (line-beginning-position) (line-end-position n))
(kill-ring-save (line-beginning-position n) (line-end-position)))))
;;;###autoload
(defun huangq-save-line-dwim (&optional arg)
"If region is active, copy region.
If ARG is nil, copy line from first non-white.
If ARG is numeric, copy ARG lines.
If ARG is non-numeric, copy line from beginning of the current line."
(interactive "P")
(if (and mark-active transient-mark-mode)
;; mark-active, save region
(kill-ring-save (region-beginning) (region-end))
(if arg
(if (numberp arg)
;; numeric arg, save ARG lines
(huangq-kill-ring-save arg)
;; other ARG, save current line
(huangq-save-one-line))
;; no ARG, save current line from first non-white
(huangq-save-one-line t))))
;; behave like vi's o command
(defun my-open-line-below (arg)
"Move to the next line and then opens a line."
(interactive "p")
(end-of-line)
(open-line arg)
(next-line arg)
(indent-according-to-mode))
(global-set-key (kbd "C-o") 'my-open-line-below)
;; behave like vi's O command
(defun my-open-line-above (arg)
"Open a new line before the current one."
(interactive "p")
(beginning-of-line)
(open-line arg)
(indent-according-to-mode))
(global-set-key (kbd "M-o") 'my-open-line-above)
;;----------------------------------------------------------------------
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
;; go to char like 'f' in vi
(defun wy-go-to-char (n char)
"Move forward to Nth occurence of CHAR.
Typing `wy-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
(interactive "p\ncGo to char: ")
(search-forward (string char) nil nil n)
(while (char-equal (read-char)
char)
(search-forward (string char) nil nil n))
(setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-c f") 'wy-go-to-char)
;;C-w remove a line
(defadvice kill-region (before slickcut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(require 'buffer-action)
(autoload 'buffer-action-compile "buffer-action")
(autoload 'buffer-action-run "buffer-action")
;(require 'company-mode)
;(require 'company-bundled-completions)
;(company-install-bundled-completions-rules)
(require 'sdcv-mode)
(global-set-key (kbd "C-c d") 'sdcv-search)
(global-set-key (kbd "C-c u") 'revert-buffer)
(defun my-python-mode-hook()
(define-key python-mode-map [return] 'newline-and-indent)
(which-function-mode 1)
(linum-mode 1))
(add-hook 'python-mode-hook 'my-python-mode-hook)
(require 'htmlize)
;;简体繁体转换
;(autoload 'hanconvert-region "hanconvert"
; "Convert a region from simple chinese to trandition chinese or
; from trandition chinese to simple chinese" t)
;(require 'w3m-load)
(require 'ido)
(ido-mode t)
;; thumbs image viewer
;; (require 'thumbs)
;;; twitter
(load-file "~/.emacs.d/Twit.el")
(global-set-key "\C-xt" 'twit-post)
;
;; pastie
;(load-file "~/.emacs.d/pastie.el")
;; yasnippet
(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
(yas/load-directory "~/.emacs.d/snippets/")
;(setq yas/trigger-key (kbd "C-c\t"))
(require 'browse-kill-ring)
;(global-set-key [(control c)(k)] 'browse-kill-ring)
(browse-kill-ring-default-keybindings)
;;{{{ word count
(defun wc ()
"Count words of the slected region while some text is selected;
Otherwise count words of this buffer"
(interactive)
(let ((msg "全文")
(begin (point-min))
(end (point-max)))
(if mark-active
(setq msg "选中"
begin (region-beginning)
end (region-end))
)
(message "统计%s字数..." msg)
(shell-command-on-region begin end "wc -m")))
;;}}}
;; blogger
;(load-file "~/.emacs.d/e-blog.el")
;; org-mode
(setq org-hide-leading-stars t)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done 'time)
(require 'muse-mode) ; load authoring mode
(require 'muse-html) ; load publishing styles I use
(require 'muse-latex)
(require 'muse-texinfo)
(require 'muse-docbook)
(require 'muse-project) ; publish files in projects
(require 'muse-wiki)
(require 'muse-book)
(setq muse-project-alist
'(("Website" ("~/docs/musepages" :default "index")
(:base "html" :path "~/html/muse")
))
)
;;; 自定义的变量
(setq muse-mode-auto-p nil)
(setq muse-mode-highlight-p t)
(setq muse-wiki-ignore-bare-project-names t)
(setq muse-colors-evaluate-lisp-tags nil)
(setq muse-html-meta-content-type "text/html; charset=utf-8")
;(setq muse-html-header "~/html/muse/header.html")
(setq muse-html-footer "~/html/muse/footer.html")
;(autoload 'scheme-smart-complete "scheme-complete" nil t)
;(eval-after-load 'scheme
; '(define-key scheme-mode-map "\t" 'scheme-complete-or-indent))
;;google region
(defun google-region (beg end) "Google the selected region." (interactive "r") (
browse-url (concat "http://www.google.com/search?ie=utf-8&oe=utf-8&q=" (buffer-substring beg end))))
(setq browse-url-browser-function 'browse-url-generic browse-url-generic-program
"/usr/bin/firefox")
(global-set-key (kbd "C-M-g") 'google-region)
;;ignore running process when quit emacs
(setq kill-buffer-query-functions
(remove 'process-kill-buffer-query-function kill-buffer-query-functions))
;; 为 view-mode 加入 vim 的按键。
(setq view-mode-hook
(lambda ()
(define-key view-mode-map "h" 'backward-char)
(define-key view-mode-map "l" 'forward-char)
(define-key view-mode-map "j" 'next-line)
(define-key view-mode-map "k" 'previous-line)))
;(require 'javascript)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
(autoload 'javascript-mode "javascript" nil t)
(defun my-javascript-mode-hook()
(interactive)
(define-key javascript-mode-map [return] 'newline-and-indent)
)
(add-hook 'javascript-mode-hook 'my-javascript-mode-hook)
;;;capslock --> M-x
(if (eq window-system 'x)
(shell-command "xmodmap -e 'clear Lock' -e 'keycode 66 = F13'"))
(global-set-key [f13] 'execute-extended-command)
(require 'vcl-mode)
(put 'upcase-region 'disabled nil)
(require 'uniquify)
;; gtalk
(setq jabber-account-list
'(("kofreestyler@gmail.com"
(:network-server . "talk.google.com")
(:connection-type . ssl))))
(add-to-list 'load-path "~/.emacs.d/vendor/gist.el")
(require 'gist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment