2006年9月27日星期三
2006年9月14日星期四
My Emacs config file
(create-fontset-from-fontset-spec
"-misc-fixed-medium-r-*-*-16-*-*-*-c-*-fontset-global,
chinese-gb2312:-*-*-medium-r-normal-*-16-*-*-*-*-*-gb2312.1980-*")
;(setq default-frame-alist
; (append '((font . "fontset-global")) default-frame-alist))
(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)
(prefer-coding-system 'euc-cn)
(setq default-process-coding-system 'euc-cn)
(setq-default pathname-coding-system 'euc-cn)
;; 改变 Emacs 固执的要你回答 yes 的行为。按 y 或空格键表示 yes,n 表示 no。
(fset 'yes-or-no-p 'y-or-n-p)
;;高亮显示要拷贝的区域
(transient-mark-mode t)
;;显示匹配的括号
(show-paren-mode t)
;;显示大文件时加快速度
(setq lazy-lock-defer-on-scrolling t)
(setq font-lock-support-mode 'lazy-lock-mode)
(setq font-lock-maximum-decoration t)
;;不要生成临时文件
(setq-default make-backup-files nil)
;;使用shift + -> 或<- 选取内容
(pc-selection-mode t)
(add-hook 'c-mode-hook 'linux-c-mode)
(add-hook 'c++-mode-hook 'linux-cpp-mode)
;; 设置imenu的排序方式为按名称排序
(setq imenu-sort-function 'imenu--sort-by-name)
(defun linux-c-mode()
;; 将回车代替C-j的功能,换行的同时对齐
(define-key c-mode-map [return] 'newline-and-indent)
(interactive)
;; 设置C程序的对齐风格
(c-set-style "K&R")
;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
(c-toggle-auto-state)
;; 此模式下,当按Backspace时会删除最多的空格
(c-toggle-hungry-state)
;; TAB键的宽度设置为4
(setq c-basic-offset 4)
;; 在菜单中加入当前Buffer的函数索引
(imenu-add-menubar-index)
;; 在状态条上显示当前光标在哪个函数体内部
(which-function-mode)
)
(defun linux-cpp-mode()
(define-key c++-mode-map [return] 'newline-and-indent)
(define-key c++-mode-map [(control c) (c)] 'compile)
(interactive)
(c-set-style "K&R")
(c-toggle-auto-state)
(c-toggle-hungry-state)
(setq c-basic-offset 8)
(imenu-add-menubar-index)
(which-function-mode)
)
;;不用 TAB 字符来indent, 这会引起很多奇怪的错误。编辑 Makefile 的时候也不用
;;担心,因为 makefile-mode 会把 TAB 键设置成真正的 TAB 字符,并且加亮显示的
(setq-default indent-tabs-mode nil)
(setq default-tab-width 8)
(setq tab-stop-list ())
;(loop for x downfrom 40 to 1 do
; (setq tab-stop-list (cons (* x 4) tab-stop-list)))
;;把这些缺省禁用的功能打开
(put 'set-goal-column 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'LaTeX-hide-environment 'disabled nil)
;;-------------------------让Emacs拥有tabs-------------------
;;http://learn.tsinghua.edu.cn/homepage/2001315450/emacs_elisp.html
;;到上面的网页下载tabbar.el 保存到/usr/share/emacs/site-lisp/
(require 'tabbar)
(tabbar-mode)
(define-prefix-command 'lwindow-map)
;;(global-set-key (kbd "") 'lwindow-map)
(global-set-key (kbd "") 'tabbar-backward-group)
(global-set-key (kbd "") 'tabbar-forward-group)
(global-set-key (kbd "") 'tabbar-backward)
(global-set-key (kbd "") 'tabbar-forward)
;;使用Win+方向键在tabbed buffer之间切换
;;调整tab的配色
(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.
'(tabbar-selected-face ((t (:inherit tabbar-default-face :background "#F0F0E8" :foreground "black" :box (:line-width 2 :color "white" :style released-button) :weight semi-bold :height 1.3))))
'(tabbar-unselected-face ((t (:inherit tabbar-default-face :background "grey" :foreground "black" :box (:line-width 2 :color "grey" :style pressed-button) :height 1.3)))))
;;;;;;;;;; global setting
;;(set-scroll-bar-mode nil) ;; 去掉滚动条
;;(tool-bar-mode -1) ;; 去掉工具栏
(setq require-final-newline t) ;; 以空行结束
(add-to-list 'load-path (expand-file-name "F:/emacs/site-lisp/")) ;; set load-path
(setq visible-bell t) ;; 关闭出错时的提示声
(setq inhibit-startup-message t) ;;关闭开启画面
(setq column-number-mode t) ;; 显示列号
(setq mouse-yank-at-point t) ;; 用光标定位文本插入位置
(setq kill-ring-max 200) ;; 设置粘贴缓冲条目数量
(setq enable-recursive-minibuffers t) ;; 设置递归使用minibuffer
;;(setq scroll-margin 3
;; scroll-conservatively 10000) ;;防止页面滚动时跳动
(setq default-major-mode 'text-mode) ;;设置默认模式是text mode
(show-paren-mode t)
(setq show-paren-style 'parentheses) ;; 设置显示括号匹配,但不跳转
(mouse-avoidance-mode 'animate) ;;让鼠标不要挡住光标
(setq user-full-name "kpld")
(setq user-mail-address "kpld@hotmail.com")
(setq frame-title-format "emacs@%b") ;;在标题栏显示buffer的名字,而不是 emacs@wangyin.com 这样没用 的提示。
(global-font-lock-mode t) ;; 进行语法加亮
(setq next-line-add-newlines nil
resize-mini-windows t
track-eol t
kill-whole-line t
Man-notify-method 'pushy
woman-cache-level 2
woman-cache-filename nil
uniquify-buffer-name-style 'forward
vc-follow-symlinks t
line-move-ignore-invisible t
ring-bell-function 'ignore
tooltip-gud-tips-p t)
;;让emacs在windows上启动时最大化
;;修改注册表如下
;;[HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs]
;;"EMACS.Toolbar"="0"
(w32-send-sys-command #xf030)
;(defun w32-restore-frame ()
;"Restore a minimized frame"
;(interactive)
;(w32-send-sys-command 61728))
;(defun w32-maximize-frame ()
;"Maximize the current frame"
;(interactive)
;(w32-send-sys-command 61488))
;(w32-maximize-frame)
;; 设置备份版本控制 start
(setq version-control t
kept-old-versions 2
kept-new-versions 5
delete-old-versions t
backup-directory-alist
'(("." . "D:/tmp")
(cons tramp-file-name-regexp nil))
backup-by-copying t
backup-by-copying-when-linked t
backup-by-copying-when-mismatch t)
(setq dired-kept-versions 1)
;; 设置备份版本控制 end
(setq dired-recursive-copies 'top) ;;让dired可以递归地拷贝和删除目录
(setq dired-recursive-deletes 'top) ;;
;; 设置显示时间
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
;;;;;;;;; 设置界面 start
(set-cursor-color "Wheat")
(set-mouse-color "Wheat")
(set-foreground-color "Wheat")
(set-background-color "DarkSlateGray")
;(if window-system
; (setq default-frame-alist
; (append
; '( (top . 80)
; (left . 100)
; (width . 110)
; (height . 35))
; default-frame-alist))
;)
;;;;;;;;; 设置界面 end
;;;;; Esay Edit for C++/C programming
;; TAB and RET auto align and indent
(add-hook 'c++-mode-hook
(lambda ()
(c-set-style "bsd")
(hs-minor-mode)
(local-set-key "\C-c\t" 'complete-symbol)
(local-set-key "\C-m" 'newline-and-indent)
(setq mslk-c++-key (make-keymap))
(local-set-key "\C-j" mslk-c++-key)
(define-key mslk-c++-key "\C-j" 'complete-symbol)
(define-key mslk-c++-key "\C-o" 'hs-hide-all)
(define-key mslk-c++-key "\C-p" 'hs-show-all)
(define-key mslk-c++-key "\C-h" 'hs-hide-block)
(define-key mslk-c++-key "\C-u" 'hs-show-block)
(define-key mslk-c++-key "\C-l" 'hs-hide-level)
(define-key mslk-c++-key "\C-m" 'hs-toggle-hiding)
))
(add-hook 'c-mode-hook 'c++-mode)
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "\\>")
(hippie-expand nil)
(indent-for-tab-command)))
(add-hook 'c-mode-common-hook
(function (lambda ()
(define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
(define-key c-mode-base-map [(control m)] 'align-newline-and-indent)
(c-toggle-auto-state))))
;;;;;;;;;;;;;;;; 调用Lisp扩展包
;;;;;;;; load ido.el
(require 'ido)
(ido-mode t)
(autoload 'table-insert "table" "WYGIWYS table editor") ;;所见即所得做表格
(require 'recentf) ;; 保存最近打开的文件
(recentf-mode 1)
(defun recentf-open-files-compl ()
(interactive)
(let* ((all-files recentf-list)
(tocpl (mapcar (function
(lambda (x) (cons (file-name-nondirectory x) x))) all-files))
(prompt (append '("File name: ") tocpl))
(fname (completing-read (car prompt) (cdr prompt) nil nil)))
(find-file (cdr (assoc-ignore-representation fname tocpl)))))
(global-set-key [(control x)(control r)] 'recentf-open-files-compl)
;;;;;;;;;;; global key setting
(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
(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.
'(blink-cursor-mode nil nil (frame))
'(column-number-mode t)
'(cua-mode nil)
'(global-font-lock-mode t nil (font-core))
'(show-paren-mode t nil (paren)))
(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.
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 在EMACS中浏览WEB网页并支持中文 ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; (require 'w3m-load)
; (setq w3m-display-inline-image t)
; (setq w3m-use-mule-ucs t)
; (setq w3m-use-toolbar t)
; (setq w3m-use-cookies t)
; (setq w3m-bookmark-file-coding-system 'chinese-iso-8bit)
; (setq w3m-coding-system 'chinese-iso-8bit)
; (setq w3m-default-coding-system 'chinese-iso-8bit)
; (setq w3m-file-coding-system 'chinese-iso-8bit)
; (setq w3m-file-name-coding-system 'chinese-iso-8bit)
; (setq w3m-terminal-coding-system 'chinese-iso-8bit)
; (setq w3m-input-coding-system 'chinese-iso-8bit)
; (setq w3m-output-coding-system 'chinese-iso-8bit)
; (setq w3m-tab-width 8)
; (setq w3m-home-page "http://www.gun.org")
; (setq w3m-view-this-url-new-session-in-background t)
; (add-hook 'w3m-fontify-after-hook 'remove-w3m-output-garbages)
; (defun remove-w3m-output-garbages()
; (interactive)
; (let ((buffer-read-only))
; (setf (point) (point-min))
; (while (re-search-forward "[\200-\240]" nil t)
; (replace-match " "))
; (set-buffer-multibyte t))
; (set-buffer-modified-p nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of configure W3M in Emacs ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Begin of configure Gnus in Emacs ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Gnus 是个古老的,强大的邮件,新闻阅读lisp程序.
;;设置头像文件可惜我一直没搞定
;(setq message-required-news-headers
; (nconc message-required-news-headers
; (list '(X-Face . gnus-random-x-face))))
;;用户资料设定
;(setq user-full-name "kpld")
;(setq user-mail-address "kpld@222.com")
;;服务器的设定
;(setq gnus-select-method '(nntp "news.yaako.com"))
;(add-to-list 'gnus-secondary-select-methods '(nntp "news.newsfan.net"))
;(add-to-list 'gnus-secondary-select-methods '(nntp "news.php.net"))
;(add-to-list 'gnus-secondary-select-methods '(nntp "news.newsgroup.com.hk"))
;(add-to-list 'gnus-secondary-select-methods '(nntp "news.CN99.com"))
;(add-to-list 'gnus-secondary-select-methods '(nntp "groups.google.com"))
;;开启代理功能,为了能让gnus支持离线浏览,gnus 5.10.x会自动开启该功能。
;(gnus-agentize)
;;自动换行功能。
;(add-hook 'message-mode-hook
; (lambda ()
; (setq fill-column 72);;这里的72是等一行到了72个字符后开始换行
; (turn-on-auto-fill)))
;(setq message-cite-function 'message-cite-original-without-signature)
;; 设定帖子的字符集
;(setq gnus-summary-show-article-charset-alist '((1 . cn-gb-2312) (2 . big5)))
;(setq gnus-default-charset 'cn-gb-2312) ;; 默认编码
;(setq gnus-group-name-charset-group-alist '((".*" . cn-gb-2312))) ;; 组名编码
;(setq gnus-summary-show-article-charset-alist '((1 . cn-gb-2312) (2 . big5))) ;; 刷新编码
;(setq gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown iso-8859-1)) ;; 忽略编码
;; 改变阅读新闻时窗口的布局,窗口划分为上4下6(比例)
;(gnus-add-configuration '(article
; (vertical 1.0
; (summary .4 point)
; (article 1.0))))
;;开启记分
;(setq gnus-use-adaptive-scoring t)
;(setq gnus-save-score t)
;(add-hook 'mail-citation-hook 'sc-cite-original)
;(add-hook 'message-sent-hook 'gnus-score-followup-article)
;(add-hook 'message-sent-hook 'gnus-score-followup-thread)
;(defvar gnus-default-adaptive-score-alist
; '((gnus-kill-file-mark (from -10))
; (gnus-unread-mark)
; (gnus-read-mark (from 10) (subjnnect 30))
; (gnus-catchup-mark (subject -10))
; (gnus-killed-mark (from -1) (subject -30))
; (gnus-del-mark (from -2) (subject -15))
; (gnus-ticked-mark (from 10))
; (gnus-dormant-mark (from 5))))
;(setq gnus-score-find-score-files-function
; '(gnus-score-find-hierarchical gnus-score-find-bnews bbdb/gnus-score)
; gnus-use-adaptive-scoring t)
;;;
;(setq gnus-confirm-mail-reply-to-news t
; message-kill-buffer-on-exit t
; message-elide-ellipsis "[...]\n"
; )
;;排序
;(setq gnus-thread-sort-functions
; '(
; (not gnus-thread-sort-by-date)
; (not gnus-thread-sort-by-number)
; ))
;; 新闻组分组
;; 有时订阅了很多新闻组,堆在一起不好管理。这个功能可以创建目录来分层管理
;; 这些新闻组。
;; group topic
;(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
;; 现在可以在group buffer里面M-x gnus-topic-create-topic来创建一个"topic",
;; 然后将某个新闻组或者其他topic给C-k掉,再移动到你创建的topic下C-y,就可以
;; 将它们收到这个topic下。
;; topic的好处除了分层之外,还有就是可以将不常看的topic折叠起来,不要显示。
;; 就像下面这样。
;;
;; [ Gnus -- 0 ]
;; [ MAIL -- 3 ]...
;; [ NEWS -- 0 ]
;; [ emacs -- 0 ]
;; *: nntp+binghe.6600.org: gnu.emacs.help
;; *: nntp+binghe.6600.org:gnu.emacs.gnus
;; [ 人文与社会 -- 0 ]
;; [ 语言 -- 0 ]
;; *: nntp+news.newsfan.net:教育就业.外语.日语
;; *: nntp+news.newsfan.net: 教育就业.外语.英语
;; [ misc -- 0 ]...
;;
;; 参考 gnus info -> Group Buffer -> Group Topics
;;中文设置
;(setq gnus-summary-show-article-charset-alist
; '((1 . cn-gb-2312) (2 . big5) (3 . gbk) (4 . utf-8)))
;(setq
; gnus-default-charset 'cn-gb-2312
; gnus-group-name-charset-group-alist '((".*" . cn-gb-2312))
; gnus-newsgroup-ignored-charsets
; '(unknown-8bit x-unknown iso-8859-1 ISO-8859-15 x-gbk GB18030 gbk DEFAULT_CHARSET))
;另外,有些用web方式发出的邮件里有html,加入下面的设置,只看其中的
;plain text部分:
;(eval-after-load "mm-decode"
; '(progn
; (add-to-list 'mm-discouraged-alternatives "text/html")
; (add-to-list 'mm-discouraged-alternatives "text/richtext")))
;;设置头像文件
;(setq gnus-posting-styles
; '((".*"
; (name "YouName")
; (face "")
;;这个我都是抄老外的,自己找去,在Gnus里看到好的头像,然后到
;;groups.google里把他的字符串贴过来 -_-!
; (address "YouEmail@gmail.com")
; (organization "www.emacs.cn")
; (signature "
; My name is K T")
; )
;))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; End of configure Gnus in Emacs ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;自动补全功能
(global-set-key [(meta ?/)] 'hippie-expand)
(setq hippie-expand-try-functions-list
'(try-expand-line
try-expand-line-all-buffers
try-expand-list
try-expand-list-all-buffers
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name
try-complete-file-name-partially
try-complete-lisp-symbol
try-complete-lisp-symbol-partially
try-expand-whole-kill))
;; 代码折叠
(load-library "hideshow")
(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)