document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. ;;kuanyui\'s ~/.emacs
  2. ;;Last updated: 2012/08/12
  3.  
  4. ;;關全域設定檔用
  5. ;;(setq inhibit-default-init t)
  6.  
  7. ;;字體美化=========================
  8. ;;(提醒,字體部份只限定Linux,且在沒有X的環境下會失效。其他OS者可以跳過。)
  9. ;;
  10. ;;以下三行注釋為~/.Xresources的內容,不是~/.emacs的。(沒有~/.Xresources檔請自行建立)
  11. ;;Xft.antialias: 1
  12. ;;Xft.hinting: 1
  13. ;;Xft.hintstyle: hintfull
  14. ;;主要意思呢就是說我們現在需要調用XWindow中的字體,並開啟抗鋸齒。
  15. (set-default-font "DejaVu Sans Mono-11")
  16. (set-fontset-font (frame-parameter nil \'font)
  17.               \'han \'("WenQuanYi Micro Hei"))
  18.  
  19.  
  20.  
  21.  
  22. ;;字體部份結束====================
  23.  
  24. ;;掃描~/.emacs.d目錄
  25. (add-to-list \'load-path "~/.emacs.d")
  26. (add-to-list \'load-path "~/.emacs.d/lisps")
  27.  
  28. ;;執行Shell外部程式的搜尋路徑(意同$PATH)
  29. (setq exec-path (append exec-path \'("/home/kuanyui/Dropbox/scripts/")))
  30. (setenv "PATH" (concat (getenv "PATH") ":/home/kuanyui/Dropbox/scripts/"))
  31.  
  32.  
  33. ;;超變態的undo-tree-mode
  34. ;;(提醒:redo會變成C-?)
  35. ;;C-x u 進入 undo-tree-visualizer-mode,t顯示時間戳。
  36. (require \'undo-tree)
  37. (global-undo-tree-mode)
  38.  
  39. ;;evil的東西
  40. ;;(add-to-list \'load-path "~/.emacs.d/lisps/evil")
  41. ;;(require \'evil)  
  42. ;;(evil-mode 1)
  43.  
  44. ;;color-theme的一堆東東
  45. ;;M-x color-theme-select可預覽所有themes,於任一theme上按d可得知該theme自動載入的方法,丟進~/.emacs即可。
  46. (add-to-list \'load-path "~/.emacs.d/themes")
  47. (add-to-list \'load-path "~/.emacs.d/themes/color-theme-6.6.0")
  48. (require \'color-theme)
  49. (eval-after-load "color-theme"
  50.   \'(progn
  51.      (color-theme-initialize)
  52.      (color-theme-hober)))
  53.  
  54. ;;Fabulous "Solarized Themes"
  55. (add-to-list \'load-path "~/.emacs.d/themes/emacs-color-theme-solarized")
  56. (require \'color-theme-solarized)
  57. (color-theme-solarized-light)
  58.  
  59. ;;行號
  60. (global-linum-mode t)
  61.  
  62. ;;當前行高亮顯示
  63. (global-hl-line-mode 1)
  64.  
  65. ;;在標題顯示文件名稱(%b)與路徑(%f)
  66. (setq frame-title-format "%n%b (%f) - %F")
  67. ;;(setq frame-title-format \'((:eval default-directory)))
  68.  
  69. ;;把捲軸移到右側
  70. (customize-set-variable \'scroll-bar-mode \'right)
  71.  
  72. ;;啟用ibuffer(比預設的那個buffer selector好用一點)
  73. (global-set-key (kbd "C-x C-b") \'ibuffer)
  74. ;;(global-set-key [(f4)] \'ibuffer)
  75. (autoload \'ibuffer "ibuffer" "List buffers." t)
  76.  
  77. ;;讓Isearch不會再主動清除搜尋的高亮顯示
  78. (setq lazy-highlight-cleanup nil)
  79.  
  80. ;;我最愛的插入日期,格式為習慣的YYYY/mm/dd(星期),使用方法為C-c d
  81. (defun my-insert-date ()
  82.     (interactive)
  83.     (insert (format-time-string "%Y/%m/%d(%a)" (current-time))))
  84.   (global-set-key (kbd "C-c d") \'my-insert-date)
  85.  
  86. ;;凸顯括號位置(而不是來回彈跳)
  87. (show-paren-mode t)
  88. (setq show-paren-style \'parentheses)
  89.  
  90. ;;隱藏工具列
  91. (tool-bar-mode -1)
  92.  
  93. ;;隱藏選單
  94. (menu-bar-mode -1)
  95.  
  96. ;;X Clipboard在光標處插入,而不是滑鼠點擊的地方插入。
  97. (setq mouse-yank-at-point t)
  98.  
  99. ;;讓Emacs可以直接打開/顯示圖片。
  100. (setq auto-image-file-mode t)
  101.  
  102. ;;recents最近開啟的檔案,C-x C-r
  103. (require \'recentf)
  104. (recentf-mode 1)
  105. (setq recentf-max-menu-items 35)
  106. (global-set-key "\\C-x\\ \\C-r" \'recentf-open-files)
  107.  
  108. ;;同名檔案不混淆(同名檔案同時開啟時,會在buffer加上目錄名稱)
  109. (require \'uniquify)
  110. (setq
  111. uniquify-buffer-name-style \'post-forward
  112. uniquify-separator ":")
  113.  
  114. ;;換掉歡迎畫面的難看GNU Logo
  115. ;;(setq  fancy-splash-image "~/.emacs.d/icon.png")
  116.  
  117. ;;完全隱藏歡迎畫面
  118. (setq inhibit-splash-screen t)
  119.  
  120. ;;拼字檢查Ispell
  121. ;;将 Ispell 里的英文辞典设为预设辞典,并用 ~/.ispell-dico-perso 文档作为个人辞典
  122. ;;(setq sgml-mode-hook
  123. ;;\'(lambda () "Defauts for SGML mode."
  124. ;;(setq ispell-personal-dictionary "~/.ispell-dico-perso")
  125. ;;))
  126. ;;自動啟動flyspell-mode拼字檢查
  127. ;;(setq-default flyspell-mode t)
  128. ;;flyspell-prog-mode是為程式設計師的輔模式,Emacs将只在注释和字符串里高亮错误的拼写。
  129. ;;(setq-default flyspell-prog-mode t)
  130.  
  131.  
  132. ;;靠近螢幕邊緣三行時就開始捲動,比較容易看上下文
  133. (setq scroll-margin 3)
  134.  
  135. ;;關閉煩人的錯誤提示音,改為在螢幕上提醒。
  136. (setq visible-bell t)
  137.  
  138. ;;超大kill ring. 防止不小心删掉重要的東西。
  139. (setq kill-ring-max 200)
  140.  
  141. ;;设置tab为4个空格的宽度
  142. ;;(setq default-tab-width 4)
  143.  
  144. ;;Tab改為插入空格
  145. ;;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.
  146. (setq-default indent-tabs-mode nil)
  147.  
  148. ;;安裝最新版markdown.el
  149. (require \'markdown-mode)
  150.  
  151. ;;Org-mode專區===========================================
  152. ;;安裝最新版org-mode 7.8.03 (2012/03/04)
  153. (add-to-list \'load-path "~/.emacs.d/lisps/org-mode/lisp/")
  154. (require \'org-install)
  155.  
  156. ;;解决org-mode下中文不自动换行的问题
  157. (add-hook \'org-mode-hook
  158. (lambda () (setq truncate-lines nil)))
  159.  
  160. ;;org-mode裡的項目變成done時會自動加上CLOSED: [timestamp]戳記;改成\'note為筆記
  161. (setq org-log-done \'time)
  162. ;;(setq org-log-done \'note)
  163. ;;Org-mode結束===========================================
  164.  
  165. ;;較完整支援shell script語法高亮。
  166. (defface font-lock-system-command-face
  167.   \'((((class color)) (:foreground "purple")))
  168.   "I am comment"
  169.   :group \'font-lock-faces)
  170.  
  171. (defun font-lock-system-command (&optional limit)
  172.   ""
  173.   (and  (search-forward-regexp "\\\\<[a-zA-Z\\\\-]+\\\\>" limit t)
  174.         (executable-find
  175.          (buffer-substring-no-properties (car (bounds-of-thing-at-point \'word))
  176.                                          (cdr (bounds-of-thing-at-point \'word)))
  177.          )))
  178.  
  179. (font-lock-add-keywords
  180.         \'sh-mode
  181.         \'((font-lock-system-command . \'font-lock-system-command-face)))
  182.  
  183. ;;Emacs內建的自動補完hippie-expand
  184. (global-set-key [(meta ?/)] \'hippie-expand)
  185. (setq hippie-expand-try-functions-list
  186. \'(try-expand-dabbrev
  187. try-expand-dabbrev-visible
  188. try-expand-dabbrev-all-buffers
  189. try-expand-dabbrev-from-kill
  190. try-complete-file-name-partially
  191. try-complete-file-name
  192. try-expand-all-abbrevs
  193. try-expand-list
  194. try-expand-line
  195. try-complete-lisp-symbol-partially
  196. try-complete-lisp-symbol))
  197.  
  198.  
  199. ;;強大的自動補全auto-complete
  200. (add-to-list \'load-path "~/.emacs.d/lisps/auto-complete")
  201. (require \'auto-complete-config)
  202. (add-to-list \'ac-dictionary-directories "~/.emacs.d/lisps/auto-complete/ac-dict")
  203. (ac-config-default)
  204.  
  205.   (global-auto-complete-mode 1)
  206.  
  207.  
  208. ;;Twittering-mode:用Emacs上Twitter
  209. (add-to-list \'load-path "~/.emacs.d/lisps/twittering-mode/")
  210. (require \'twittering-mode)
  211. (setq twittering-use-master-password t) ;;This requires GnuPG. And also, either EasyPG or alpaca.el (0.13) is necessary.
  212. (twittering-enable-unread-status-notifier) ;;顯示未讀訊息數
  213. (setq-default twittering-icon-mode t) ;;預設顯示頭像
  214.  
  215. ;;開啟自己的favorite timeline
  216. (defun my-twittering-favorites-timeline ()
  217. (interactive)
  218. (twittering-visit-timeline ":favorites"))
  219.  
  220. (add-hook \'twittering-mode-hook
  221.            (lambda ()
  222.              (mapc (lambda (pair)
  223.                      (let ((key (car pair))
  224.                            (func (cdr pair)))
  225.                        (define-key twittering-mode-map
  226.                          (read-kbd-macro key) func)))
  227.                    \'(("R" . twittering-replies-timeline)
  228.                      ("U" . twittering-user-timeline)
  229.                      ("W" . twittering-update-status-interactive)
  230.                      ("O" . twittering-organic-retweet)
  231.                      ("N" . twittering-native-retweet)
  232.                      ("H" . twittering-home-timeline)
  233.                      ("F" . twittering-favorite)
  234.                      ("V" . twittering-visit-timeline)
  235.                      ("M" . my-twittering-favorites-timeline)))))
  236. ;;("F" . twittering-friends-timeline)這到底有啥屁用...
  237.  
  238. ;;以詞彙過濾不要的Tweets
  239. (setq twittering-tweet-filters \'("要過濾掉的詞彙balabala" "以空格分開balabala"))                                  
  240. (defun twittering-filter-tweets ()                                            
  241.   (setq non-matching-statuses \'())                                            
  242.   (dolist (status twittering-new-tweets-statuses)                            
  243.     (setq matched-tweets 0)                                                  
  244.     (dolist (pat twittering-tweet-filters)                                    
  245.       (if (string-match pat (cdr (assoc \'text status)))                      
  246.           (setq matched-tweets (+ 1 matched-tweets))))                        
  247.     (if (= 0 matched-tweets)                                                  
  248.         (setq non-matching-statuses (append non-matching-statuses `(,status)))))
  249.   (setq new-statuses non-matching-statuses))                                  
  250. (add-hook \'twittering-new-tweets-hook \'twittering-filter-tweets)
  251.  
  252.  
  253.  
  254. (global-set-key (kbd "<f1>") \'kmacro-start-macro-or-insert-counter)
  255. (global-set-key (kbd "<f2>") \'kmacro-end-or-call-macro)
  256. ;;(global-set-key (kbd "<f3>") \'run-script)
  257. ;;(defun run-script ()
  258. ;;"Execute the shell script in the current buffer."
  259. ;;(interactive)
  260. ;;( ))
  261.  
  262.  
  263.  
  264. (global-set-key (kbd "<f4>") \'shell)
  265.  
  266. (global-set-key (kbd "<f3>") \'open-zsh)
  267. (defun open-zsh ()
  268.  "zsh"
  269.  (interactive)
  270.  (term "/bin/zsh"))
  271.  
  272. ;;用f5~f8調整frame大小
  273. (global-set-key [(f5)] \'shrink-window-horizontally)
  274. (global-set-key [(f8)] \'enlarge-window-horizontally)
  275. (global-set-key [(f6)] \'shrink-window)
  276. (global-set-key [(f7)] \'enlarge-window)
  277.  
  278. (global-set-key (kbd "<f9>") \'open-note)
  279. (defun open-note ()
  280.  "Open stick note."
  281.  (interactive)
  282.  (find-file "~/Dropbox/notes.org"))
  283.  
  284. (global-set-key (kbd "<f10>") \'open-todo)
  285. (defun open-todo ()
  286.  "Open todo list."
  287.  (interactive)
  288.  (find-file "~/Dropbox/todo.org"))
  289.  
  290.  
  291. (global-set-key (kbd "<f11>") \'open-diary)
  292. (defun open-diary ()
  293.  "Open diary."
  294.  (interactive)
  295.  (find-file "~/Dropbox/Diary/diary_2012_6-12.org"))
  296. (global-set-key [(f12)] \'twit)
  297.  
  298. ;;調用word-count-for-emacs來計算字數 (能正確計算中英文夾雜文件的字數)
  299. ;;詳情請見 http://kuanshome.blogspot.com/2012/03/emacs.html
  300. (global-set-key (kbd "C-c w c") \'word-count)
  301. (defun word-count nil "Count words in buffer (include CJK characters)" (interactive)
  302. (shell-command-on-region (point-min) (point-max) "word-count-for-emacs"))
  303.  
  304.  
  305. ;; screenshot in org-mode
  306. ;; modified by gift.young@gmail.com
  307. ;; based on [http://praktikanten.brueckenschlaeger.org/2010/11/28/screenshots-in-org-mode]
  308. (defun my-screenshot ()
  309. "Take a screenshot into a unique-named file in the current buffer file
  310. directory and insert a link to this file."
  311. (interactive)
  312. (setq filename
  313. (concat (make-temp-name
  314. (concat (file-name-directory (buffer-file-name)) "images/" ) ) ".png"))
  315. (if (file-accessible-directory-p (concat (file-name-directory
  316. (buffer-file-name)) "images/"))
  317. nil
  318. (make-directory "images"))
  319. (call-process-shell-command "scrot" nil nil nil nil "-s" (concat "\\"" filename "\\"" ))
  320. (insert (concat "[[" filename "]]"))
  321. (org-display-inline-images)
  322. )
  323.  
  324. (global-set-key (kbd "s-s") \'my-screenshot)
  325.  
  326. ;;popup-kill-ring
  327. (add-to-list \'load-path "~/.emacs.d/lisps/popup-kill-ring/")
  328. (require \'popup)
  329. (require \'pos-tip)
  330. (require \'popup-kill-ring)
  331. (global-set-key "\\M-y" \'popup-kill-ring)
  332.  
  333.  
  334. ;; StarDict for Emacs
  335. ;; author: pluskid
  336. ;; 调用 stardict 的命令行接口来查辞典
  337. ;; 如果选中了 region 就查询 region 的内容,
  338. ;; 否则就查询当前光标所在的词
  339. (global-set-key (kbd "C-c s") \'kid-star-dict)
  340. (defun kid-star-dict ()
  341.   (interactive)
  342.   (let ((begin (point-min))
  343.         (end (point-max)))
  344.     (if mark-active
  345.         (setq begin (region-beginning)
  346.               end (region-end))
  347.       (save-excursion
  348.         (backward-word)
  349.         (mark-word)
  350.         (setq begin (region-beginning)
  351.               end (region-end))))
  352.     ;; 有时候 stardict 会很慢,所以在回显区显示一点东西
  353.     ;; 以免觉得 Emacs 在干什么其他奇怪的事情。
  354.     (message "searching for %s ..." (buffer-substring begin end))
  355.     (tooltip-show
  356.      (shell-command-to-string
  357.       (concat "sdcv -n "
  358.               (buffer-substring begin end))))))
  359.  
  360.  
  361. ;;Term下不要使用當行高亮,避免使用如MOC(music on console)等程式時出現的無意義當行高亮。
  362. (add-hook \'term-mode-hook
  363. (lambda () (setq global-hl-line-mode nil)))
  364. ;;Linux下與其他Applications的剪貼簿
  365. (setq x-select-enable-clipboard t)
');