;;kuanyui\'s ~/.emacs
;;Last updated: 2012/08/12
;;關全域設定檔用
;;(setq inhibit-default-init t)
;;字體美化=========================
;;(提醒,字體部份只限定Linux,且在沒有X的環境下會失效。其他OS者可以跳過。)
;;
;;以下三行注釋為~/.Xresources的內容,不是~/.emacs的。(沒有~/.Xresources檔請自行建立)
;;Xft.antialias: 1
;;Xft.hinting: 1
;;Xft.hintstyle: hintfull
;;主要意思呢就是說我們現在需要調用XWindow中的字體,並開啟抗鋸齒。
(set-default-font "DejaVu Sans Mono-11")
(set-fontset-font (frame-parameter nil \'font)
\'han \'("WenQuanYi Micro Hei"))
;;字體部份結束====================
;;掃描~/.emacs.d目錄
(add-to-list \'load-path "~/.emacs.d")
(add-to-list \'load-path "~/.emacs.d/lisps")
;;執行Shell外部程式的搜尋路徑(意同$PATH)
(setq exec-path (append exec-path \'("/home/kuanyui/Dropbox/scripts/")))
(setenv "PATH" (concat (getenv "PATH") ":/home/kuanyui/Dropbox/scripts/"))
;;超變態的undo-tree-mode
;;(提醒:redo會變成C-?)
;;C-x u 進入 undo-tree-visualizer-mode,t顯示時間戳。
(require \'undo-tree)
(global-undo-tree-mode)
;;evil的東西
;;(add-to-list \'load-path "~/.emacs.d/lisps/evil")
;;(require \'evil)
;;(evil-mode 1)
;;color-theme的一堆東東
;;M-x color-theme-select可預覽所有themes,於任一theme上按d可得知該theme自動載入的方法,丟進~/.emacs即可。
(add-to-list \'load-path "~/.emacs.d/themes")
(add-to-list \'load-path "~/.emacs.d/themes/color-theme-6.6.0")
(require \'color-theme)
(eval-after-load "color-theme"
\'(progn
(color-theme-initialize)
(color-theme-hober)))
;;Fabulous "Solarized Themes"
(add-to-list \'load-path "~/.emacs.d/themes/emacs-color-theme-solarized")
(require \'color-theme-solarized)
(color-theme-solarized-light)
;;行號
(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好用一點)
(global-set-key (kbd "C-x C-b") \'ibuffer)
;;(global-set-key [(f4)] \'ibuffer)
(autoload \'ibuffer "ibuffer" "List buffers." t)
;;讓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)
;;隱藏工具列
(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)
;;同名檔案不混淆(同名檔案同時開啟時,會在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)
;;拼字檢查Ispell
;;将 Ispell 里的英文辞典设为预设辞典,并用 ~/.ispell-dico-perso 文档作为个人辞典
;;(setq sgml-mode-hook
;;\'(lambda () "Defauts for SGML mode."
;;(setq ispell-personal-dictionary "~/.ispell-dico-perso")
;;))
;;自動啟動flyspell-mode拼字檢查
;;(setq-default flyspell-mode t)
;;flyspell-prog-mode是為程式設計師的輔模式,Emacs将只在注释和字符串里高亮错误的拼写。
;;(setq-default flyspell-prog-mode t)
;;靠近螢幕邊緣三行時就開始捲動,比較容易看上下文
(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 nil)
;;安裝最新版markdown.el
(require \'markdown-mode)
;;Org-mode專區===========================================
;;安裝最新版org-mode 7.8.03 (2012/03/04)
(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)
;;Org-mode結束===========================================
;;較完整支援shell script語法高亮。
(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
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
;;強大的自動補全auto-complete
(add-to-list \'load-path "~/.emacs.d/lisps/auto-complete")
(require \'auto-complete-config)
(add-to-list \'ac-dictionary-directories "~/.emacs.d/lisps/auto-complete/ac-dict")
(ac-config-default)
(global-auto-complete-mode 1)
;;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"))
(add-hook \'twittering-mode-hook
(lambda ()
(mapc (lambda (pair)
(let ((key (car pair))
(func (cdr pair)))
(define-key twittering-mode-map
(read-kbd-macro key) func)))
\'(("R" . twittering-replies-timeline)
("U" . twittering-user-timeline)
("W" . twittering-update-status-interactive)
("O" . twittering-organic-retweet)
("N" . twittering-native-retweet)
("H" . twittering-home-timeline)
("F" . twittering-favorite)
("V" . twittering-visit-timeline)
("M" . my-twittering-favorites-timeline)))))
;;("F" . twittering-friends-timeline)這到底有啥屁用...
;;以詞彙過濾不要的Tweets
(setq twittering-tweet-filters \'("要過濾掉的詞彙balabala" "以空格分開balabala"))
(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)
(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>") \'run-script)
;;(defun run-script ()
;;"Execute the shell script in the current buffer."
;;(interactive)
;;( ))
(global-set-key (kbd "<f4>") \'shell)
(global-set-key (kbd "<f3>") \'open-zsh)
(defun open-zsh ()
"zsh"
(interactive)
(term "/bin/zsh"))
;;用f5~f8調整frame大小
(global-set-key [(f5)] \'shrink-window-horizontally)
(global-set-key [(f8)] \'enlarge-window-horizontally)
(global-set-key [(f6)] \'shrink-window)
(global-set-key [(f7)] \'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 "<f11>") \'open-diary)
(defun open-diary ()
"Open diary."
(interactive)
(find-file "~/Dropbox/Diary/diary_2012_6-12.org"))
(global-set-key [(f12)] \'twit)
;;調用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"))
;; screenshot in org-mode
;; modified by gift.young@gmail.com
;; based on [http://praktikanten.brueckenschlaeger.org/2010/11/28/screenshots-in-org-mode]
(defun my-screenshot ()
"Take a screenshot into a unique-named file in the current buffer file
directory and insert a link to this file."
(interactive)
(setq filename
(concat (make-temp-name
(concat (file-name-directory (buffer-file-name)) "images/" ) ) ".png"))
(if (file-accessible-directory-p (concat (file-name-directory
(buffer-file-name)) "images/"))
nil
(make-directory "images"))
(call-process-shell-command "scrot" nil nil nil nil "-s" (concat "\\"" filename "\\"" ))
(insert (concat "[[" filename "]]"))
(org-display-inline-images)
)
(global-set-key (kbd "s-s") \'my-screenshot)
;;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)
;; StarDict for Emacs
;; author: pluskid
;; 调用 stardict 的命令行接口来查辞典
;; 如果选中了 region 就查询 region 的内容,
;; 否则就查询当前光标所在的词
(global-set-key (kbd "C-c s") \'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))
(tooltip-show
(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)