(
defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(c-mode)
(c-set-style "K&R")
(setq c-basic-offset 8)
)
(setq auto-mode-alist (cons '("/scratchbox/x.*/.*//.[ch]$" . linux-c-mode)
auto-mode-alist))
;;语法高亮
(global-font-lock-mode t)
(set-language-environment 'Chinese-GB)
(set-keyboard-coding-system 'euc-cn)
(set-clipboard-coding-system 'euc-cn)
(set-terminal-coding-system 'euc-cn)
(set-buffer-file-coding-system 'euc-cn)
(set-selection-coding-system 'euc-cn)
(modify-coding-system-alist 'process "*" 'euc-cn)
(setq default-process-coding-system '(euc-cn . euc-cn))
(setq-default pathname-coding-system 'euc-cn)
(prefer-coding-system 'utf-8)
;;使用文泉驿中文字体,同时设定字体大小。
;(create-fontset-from-fontset-spec
; "-adobe-courier-medium-r-*-*-16-*-*-*-*-*-fontset-ifree,
; chinese-gb2312:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-big5-1:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-big5-2:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-sisheng:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-3:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-4:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-5:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-6:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-7:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0208-1978:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0208:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0212:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0213-1:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0213-2:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1"
;)
;(set-default-font "fontset-ifree")
(create-fontset-from-fontset-spec
(concat
"-*-courier-medium-r-normal-*-16-*-*-*-*-*-fontset-courier,"
"chinese-gb2312:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gb2312*-*,"
"mule-unicode-0100-24ff:-*-simsun-medium-r-*-*-16-*-*-*-c-*-iso10646*-*,"
"korean-ksc5601:-*-*-medium-r-*-*-16-*-*-*-*-*-ksc5601*-*,"
"chinese-cns11643-5:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"chinese-cns11643-6:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"chinese-cns11643-7:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"sjis:-*-medium-r-normal--16-*-jisx0208*-*"))
(set-default-font "fontset-courier")
(setq default-frame-alist
(append
'((font . "fontset-courier")) default-frame-alist)
)
;;(add-to-list 'after-make-frame-functions
;; (lambda (new-frame) (select-frame new-frame)
;; (set-default-font "fontset-ifree")
;; )
;;)
;;通过在.emacs中设置字体解决了emacs字体颠倒的问题
;;首先设置环境变量HOME,使其指向一个特定的目录
;;在这个目录下建立.emacs文件,使其内容如本文所示
;; Are we running XEmacs or Emacs?
(defvar running-xemacs (string-match "XEmacs//|Lucid" emacs-version))
;; Set up the keyboard so the delete key on both the regular keyboard
;; and the keypad delete the character under the cursor and to the right
;; under X, instead of the default, backspace behavior.
(global-set-key [delete] 'delete-char)
(global-set-key [kp-delete] 'delete-char)
;;设置中文显示
;(set-keyboard-coding-system 'chinese-iso-8bit-dos) ; input
;(set-selection-coding-system 'chinese-iso-8bit-dos) ; copy/paste
;;{{{ ---- <edited by yonsan> +++++++++++++++++++++++++++++++++++++++++++++++
;(create-fontset-from-fontset-spec
; "-*-simsun-medium-r-*-*-16-*-*-*-*-*-fontset-yonsan,
; chinese-gbk-0:-*-simsun-medium-r-*-*-12-*")
;;}}}
;;{{{ ---- <edited by yonsan> +++++++++++++++++++++++++++++++++++++++++++++++
;(set-default-font "fontset-yonsan")
;;}}}
;(set-default-font "-*-MS Song-bold-r-*-*-19-*-*-*-c-*-gb2312-*1")
;(set-default-font "chinese-gb2312:-*-宋体-*-*-*-*-16-*-*-*-c-*-gb2312*-*")
;(set-default-font "-*-Courier New-normal--r-*-*-14-*-*-*-c-*-fontset-chinese")
;(set-default-font "-raster-Terminal-normal-r-normal-normal-20-150-96-96-c-100-gb2312")
(set-frame-height (selected-frame) 34)
(set-frame-width (selected-frame) 81)
;(set-frame-height (selected-frame) 36)
;(set-frame-width (selected-frame) 88)
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
(put 'upcase-region 'disabled nil)
(cond (running-xemacs
))
;; Always end a file with a newline
(setq require-final-newline t)
;; Stop at the end of the file, not just add lines
(setq next-line-add-newlines nil)
(global-set-key (quote [f4]) (quote set-mark-command))
(global-set-key (quote [f3]) (quote goto-line))
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-set-style "k&r")
;; offset customizations not in my-c-style
(c-set-offset 'member-init-intro '++)
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline and hungry-delete
(c-toggle-auto-hungry-state 1)
(font-lock-mode 2)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
(define-key c-mode-base-map "/C-m" 'newline-and-indent)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-to-list 'load-path "~/Emacs/download.e")
;; enable visual feedback on selections
;(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" (system-name)))
;; default to unified diffs
(setq diff-switches "-u")
;; always end a file with a newline
;(setq require-final-newline 'query)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
(load-file "/usr/share/cscope/xcscope.el")
(require 'xcscope)
;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/semantic")
;;(setq semantic-load-turn-everything-on t)
;;(require 'semantic-load)
;; Load CEDET
;(load-file "/home/Harrison/Emacs/cedet-1.0pre4/common/cedet.el")
;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ideas.
;; Select one of the following:
;; * This enables the database and idle reparse engines
;(semantic-load-enable-minimum-features)
;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
;(semantic-load-enable-code-helpers)
;; * This enables even more coding tools such as the nascent intellisense mode
;; decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-guady-code-helpers)
;; * This turns on which-func support (Plus all other code helpers)
;; (semantic-load-enable-excessive-code-helpers)
;; This turns on modes that aid in grammar writing and semantic tool
;; development. It does not enable any other features such as code
;; helpers above.
;(semantic-load-enable-semantic-debugging-helpers)
;
;;semantic
;(load-file "~/Emacs/semantic-1.4.4/semantic.el")
;(require 'semantic-tag)
;;配置Semantic的检索范围:
(setq semanticdb-project-roots
(list
(expand-file-name "/")))
;;自定义自动补齐命令
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "//>")
(hippie-expand nil)
(indent-for-tab-command))
)
;(global-set-key [(control tab)] 'my-indent-or-complete)
(autoload 'senator-try-expand-semantic "senator")
;;hippie的自动补齐策略,优先调用了senator的分析结果
(setq hippie-expand-try-functions-list
'(
senator-try-expand-semantic
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-expand-list
try-expand-list-all-buffers
try-expand-line
try-expand-line-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-whole-kill
)
)
(global-set-key [f12] 'ecb-activate) ;;定义F12键为激活ecb
(global-set-key [C-f12] 'ecb-deactivate) ;;定义Ctrl+F12为停止ecb
(global-set-key [f11] 'delete-other-windows) ;;设置F11为删除其它窗口
;;(global-set-key [(meta return)] 'semantic-ia-complete-symbol-menu) ;;设置Alt+Enter为自动补全菜单
(global-set-key [C-f9] 'visit-tags-table)
(global-set-key [C-f10] 'find-tag)
;(load-file "~/Emacs/speedbar-0.14beta4/speedbar.el")
(require 'speedbar)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
;;代码自动补齐
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;;(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;颜色设置,其实有个color-theme.el可以将Emacs设置丰富多彩,非常漂亮,不过启动有些慢(我得机器不行),我只是选择了一些颜色设置。
;; 指针颜色设置为白色
(set-cursor-color "white")
;; 鼠标颜色设置为白色
(set-mouse-color "white")
;; 设置背景颜色和字体颜色
(set-foreground-color "white")
(set-background-color "black")
;;(set-background-color "darkblue")
;; 设置另外一些颜色:语法高亮显示的背景和主题,区域选择的背景和主题,二次选择的背景和选择
(set-face-foreground 'highlight "white")
(set-face-background 'highlight "blue")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")
;;外观设置
;;去掉工具栏
;;(tool-bar-mode nil)
;;去掉菜单栏,我将F10绑定为显示菜单栏,万一什么东西忘了,需要菜单栏了可以摁F10调出,再摁F10就去掉菜单
;;(menu-bar-mode nil)
;;不要滚动栏,现在都用滚轴鼠标了,可以不用滚动栏了
;;(scroll-bar-mode nil)
;;下面是用 SHIFT+% 找配对
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "//s/(") (forward-list 1) (backward-char 1))
((looking-at "//s/)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1))))
)
;;下面的这个设置可以让光标指到某个括号的时候显示与它匹配的括号
(show-paren-mode t)
;(setq show-paren-style 'parentheses)
;;设置tab为4个空格的宽度,而不是原来的2
(setq indent-tabs-mode nil)
(setq tab-stop-list ())
(setq default-tab-width 4)
(setq default-tab-width 4)
;;编辑器自动添上配对的{}
(add-hook 'ruby-mode-hook
(lambda()
(require 'ruby-electric)
(ruby-electric-mode t)
))
;;问题是自动缩进
(mapcar
(lambda (mode)
(let ((mode-hook (intern (concat (symbol-name mode) "-hook")))
(mode-map (intern (concat (symbol-name mode) "-map"))))
(add-hook mode-hook
`(lambda nil
(local-set-key
(kbd "RET")
(or (lookup-key ,mode-map "/C-j")
(lookup-key global-map "/C-j"))))))) '(c-mode c++-mode cperl-mode emacs-lisp-mode java-mode html-mode lisp-mode ruby-mode sh-mode))
;;格式化整个文件
(defun iwb ()
"indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil))
(defun my-c++-mode-hook()
(setq tab-width 4 indent-tabs-mode nil)
(c-set-style "stroustrup")
)
(defun my-c-mode-common-hook()
(setq tab-width 4 indent-tabs-mode nil)
;;;hungry-delete and auto-newline
(c-toggle-auto-hungry-state 1)
''按键定义
(define-key c-mode-base-map [(control /')] 'hs-toggle-hiding)
(define-key c-mode-base-map [(return)] 'newline-and-indent )
(define-key c-mode-base-map [(f7)] 'compile)
(define-key c-mode-base-map [(meta /')] 'c-indent-command)
;;代码自动补齐
;;(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;; (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;;预处理设置
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ecb-options-version "2.32"))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
;;中自动添加有半边括号的功能
;; C mode
(add-hook 'c-mode-hook 'hs-minor-mode)
(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-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)
(defun my-c-mode-hook ()
;;; .... 其他配置功能
(local-set-key (kbd "{") 'skeleton-c-mode-left-brace)
;;; .... 其他配置功能
)
(defun skeleton-c-mode-left-brace (arg)
(interactive "*P")
(if (c-in-literal (c-most-enclosing-brace (c-parse-state)))
(self-insert-command 1)
;; auto insert complex things.
(let* ((current-line (delete-and-extract-region (line-beginning-position) (line-end-position)))
(lines (and arg (mark t) (delete-and-extract-region (mark t) (point))))
(after-point (make-marker)))
;;; delete extra blank begin and after the LINES
(setq lines (and lines
(with-temp-buffer
(insert lines)
(beginning-of-buffer)
(delete-blank-lines)
(delete-blank-lines)
(end-of-buffer)
(delete-blank-lines)
(delete-blank-lines)
(buffer-string))))
(save-excursion
(let* ((old-point (point)))
(insert (if current-line current-line "") "{/n")
(and lines (insert lines))
(move-marker after-point (point))
(insert "/n}/n")
(indent-region old-point (point) nil)))
(goto-char after-point)
(c-indent-line)
)))
;;在保存文件的时候,会自动给脚本增加可执行权限。
(setq my-shebang-patterns
(list "^#!/usr/.*/perl//(//( //)//|//( .+ //)//)-w *.*"
"^#!/usr/.*/sh"
"^#!/usr/.*/bash"
"^#!/bin/sh"
"^#!/.*/perl"
"^#!/.*/awk"
"^#!/.*/sed"
"^#!/bin/bash"))
(add-hook
'after-save-hook
(lambda ()
(if (not (= (shell-command (concat "test -x " (buffer-file-name))) 0))
(progn
;; This puts message in *Message* twice, but minibuffer
;; output looks better.
(message (concat "Wrote " (buffer-file-name)))
(save-excursion
(goto-char (point-min))
;; Always checks every pattern even after
;; match. Inefficient but easy.
(dolist (my-shebang-pat my-shebang-patterns)
(if (looking-at my-shebang-pat)
(if (= (shell-command
(concat "chmod u+x " (buffer-file-name)))
0)
(message (concat
"Wrote and made executable "
(buffer-file-name))))))))
;; This puts message in *Message* twice, but minibuffer output
;; looks better.
(message (concat "Wrote " (buffer-file-name))))))
;;
(define-auto-insert 'cperl-mode "perl.tpl" )
(define-auto-insert 'sh-mode '(nil "#!/bin/bash/n/n"))
; 也可以是,不过我没有试过
; (define-auto-insert "//.pl" "perl.tpl" )
(add-hook 'find-file-hooks 'auto-insert)
;; 自动为 C/C++ 的头文件添加 #define 保护。
(define-auto-insert
'("//.//([Hh]//|hh//|hxx//|hpp//)//'" . "C / C++ header")
'((upcase (concat "_"
(replace-regexp-in-string
"[^a-zA-Z0-9]" "_"
(format "%s_%d_" (file-name-nondirectory buffer-file-name) (random)))))
"#ifndef " str /n
"#define " str "/n/n"
_ "/n/n#endif"))
;;以下使用头文件信息
(require 'header)
(defvar wcy-header-project-name "Gpepe")
(defun wcy-c-mode-config-header ()
(interactive)
(setq header-copyright-notice "
(c) 2002 XXXX.LtD
XXX(CHINA) INVESTMENT CO.,LTD.
addr: 3/F,Tower R2-B, South Area,Hi-tech industrial PARK Shenzhen.China
tel : int +86-755-xxxx Ext. 2632
fax : int +86-10-xxxxxx
The program may be used and/or copied only with the written
permission of Nokia or in accordance with the terms and conditions
stipulated in the agreement/contract under which the program heve
been supplied.
")
(make-local-variable 'user-full-name)
(make-local-variable 'user-mail-address)
(setq user-full-name "Harrison.zhu")
(setq user-mail-address "zmc_322@sina.com")
(setq make-header-hooks '(header-mode-line
header-blank
;;header-rcs
;;header-AFS
wcy-header-file-name
wcy-header-project-name
wcy-header-file-description
header-creation-date
;;header-rcs
header-author
wcy-header-author-email
;;header-modification-author
;;header-modification-date
;;header-update-count
header-blank
header-copyright
header-blank
;;header-status
;; Re-enable the following lines if you wish
header-blank
;;header-history
;;header-purpose
;;header-toc
header-blank
wcy-header-end-comment
))
(setq file-header-update-alist nil)
(progn
(register-file-header-action "[ /t]Update Count[ /t]*: "
'update-write-count)
(register-file-header-action "[ /t]Last Modified By[ /t]*: "
'update-last-modifier)
(register-file-header-action "[ /t]Last Modified On[ /t]*: "
'update-last-modified-date)
(register-file-header-action " File : *//(.*//) *$" 'wcy-update-file-name)
))
(defun wcy-header-file-name ()
"Places the buffer's file name and leaves room for a description."
(insert header-prefix-string "File : " (buffer-name) "/n")
(setq return-to (1- (point))))
(defun wcy-header-project-name ()
(insert header-prefix-string "Program/Library : " wcy-header-project-name "/n"))
(defun wcy-header-file-description()
(insert header-prefix-string "Description : /n"))
(defun wcy-header-author-email ()
(insert header-prefix-string "Mail : " user-mail-address "/n"))
(defun wcy-header-end-comment ()
(if comment-end
(insert comment-end "/n")))
(defun wcy-update-file-name ()
(beginning-of-line)
;; verify that we are looking at a file name for this mode
(if (looking-at
(concat (regexp-quote (header-prefix-string)) "File : *//(.*//) *$"))
(progn
(goto-char (match-beginning 1))
(delete-region (match-beginning 1) (match-end 1))
(insert (file-name-nondirectory (buffer-file-name)) )
)))
;删除匹配括号间内容
(defun kill-match-paren (arg)
(interactive "p")
(cond ((looking-at "[([{]") (kill-sexp 1) (backward-char))
((looking-at "[])}]") (forward-char) (backward-kill-sexp 1))
(t (self-insert-command (or arg 1)))))
(global-set-key (kbd "C-x %") 'kill-match-paren)
;;行跳转
(define-key global-map "/C-c/C-g" 'goto-line)
;; 跳转函数,类似vi的f键
(defun wy-go-to-char (n char)
"Move forward to Nth occurence of CHAR.
Typing `wy-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
(interactive "p/ncGo to char: ")
(search-forward (string char) nil nil n)
(while (char-equal (read-char)
char)
(search-forward (string char) nil nil n))
(setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-c a") 'wy-go-to-char)
;;解决中文乱码问题
;;(require 'un-define)
;;CEDET 下的一个不错的工具
(global-set-key [(f5)] 'speedbar)
;;show line number
(load-file "~/Emacs/download.e/display-line-number.el")
;; 加载显示行号模块
(require 'display-line-number)
;; 如果想所有打开的文件都显示行的话就打开下面的注释
;;(global-display-line-number-mode 0)
;; 设置显示格式
(setq display-line-number-format "%4d|")
;; 在 tool bar 上增加一个图标,
;; 注意: 一定要在 load-path 中 可以找到 display-line-nuber.xpm 文件才行。
;;
(tool-bar-add-item "display-line-number"
'display-line-number-mode
'display-line-number-mode
:help "display line number!"
:button (cons :toggle '(and (boundp
display-line-number-mode)
display-line-number-mode)))
;;
;; 使用方法
;; M-x display-line-number-mode
;; 用来 toggle 显示行号的模式
;; M-x display-line-number-mode-on
;; 启动显示行号的模式
;; M-x display-line-number-mode-off
;; 关闭显示行号的模式
;; 仅对某种 mode 启动显示行号的模式
;; (add-hook 'c-mode-hook 'display-line-number-mode)
(add-hook 'speedbar-timer-hook
(lambda ()
(speedbar-refresh)))
(setq speedbar-verbosity-level 0)
(autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
(autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
(global-set-key [(f6)] 'speedbar-get-focus)
defun linux-c-mode ()
"C mode with adjusted defaults for use with the Linux kernel."
(interactive)
(c-mode)
(c-set-style "K&R")
(setq c-basic-offset 8)
)
(setq auto-mode-alist (cons '("/scratchbox/x.*/.*//.[ch]$" . linux-c-mode)
auto-mode-alist))
;;语法高亮
(global-font-lock-mode t)
(set-language-environment 'Chinese-GB)
(set-keyboard-coding-system 'euc-cn)
(set-clipboard-coding-system 'euc-cn)
(set-terminal-coding-system 'euc-cn)
(set-buffer-file-coding-system 'euc-cn)
(set-selection-coding-system 'euc-cn)
(modify-coding-system-alist 'process "*" 'euc-cn)
(setq default-process-coding-system '(euc-cn . euc-cn))
(setq-default pathname-coding-system 'euc-cn)
(prefer-coding-system 'utf-8)
;;使用文泉驿中文字体,同时设定字体大小。
;(create-fontset-from-fontset-spec
; "-adobe-courier-medium-r-*-*-16-*-*-*-*-*-fontset-ifree,
; chinese-gb2312:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-big5-1:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-big5-2:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-sisheng:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-3:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-4:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-5:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-6:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; chinese-cns11643-7:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0208-1978:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0208:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0212:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0213-1:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1,
; japanese-jisx0213-2:-wenquanyi-wenquanyi bitmap song-medium-r-normal--16-160-75-75-p-80-iso10646-1"
;)
;(set-default-font "fontset-ifree")
(create-fontset-from-fontset-spec
(concat
"-*-courier-medium-r-normal-*-16-*-*-*-*-*-fontset-courier,"
"chinese-gb2312:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gb2312*-*,"
"mule-unicode-0100-24ff:-*-simsun-medium-r-*-*-16-*-*-*-c-*-iso10646*-*,"
"korean-ksc5601:-*-*-medium-r-*-*-16-*-*-*-*-*-ksc5601*-*,"
"chinese-cns11643-5:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"chinese-cns11643-6:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"chinese-cns11643-7:-*-simsun-medium-r-*-*-16-*-*-*-c-*-gbk*-*,"
"sjis:-*-medium-r-normal--16-*-jisx0208*-*"))
(set-default-font "fontset-courier")
(setq default-frame-alist
(append
'((font . "fontset-courier")) default-frame-alist)
)
;;(add-to-list 'after-make-frame-functions
;; (lambda (new-frame) (select-frame new-frame)
;; (set-default-font "fontset-ifree")
;; )
;;)
;;通过在.emacs中设置字体解决了emacs字体颠倒的问题
;;首先设置环境变量HOME,使其指向一个特定的目录
;;在这个目录下建立.emacs文件,使其内容如本文所示
;; Are we running XEmacs or Emacs?
(defvar running-xemacs (string-match "XEmacs//|Lucid" emacs-version))
;; Set up the keyboard so the delete key on both the regular keyboard
;; and the keypad delete the character under the cursor and to the right
;; under X, instead of the default, backspace behavior.
(global-set-key [delete] 'delete-char)
(global-set-key [kp-delete] 'delete-char)
;;设置中文显示
;(set-keyboard-coding-system 'chinese-iso-8bit-dos) ; input
;(set-selection-coding-system 'chinese-iso-8bit-dos) ; copy/paste
;;{{{ ---- <edited by yonsan> +++++++++++++++++++++++++++++++++++++++++++++++
;(create-fontset-from-fontset-spec
; "-*-simsun-medium-r-*-*-16-*-*-*-*-*-fontset-yonsan,
; chinese-gbk-0:-*-simsun-medium-r-*-*-12-*")
;;}}}
;;{{{ ---- <edited by yonsan> +++++++++++++++++++++++++++++++++++++++++++++++
;(set-default-font "fontset-yonsan")
;;}}}
;(set-default-font "-*-MS Song-bold-r-*-*-19-*-*-*-c-*-gb2312-*1")
;(set-default-font "chinese-gb2312:-*-宋体-*-*-*-*-16-*-*-*-c-*-gb2312*-*")
;(set-default-font "-*-Courier New-normal--r-*-*-14-*-*-*-c-*-fontset-chinese")
;(set-default-font "-raster-Terminal-normal-r-normal-normal-20-150-96-96-c-100-gb2312")
(set-frame-height (selected-frame) 34)
(set-frame-width (selected-frame) 81)
;(set-frame-height (selected-frame) 36)
;(set-frame-width (selected-frame) 88)
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
(put 'upcase-region 'disabled nil)
(cond (running-xemacs
))
;; Always end a file with a newline
(setq require-final-newline t)
;; Stop at the end of the file, not just add lines
(setq next-line-add-newlines nil)
(global-set-key (quote [f4]) (quote set-mark-command))
(global-set-key (quote [f3]) (quote goto-line))
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-set-style "k&r")
;; offset customizations not in my-c-style
(c-set-offset 'member-init-intro '++)
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline and hungry-delete
(c-toggle-auto-hungry-state 1)
(font-lock-mode 2)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
(define-key c-mode-base-map "/C-m" 'newline-and-indent)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-to-list 'load-path "~/Emacs/download.e")
;; enable visual feedback on selections
;(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" (system-name)))
;; default to unified diffs
(setq diff-switches "-u")
;; always end a file with a newline
;(setq require-final-newline 'query)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
(load-file "/usr/share/cscope/xcscope.el")
(require 'xcscope)
;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/semantic")
;;(setq semantic-load-turn-everything-on t)
;;(require 'semantic-load)
;; Load CEDET
;(load-file "/home/Harrison/Emacs/cedet-1.0pre4/common/cedet.el")
;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ideas.
;; Select one of the following:
;; * This enables the database and idle reparse engines
;(semantic-load-enable-minimum-features)
;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
;(semantic-load-enable-code-helpers)
;; * This enables even more coding tools such as the nascent intellisense mode
;; decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-guady-code-helpers)
;; * This turns on which-func support (Plus all other code helpers)
;; (semantic-load-enable-excessive-code-helpers)
;; This turns on modes that aid in grammar writing and semantic tool
;; development. It does not enable any other features such as code
;; helpers above.
;(semantic-load-enable-semantic-debugging-helpers)
;
;;semantic
;(load-file "~/Emacs/semantic-1.4.4/semantic.el")
;(require 'semantic-tag)
;;配置Semantic的检索范围:
(setq semanticdb-project-roots
(list
(expand-file-name "/")))
;;自定义自动补齐命令
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "//>")
(hippie-expand nil)
(indent-for-tab-command))
)
;(global-set-key [(control tab)] 'my-indent-or-complete)
(autoload 'senator-try-expand-semantic "senator")
;;hippie的自动补齐策略,优先调用了senator的分析结果
(setq hippie-expand-try-functions-list
'(
senator-try-expand-semantic
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-expand-list
try-expand-list-all-buffers
try-expand-line
try-expand-line-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-whole-kill
)
)
(global-set-key [f12] 'ecb-activate) ;;定义F12键为激活ecb
(global-set-key [C-f12] 'ecb-deactivate) ;;定义Ctrl+F12为停止ecb
(global-set-key [f11] 'delete-other-windows) ;;设置F11为删除其它窗口
;;(global-set-key [(meta return)] 'semantic-ia-complete-symbol-menu) ;;设置Alt+Enter为自动补全菜单
(global-set-key [C-f9] 'visit-tags-table)
(global-set-key [C-f10] 'find-tag)
;(load-file "~/Emacs/speedbar-0.14beta4/speedbar.el")
(require 'speedbar)
(require 'cc-mode)
(c-set-offset 'inline-open 0)
(c-set-offset 'friend '-)
(c-set-offset 'substatement-open 0)
;;代码自动补齐
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;;(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;颜色设置,其实有个color-theme.el可以将Emacs设置丰富多彩,非常漂亮,不过启动有些慢(我得机器不行),我只是选择了一些颜色设置。
;; 指针颜色设置为白色
(set-cursor-color "white")
;; 鼠标颜色设置为白色
(set-mouse-color "white")
;; 设置背景颜色和字体颜色
(set-foreground-color "white")
(set-background-color "black")
;;(set-background-color "darkblue")
;; 设置另外一些颜色:语法高亮显示的背景和主题,区域选择的背景和主题,二次选择的背景和选择
(set-face-foreground 'highlight "white")
(set-face-background 'highlight "blue")
(set-face-foreground 'region "cyan")
(set-face-background 'region "blue")
(set-face-foreground 'secondary-selection "skyblue")
(set-face-background 'secondary-selection "darkblue")
;;外观设置
;;去掉工具栏
;;(tool-bar-mode nil)
;;去掉菜单栏,我将F10绑定为显示菜单栏,万一什么东西忘了,需要菜单栏了可以摁F10调出,再摁F10就去掉菜单
;;(menu-bar-mode nil)
;;不要滚动栏,现在都用滚轴鼠标了,可以不用滚动栏了
;;(scroll-bar-mode nil)
;;下面是用 SHIFT+% 找配对
(global-set-key "%" 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert %."
(interactive "p")
(cond ((looking-at "//s/(") (forward-list 1) (backward-char 1))
((looking-at "//s/)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1))))
)
;;下面的这个设置可以让光标指到某个括号的时候显示与它匹配的括号
(show-paren-mode t)
;(setq show-paren-style 'parentheses)
;;设置tab为4个空格的宽度,而不是原来的2
(setq indent-tabs-mode nil)
(setq tab-stop-list ())
(setq default-tab-width 4)
(setq default-tab-width 4)
;;编辑器自动添上配对的{}
(add-hook 'ruby-mode-hook
(lambda()
(require 'ruby-electric)
(ruby-electric-mode t)
))
;;问题是自动缩进
(mapcar
(lambda (mode)
(let ((mode-hook (intern (concat (symbol-name mode) "-hook")))
(mode-map (intern (concat (symbol-name mode) "-map"))))
(add-hook mode-hook
`(lambda nil
(local-set-key
(kbd "RET")
(or (lookup-key ,mode-map "/C-j")
(lookup-key global-map "/C-j"))))))) '(c-mode c++-mode cperl-mode emacs-lisp-mode java-mode html-mode lisp-mode ruby-mode sh-mode))
;;格式化整个文件
(defun iwb ()
"indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil))
(defun my-c++-mode-hook()
(setq tab-width 4 indent-tabs-mode nil)
(c-set-style "stroustrup")
)
(defun my-c-mode-common-hook()
(setq tab-width 4 indent-tabs-mode nil)
;;;hungry-delete and auto-newline
(c-toggle-auto-hungry-state 1)
''按键定义
(define-key c-mode-base-map [(control /')] 'hs-toggle-hiding)
(define-key c-mode-base-map [(return)] 'newline-and-indent )
(define-key c-mode-base-map [(f7)] 'compile)
(define-key c-mode-base-map [(meta /')] 'c-indent-command)
;;代码自动补齐
;;(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
;; (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;;预处理设置
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(ecb-options-version "2.32"))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
;;中自动添加有半边括号的功能
;; C mode
(add-hook 'c-mode-hook 'hs-minor-mode)
(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-hook)
(add-hook 'c++-mode-hook 'my-c-mode-hook)
(defun my-c-mode-hook ()
;;; .... 其他配置功能
(local-set-key (kbd "{") 'skeleton-c-mode-left-brace)
;;; .... 其他配置功能
)
(defun skeleton-c-mode-left-brace (arg)
(interactive "*P")
(if (c-in-literal (c-most-enclosing-brace (c-parse-state)))
(self-insert-command 1)
;; auto insert complex things.
(let* ((current-line (delete-and-extract-region (line-beginning-position) (line-end-position)))
(lines (and arg (mark t) (delete-and-extract-region (mark t) (point))))
(after-point (make-marker)))
;;; delete extra blank begin and after the LINES
(setq lines (and lines
(with-temp-buffer
(insert lines)
(beginning-of-buffer)
(delete-blank-lines)
(delete-blank-lines)
(end-of-buffer)
(delete-blank-lines)
(delete-blank-lines)
(buffer-string))))
(save-excursion
(let* ((old-point (point)))
(insert (if current-line current-line "") "{/n")
(and lines (insert lines))
(move-marker after-point (point))
(insert "/n}/n")
(indent-region old-point (point) nil)))
(goto-char after-point)
(c-indent-line)
)))
;;在保存文件的时候,会自动给脚本增加可执行权限。
(setq my-shebang-patterns
(list "^#!/usr/.*/perl//(//( //)//|//( .+ //)//)-w *.*"
"^#!/usr/.*/sh"
"^#!/usr/.*/bash"
"^#!/bin/sh"
"^#!/.*/perl"
"^#!/.*/awk"
"^#!/.*/sed"
"^#!/bin/bash"))
(add-hook
'after-save-hook
(lambda ()
(if (not (= (shell-command (concat "test -x " (buffer-file-name))) 0))
(progn
;; This puts message in *Message* twice, but minibuffer
;; output looks better.
(message (concat "Wrote " (buffer-file-name)))
(save-excursion
(goto-char (point-min))
;; Always checks every pattern even after
;; match. Inefficient but easy.
(dolist (my-shebang-pat my-shebang-patterns)
(if (looking-at my-shebang-pat)
(if (= (shell-command
(concat "chmod u+x " (buffer-file-name)))
0)
(message (concat
"Wrote and made executable "
(buffer-file-name))))))))
;; This puts message in *Message* twice, but minibuffer output
;; looks better.
(message (concat "Wrote " (buffer-file-name))))))
;;
(define-auto-insert 'cperl-mode "perl.tpl" )
(define-auto-insert 'sh-mode '(nil "#!/bin/bash/n/n"))
; 也可以是,不过我没有试过
; (define-auto-insert "//.pl" "perl.tpl" )
(add-hook 'find-file-hooks 'auto-insert)
;; 自动为 C/C++ 的头文件添加 #define 保护。
(define-auto-insert
'("//.//([Hh]//|hh//|hxx//|hpp//)//'" . "C / C++ header")
'((upcase (concat "_"
(replace-regexp-in-string
"[^a-zA-Z0-9]" "_"
(format "%s_%d_" (file-name-nondirectory buffer-file-name) (random)))))
"#ifndef " str /n
"#define " str "/n/n"
_ "/n/n#endif"))
;;以下使用头文件信息
(require 'header)
(defvar wcy-header-project-name "Gpepe")
(defun wcy-c-mode-config-header ()
(interactive)
(setq header-copyright-notice "
(c) 2002 XXXX.LtD
XXX(CHINA) INVESTMENT CO.,LTD.
addr: 3/F,Tower R2-B, South Area,Hi-tech industrial PARK Shenzhen.China
tel : int +86-755-xxxx Ext. 2632
fax : int +86-10-xxxxxx
The program may be used and/or copied only with the written
permission of Nokia or in accordance with the terms and conditions
stipulated in the agreement/contract under which the program heve
been supplied.
")
(make-local-variable 'user-full-name)
(make-local-variable 'user-mail-address)
(setq user-full-name "Harrison.zhu")
(setq user-mail-address "zmc_322@sina.com")
(setq make-header-hooks '(header-mode-line
header-blank
;;header-rcs
;;header-AFS
wcy-header-file-name
wcy-header-project-name
wcy-header-file-description
header-creation-date
;;header-rcs
header-author
wcy-header-author-email
;;header-modification-author
;;header-modification-date
;;header-update-count
header-blank
header-copyright
header-blank
;;header-status
;; Re-enable the following lines if you wish
header-blank
;;header-history
;;header-purpose
;;header-toc
header-blank
wcy-header-end-comment
))
(setq file-header-update-alist nil)
(progn
(register-file-header-action "[ /t]Update Count[ /t]*: "
'update-write-count)
(register-file-header-action "[ /t]Last Modified By[ /t]*: "
'update-last-modifier)
(register-file-header-action "[ /t]Last Modified On[ /t]*: "
'update-last-modified-date)
(register-file-header-action " File : *//(.*//) *$" 'wcy-update-file-name)
))
(defun wcy-header-file-name ()
"Places the buffer's file name and leaves room for a description."
(insert header-prefix-string "File : " (buffer-name) "/n")
(setq return-to (1- (point))))
(defun wcy-header-project-name ()
(insert header-prefix-string "Program/Library : " wcy-header-project-name "/n"))
(defun wcy-header-file-description()
(insert header-prefix-string "Description : /n"))
(defun wcy-header-author-email ()
(insert header-prefix-string "Mail : " user-mail-address "/n"))
(defun wcy-header-end-comment ()
(if comment-end
(insert comment-end "/n")))
(defun wcy-update-file-name ()
(beginning-of-line)
;; verify that we are looking at a file name for this mode
(if (looking-at
(concat (regexp-quote (header-prefix-string)) "File : *//(.*//) *$"))
(progn
(goto-char (match-beginning 1))
(delete-region (match-beginning 1) (match-end 1))
(insert (file-name-nondirectory (buffer-file-name)) )
)))
;删除匹配括号间内容
(defun kill-match-paren (arg)
(interactive "p")
(cond ((looking-at "[([{]") (kill-sexp 1) (backward-char))
((looking-at "[])}]") (forward-char) (backward-kill-sexp 1))
(t (self-insert-command (or arg 1)))))
(global-set-key (kbd "C-x %") 'kill-match-paren)
;;行跳转
(define-key global-map "/C-c/C-g" 'goto-line)
;; 跳转函数,类似vi的f键
(defun wy-go-to-char (n char)
"Move forward to Nth occurence of CHAR.
Typing `wy-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
(interactive "p/ncGo to char: ")
(search-forward (string char) nil nil n)
(while (char-equal (read-char)
char)
(search-forward (string char) nil nil n))
(setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-c a") 'wy-go-to-char)
;;解决中文乱码问题
;;(require 'un-define)
;;CEDET 下的一个不错的工具
(global-set-key [(f5)] 'speedbar)
;;show line number
(load-file "~/Emacs/download.e/display-line-number.el")
;; 加载显示行号模块
(require 'display-line-number)
;; 如果想所有打开的文件都显示行的话就打开下面的注释
;;(global-display-line-number-mode 0)
;; 设置显示格式
(setq display-line-number-format "%4d|")
;; 在 tool bar 上增加一个图标,
;; 注意: 一定要在 load-path 中 可以找到 display-line-nuber.xpm 文件才行。
;;
(tool-bar-add-item "display-line-number"
'display-line-number-mode
'display-line-number-mode
:help "display line number!"
:button (cons :toggle '(and (boundp
display-line-number-mode)
display-line-number-mode)))
;;
;; 使用方法
;; M-x display-line-number-mode
;; 用来 toggle 显示行号的模式
;; M-x display-line-number-mode-on
;; 启动显示行号的模式
;; M-x display-line-number-mode-off
;; 关闭显示行号的模式
;; 仅对某种 mode 启动显示行号的模式
;; (add-hook 'c-mode-hook 'display-line-number-mode)
(add-hook 'speedbar-timer-hook
(lambda ()
(speedbar-refresh)))
(setq speedbar-verbosity-level 0)
(autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
(autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
(global-set-key [(f6)] 'speedbar-get-focus)