主题: 我的emacs配置文件
作者: Roddy, 发布日期: 2009-01-24 23:39:57, 浏览数: 8014

KindEditor是用emacs编辑器开发的,以下是我的dot emacs。

;; Roddy's emacs file
;; Created: 25-Aug-2008
;; Last Modified: 28-Sep-2008

;; display time
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; paren highlighting
(show-paren-mode t)

;; no backup files
(setq make-backup-files nil)

;; auto revert
(global-auto-revert-mode 1)

;; when beginning of line, delete the line
(setq-default kill-whole-line t)

;; display column and line number
(setq column-number-mode t)
(setq line-number-mode t)

;; don't display startup page
(setq inhibit-startup-message t)

;; UTF-8 setup
(set-language-environment "Chinese-GB")
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(defalias 'ucode 'universal-coding-system-argument)

;; TAB setup
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)

;; default mode
(setq default-major-mode 'text-mode)

;; Perl coding rule
(defalias 'perl-mode 'cperl-mode)
(add-hook 'cperl-mode-hook
'(lambda()
(local-set-key (kbd "C-h f") 'cperl-perldoc)
(setq cperl-indent-level 4)
(setq cperl-continued-statement-offset 4)
(setq cperl-continued-brace-offset -4)
(setq cperl-brace-offset 0)
(setq cperl-label-offset -2)
(setq cperl-tab-always-indent nil)
(setq cperl-extra-newline-before-brace nil)
(setq cperl-extra-newline-before-brace-multiline nil)))
(custom-set-faces
'(cperl-array-face ((t (:foreground "yellow" :weight bold))))
'(cperl-hash-face ((t (:foreground "red" :weight bold)))))

;; for template file
(add-to-list 'auto-mode-alist '("\\.tmpl$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.tpl$" . html-mode))

;; for php file
(add-to-list 'load-path "~/")
(require 'php-mode)
(add-to-list 'auto-mode-alist
'("\\.php[34]?\\'\\|\\.phtml\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.module\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc\\'" . php-mode))
(add-hook 'php-mode-hook
'(lambda()
(setq tab-width 4)
(setq c-basic-offset 4)
(setq indent-tabs-mode nil)))

;; for po file
(add-to-list 'auto-mode-alist '("\\.po$" . po-mode))

;; for javascript file
(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))

;; for css file
(autoload 'css-mode "css-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(defcustom css-indent-level 4 "Number of spaces for each indent step.")

;; turn on font-lock mode
(defface my-face-b-1 '((t (:background "yellow"))) nil)
(defface my-face-b-2 '((t (:background "gray"))) nil)
(defface my-face-u-1 '((t (:foreground "red" :underline t))) nil)
(defface my-face-u-2 '((t (:background "red"))) nil)
(defvar my-face-b-1 'my-face-b-1)
(defvar my-face-b-2 'my-face-b-2)
(defvar my-face-u-1 'my-face-u-1)
(defvar my-face-u-2 'my-face-u-2)
(defadvice font-lock-mode (before my-font-lock-mode ())
(font-lock-add-keywords
major-mode
'(
(" " 0 my-face-b-1 append)
("\t" 0 my-face-b-2 append)
("[ ]+$" 0 my-face-u-1 append)
("\r" 0 my-face-u-2 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
(add-hook 'find-file-hooks
'(lambda ()
(if font-lock-mode
nil
(font-lock-mode t))) t)
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))

;; set command disabled status
(put 'scroll-left 'disabled nil)

;; copy lines
(defun copy-lines(&optional arg)
(interactive "p")
(save-excursion
(beginning-of-line)
(set-mark (point))
(next-line arg)
(kill-ring-save (mark) (point))))

;; ido
(ido-mode 'buffer)

;; execute perl
(defun execute-perl()
"excute perl"
(interactive)
(let ((filename buffer-file-name)
(cmd "")
(oldbuf (current-buffer))
(end (point-max)))
(if filename
(save-buffer)
(save-excursion
(setq filename (concat (getenv "tmp") "/temp.pl"))
(set-buffer (create-file-buffer filename))
(insert-buffer-substring oldbuf 1 end)
(write-file filename)
(kill-buffer (current-buffer))))
(setq cmd (concat "perl -w " filename))
(message "%s ..." cmd)
(shell-command cmd)))

;; my key
(global-set-key [f3] 'replace-string)
(global-set-key [f4] 'replace-regexp)
(global-set-key [f5] 'undo)
(global-set-key [f6] 'copy-lines)
(global-set-key [f7] 'toggle-truncate-lines)
(global-set-key [f8] 'execute-perl)
(global-set-key "\M-g" 'goto-line)
(global-set-key "\C-x," 'scroll-right)
(global-set-key "\C-x." 'scroll-left)

发表新帖 发表回复