其實和不少人的emacs配置文件同樣,個人配置文件也是在網上來回copy過來的,不過你們都是在copy來copy去的,因此我就不在寫參考自哪裏了:) css
個人emacs版本: linux
[laolang@laolang ~]$ pacman -Q emacs emacs 24.5-2 [laolang@laolang ~]$
基本配置: c++
;;;;;;;;;;;;;;;基本配置;;;;;;;;;;;;;;;;;;; ;;--------- 顯示設置-------------- ;; ---color -theme ;(add-to-list 'load-path "~/.emacs.d/base/color-theme") (add-to-list 'load-path "~/.emacs.d/plugin/color-theme") (require 'color-theme) (color-theme-initialize) ;(color-theme-lawrence) (color-theme-euphoria) ;;;--- 顯示行號 (require 'linum) (setq linum-format "%3d ") ;;;---對全部文件生效 (add-hook 'find-file-hooks (lambda () (linum-mode 1))) ;;;--- 顯示列號 (setq column-number-mode t) (setq line-number-mode t) ;;;--- 去掉工具欄 (tool-bar-mode 0) ;;;---去掉菜單欄 (menu-bar-mode 0) ;;;--- 去掉滾動欄 (scroll-bar-mode 0) ;;------------顯示時間設置------------------------------ (display-time-mode 1);;啓用時間顯示設置,在minibuffer上面的那個槓上 (setq display-time-24hr-format t);;時間使用24小時制 (setq display-time-day-and-date t);;時間顯示包括日期和具體時間 (setq display-time-use-mail-icon t);;時間欄旁邊啓用郵件設置 (setq display-time-interval 10);;時間的變化頻率,單位多少來着? ;;;; -------- 默認行爲設置-------------- ;;;--- 關閉出錯量的提示音 (setq visible-bell t) ;; ---禁止備份 (setq make-backup-files nil) ;; 不生成臨時文件 (setq-default make-backup-files nil) ;;容許emacs和外部其餘程序的粘貼 (setq x-select-enable-clipboard t) ;;;---防止頁面滾動時跳動, ;;scroll-margin 3 能夠在靠近屏幕邊沿3行時就開始滾動 ;;scroll-step 1 設置爲每次翻滾一行,可使頁面更連續 (setq scroll-step 1 scroll-margin 3 scroll-conservatively 10000) ;;-------- 改變Emacs要你回答yes的行爲,按y或空格鍵表示yes,n表示no。 (fset 'yes-or-no-p 'y-or-n-p) ;;--------------- ido ;;ido的配置,這個可使你在用C-x C-f打開文件的時候在後面有提示; ;;這裏是直接打開了ido的支持,在emacs23中這個是自帶的. (ido-mode t) ;;ido模式中不保存目錄列表,解決退出Emacs時ido要詢問編碼的問題。 (setq ido-save-directory-list-file nil) ;;--- 括號匹配 ;;打開括號匹配顯示模式 (show-paren-mode t) ;;括號匹配時能夠高亮顯示另一邊的括號,但光標不會煩人的跳到另外一個括號處 (setq show-paren-style 'parenthesis) ;;---- 在行首 C-k 時,同時刪除該行 (setq-default kill-whole-line t) ;;;;;;;;;;;;;;;基本配置結束;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;基本功能設置;;;;;;;;;;;;;;;;;;; ;;--- 插入日期---------- (defun insert-current-date () "Insert the current date" (interactive "*") ;(insert (format-time-string "%Y/%m/%d %H:%M:%S" (current-time)))) (insert (format-time-string "%Y/%m/%d" (current-time)))) (global-set-key "\C-xd" 'insert-current-date) ;;--- 插入日期---------- (defun insert-current-time () "Insert the current time" (interactive "*") ;(insert (format-time-string "%Y/%m/%d %H:%M:%S" (current-time)))) (insert (format-time-string "%H:%M:%S" (current-time)))) (global-set-key "\C-xt" 'insert-current-time) ;;;;;;;;;;;;;基本功能結束我只寫了基本的配置,還有不少配置我沒寫,好比在emacs中寫代碼的時候,有時候鼠標會把字擋住,因此也有鼠標與光標重合時,讓鼠標移動到其餘地方的配置,不過我認爲這些都不是太大的問題。另外個人emacs配置全都寫在~/.eamcs中,在網上看到的都是在~/.emacs.d/init.el中寫加載路徑,而後不一樣的目錄下配置不一樣的功能,不過如今個人emacs只是寫一下簡單的c/c++,不會寫org,使用w3m上網,管理目錄,或者煮咖啡之類的。
須要注意的是,個人配色方案,個人系統是archlinux,不知道爲何在GUI界面下的emacs是沒法輸入中文的,emacs自帶的輸入法又太坑,因此我通常是打開一個terminal,而後在terminal中使用 emacs的命令行形式 shell
編程相關:[主要是auto-complate和auto-complete-clang的配置] 編程
其中有幾行頭文件的位置,在終端輸入如下命令便可看到: ruby
echo "" | g++ -v -x c++ -E -
;;;;;;;;;;;;;;;; 編程相關 ;;--------自動補全括號 ;;輸入左邊的括號,就會自動補全右邊的部分.包括(), "", [] , {} , 等等。 (defun my-c-mode-auto-pair () (interactive) (make-local-variable 'skeleton-pair-alist) (setq skeleton-pair-alist '( (?` ?` _ "''") (?\( ? _ " )") (?\[ ? _ " ]") (?{ \n > _ \n ?} >))) (setq skeleton-pair t) (local-set-key (kbd "(") 'skeleton-pair-insert-maybe) (local-set-key (kbd "{") 'skeleton-pair-insert-maybe) (local-set-key (kbd "`") 'skeleton-pair-insert-maybe) (local-set-key (kbd "[") 'skeleton-pair-insert-maybe)) (add-hook 'c-mode-hook 'my-c-mode-auto-pair) (add-hook 'c++-mode-hook 'my-c-mode-auto-pair) ;;;;---------- melpa 基本的源配置 (require 'package) ;; You might already have this line (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (when (< emacs-major-version 24) ;; For important compatibility libraries like cl-lib (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))) (package-initialize) ;; You might already have this line (add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t) ;;;;-----------melpa -> auto-complete ;; 開啓 auto-complete (add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-20150618.1949/") (require 'auto-complete) ;(add-to-list 'ac-dictionary-directories "~/.emacs.d/el-get/auto-complete/ac-dict/") ;(add-to-list 'ac-user-dictionary-files "~/.emacs.d/el-get/auto-complete/dict/guotf.dict") (require 'auto-complete-config) (add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.5.0/dict") (ac-config-default) ;;;; ------------melpa -> auto-complete-clang (add-to-list 'load-path "~/.emacs.d/elpa/auto-complete-clang-20140409.52") (require 'auto-complete-clang) ;;(setq ac-clang-auto-save t) ;; 設置不自動啓動 (setq ac-auto-start nil) ;; 設置響應時間 0.5 (setq ac-quick-help-delay 0.5) ;;(ac-set-trigger-key "TAB") ;;(define-key ac-mode-map [(control tab)] 'auto-complete) ;; 提示快捷鍵爲 M-/ (define-key ac-mode-map (kbd "M-/") 'auto-complete) (defun my-ac-config () (setq ac-clang-flags (mapcar(lambda (item)(concat "-I" item)) (split-string " /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0 /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0/x86_64-unknown-linux-gnu /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../include/c++/5.2.0/backward /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include /usr/local/include /usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/include-fixed /usr/include " ))) (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers)) (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup) (add-hook 'c-mode-common-hook 'ac-cc-mode-setup) (add-hook 'ruby-mode-hook 'ac-ruby-mode-setup) (add-hook 'css-mode-hook 'ac-css-mode-setup) (add-hook 'auto-complete-mode-hook 'ac-common-setup) (global-auto-complete-mode t)) (defun my-ac-cc-mode-setup () (setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources))) (add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup) ;; ac-source-gtags (my-ac-config) (ac-config-default) ;; 結束