Created
August 18, 2013 14:28
-
-
Save kuanyui/6261922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;kuanyui's ~/.emacs | |
;;Time-stamp: "此文件最後是在2013-08-18 22:05:18由kuanyui修改" | |
;;掃描~/.emacs.d目錄 | |
(add-to-list 'load-path "~/.emacs.d") | |
(add-to-list 'load-path "~/.emacs.d/lisps") | |
;;執行Shell外部程式的搜尋路徑(意同$PATH) | |
(setenv "PATH" (concat (getenv "PATH") ":/home/kuanyui/Dropbox/scripts/")) | |
(setq shell-file-name "/bin/zsh") | |
(setq shell-command-switch "-ic") | |
;;GUI Emacs調整字體大小 | |
(defun sacha/increase-font-size () | |
(interactive) | |
(set-face-attribute 'default | |
nil | |
:height | |
(ceiling (* 1.10 | |
(face-attribute 'default :height))))) | |
(defun sacha/decrease-font-size () | |
(interactive) | |
(set-face-attribute 'default | |
nil | |
:height | |
(floor (* 0.9 | |
(face-attribute 'default :height))))) | |
(global-set-key (kbd "C-+") 'sacha/increase-font-size) | |
(global-set-key (kbd "C--") 'sacha/decrease-font-size) | |
;;超變態的undo-tree-mode | |
;;(提醒:redo會變成C-?) | |
;;C-x u 進入 undo-tree-visualizer-mode,t顯示時間戳。 | |
(require 'undo-tree) | |
(global-undo-tree-mode) | |
(global-set-key (kbd"C-M-_") 'undo-tree-redo) | |
;;行號 | |
(global-linum-mode t) | |
;;當前行高亮顯示 | |
(global-hl-line-mode 1) | |
;;在標題顯示文件名稱(%b)與路徑(%f) | |
(setq frame-title-format "%n%b (%f) - %F") | |
;;(setq frame-title-format '((:eval default-directory))) | |
;;把捲軸移到右側 | |
(customize-set-variable 'scroll-bar-mode 'right) | |
;;啟用ibuffer(比預設的那個buffer selector好用一點) | |
;;(add-to-list 'load-path "~/.emacs.d/lisps") | |
;;(require 'ibuffer) | |
(global-set-key (kbd "C-x C-b") 'ibuffer) | |
(autoload 'ibuffer "ibuffer" "List buffers." t) | |
;; Let's group buffers with ibuffer!!! | |
(setq ibuffer-saved-filter-groups | |
(quote (("default" | |
("Dired" (mode . dired-mode)) | |
("Note" (or | |
(name . "^\\*Calendar\\*$") | |
(name . "^diary$") | |
(mode . org-mode) | |
(mode . muse-mode))) | |
("IRC" (or | |
(mode . erc-mode) | |
(mode . rcirc-mode))) | |
("Emacs" (or | |
(name . "^\\*scratch\\*$") | |
(name . "^\\*Messages\\*$") | |
(name . ".emacs"))) | |
("Magit" (name . "*magit*")) | |
("Help" (or | |
(name . "\*Help\*") | |
(name . "\*Apropos\*") | |
(mode . "help") | |
(name . "\*info\*"))) | |
)))) | |
;; auto update ibuffer | |
(add-hook 'ibuffer-mode-hook | |
'(lambda () | |
(ibuffer-auto-mode 1) | |
(ibuffer-switch-to-saved-filter-groups "default"))) | |
;; Do not show empty group | |
(setq ibuffer-show-empty-filter-groups nil) | |
;;讓Isearch不會再主動清除搜尋的高亮顯示 | |
(setq lazy-highlight-cleanup nil) | |
;;我最愛的插入日期,格式為習慣的YYYY/mm/dd(星期),使用方法為C-c d | |
(defun my-insert-date () | |
(interactive) | |
(insert (format-time-string "%Y/%m/%d(%a)" (current-time)))) | |
(global-set-key (kbd "C-c d") 'my-insert-date) | |
;;凸顯括號位置(而不是來回彈跳) | |
(show-paren-mode t) | |
;;(setq show-paren-style 'parentheses) | |
(setq show-paren-style 'expression) ;;另一種突顯方式(突顯整個括號範圍) | |
;;隱藏工具列 | |
(tool-bar-mode -1) | |
;;隱藏選單 | |
(menu-bar-mode -1) | |
;;X Clipboard在光標處插入,而不是滑鼠點擊的地方插入。 | |
(setq mouse-yank-at-point t) | |
;;讓Emacs可以直接打開/顯示圖片。 | |
(setq auto-image-file-mode t) | |
;;recents最近開啟的檔案,C-x C-r | |
(require 'recentf) | |
(recentf-mode 1) | |
(setq recentf-max-menu-items 35) | |
(global-set-key "\C-x\ \C-r" 'recentf-open-files) | |
;;(run-with-timer 0 (* 10 60) 'recentf-save-list) | |
;;同名檔案不混淆(同名檔案同時開啟時,會在buffer加上目錄名稱) | |
(require 'uniquify) | |
(setq | |
uniquify-buffer-name-style 'post-forward | |
uniquify-separator ":") | |
;;換掉歡迎畫面的難看GNU Logo | |
;;(setq fancy-splash-image "~/.emacs.d/icon.png") | |
;;完全隱藏歡迎畫面 | |
(setq inhibit-splash-screen t) | |
;;自動啟動flyspell-mode拼字檢查 | |
;;(setq-default flyspell-mode t) | |
;;flyspell-prog-mode是為程式設計師的輔模式,Emacs将只在注释和字符串里高亮错误的拼写。 | |
;;(setq-default flyspell-prog-mode t) | |
(global-set-key (kbd "C-x <f3>") 'flyspell-mode) | |
(global-set-key (kbd "C-c <f3>") 'flyspell-buffer) | |
(global-set-key (kbd "<f3>") 'flyspell-check-previous-highlighted-word) | |
(global-set-key (kbd "C-x <f4>") 'ispell-buffer) | |
(global-set-key (kbd "<f4>") 'ispell-word) ;;M-$,有夠難記,很容易跟query-replace的M-%搞混 | |
;; aspell | |
(setq ispell-program-name "aspell" | |
ispell-extra-args '("--sug-mode=ultra")) | |
(setq ispell-dictionary "american") | |
;;靠近螢幕邊緣三行時就開始捲動,比較容易看上下文 | |
(setq scroll-margin 3) | |
;;關閉煩人的錯誤提示音,改為在螢幕上提醒。 | |
(setq visible-bell t) | |
;;超大kill ring. 防止不小心删掉重要的東西。 | |
(setq kill-ring-max 200) | |
;;设置tab为4个空格的宽度 | |
;;(setq default-tab-width 4) | |
;;Tab改為插入空格 | |
;;abs look fine on a terminal or with ordinary printing, but they produce badly indented output when you use TeX or Texinfo since TeX ignores tabs. | |
(setq-default indent-tabs-mode t) | |
;;每次修改文件自動更新Time-stamp | |
;;将time-stamp加入write-file-hooks,就能在每次保存文件时自动更新time-stamp | |
(add-hook 'write-file-hooks 'time-stamp) | |
(setq time-stamp-format | |
"此文件最後是在%04y-%02m-%02d %02H:%02M:%02S由%:u修改" | |
time-stamp-active t | |
time-stamp-warn-inactive t) | |
;;這個marco太多此一舉了......先暫時註解保留看情形(不然重寫好麻煩)。 | |
;;(fset 'insert-time-stamp | |
;; (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ("Time-stamp: \" \" | |
" 0 "%d")) arg))) | |
;;(global-set-key (kbd "C-c t i m e") 'insert-time-stamp) | |
;;安裝最新版markdown.el | |
(require 'markdown-mode) | |
(autoload 'markdown-mode "markdown-mode" | |
"Major mode for editing Markdown files" t) | |
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode)) | |
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode)) | |
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode)) | |
(add-to-list 'auto-mode-alist '("\\.mdown\\'" . markdown-mode)) | |
(setq markdown-enable-math t) | |
;;把markdown的outline搞得跟org-mode的key-binding接近一點 | |
;;靠背老子寫不出來啦 | |
;;(defun markdown-insert-new-header () | |
;; "Insert a new line along with a header" | |
;; (interactive) | |
;; (move-end-of-line)(newline)(markdown-insert-header-dwim)) | |
;; | |
;;(add-hook 'markdown-mode-hook | |
;; (lambda () (define-key markdown-mode-map (kbd "C-c RET") 'markdown-insert-new-header))) | |
;;(define-key markdown-mode-map (kbd "C-c RET") 'markdown-insert-new-header) | |
;;Org-mode專區=========================================== | |
;;安裝最新版org-mode | |
(add-to-list 'load-path "~/.emacs.d/lisps/org-mode/lisp/") | |
(require 'org-install) | |
;;解决org-mode下中文不自动换行的问题 | |
(add-hook 'org-mode-hook | |
(lambda () (setq truncate-lines nil))) | |
;;org-mode裡的項目變成done時會自動加上CLOSED: [timestamp]戳記;改成'note為筆記 | |
(setq org-log-done 'time) | |
;;(setq org-log-done 'note) | |
(defun org-insert-bold () | |
"Insert *bold* at cursor point." | |
(interactive) | |
(insert " ** ") | |
(backward-char 2)) | |
(global-set-key (kbd "C-c b") 'org-insert-bold) | |
(defun org-insert-blockquote () | |
"Insert *bold* at cursor point." | |
(interactive) | |
(move-end-of-line)(newline 2)(insert "#+BEGIN_QUOTE")(newline 2)(insert "#+END_QUOTE")(previous-line 1)) | |
(global-set-key (kbd "C-c i q") 'org-insert-blockquote) | |
(defun org-insert-center-block () | |
"Insert *bold* at cursor point." | |
(interactive) | |
(move-end-of-line)(newline 2)(insert "#+BEGIN_CENTER")(newline 2)(insert "#+END_CENTER")(previous-line 1)) | |
(global-set-key (kbd "C-c i c") 'org-insert-center-block) | |
(defun org-insert-image () | |
"Insert image in org-mode" | |
(interactive) | |
(let* ((insert-default-directory nil)) | |
(insert-string (concat "[[file:" (read-file-name "Enter the image file ") "]]")))) | |
(global-set-key (kbd "C-c i i") 'org-insert-image) | |
;; 指定agenda檔案位置清單 | |
(setq org-agenda-files (list "~/Dropbox/todo.org")) | |
(global-set-key "\C-ca" 'org-agenda) | |
;;快速插入自訂org export template | |
(define-skeleton org-export-skeleton | |
"Inserts my org export skeleton into current buffer. | |
This only makes sense for empty buffers." | |
"標題: " | |
"#+TITLE: " str | " *** 標題 *** " " " \n | |
"#+AUTHOR: kuanyui" \n | |
"#+EMAIL: " \n | |
"#+DATE: "(insert (format-time-string "%Y/%m/%d(%a)" )) \n | |
"#+DESCRIPTION:" \n | |
"#+KEYWORDS:" \n | |
"#+LANGUAGE: zh" \n | |
"#+OPTIONS: H:3 num:t toc:t \\n:t @:t ::t |:t ^:t -:t f:t *:t <:t" \n | |
"#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc" \n | |
"#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js" \n | |
"#+EXPORT_SELECT_TAGS: export" \n | |
"#+EXPORT_EXCLUDE_TAGS: noexport" \n | |
"#+LINK_UP: " \n | |
"#+LINK_HOME: " \n | |
"#+XSLT:" \n | |
) | |
(global-set-key (kbd "C-c i t") 'org-export-skeleton) | |
;;Org-mode結束=========================================== | |
;;比預設值較完整地支援shell script語法高亮。 | |
;;感謝[email protected] | |
(defface font-lock-system-command-face | |
'((((class color)) (:foreground "purple"))) | |
"I am comment" | |
:group 'font-lock-faces) | |
(defun font-lock-system-command (&optional limit) | |
"" | |
(and (search-forward-regexp "\\<[a-zA-Z\\-]+\\>" limit t) | |
(executable-find | |
(buffer-substring-no-properties (car (bounds-of-thing-at-point 'word)) | |
(cdr (bounds-of-thing-at-point 'word))) | |
))) | |
(font-lock-add-keywords | |
'sh-mode | |
'((font-lock-system-command . 'font-lock-system-command-face))) | |
;;Emacs內建的自動補完hippie-expand | |
(global-set-key [(meta ?/)] 'hippie-expand) | |
(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-complete-lisp-symbol-partially ; 部分补全 elisp symbol | |
try-complete-lisp-symbol)) ; 补全 lisp symbol | |
(load "~/.emacs.d/lisps/complete-with-calc.el") | |
;;補全另一選擇company-mode | |
;;(add-to-list 'load-path "~/.emacs.d/lisps/company") | |
;;(autoload 'company-mode "company" nil t) | |
;;(company-mode 1) | |
;;popup-kill-ring | |
(add-to-list 'load-path "~/.emacs.d/lisps/popup-kill-ring/") | |
;;(require 'popup) | |
(require 'pos-tip) | |
(require 'popup-kill-ring) | |
(global-set-key "\M-y" 'popup-kill-ring) | |
;;Twittering-mode:用Emacs上Twitter | |
(add-to-list 'load-path "~/.emacs.d/lisps/twittering-mode/") | |
(require 'twittering-mode) | |
(setq twittering-use-master-password t) ;;This requires GnuPG. And also, either EasyPG or alpaca.el (0.13) is necessary. | |
(twittering-enable-unread-status-notifier) ;;顯示未讀訊息數 | |
;;(setq-default twittering-icon-mode t) ;;預設顯示頭像 | |
;;開啟自己的favorite timeline | |
(defun my-twittering-favorites-timeline () | |
(interactive) | |
(twittering-visit-timeline ":favorites")) | |
;;(defun twittering-mode-hook-func () | |
;; (set-face-bold-p 'twittering-username-face t) | |
;; (set-face-foreground 'twittering-username-face "SkyBlue3") | |
;; (set-face-foreground 'twittering-uri-face "#a0a0a0") | |
;; (set-face-foreground 'twittering-timeline-footer-face "#a0a0a0") | |
;; (set-face-foreground 'twittering-timeline-header-face "#a0a0a0")) | |
;;(add-hook 'twittering-mode-hook 'twittering-mode-hook-func) | |
(define-key twittering-mode-map (kbd "R") 'twittering-replies-timeline) | |
(define-key twittering-mode-map (kbd "U") 'twittering-user-timeline) | |
(define-key twittering-mode-map (kbd "W") 'twittering-update-status-interactive) | |
(define-key twittering-mode-map (kbd "O") 'twittering-organic-retweet) | |
(define-key twittering-mode-map (kbd "N") 'twittering-native-retweet) | |
(define-key twittering-mode-map (kbd "H") 'twittering-home-timeline) | |
(define-key twittering-mode-map (kbd "F") 'twittering-favorite) | |
(define-key twittering-mode-map (kbd "V") 'twittering-visit-timeline) | |
(define-key twittering-mode-map (kbd "M") 'my-twittering-favorites-timeline) | |
(define-key twittering-mode-map (kbd "M-w") 'twittering-push-tweet-onto-kill-ring) | |
(define-key twittering-mode-map (kbd "C-w") 'twittering-push-uri-onto-kill-ring) | |
(define-key twittering-mode-map (kbd "D") 'twittering-direct-messages-timeline) | |
;;類似pentadactyl按[f]後輸入數字開啟連結 | |
(autoload 'twittering-numbering "twittering-numbering" nil t) | |
(add-hook 'twittering-mode-hook 'twittering-numbering) | |
;;以詞彙過濾不要的Tweets | |
(setq twittering-tweet-filters '("无锡气象" "黑夜给了我黑色的眼睛,我却用它来寻找光明。" "如果你现在赖在床上,你可能会完成一个梦。如果你现在起来做事,你可能会完成一个梦想。")) | |
(defun twittering-filter-tweets () | |
(setq non-matching-statuses '()) | |
(dolist (status twittering-new-tweets-statuses) | |
(setq matched-tweets 0) | |
(dolist (pat twittering-tweet-filters) | |
(if (string-match pat (cdr (assoc 'text status))) | |
(setq matched-tweets (+ 1 matched-tweets)))) | |
(if (= 0 matched-tweets) | |
(setq non-matching-statuses (append non-matching-statuses `(,status))))) | |
(setq new-statuses non-matching-statuses)) | |
(add-hook 'twittering-new-tweets-hook 'twittering-filter-tweets) | |
;;有了tmux就不須要Emacs裡那個問題多多的terminal emulator了。 | |
(global-set-key (kbd "<f1>") 'kmacro-start-macro-or-insert-counter) | |
(global-set-key (kbd "<f2>") 'kmacro-end-or-call-macro) | |
;;(global-set-key (kbd "<f3>") 'open-zsh) | |
;;(defun open-zsh () | |
;; "zsh" | |
;; (interactive) | |
;; (term "/bin/zsh")) | |
;;用f5~f8調整frame大小 | |
(global-set-key (kbd "C-x <f5>") 'shrink-window-horizontally) | |
(global-set-key (kbd "C-x <f6>") 'enlarge-window-horizontally) | |
(global-set-key (kbd "C-x <f7>") 'shrink-window) | |
(global-set-key (kbd "C-x <f8>") 'enlarge-window) | |
(global-set-key (kbd "<f9>") 'open-note) | |
(defun open-note () | |
"Open stick note." | |
(interactive)(find-file "~/Dropbox/notes.org")) | |
(global-set-key (kbd "<f10>") 'open-todo) | |
(defun open-todo () | |
"Open todo list." | |
(interactive)(find-file "~/Dropbox/todo.org")) | |
(global-set-key (kbd "C-x <f11>") 'open-diary) | |
(defun open-diary () | |
"Open diary." | |
(interactive)(find-file "~/Dropbox/Diary/diary_2013.org")) | |
(global-set-key [(f12)] 'twit) | |
(defun open-blog-dir () | |
(interactive)(find-file "~/Dropbox/Blog/kuanyui.github.io/")) | |
(global-set-key (kbd "C-x <f12>") 'open-blog-dir) | |
;;調用word-count-for-emacs來計算字數 (能較正確計算中英文夾雜文件的字數) | |
;;詳情請見 http://kuanshome.blogspot.com/2012/03/emacs.html | |
(global-set-key (kbd "C-c w c") 'word-count) | |
(defun word-count nil "Count words in buffer (include CJK characters)" | |
(interactive) | |
(shell-command-on-region (point-min) (point-max) "word-count-for-emacs")) | |
(global-set-key (kbd "C-c t") 'test-light-theme) | |
(defun test-light-theme () "test new theme" | |
(interactive) | |
(load-theme 'moe-light)) | |
(global-set-key (kbd "C-c r") 'test-dark-theme) | |
(defun test-dark-theme () "test new theme" | |
(interactive) | |
(load-theme 'moe-dark)) | |
;; StarDict for Emacs | |
;; author: pluskid | |
;; 调用 stardict 的命令行接口来查辞典,如果选中了 region 就查询 region 的内容,否则就查询当前光标所在的词 | |
(global-set-key (kbd "C-c k") 'kid-star-dict) | |
(defun kid-star-dict () | |
(interactive) | |
(let ((begin (point-min)) | |
(end (point-max))) | |
(if mark-active | |
(setq begin (region-beginning) | |
end (region-end)) | |
(save-excursion | |
(backward-word) | |
(mark-word) | |
(setq begin (region-beginning) | |
end (region-end)))) | |
;; 有时候 stardict 会很慢,所以在回显区显示一点东西 | |
;; 以免觉得 Emacs 在干什么其他奇怪的事情。 | |
(message "searching for %s ..." (buffer-substring begin end)) | |
(popup-tip | |
(shell-command-to-string | |
(concat "sdcv -n " | |
(buffer-substring begin end)))))) | |
;;Term下不要使用當行高亮,避免使用如MOC(music on console)等程式時出現的無意義當行高亮。 | |
(add-hook 'term-mode-hook | |
(lambda () (setq global-hl-line-mode nil))) | |
;;Linux下與其他Applications的剪貼簿 | |
;;(setq x-select-enable-clipboard t) | |
(setq x-select-enable-clipboard t) | |
(setq interprogram-paste-function 'x-cut-buffer-or-selection-value) | |
;;(load-file "~/.emacs.d/lisps/copypaste.el") | |
(defun cp () | |
(interactive) | |
(if (region-active-p) | |
(progn | |
(shell-command-on-region (region-beginning) (region-end) "xsel -i") | |
(message "Yanked region to clipboard!") | |
(deactivate-mark)) | |
(message "No region active; can't yank to clipboard!"))) | |
;;Stardict in Emacs | |
(require 'sdcv-mode) | |
(global-set-key (kbd "C-c s") 'sdcv-search) | |
;;解決tmux下無法切換buffer以及一些key-binding的問題 | |
(global-set-key (kbd "C-x M-[ d") 'previous-buffer) | |
(global-set-key (kbd "C-x M-[ c") 'next-buffer) | |
(global-set-key (kbd "M-[ c") 'forward-word) | |
(global-set-key (kbd "M-[ d") 'backward-word) | |
(global-set-key (kbd "C-c M-[ d") 'backward-sexp) | |
(global-set-key (kbd "C-c M-[ c") 'forward-sexp) | |
(global-set-key (kbd "C-c M-[ a") 'backward-up-list) | |
(global-set-key (kbd "C-c M-[ b") 'down-list) | |
;;下面這幾個原本的binding不好按或者會跟kwin衝。 | |
(global-set-key (kbd "C-c <C-left>") 'backward-sexp) | |
(global-set-key (kbd "C-c <C-right>") 'forward-sexp) | |
(global-set-key (kbd "C-c <C-up>") 'backward-up-list) | |
(global-set-key (kbd "C-c <C-down>") 'down-list) | |
(global-set-key (kbd "C-c C-e") 'eval-buffer) ;;這樣測試.emacs方便多了... | |
;; xclip-mode | |
(load "~/.emacs.d/lisps/xclip-1.0.el") | |
(define-minor-mode xclip-mode | |
"Minor mode to use the `xclip' program to copy&paste." | |
:global t | |
(if xclip-mode | |
(turn-on-xclip) | |
(turn-off-xclip))) | |
(xclip-mode t) | |
;;emacs內建書籤存檔 | |
(setq bookmark-save-flag 1) | |
;;靠杯,連這都要自己設定會不會太蠢了emacs? | |
(setq snake-score-file | |
"~/.emacs.d/snake-scores") | |
;; helm-mode(前anything.el) | |
;;(add-to-list 'load-path "~/.emacs.d/lisps/helm") | |
;;(require 'helm-config) | |
;;(helm-mode) | |
;;(global-set-key (kbd "C-x C-f") 'helm-find-files) | |
;;(global-set-key (kbd "C-x C-b") 'helm-buffers-list) | |
;;(global-set-key (kbd "C-c C-f") 'helm-for-files) | |
;;(global-set-key (kbd "M-x") 'helm-M-x) | |
;; smart-window.el | |
(add-to-list 'load-path "~/.emacs.d/lisps/smart-window/") | |
(require 'smart-window) | |
;;(setq smart-window-remap-keys 0) | |
(global-set-key (kbd "C-x w") 'smart-window-move) | |
(global-set-key (kbd "C-x W") 'smart-window-buffer-split) | |
(global-set-key (kbd "C-x M-w") 'smart-window-file-split) | |
(global-set-key (kbd "C-x R") 'smart-window-rotate) | |
(global-set-key (kbd "C-x 2") 'sw-below) | |
(global-set-key (kbd "C-x 3") 'sw-right) | |
;;Emacs24開始內建的package.el相關設定 | |
(require 'package) | |
(package-initialize) | |
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) | |
;;rainbow-mode | |
(require 'rainbow-mode) | |
(global-set-key (kbd "C-x r a") 'rainbow-mode) | |
;; CSS and Rainbow modes | |
(defun all-css-modes() (css-mode) (rainbow-mode)) | |
;; Load both major and minor modes in one call based on file type | |
(add-to-list 'auto-mode-alist '("\\.css$" . all-css-modes)) | |
;;switch frames in a visual way | |
(require 'switch-window) | |
;;customize theme =w=+ | |
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/") ;;Emacs24之後的theme路徑指定 | |
(load-theme 'moe-dark t) | |
(add-to-list 'load-path "~/.emacs.d/themes/") | |
;;(enable-theme 'moe-dark) | |
;;(load-file "~/.emacs.d/themes/zenburn-theme.el")) ;;都不行就直接用這招 | |
;;;;Zsh style completetion! | |
;;(add-to-list 'load-path "~/.emacs.d/lisps/emacs-zlc-master") | |
;;(require 'zlc) | |
;;(zlc-mode t) | |
;;(let ((map minibuffer-local-map)) | |
;; ;;; like menu select | |
;; (define-key map (kbd "<down>") 'zlc-select-next-vertical) | |
;; (define-key map (kbd "<up>") 'zlc-select-previous-vertical) | |
;; (define-key map (kbd "<right>") 'zlc-select-next) | |
;; (define-key map (kbd "<left>") 'zlc-select-previous) | |
;; | |
;; ;;; reset selection | |
;; (define-key map (kbd "C-c") 'zlc-reset)) | |
;; 其實以下六行我好像根本沒在按,已經習慣按M-p跟M-n了 | |
(define-key minibuffer-local-must-match-map "\C-p" 'previous-history-element) | |
(define-key minibuffer-local-must-match-map "\C-n" 'next-history-element) | |
(define-key minibuffer-local-completion-map "\C-p" 'previous-history-element) | |
(define-key minibuffer-local-completion-map "\C-n" 'next-history-element) | |
(define-key minibuffer-local-map "\C-p" 'previous-history-element) | |
(define-key minibuffer-local-map "\C-n" 'next-history-element) | |
;;自動補全auto-complete | |
;;(add-to-list 'load-path "~/.emacs.d/lisps/auto-complete") | |
(require 'auto-complete-config) | |
(add-to-list 'ac-user-dictionary-files "~/.emacs.d/ac-dict") | |
(ac-config-default) | |
(global-auto-complete-mode 1) | |
(define-key ac-mode-map (kbd "C-c h") 'ac-last-quick-help) | |
(define-key ac-mode-map (kbd "C-c H") 'ac-last-help) | |
(setq ac-use-menu-map t) | |
(define-key ac-complete-mode-map (kbd "C-s") 'ac-isearch) ;;我真的無法理解為何連這個都必須自己設定勒? | |
(define-key ac-complete-mode-map (kbd "M-p") 'ac-quick-help-scroll-up) | |
(define-key ac-complete-mode-map (kbd "M-n") 'ac-quick-help-scroll-down) | |
;; multiple-cursors | |
(require 'multiple-cursors) | |
(global-set-key (kbd "C-x C-@") 'mc/edit-lines) | |
;;以下四種key-binding皆無法在terminal下使用orz改用M-'與M-"應該就沒問題,有空再來研究。 | |
;;(global-set-key (kbd "C->") 'mc/mark-next-like-this) | |
;;(global-set-key (kbd "C-;") 'mc/mark-next-like-this) | |
;;(global-set-key (kbd "C-<") 'mc/mark-previous-like-this) | |
;;(global-set-key (kbd "C-:") 'mc/mark-previous-like-this) | |
(global-set-key (kbd "M-'") 'mc/mark-next-like-this) | |
(global-set-key (kbd "M-\"") 'mc/mark-previous-like-this) | |
(global-set-key (kbd "C-c M-'") 'mc/mark-all-like-this) | |
;; set-mark, multiple-cursors & cua-mode | |
(cua-mode t) | |
(setq cua-enable-cua-keys nil) ;;変なキーバインド禁止 | |
(global-set-key (kbd "C-c C-@") 'cua-set-rectangle-mark) | |
(global-set-key (kbd "M-RET") 'set-mark-command) ;這他媽的會跟org-mode衝啊! | |
(global-set-key (kbd "C-c RET") 'cua-set-rectangle-mark) | |
(global-set-key (kbd "C-x RET") 'mc/edit-lines) | |
(add-hook 'org-mode-hook | |
(lambda () | |
(define-key org-mode-map (kbd "M-RET") 'set-mark-command) ;;讓org-mode能用M-RET來set-mark-command | |
(define-key org-mode-map (kbd "C-c SPC") 'ace-jump-word-mode) | |
(define-key org-mode-map (kbd "C-c C-e") 'org-export) | |
)) | |
;; ace-jump | |
(global-set-key (kbd "C-c SPC") 'ace-jump-word-mode) | |
;; goto-chg | |
(global-set-key (kbd "C-x j") 'goto-last-change) | |
(global-set-key (kbd "C-x C-j") 'goto-last-change-reverse) | |
;; dired+ | |
(require 'dired+) | |
(defun dired-open-file () | |
"Open file with external program in dired" | |
(interactive) | |
(let* ((file (dired-get-filename nil t))) | |
(message "Opening %s..." file) | |
(call-process "kde-open" nil 0 nil file) | |
(message "Opening %s done" file))) | |
(add-hook 'dired-mode-hook | |
(lambda () | |
(define-key dired-mode-map (kbd "M-RET") 'dired-open-file))) | |
;; use single dired buffer | |
(require 'dired-single) | |
;; dired renaming like GUI file manager | |
;;(require 'dired-efap) | |
;;(define-key dired-mode-map [f2] 'dired-efap) | |
;; dired hide/show detail infomation | |
(require 'dired-details) | |
(dired-details-install) | |
;; | |
(defun my-dired-init () | |
"Bunch of stuff to run for dired, either immediately or when it's | |
loaded." | |
;; <add other stuff here> | |
(define-key dired-mode-map (kbd "RET") 'dired-single-buffer) | |
(define-key dired-mode-map [mouse-1] 'dired-single-buffer-mouse) | |
(define-key dired-mode-map "^" | |
(function | |
(lambda nil (interactive) (dired-single-buffer "..")))) | |
(define-key dired-mode-map "q" | |
(function | |
(lambda nil (interactive) (dired-single-buffer ".."))))) | |
;; if dired's already loaded, then the keymap will be bound | |
(if (boundp 'dired-mode-map) | |
;; we're good to go; just add our bindings | |
(my-dired-init) | |
;; it's not loaded yet, so add our bindings to the load-hook | |
(add-hook 'dired-load-hook 'my-dired-init)) | |
(global-set-key [(f5)] 'dired-single-magic-buffer) | |
(global-set-key (kbd "C-x <f5>") (function | |
(lambda nil (interactive) | |
(dired-single-magic-buffer default-directory)))) | |
(global-set-key (kbd "C-c <f5>") (function | |
(lambda nil (interactive) | |
(message "Current directory is: %s" default-directory)))) | |
(global-set-key [(meta f5)] 'dired-single-toggle-buffer-name) | |
;;hide didden file | |
(require 'dired-x) | |
(setq dired-omit-files "^\\...+$") | |
(add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1))) | |
;;human-readable file size | |
(setq dired-listing-switches "-alh") | |
;;sort file | |
(require 'dired-sort) | |
;;sort directories first | |
(defun dired-directory-sort () | |
"Dired sort hoOBok to list directories first." | |
(save-excursion | |
(let (buffer-read-only) | |
(forward-line 2) ;; beyond dir. header | |
(sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max)))) | |
(and (featurep 'xemacs) | |
(fboundp 'dired-insert-set-properties) | |
(dired-insert-set-properties (point-min) (point-max))) | |
(set-buffer-modified-p nil)) | |
(add-hook 'dired-after-readin-hook 'dired-directory-sort) | |
(defun dired-show-only (regexp) | |
(interactive "sFiles to show (regexp): ") | |
(dired-mark-files-regexp regexp) | |
(dired-toggle-marks) | |
(dired-do-kill-lines)) | |
(define-key dired-mode-map (kbd "C-i") 'dired-show-only) | |
(defun dired-open-mounted-media-dir () | |
(interactive) | |
(find-file "/var/run/media/")) | |
(define-key dired-mode-map (kbd "C-c m") 'dired-open-mounted-media-dir) | |
(defun dired-add-to-smplayer-playlist () | |
"Add a multimedia file or all multimedia files under a directory into SMPlayer's playlist via Dired." | |
(interactive) | |
(require 'cl) | |
(let* (PATTERN FILE full-path-FILE n) | |
(setq PATTERN "\\(\\.mp4\\|\\.flv\\|\\.rmvb\\|\\.mkv\\|\\.avi\\|\\.rm\\|\\.mp3\\|\\.wav\\|\\.wma\\|\\.m4a\\|\\.mpeg\\|\\.aac\\|\\.ogg\\|\\.flac\\|\\.ape\\|\\.mp2\\)$") | |
(setq FILE (dired-get-filename nil t)) | |
(setq n 0) | |
(if (file-directory-p FILE) ;if it's a dir. | |
(progn | |
(setq full-path-FILE (cl-loop for i in (directory-files FILE nil PATTERN) | |
collect (concat FILE "/" i))) | |
(message "Opening %s files..." (list-length full-path-FILE)) | |
(cl-loop for i in full-path-FILE | |
do (call-process "smplayer" nil 0 nil "-add-to-playlist" i) | |
(sit-for 0.1)) ;Or playlist will be not in order. | |
(dired-next-line 1) | |
) | |
(if (string-match PATTERN FILE) ;if it's a file | |
(progn | |
(call-process "smplayer" nil 0 nil "-add-to-playlist" FILE) | |
(dired-next-line 1)) | |
(progn | |
(message "This is not a supported audio or video file.") | |
(dired-next-line 1)))))) | |
(define-key dired-mode-map (kbd "M-a") 'dired-add-to-smplayer-playlist) | |
(define-key dired-mode-map (kbd "C-x <f2>") 'wdired-change-to-wdired-mode) | |
(require 'magit) | |
(global-set-key (kbd "C-x g i t s") 'magit-status) | |
(global-set-key (kbd "C-x g i t l") 'magit-log) | |
(require 'rainbow-delimiters) | |
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode) | |
(require 'org-html5presentation) | |
;; SLIME | |
(require 'slime) | |
(require 'ac-slime) | |
(add-hook 'slime-mode-hook 'set-up-slime-ac) | |
(add-hook 'slime-repl-mode-hook 'set-up-slime-ac) | |
(eval-after-load "auto-complete" | |
'(add-to-list 'ac-modes 'slime-repl-mode)) | |
(add-hook 'lisp-mode-hook (lambda () (slime-mode t))) | |
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t))) | |
;; Optionally, specify the lisp program you are using. Default is "lisp" | |
(setq inferior-lisp-program "clisp") | |
(setq slime-net-coding-system 'utf-8-unix) | |
(slime-setup) | |
;;(defun keyboard-quit-custom () | |
;; (interactive) | |
;; (lazy-highlight-cleanup)(keyboard-quit)) | |
;;(global-set-key (kbd "C-g") 'keyboard-quit-custom) | |
;; Paredit | |
;;(add-hook 'prog-mode-hook 'paredit-everywhere-mode) ; paredit-everywhere | |
;;; mmm-mode | |
(require 'mmm-mode) | |
(require 'mmm-auto) | |
(setq mmm-global-mode 'maybe) | |
(mmm-add-classes | |
'((mmm-ml-css-mode | |
:submode css-mode | |
:face mmm-code-submode-face | |
:front "<style[^>]*>" | |
:back "\n?[ \t]*</style>" | |
) | |
(mmm-ml-javascript-mode | |
:submode javascript-mode | |
:face mmm-code-submode-face | |
:front "<script[^>]*>[^<]" | |
:front-offset -1 | |
:back "\n?[ \t]*</script>" | |
) | |
)) | |
(mmm-add-mode-ext-class 'html-mode nil 'mmm-ml-javascript-mode) | |
(mmm-add-mode-ext-class 'html-mode nil 'mmm-ml-css-mode) | |
;; 超混亂lisp的function highlight | |
;;(defvar font-lock-func-face | |
;; (defface font-lock-func-face | |
;; '((nil (:weight bold)) | |
;; (t (:bold t :italic t))) | |
;; "Font Lock mode face used for function calls." | |
;; :group 'font-lock-highlighting-faces)) | |
(font-lock-add-keywords 'emacs-lisp-mode | |
'( | |
("'[-a-zA-Z_][-a-zA-Z0-9_/]*" 0 'font-lock-constant-face) | |
("(\\([-a-zA-Z0-9_/]+\\)" 1 'font-lock-keyword-face) | |
("(setq \\([-a-zA-Z0-9_/]+\\)" 1 'font-lock-variable-name-face) | |
)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment