其实和很多人的emacs配置文件一样,我的配置文件也是在网上来回copy过来的,不过大家都是在copy来copy去的,所以我就不在写参考自哪里了:)
我的emacs版本:
[laolang@laolang ~]$ pacman -Q emacs
emacs 24.5-2
[laolang@laolang ~]$
基本配置:
;;;;;;;;;;;;;;;基本配置;;;;;;;;;;;;;;;;;;;
;;--------- 显示设置--------------
;; ---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的命令行形式
编程相关:[主要是auto-complate和auto-complete-clang的配置]
其中有几行头文件的位置,在终端输入以下命令即可看到:
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)
;; 结束
来源:oschina
链接:https://my.oschina.net/u/1442002/blog/515657