2009年1月19日星期一

Emacs配置文件

emacs是传说中可以煮咖啡的编辑器,以前一直觉得配置有点烦,就没怎么用。现在闲来无事,好好研究一下。网上找了好多配置,融合了一下,比较适合自己。放在这里备份:



;一般设置==============================
(setq initial-frame-alist '((top . 0) (left . 0) (width . 142) (height . 49)));启动自动最大化
(setq default-major-mode 'text-mode);一打开就起用 text 模式。
(global-font-lock-mode t);语法高亮
(auto-image-file-mode t);打开图片显示功能
(fset 'yes-or-no-p 'y-or-n-p);以 y/n代表 yes/no,可能你觉得不需要,呵呵。
(column-number-mode t);显示列号
(show-paren-mode t);显示括号匹配
(display-time-mode 1);显示时间,格式如下
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(tool-bar-mode nil);去掉那个大大的工具栏
;(scroll-bar-mode nil);去掉滚动条,因为可以使用鼠标滚轮了 ^_^
(mouse-avoidance-mode 'animate);光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。很好玩阿,这个功能
(setq mouse-yank-at-point t);支持中键粘贴
(transient-mark-mode t);这个忘了,郁闷!
(setq x-select-enable-clipboard t);支持emacs和外部程序的粘贴
(setq frame-title-format "Lear@%b");在标题栏提示你目前在什么位置。你要把zhan改成自己的用户名
(setq default-fill-column 80);默认显示 80列就换行
(setq frame-title-format;设置标题栏显示文件的完整路径名
'("%S" (buffer-file-name "%f"
(dired-directory dired-directory "%b"))))

; 编程相关的===========================
(setq default-tab-width 4);设置Tab宽度为4
(setq tab-width 4 indent-tabs-mode nil);设置Tab换为4个空格,不用Tab进行排版
(show-paren-mode t);显示括号匹配
;键绑定初始化==========================
;; 导入重做
;(require 'redo)
;; tabbar
;(require 'tabbar)
;(tabbar-mode t)
;;设置键绑定==========================(不知道有什么用)
(global-set-key [C-up] 'tabbar-backward-group)
(global-set-key [C-down] 'tabbar-forward-group)
(global-set-key [C-left] 'tabbar-backward)
(global-set-key [C-right] 'tabbar-forward)
; 自定义键绑定==========================
(global-set-key [f6] 'dired-jump);文件管理器
(global-set-key [f10] 'menu-bar-mode);打开/关闭菜单
(global-set-key (kbd "C-v") 'yank);粘贴
(global-set-key (kbd "C-z") 'undo);撤消
(global-set-key (kbd "C-y") 'redo);重做
(global-set-key (kbd "C-s") 'save-buffer);保存
(global-set-key (kbd "C-a") 'mark-whole-buffer);全选
(global-set-key (kbd "C-x C-s") 'isearch-forward);向下查找
(global-set-key [delete] 'delete-char);delete 删除一个字符
; 多句的编写的小方法====================
;;多句的编写的小方法

;;; 这个忘了是从哪个地方弄来的,在保存~/.emacs文件自动编译为.elc文件
;;;;目前只是对~/.emacs有效,其余的*.el文件还没有去弄,以后有空我会改的
;;;;小知识:由于配置文件越来越大,你的*.el配置文件最好都编译为*.elc文件,这样在启动emacs速度会有很大的提升
(defun autocompile nil
"compile itself if ~/.emacs"
(interactive)
(if (string= (buffer-file-name) (concat default-directory ".emacs"))
(byte-compile-file (buffer-file-name))))
(add-hook 'after-save-hook 'autocompile)

;;;删除一行
(defun zl-delete-line nil
"delete the whole line"
(interactive)
(beginning-of-line);光标移动到行首
(push-mark);做个标记
(beginning-of-line 2);移动到下一行行首
(kill-region (point) (mark)));光标和标记之间的删掉

(global-set-key (kbd "C-d") 'zl-delete-line);删除一行

;;新建一行,不管光标在哪
(defun zl-newline nil
"open new line belowe current line"
(interactive)
(end-of-line)
(newline))

(global-set-key [S-return] 'zl-newline);绑定Shift-回车

;;本行上面新建一行,不管光标在哪
(defun zl-newline-up nil
"open new line up current line"
(interactive)
(beginning-of-line)
(newline)
(backward-char))

(global-set-key [C-S-return] 'zl-newline-up);绑定Ctrl-shift-回车

; 设置颜色主题=================================
(add-to-list 'load-path
"~/.emacs.d/color-theme-6.6.0")
(require 'color-theme)
(color-theme-initialize)
(color-theme-dark-laptop)

没有评论: