Skip to content

Instantly share code, notes, and snippets.

@kuanyui
Created July 2, 2013 17:32
Show Gist options
  • Save kuanyui/5911340 to your computer and use it in GitHub Desktop.
Save kuanyui/5911340 to your computer and use it in GitHub Desktop.
My temporary Emacs init file "for Windows"...
;;Emacs24開始內建的package.el相關設定
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
;;超變態的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)))
;;啟用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)))
("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)
;;同名檔案不混淆(同名檔案同時開啟時,會在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)
;;靠近螢幕邊緣三行時就開始捲動,比較容易看上下文
(setq scroll-margin 3)
;;關閉煩人的錯誤提示音,改為在螢幕上提醒。
(setq visible-bell t)
;;超大kill ring. 防止不小心删掉重要的東西。
(setq kill-ring-max 200)
;;安裝最新版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)
;;Org-mode專區===========================================
;;解决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)
;;快速插入自訂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: [email protected]" \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結束===========================================
;;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
;;popup-kill-ring
;;(require 'popup)
;;(require 'pos-tip)
;;(require 'popup-kill-ring)
;;(global-set-key "\M-y" 'popup-kill-ring)
;;有了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)
;; 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)
;;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)
;; moe-theme
(load-theme 'moe-light t)
;;自動補全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+)
;; 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)
;;sort file
;;(require 'dired-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)
(require 'rainbow-delimiters)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(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.
'(custom-safe-themes (quote ("4b4603f15f5e56fbd569370b1194cf4a484e4f108e9c5247a888cb6da9f6f5c8" default))))
(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.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment