我的Emacs配置

我拿Emacs主要用来开发,现在也是刚入门

1、ECB修改配置

由于ECB开启时会有一个INFO提醒,所以用改名的方法对它进行屏蔽

cd /usr/share/ecb
sudo mv ecb.info.gz ecb.info.gz.rename

2、CSCOPE修改

在PHP下使用cscope需要修改一下/usr/bin/cscope-indexer

 egrep -i '\.([chly](xx|pp)*|cc|hh|x|php|sh|inc)$' | \附近修改,将php加入其中

另外对工程分析的方法为,进入Emacs下工程所在位置,用C-c s L生成列表,用工具栏按钮也可以生成

3、mmm-mode的安装

直接在终端输入sudo apt-get install mmm-mode即可

4、以下是其他配置文件:

;;将lisp扩展目录加入load-path
(add-to-list 'load-path "~/emacs-lisp")
;; (require 'color-theme)
;; (require 'color-theme-ahei)
;; (color-theme-clarity)
;;打开php模式
(require 'php-mode)
(add-hook 'php-mode-user-hook 'turn-on-font-lock)

(set-foreground-color "grey")
(set-background-color "black")
(set-cursor-color "gold1")
(set-mouse-color "gold1")

;;到倒数第二行自动翻页
(setq scroll-margin 2 scroll-conservatively 10000)

;; 不产生备份文件
(setq make-backup-files nil)
(setq-default make-backup-files nil)
;;关闭自动保存模式
(setq auto-save-mode nil)
;;不生成 #filename# 临时文件
(setq auto-save-default nil)

;;显示行号
(require 'linum)
(global-linum-mode t)

;; 隐藏滚动条
;;(scroll-bar-mode -1)
(set-scroll-bar-mode 'right)
;; 打开图片显示功能
;;(auto-image-file-mode t)

;; 支持emacs和外部程序的粘贴
(setq x-select-enable-clipboard t)

;; 显示日期时间
(setq display-time-day-and-date t)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(setq display-time-use-mail-icon t)
(setq display-time-interval 10)
(display-time)

;; 标题栏,显示"buffer的名字@Emacs"
(setq frame-title-format "Emacs@%b")

;; 显示光标位置:
(setq column-number-mode t)
(setq line-number-mode t)

;; 设置kill-ring-max为200
(setq kill-ring-max 200)

;; 设置让光标指到某个括号与它匹配的括号
(show-paren-mode t)
(setq show-paren-style 'parentheses)

;; 高亮显示选择区域
(setq transient-mark-mode t)

;;使用M+;注释行
(defun qiang-comment-dwim-line (&optional arg)
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key "\M-;" 'qiang-comment-dwim-line)

;;设置字体
(set-default-font " -bitstream-Courier 10 Pitch-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1")

;;使用M+k来复制当前光标到整行,使用C+w来剪切整行,用M+w来复制整行
(defadvice kill-line (before check-position activate)
(if (member major-mode
'(emacs-lisp-mode scheme-mode lisp-mode
c-mode c++-mode objc-mode js-mode
latex-mode plain-tex-mode))
(if (and (eolp) (not (bolp)))
(progn (forward-char 1)
(just-one-space 0)
(backward-char 1)))))

(defadvice kill-ring-save (before slick-copy activate compile)
(interactive (if mark-active (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))

(defadvice kill-region (before slick-cut activate compile)
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))

(defun qiang-copy-line (arg)
(interactive "p")
(kill-ring-save (point)
(line-end-position))
(message "%d line%s copied" arg (if (= 1 arg) "" "s")))

(global-set-key (kbd "M-k") 'qiang-copy-line)

;;拷贝代码自动格式化
(dolist (command '(yank yank-pop))
(eval
`(defadvice ,command (after indent-region activate)
(and (not current-prefix-arg)
(member major-mode
'(emacs-lisp-mode
lisp-mode
clojure-mode
scheme-mode
haskell-mode
ruby-mode
rspec-mode
python-mode
c-mode
php-mode
c++-mode
objc-mode
latex-mode
js-mode
plain-tex-mode))
(let ((mark-even-if-inactive transient-mark-mode))
(indent-region (region-beginning) (region-end) nil))))))

;;设置开启路径
(setq default-directory "/var/www")
(cd "/var/www")
(find-file "/var/www")

;;关闭开启提醒
(setq inhibit-startup-message t)

;;关闭gnu启动界面
(setq gnus-inhibit-startup-message t)

;;将提示改为y or n
(fset 'yes-or-no-p 'y-or-n-p)

;;设置个人信息
(setq user-full-name "YanSu")
(setq user-mail-address "jansy000@163.com")

;;取消C+空格的标记
(global-set-key (kbd "C-SPC") 'nil)
;;设置M+空格为标记
(global-set-key (kbd "M-<SPC>") 'set-mark-command)

;;光标显示为一竖线
(setq-default cursor-type 'bar)
;; 没有提示音,也不闪屏。
(setq ring-bell-function 'ignore)
;;利用C+回车进行直接回车换行,等同与其他IDE中shift+换行的功能
(global-set-key (kbd "C-<return>") "\C-e \t\n")
;;利用M+回车进行本行换行
(global-set-key [(meta return)] "\C-a \t\n")

;;配置xcscope
(require 'xcscope)
(add-hook 'php-mode-hook '(lambda() (require 'xcscope)))
;;修改快捷键
(define-key global-map [(f4)] 'cscope-find-this-symbol)
(define-key global-map [(f5)] 'cscope-find-global-definition)
(define-key global-map [(f6)] 'cscope-find-functions-calling-this-function)
(define-key global-map [(f7)] 'cscope-find-called-functions)

(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.
)

;;定义F12键为激活ecb
(global-set-key [f12] 'ecb-activate)
;;定义Ctrl+F12为停止ecb
(global-set-key [C-f12] 'ecb-deactivate)

(global-set-key [(control tab)] 'other-window);切换窗口
(global-set-key (kbd "C-c 1") 'ecb-goto-window-directories)
(global-set-key (kbd "C-c 2") 'ecb-goto-window-sources)
(global-set-key (kbd "C-c 3") 'ecb-goto-window-methods)
(global-set-key (kbd "C-c 4") 'ecb-goto-window-history)
(global-set-key (kbd "C-c 0") 'ecb-goto-window-edit-last)
;;(global-set-key (kbd "C-z") 'undo);撤消
(global-set-key (kbd "C-x C-a") 'mark-whole-buffer);全选


;; 不显示工具栏
(tool-bar-mode -1)
;;总是不显示菜单,按ctrl+鼠标右键还是能调出菜单
(menu-bar-mode -1)

;;去掉烦人的警告铃声
(setq visible-bell nil)

;;利用C+?自动补全
(global-set-key [(meta ?/)] 'hippie-expand)
;;(global-set-key [(tab)] '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))

 

;;代码折叠设置
(load-library "hideshow")
(add-hook 'c-mode-hook 'hs-minor-mode)
(add-hook 'c++-mode-hook 'hs-minor-mode)
(add-hook 'java-mode-hook 'hs-minor-mode)
(add-hook 'perl-mode-hook 'hs-minor-mode)
(add-hook 'php-mode-hook 'hs-minor-mode)
(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode)
;;用F3控制代码块折叠
(global-set-key [f3] 'hs-toggle-hiding)
;;用F2来关闭buffer
(global-set-key [f2] 'kill-buffer)
;;用F1来打开file
(global-set-key [f1] 'find-file)
;;自动刷新当前buffer
(global-auto-revert-mode t)
;;用C+o来复制当前单词
(defun copy-word (&optional arg)
(interactive)
(setq onPoint (point))
(let (
( beg (progn (re-search-backward "[^a-zA-Z0-9_]" (line-beginning-position) 3 1)
(if (looking-at "[^a-zA-Z0-9_]") (+ (point) 1) (point) ) )
)
( end (progn (goto-char onPoint) (re-search-forward "[^a-zA-Z0-9_]" (line-end-position) 3 1)
(if (looking-back "[^a-zA-Z0-9_]") (- (point) 1) (point) ) )
))
(copy-region-as-kill beg end)
)
)
;;C+o复制某个单词
(global-set-key [(control o)] 'copy-word)

;;配置ecb
(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.
'(ecb-fix-window-size t)
'(ecb-key-map (quote ("C-c ." (t "fh" ecb-history-filter) (t "fs" ecb-sources-filter) (t "fm" ecb-methods-filter) (t "fr" ecb-methods-filter-regexp) (t "ft" ecb-methods-filter-tagclass) (t "fc" ecb-methods-filter-current-type) (t "fp" ecb-methods-filter-protection) (t "fn" ecb-methods-filter-nofilter) (t "fl" ecb-methods-filter-delete-last) (t "ff" ecb-methods-filter-function) (t "p" ecb-nav-goto-previous) (t "n" ecb-nav-goto-next) (t "lc" ecb-change-layout) (t "lr" ecb-redraw-layout) (t "lw" ecb-toggle-ecb-windows) (t "lt" ecb-toggle-layout) (t "s" ecb-window-sync) (t "r" ecb-rebuild-methods-buffer) (t "a" ecb-toggle-auto-expand-tag-tree) (t "x" ecb-expand-methods-nodes) (t "h" ecb-show-help) (t "C-c 0" ecb-goto-window-edit-last) (t "g1" ecb-goto-window-edit1) (t "g2" ecb-goto-window-edit2) (t "gc" ecb-goto-window-compilation) (t "C-c 1" ecb-goto-window-directories) (t "C-c 2" ecb-goto-window-sources) (nil "C-c 3" ecb-goto-window-methods) (t "C-c 4" ecb-goto-window-history) (t "ga" ecb-goto-window-analyse) (t "gb" ecb-goto-window-speedbar) (t "md" ecb-maximize-window-directories) (t "ms" ecb-maximize-window-sources) (t "mm" ecb-maximize-window-methods) (t "mh" ecb-maximize-window-history) (t "ma" ecb-maximize-window-analyse) (t "mb" ecb-maximize-window-speedbar) (t "e" eshell) (t "o" ecb-toggle-scroll-other-window-scrolls-compile) (t "\\" ecb-toggle-compile-window) (t "/" ecb-toggle-compile-window-height) (t "," ecb-cycle-maximized-ecb-buffers) (t "." ecb-cycle-through-compilation-buffers))))
'(ecb-options-version "2.40")
'(ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1))
'(ecb-tip-of-the-day nil)
'(ecb-windows-witdh 0.2))
;;最大化
(if window-system
(defun my-maximized ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
)
)
;;启动时最大化
;;(if window-system
;; (my-maximized)
;;)

;;括号自动补全
(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)
(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-common-hook 'my-c-mode-auto-pair)
;;(require 'color-theme)


;; (setq my-tab-width 4)

;; (defun indent-block()
;; (shift-region my-tab-width)
;; (setq deactivate-mark nil))

;; (defun unindent-block()
;; (shift-region (- my-tab-width))
;; (setq deactivate-mark nil))

;; (defun shift-region(numcols)
;; (if (< (point)(mark))
;; (if (not(bolp)) (progn (beginning-of-line)(exchange-point-and-mark) (end-of-line)))
;; (progn (end-of-line)(exchange-point-and-mark)(beginning-of-line)))
;; (setq region-start (region-beginning))
;; (setq region-finish (region-end))
;; (save-excursion
;; (if (< (point) (mark)) (exchange-point-and-mark))
;; (let ((save-mark (mark)))
;; (indent-rigidly region-start region-finish numcols))))

;; (defun indent-or-complete ()
;; (interactive)
;; (if mark-active
;; (indent-block)
;; (if (looking-at "\\>")
;; (hippie-expand nil)
;; (insert "\t"))))

;; (defun my-unindent()
;; (interactive)
;; (if mark-active
;; (unindent-block)
;; (progn
;; (unless(bolp)
;; (if (looking-back "^[ \t]*")
;; (progn
;; (let ((a (length(buffer-substring-no-properties (point-at-bol) (point)))))
;; (progn
;; (if (> a my-tab-width)
;; (delete-backward-char my-tab-width)
;; (backward-delete-char a)))))
;; (progn
;; (if(looking-back "[ \t]\\{2,\\}")
;; (delete-horizontal-space)
;; (backward-kill-word 1))))))))

;; (add-hook 'find-file-hooks (function (lambda ()
;; (unless (eq major-mode 'org-mode)
;; (local-set-key (kbd "<tab>") 'indent-or-complete)))))

;; (if (not (eq major-mode 'org-mode))
;; (progn
;; (define-key global-map "\t" 'indent-or-complete)
;; (define-key global-map [S-tab] 'my-unindent)
;; (define-key global-map [C-S-tab] 'my-unindent)))

;; (require 'yasnippet-bundle)

(setq c-basic-offset 4)
(setq default-tab-width 4)
(setq-default indent-tabs-mode nil)

(require 'multi-web-mode)
(setq mweb-default-major-mode 'html-mode)
(setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
(js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
(css-mode "<style +type=\"text/css\"[^>]*>" "</style>")
(html-mode "<html*" "</html>")
))
(setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
(multi-web-global-mode 1)

(add-to-list 'load-path "~/emacs-lisp/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/emacs-lisp//ac-dict")
(ac-config-default)

(add-hook 'html-mode-hook
(lambda()
(setq sgml-basic-offset 4)
(setq indent-tabs-mode t)))

(require 'yasnippet-bundle)

 

//2012年6月19日

posted @ 2012-05-04 21:11  紫月冰河  阅读(705)  评论(0编辑  收藏  举报