Simon的emacs 配置

作者: csbde 分类: SoftWare 发布时间: 2008-12-06 22:39

;; Inhibit spalsh message (setq inhibit-startup-message t) (setq inhibit-splash-screen t) (setq initial-scratch-message nil) ;;load path (add-to-list 'load-path "~/.emacs.d/site-lisp/") ;;一些保存路径 (setq todo-file-do "~/.emacs.d/todo/do") (setq todo-file-done "~/.emacs.d/todo/done") (setq todo-file-top "~/.emacs.d/todo/top") (setq diary-file "~/.emacs.d/diary") ;; stop when error occupied (add-hook 'after-init-hook (lambda() (setq debug-on-error t))) ;; determine OS type (defvar running-on-windows (equal system-type 'windows-nt) "If use emacs on windows, it is true." ) (defvar running-on-linux (equal system-type 'gnu/linux) "If use emacs on Linux, it is true." ) ;; Set language (when running-on-linux (set-language-environment 'utf-8) ;; default-coding-systems include [keyboard/terminal/file-name]-coding-system (set-default-coding-systems 'utf-8) (set-clipboard-coding-system 'utf-8) (set-buffer-file-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (setq-default pathname-coding-system 'utf-8) ) ;;If Run On windows (when running-on-windows ;;去除工具条 (tool-bar-mode nil) ;;去除菜单栏 (menu-bar-mode nil) ;;推荐关闭行号窗口中的滚动条 (set-scroll-bar-mode nil) ;;最大化Emacs窗口 (require 'maxframe) (add-hook 'window-setup-hook 'maximize-frame t) (setq ascii-font "-outline-Courier New-normal-r-normal-normal-13-97-96-96-c-*-iso8859-1") (setq chinese-font "-outline-宋体-normal-r-normal-normal-13-*-96-96-c-*-iso10646-1") (defun wheer-set-font (en-font cn-font) (create-fontset-from-fontset-spec (replace-regexp-in-string "iso8859-1" "fontset-wheer" en-font)) (set-fontset-font "fontset-wheer" 'gb18030 cn-font) (set-fontset-font "fontset-wheer" 'latin en-font) (set-fontset-font "fontset-default" 'gb18030 cn-font) (set-fontset-font "fontset-default" 'latin en-font) (set-default-font "fontset-wheer") (setq default-frame-alist (append '((font . "fontset-wheer")) default-frame-alist))) (wheer-set-font ascii-font chinese-font) (set-language-environment "Chinese-GB18030") (setq file-name-coding-system 'gb18030) ) ;; convert dos to UNIX, or UNIX to dos. emacs command: 'C-x RET f unix/dos RET' (defun dos2unix() "convert dos to unix" (interactive) (goto-char (point-min)) (while (search-forward "rn" nil t) (replace-match "n")) ) (defun unix2dos() "convert unix to dos" (interactive) (goto-char (point-min)) (while (search-forward "n" nil t) (replace-match "rn")) ) (dos2unix) ;; start emacs server in default (server-mode) ;;(server-start) ;; set read-only when open a file ;;(add-hook 'find-file-hook (lambda()(setq buffer-read-only t))) ;;(setq kill-read-only-ok t) ;;(setq buffer-read-only t) ;;高亮显示匹配的括号 (show-paren-mode t) (setq show-paren-style 'parentheses) ;; save emacs history and desktop (savehist-mode t) ;; Display battery (display-battery-mode t) ;;Show Row Number (require 'setnu) ;;Set title name is buffer name, file(%f) frame(%F), buffer(%b) (setq frame-title-format "%b") ;; Set autosave (setq auto-save-interval 50) (setq auto-save-timeout 10) ;; highlight selection (setq transient-mark-mode t) ;; Nicer scroll (setq scroll-step 1) ;; stop ring (setq visible-bell nil) ;; Don't ask yes-or-no, use y-or-n ;;(fset 'yes-or-no-p 'y-or-n-p) (defalias 'yes-or-no-p 'y-or-n-p) ;; Please stop blinking! (if (fboundp 'blink-cursor-mode) (blink-cursor-mode 0)) ;; make temp buffer fit to size (setq even-window-heights nil) (temp-buffer-resize-mode t) (setq temp-buffer-max-height (lambda(buffer) (min 15 (/ (- (frame-height) 2) 2)))) ;; Display tiem stamp (setq time-stamp-toggle-active t) ;;使用Ibuffer (require 'ibuffer) (global-set-key (kbd "C-x C-b") 'ibuffer) ;;颜色设置 ;;在非窗口环境的时候置颜色 (cond ((not window-system) ;; 如果不在 window 环境中(字符界面时) (setq frame-background-mode 'dark) ;; 设置背景为黑的,这样 Emacs 的很多缺省颜色会和黑色背景协调。 (eval-after-load "log-view" ;; 设置 log-view 的颜色。 '(progn (set-face-attribute 'log-view-file-face nil :foreground "blue" :weight 'bold) (set-face-attribute 'log-view-message-face nil :foreground "yellow" :weight 'bold)))) ;;窗口环境下的设置 ((window-system) (setq default-frame-alist '( (foreground-color . "Wheat") (background-color . "DarkSlateGray") (cursor-color . "Orchid") ) ))) ;;状态栏显示行号 (setq column-number-mode t) (setq line-number-mode t) ;;enable to bidirectionally copy and paste between X app with emacs;可以从外面拷东西 (setq x-select-enable-clipboard t) ;; 显示时间 (setq display-time-24hr-format t) (setq display-time-day-and-date t) (display-time) ;;可以操作压缩文档 (auto-compression-mode 1) ;;鼠标自动避开指针;如当你输入的时候;指针到了鼠标的位置;鼠标有点挡住视线了 (mouse-avoidance-mode 'animate) ;; 设置默认模式为Text (setq default-major-mode 'text-mode) ;; 让Emacs可以打开和显示图片 (auto-image-file-mode) ;; highlight selection 高亮当前行 (require 'hl-line) (global-hl-line-mode t) ;; 配置Shell颜色 (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) (setq ansi-color-for-comint-mode t) ;; ======================== ;; ==== Feature Setting ==== ;; ======================== ;; Emacs 中,改变文件时,默认都会产生备份文件(以 ~ 结尾的文件)。可以完全去掉 ;; (并不可取),也可以制定备份的方式。这里采用的是,把所有的文件备份都放在一 ;; 个固定的地方("~/var/tmp")。对于每个备份文件,保留最原始的两个版本和最新的 ;; 五个版本。并且备份的时候,备份文件是复本,而不是原件。 (setq version-control t) (setq kept-old-versions 2) (setq kept-new-versions 5) (setq delete-old-versions t) (setq backup-directory-alist '(("." . "~/var/tmp"))) (setq backup-by-copying t) ;; 在行首 C-k 时,同时删除该行。 (setq-default kill-whole-line t) ;; auto-newline 子模式,自动换行缩进; ;; hungry-delete 子模式,一个 Backspace 删除尽可能多的空白; ;; which-func-mode 在模式行中显示当前行在哪个函数中。 (add-hook 'c-mode-common-hook (lambda () (c-toggle-auto-hungry-state 1) (which-func-mode 1))) ;;可以递归的删除目录 (setq dired-recursive-deletes t) ;;可以递归的进行拷贝 (setq dired-recursive-copies t) ;; 1. s s 按照文件大小排序。 ;; 2. s x 按照文件扩展名排序。 ;; 3. s t 按照文件访问时间排序。 ;; 4. s n 按照文件名称的字母顺序排序。 (add-hook 'dired-mode-hook (lambda () (interactive) (make-local-variable 'dired-sort-map) (setq dired-sort-map (make-sparse-keymap)) (define-key dired-mode-map "s" dired-sort-map) (define-key dired-sort-map "s" '(lambda () "sort by Size" (interactive) (dired-sort-other (concat dired-listing-switches "S")))) (define-key dired-sort-map "x" '(lambda () "sort by eXtension" (interactive) (dired-sort-other (concat dired-listing-switches "X")))) (define-key dired-sort-map "t" '(lambda () "sort by Time" (interactive) (dired-sort-other (concat dired-listing-switches "t")))) (define-key dired-sort-map "n" '(lambda () "sort by Name" (interactive) (dired-sort-other (concat dired-listing-switches "")))))) ;; ======================== ;; ==== Compile Setting ==== ;; ======================== (defun smart-compile () "Simply compile your file according to the file type." (interactive) (save-some-buffers t) (let ((compile-command nil) (alist (list '(".c$" . "gcc -Wall ") '(".cc$" . "g++") '(".cpp$" . "g++")))) (while (not (null alist)) (if (string-match (caar alist) (buffer-file-name)) (setq compile-command (concat (cdar alist) " " """ (buffer-file-name) """ " -ggdb3 " ))) (setq alist (cdr alist))) (if (null compile-command) (setq compile-command (read-from-minibuffer "Compile command: "))) (compile compile-command) )) ;; set compile command ;; (setq compile-command '"gcc -Wall -O2 %b -ggdb3 -o") ;; enable windmove key binding, S-up/down/left/right (windmove-default-keybindings) ;; font lock (global-font-lock-mode t) ;; cwarn (global-cwarn-mode t) ;; define my mode function, and bind it to many edit mode. (defun my-common-mode() ;; convert tab to space (setq-default indent-tabs-mode nil) ;; hideshow mode (hs-minor-mode) ) ;; for c and c++ (defun my-cc-mode() ;; load my define mode (my-common-mode) ;; use "stroustrup" as basical c style, but modify tab width in below. (c-set-style "stroustrup") (setq default-tab-width 2) ;; use (defvar Variable) to impl dynamic variable (defvar c-basic-offset) (setq c-basic-offset 2) ;; useful key binding. use (defvar Variable) to impl dynamic variable (defvar c-mode-base-map) (define-key c-mode-base-map [(f5)] 'smart-compile) (define-key c-mode-base-map [(f6)] 'gdba) ) ;;(add-hook 'text-mode-hook 'my-common-mode) ;;(add-hook 'makefile-mode-hook 'my-common-mode) (add-hook 'c-mode-common-hook 'my-cc-mode) (add-hook 'cc-mode-common-hook 'my-cc-mode) (add-hook 'idl-mode-hook 'my-cc-mode) (add-hook 'java-mode-hook 'my-common-mode) (add-hook 'diff-mode-hook 'my-common-mode) (add-hook 'perl-mode-hook 'my-common-mode) (add-hook 'php-mode-hook 'my-common-mode) (add-hook 'lisp-mode-hook 'my-common-mode) (add-hook 'emacs-lisp-mode-hook 'my-common-mode) ;; gdb (setq gdb-many-windows t) ;; ======================== ;; ===== Key bind ==== ;; ======================== (global-set-key [f3] (quote setnu-mode)) ;;跳转到 Emacs 的另一个窗口 (global-set-key (kbd "") 'other-window) (global-set-key (kbd "") 'dired) (global-set-key (kbd "") 'shell-command) (global-set-key (kbd "C-") 'shell) (global-set-key (kbd "") 'eshell) (global-set-key (kbd "C-c C-g") 'goto-line) ;; ======================== ;; == 3rd part plugins == ;; ======================== ;;ecb setting (when (locate-library "ecb") (require 'ecb-autoloads) ;;加载ecb (setq ecb-auto-activate nil ecb-tip-of-the-day nil ecb-tree-indent 4 ecb-windows-height 0.5 ecb-windows-width 0.18 ecb-auto-compatibility-check nil ecb-version-check nil inhibit-startup-message t) ;;ecb绑定 (global-set-key (kbd "C-x C-1") 'ecb-goto-window-directories) (global-set-key (kbd "C-x C-2") 'ecb-goto-window-sources) (global-set-key (kbd "C-x C-3") 'ecb-goto-window-methods) (global-set-key (kbd "C-x C-4") 'ecb-goto-window-history) (global-set-key (kbd "C-x C-0") 'ecb-goto-window-edit-last) ;; set F12 to activate ecb and Ctrl + F12 to deactive it. (global-set-key (kbd "") 'ecb-activate) (global-set-key (kbd "C-") 'ecb-deactivate) ) ;; cedet (when (locate-library "cedet") (require 'cedet) ) ;; session (when (locate-library "session") (require 'session) (add-hook 'after-init-hook 'session-initialize) ) ;;doxymacs (when (locate-library "doxymacs") (require 'doxymacs) (add-hook 'c-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode (add-hook 'c++-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode ) ;; xcscope (when (locate-library "xcscope") (require 'xcscope) ;; define a function to set list entry window height, and add it to hook (defun cscope-set-list-entry-window-height (wanted-height) "set cscope-list-entry-window height." (interactive) (shrink-window (- (window-height) wanted-height)) (recenter 1)) (add-hook 'cscope-list-entry-hook (lambda() (cscope-set-list-entry-window-height 11))) ) ;; ======================== ;; == custom set == ;; ======================== (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. '(display-time-mode t) '(ecb-gzip-setup (quote cons)) '(ecb-options-version "2.32") '(ecb-tar-setup (quote cons)) '(ecb-wget-setup (quote cons)) '(transient-mark-mode t) '(weblogger-config-alist (quote (("Simon" ("user" . "admin") ("server-url" . "http://www.9wy.net/xmlrpc.php") ("weblog" . "1")))))) (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. ) ;; Set personal infomation (setq user-full-name "SimonCHEN") (setq user-mail-address "[email protected]") ;;Calendar Setting ;; 设置 calendar 的显示 (setq calendar-remove-frame-by-deleting t) (setq calendar-week-start-day 1) ;;设置星期一为每周的第一天 (setq mark-diary-entries-in-calendar t) ;;标记calendar上有diary的日期 (setq mark-holidays-in-calendar nil) ;;为了突出有diary的日期,calendar上不标记节日 (setq view-calendar-holidays-initially nil) ;;打开calendar的时候不显示一堆节日 ;; 让emacs能计算日出日落的时间,在 calendar 上用 S 即可看到 (setq calendar-latitude +31.27) (setq calendar-longitude +104.10) (setq calendar-location-name "SiChuan") ;; 去掉不关心的节日,设定自己在意的节日,在 calendar 上用 h 显示节日 (setq christian-holidays nil) (setq hebrew-holidays nil) (setq islamic-holidays nil) (setq solar-holidays nil) ]]>

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注