2008年10月14日 星期二

我的 emacs 配置文件




~/.emacs

;;======================
;; emacs 设置
;;======================

;; 将emacs作为server使用,目前我给mutt使用
(server-start)

;; Tab = 4 spaces
(setq default-tab-width 4)

;; 是配置文件立即生效
;M-x eval-current-buffer

;; 禁用工具栏
(tool-bar-mode nil)

;; 禁用滚动栏,用鼠标滚轮替代
; 滚动条的值可以是 nil 'left 'right
; (set-scroll-bar-mode 'left)
(scroll-bar-mode nil)

;; 禁用菜单栏,F10开启或关闭菜单
(menu-bar-mode nil)


;; 禁用启动画面
(setq inhibit-startup-message t)


;;====================
;; 键绑定
;;====================
;; 绑定键设置时注明键对应的命令是个好习惯

;; C-z 设置标记 ;; C-z: M-x iconify-or-deiconify-frame: C-z,C-x C-z
(global-set-key (kbd "C-z") 'set-mark-command)

;; F10 显示/隐藏菜单 ;; M-x menu-bar-open
;;(global-set-key (kbd "F10") 'menu-bar-mode)

;; 语言环境和字体设置
(set-language-environment 'utf-8)
(prefer-coding-system 'utf-8)

;;(set-fontset-font "fontset-default" 'gb18030 '("Microsoft YaHei" . "unicode-bmp"))
;(set-default-font "Monospace-12")
(set-default-font "WenQuanYi Zen Hei-13")
(set-fontset-font (frame-parameter nil 'font)
'unicode '("WenQuanYi Zen Hei" . "unicode-bmp"))
(set-fontset-font (frame-parameter nil 'font)
'han '("WenQuanYi Zen Hei" . "unicode-bmp"))
(set-fontset-font (frame-parameter nil 'font)
'symbol '("WenQuanYi Zen Hei" . "unicode-bmp"))
(set-fontset-font (frame-parameter nil 'font)
'cjk-misc '("WenQuanYi Zen Hei" . "unicode-bmp"))
(set-fontset-font (frame-parameter nil 'font)
'bopomofo '("WenQuanYi Zen Hei" . "unicode-bmp"))


;; 指针颜色设置为白色,seems not working, add it at the bottom
(set-cursor-color "white")
;; 鼠标颜色设置为白色
(set-mouse-color "white")
; 设置光标
; (set-default 'cursor-type 'bar)
(setq-default cursor-type 'box)

;; 设置背景颜色和字体颜色
(set-foreground-color "#FDFF00")
(set-background-color "#343434") ;;增强对比度
;; 设置另外一些颜色:语法高亮显示的背景和主题,区域选择的背景和主题,二次选择的背景和选择
(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")
;;设置日历的一些颜色
(setq calendar-load-hook
'(lambda ()
(set-face-foreground 'diary-face "skyblue")
(set-face-background 'holiday-face "slate blue")
(set-face-foreground 'holiday-face "white")))

;;hilights grammer
(global-font-lock-mode t)


;;时间显示设置
;;启用时间显示设置,在minibuffer上面的那个杠上(忘了叫什么来着)
(display-time-mode 1)
;;时间使用24小时制
(setq display-time-24hr-format t)
;;时间显示包括日期和具体时间
(setq display-time-day-and-date t)

;;所有的问题用y/n方式,不用yes/no方式。
(fset 'yes-or-no-p 'y-or-n-p)

;;鼠标自动避开指针,如当你输入的时候,指针到了鼠标的位置,鼠标有点挡住视线了
(mouse-avoidance-mode 'animate)
;;允许自动打开图片,如wiki里面
(auto-image-file-mode)
;;可以操作压缩文档
(auto-compression-mode 1)
;;在minibuffer上面可以显示列号
(column-number-mode t)
;;显示默认的文档的宽度,看起来比较舒服?
(setq fill-column 72)
(setq default-fill-column 72)
;;设置文本的行距
(setq default-line-spacing 1)
;;指针不要闪
(blink-cursor-mode -1)
(transient-mark-mode 1)
;;当指针到一个括号时,自动显示所匹配的另一个括号
(show-paren-mode 1)
;;是用滚轴鼠标
(mouse-wheel-mode t)
;;去掉烦人的警告铃声
(setq visible-bell t)
;;滚动页面时比较舒服
(setq scroll-step 1
scroll-margin 3
scroll-conservatively 10000)

;;不产生备份文件
(setq make-backup-files nil)

;;开启图片浏览
(auto-image-file-mode t)

;在标题栏显示目前在什么位置
(setq frame-title-format "yang@%b")

;Emacs fill设置
(setq adaptive-fill-regexp "[ \t]+\\|[
\t]*\\([0-9]+\\.\\|\\*+\\)[ \t]*")
(setq adaptive-fill-first-line-regexp "^\\* *$")

(put 'upcase-region 'disabled nil)

(put 'erase-buffer 'disabled nil)

;;Emacs-muse的配置部分
(require 'muse-mode)
(require 'muse-html)
(require 'muse-wiki nil t)
(require 'muse-project)
; 设置编码方式为 utf-8
(setq muse-html-meta-content-type (concat "text/html; charset=utf-8"))
; 新建一个 wiki 工程
(setq muse-project-alist
'(("wiki"
("~/doc/wiki/muse" :default "index")
(:base "html" :path "~/doc/wiki/publish"))
("linux"
("~/doc/wiki/muse/free" :default "index")
(:base "html" :path "~/doc/wiki/publish/free"))
("文学"
("~/doc/wiki/muse/文学" :default "index")
(:base "html" :path "~/doc/wiki/publish/文学"))
("健康"
("~/doc/wiki/muse/健康" :default "index")
(:base "html" :path "~/doc/wiki/publish/健康"))))
; 在设置图片位置的时候,以当前编辑文件将要发布到的目录为基准
(setq muse-colors-inline-image-method 'muse-colors-use-publishing-directory)
; 增加 tag ,它使用source-highlight高亮muse中的代码
(defun muse-publish-source-tag (beg end attrs)
(let ((lang (cdr (assoc "lang" attrs)))
(style (muse-style-element :base))
hcodes)
(if (string-equal style "pdf") (setq style "latex"))
(if lang
(progn
(muse-publish-command-tag
beg end
(cons (cons "interp" (format "echo \"

$(source-highlight -s %s -f %s)
\"" lang style))
attrs))
(muse-publish-mark-read-only beg (point)))
(error "No lang attribute specified in tag"))))

(add-to-list
'muse-publish-markup-tags '("source" t t nil muse-publish-source-tag))

;; 农历
;(add-to-list 'load-path "~/.emacs.d/")
;(require 'chinese-calendar)


;; 用标签显示打开的文件
;(require 'tabbar)
;(tabbar-mode)
;(global-set-key (kbd "S-") 'tabbar-backwark-group)
;(global-set-key (kbd "S-") 'tabbar-forward-group)
;(global-set-key (kbd "S-") 'tabbar-backward)
;(global-set-key (kbd "S-") 'tarbbar-forward)

;; color-theme
(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
(require 'color-theme)
(color-theme-select)
(color-theme-robin-hood)
;(color-theme-gnome2)

;; sdcv 翻译单词
;; author: pluskid
;; 调用 stardict 的命令行接口来查辞典
;; 如果选中了 region 就查询 region 的内容,
;; 否则就查询当前光标所在的词

; 使用tooltip方式显示结果,必须在 X 下
;(global-set-key (kbd "C-c d") 'kid-star-dict)
;(defun kid-star-dict ()
; (interactive)
; (let ((begin (point-min))
; (end (point-max)))
; (if mark-active
; (setq begin (region-beginning)
; end (region-end))
; (save-excursion
; (backward-word)
; (mark-word)
; (setq begin (region-beginning)
; end (region-end))))
; ;; 有时候 stardict 会很慢,所以在回显区显示一点东西
; ;; 以免觉得 Emacs 在干什么其他奇怪的事情。
; (message "searching for %s ..." (buffer-substring begin end))
; (tooltip-show
; (shell-command-to-string
; (concat "sdcv -n "
; (buffer-substring begin end))))))

; 打开一个buffer显示查询结果
(global-set-key (kbd "C-c d") 'kid-sdcv-to-buffer)
(defun kid-sdcv-to-buffer ()
(interactive)
(let ((word (if mark-active
(buffer-substring-no-properties (region-beginning) (region-end))
(current-word nil t))))
(setq word (read-string (format "Search the dictionary for (default %s): " word)
nil nil word))
(set-buffer (get-buffer-create "*sdcv*"))
(buffer-disable-undo)
(erase-buffer)
(let ((process (start-process-shell-command "sdcv" "*sdcv*" "sdcv" "-n" word)))
(set-process-sentinel
process
(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(unless (string= (buffer-name) "*sdcv*")
(setq kid-sdcv-window-configuration (current-window-configuration))
(switch-to-buffer-other-window "*sdcv*")
(local-set-key (kbd "d") 'kid-sdcv-to-buffer)
(local-set-key (kbd "q") (lambda ()
(interactive)
(bury-buffer)
(unless (null (cdr (window-list))) ; only one window
(delete-window)))))
(goto-char (point-min))))))))


;; Org mode 设置
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)

(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.
'(canlock-password "2fb8ea64b90bfcccc6e15b08800687d00c610af3"))
(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.
)


;; 绑定 F11 到emacs窗口全屏
(global-set-key [f11]
(lambda ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0))
)
)

0 评论: