我的.emacs

(global-set-key [f1] 'cvs-examine)      ; 开始 PCL-CVS
(global-set-key [f5] 'undo)             ; 或许 C-_ 或 C-/ 更方便
(global-set-key [f6] 'eshell)           ; 一个 elisp 写的 shell
(global-set-key [f7] 'calendar)         ; Emacs 的日历系统
(global-set-key [f9] 'view-mode)        ; 只读方式查看文件
(global-set-key [f8] 'other-window)     ; 跳转到 Emacs 的另一个窗口
(global-set-key [f11] 'compile)         ; 在 Emacs 中编译
(global-set-key [f12] 'gdb)             ; 在 Emacs 中调试
;; 这些功能键有时候还是很有用的。除了直接设置之外,还可以配合 Shift, Ctrl 设
;; 置,比如:
;;
;; (global-set-key [(shift f1)] 'goto-line)
;;
;; 实际上 Shift-F1 也可以用 F13 表示。

(global-set-key "\C-x\C-b" 'electric-buffer-list)

;; C-x C-b 缺省的绑定很不好用,改成一个比较方便的 electric-buffer-list,执行
;; 之后:
;;     光标自动转到 Buffer List buffer 中;
;;     n, p   上下移动选择 buffer;
;;     S      保存改动的 buffer;
;;     D      删除 buffer。
;; 除此之外,不错的选择还有 ibuffer,不妨试试 M-x ibuffer。

(global-set-key "\C-x\C-j" 'dired-jump)
;; Dired-x 在 Dired 之上又提供了很多有用的功能,这是其中之一。可以方便的在任
;; 何时候跳转到当前目录的 Dired buffer 中。

(global-set-key "\C-xk" 'kill-this-buffer)
;; 按下 C-x k 立即关闭掉当前的 buffer,需要关闭掉别的 buffer 时,按C-x C-b
;; 用 D 就 ok 了。

(global-set-key "\C-c\C-o" 'occur)
;; occur 功能,列出当前 buffer 中匹配的行。如果你在 Emacs 阅读这篇说明,试试
;; M-x occur RET chunyu RET 和 C-u 2 M-x occur RET chunyu RET。

(global-set-key "\C-c\C-v" 'view-mode)
;; 查看文件,翻页比较方便,不用 C-v M-v 了。

(global-set-key "\C-c\C-z" 'pop-global-mark)
;; 很多文件的时候,在几个文件中跳转到曾经用过的 mark 地方。

(global-set-key "\C-\\" 'toggle-truncate-lines)
;; 基本不用 Emacs 的输入法,绑定给折行命令吧

(global-set-key "\C-z" 'set-mark-command)
;; C-SPC 多数时候都是操作系统的输入法切换,set-mark-command 无论如何都要设置
;; 在一个方便的位置。而用来挂起 Emacs 的命令可以用 C-x C-z,也很方便。

(global-set-key "\M-/" 'hippie-expand)
;; 自动补全,M-/ 原来的绑定 dabbrev-expand 也是这个功能,然而 hippie-expand
;; 功能更强而且可以扩展。

(global-set-key "\M-o" 'other-window)
;; 除了在 Dired buffer 中,基本都可以用来 other-window。

(global-set-key "\M-n" 'gnus)
;; 启动新闻组客户端 gnus。

;;(global-set-key [(home)] 'beginning-of-buffer)
;;(global-set-key [(end)] 'end-of-buffer)
;; 以前的 Emacs 都是如此绑定的,Emacs 21 之后反而使我不习惯了。不过现在我已
;; 经基本不用了,因为 M-< 和 M-> 更方便。而且,如果你是新手,还是行首和行尾
;; 更直观。

;;(global-set-key [(insertchar)] 'overwrite-mode)
;; 平时用 PuTTY 登陆到 Linux 机器上使用,但是不知道为什么 INSERT 键到了
;; Emacs 中变成 insertchar 了,索性从新绑定一下。

(define-prefix-command 'ctl-x-m-map)
(global-set-key "\C-xm" 'ctl-x-m-map)
;; 定义了一个新的前缀,并且绑定到 C-x m,后面给这个前缀绑定一些键。而原来的
;; mail 对我基本没用处,或许都是因为 gnus :)。

(define-key ctl-x-m-map "s" 'dictionary-search)
;; 【dictionary.el】查词典。

(define-key ctl-x-m-map "c" 'boxquote-shell-command)
(define-key ctl-x-m-map "f" 'boxquote-describe-function)
(define-key ctl-x-m-map "i" 'boxquote-insert-file)
(define-key ctl-x-m-map "k" 'boxquote-describe-key)
(define-key ctl-x-m-map "p" 'boxquote-paragraph)
(define-key ctl-x-m-map "r" 'boxquote-region)
(define-key ctl-x-m-map "t" 'boxquote-title)
(define-key ctl-x-m-map "u" 'boxquote-unbox)
(define-key ctl-x-m-map "v" 'boxquote-describe-variable)
(define-key ctl-x-m-map "y" 'boxquote-yank)
;;【boxquote.el】在邮件或新闻组中做出漂亮的引用。

(define-key ctl-x-m-map "e" 'cvs-examine)
;; 开始 PCL-CVS。

(define-key ctl-x-m-map "m" 'man-follow)
;; 查看光标处的单词的 man page。

(define-key ctl-x-m-map "g" 'run-scheme)
;; 启动 scheme 交互环境。

(define-key ctl-x-m-map "b" 'list-bookmarks)
;; 列出所有书签。
;; C-x r m BOOKMARK RET 将当前文档的当前位置,设置为名字是 BOOKMARK 的书签;
;; C-r r b BOOKMARK RET 跳转到名字为 BOOKMARK 的书签。

(define-key ctl-x-m-map "l" 'browse-kill-ring)
;;【browse-kill-ring.el】查看 kill-ring,都曾经 kill 过哪些文本。

(define-key ctl-x-m-map "a" 'align-current)
;; 重新排列为整齐的格式。参考 EMACSDIR/lisp/align.el 的注释。

(define-key ctl-x-m-map "w" 'ibuffer)
;; 管理 Emacs 所打开的 buffer。

(define-prefix-command 'meta-m-map)
(global-set-key "\M-m" 'meta-m-map)
(define-key meta-m-map "\M-m" 'back-to-indentation)
;; 原来 M-m 所绑定的键,现在放在 M-m M-m,同时 M-m 成为了另一个前缀。

(define-key meta-m-map "\M-i" 'imenu)
;; 用当前缓冲中所定义的函数之类移动光标。imenu 自动的扫描所打开的文件,根据
;; 内容以及相应的模式判断那些可以作为索引项。打开一个已经写的差不多的 C 文件,
;; M-x imenu RET 试试。
;; 环境的设置 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq inhibit-startup-message t)
;; 不显示 Emacs 的开始画面。

(setq default-major-mode 'text-mode)
;; 任意的打开一个新文件时,缺省使用 text-mode。

(setq next-line-add-newlines nil)
;; Emacs 21 中已经是缺省设置。按 C-n 或向下键时不添加新行。

(setq require-final-newline t)
;; 存盘的时候,要求最后一个字符时换行符。

(setq resize-mini-windows nil)
;; mini buffer 的大小保持不变。

(setq track-eol t)
;; 当光标在行尾上下移动的时候,始终保持在行尾。

(setq Man-notify-method 'pushy)
;; 当浏览 man page 时,直接跳转到 man buffer。

(setq uniquify-buffer-name-style 'forward)
;; 当有两个文件名相同的缓冲时,使用前缀的目录名做 buffer 名字,不用原来的
;; foobar<?> 形式。

(setq suggest-key-bindings 1)
;; 当使用 M-x COMMAND 后,过 1 秒钟显示该 COMMAND 绑定的键。

(setq line-number-display-limit 1000000)
;; 当行数超过一定数值,不再显示行号。

(setq kill-ring-max 200)
;; kill-ring 最多的记录个数。

(setq ring-bell-function 'ignore)
;; 彻底的消除 ring-bell 的效果。

(setq apropos-do-all nil)
;; M-x apropos 时多查询些结果,但需要更多的 CPU。

(setq bookmark-save-flag 1)
;; 每当设置书签的时候都保存书签文件,否则只在你退出 Emacs 时保存。

(setq bookmark-default-file "~/.emacs.d/.emacs.bmk")
;; 缺省书签文件的路径及文件名。

(setq dired-listing-switches "-avl")
;; Dired buffer 中列出文件时传递给 ls 的参数。加个 "l" 可以使大写的文件名在
;; 顶部,临时的改变可以用 C-u s。

(setq dired-recursive-copies t)
(setq dired-recursive-deletes t)
;; 复制(删除)目录的时,第归的复制(删除)其中的子目录。

(setq cvs-dired-use-hook 'always)
;; 在一个 CVS 本地拷贝目录的 Dired buffer 中时,如果进入 CVS 目录,自动进入
;; PCL-CVS 界面。

(setq abbrev-file-name "~/.emacs.d/.abbrev_defs")
;; 缺省的定义缩写的文件。

(setq custom-file "~/.emacs.d/.emacs_custom.el")
;; M-x customize 功能保存设置的文件。默认的是 Emacs 的初始化文件 .emacs。

(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(setq display-time-use-mail-icon t)
(setq display-time-interval 10)
;; 在 mode-line 上显示时间。

(setq gnus-inhibit-startup-message t)
(setq gnus-init-file "~/.emacs.d/.gnus.el")
;; 设置 gnus 的初始化文件。

(setq mail-signature-file "~/.sig/default")
(setq mail-user-agent 'gnus-user-agent)
(setq mail-alias-file "~/.mailrc")
;; 关于 mail 的简单设置,其他的和 mail 相关的东西都在 .gnus.el 中。

(setq user-full-name "Your Name")
(setq user-mail-address "yourmail@address.com")
;; 缺省的名字和邮件地址,很多地方用得到,比如 VC(version control) 中产生
;; ChangeLog 文件。

(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S chunyu")
;; 设置时间戳,标识出最后一次保存文件的时间。

(setq diary-file "~/.emacs.d/.diary")
;; 默认的日记文件

(setq calendar-latitude +45.75)
(setq calendar-longitude +126.63)
(setq calendar-location-name "Harbin")
;; 设置所在地的经纬度和地名,calendar 可以根据这些信息告知你每天的日出和日落
;; 的时间。

(setq calendar-remove-frame-by-deleting t)
(setq calendar-week-start-day 1)
(setq christian-holidays nil)
(setq hebrew-holidays nil)
(setq islamic-holidays nil)
(setq solar-holidays nil)
(setq general-holidays '((holiday-fixed 1 1 "元旦")
                         (holiday-fixed 4 1 "愚人节")
                         (holiday-float 5 0 2 "母亲节")
                         (holiday-float 6 0 3 "父亲节")))
;; 去掉了我不感兴趣的节日。

(setq mark-diary-entries-in-calendar t)
(setq appt-issue-message nil)
(setq mark-holidays-in-calendar nil)
(setq view-calendar-holidays-initially nil)

(setq chinese-calendar-celestial-stem
      ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
(setq chinese-calendar-terrestrial-branch
      ["子" "丑" "寅" "卯" "辰" "巳" "午" "未" "申" "酉" "戌" "亥"])
;; Calendar 中 p C 可以看到我们的阴历有中文的天干地支。

(setq todo-file-do "~/.emacs.d/todo-do")
(setq todo-file-done "~/.emacs.d/todo-done")
(setq todo-file-top "~/.emacs.d/todo-top")
;; Emacs TODO 模式的相关文件。

(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)
;; Emacs 中,改变文件时,默认都会产生备份文件(以 ~ 结尾的文件)。可以完全去掉
;; (并不可取),也可以制定备份的方式。这里采用的是,把所有的文件备份都放在一
;; 个固定的地方("~/var/tmp")。对于每个备份文件,保留最原始的两个版本和最新的
;; 五个版本。并且备份的时候,备份文件是复本,而不是原件。

(setq font-lock-maximum-decoration t)
(setq font-lock-global-modes '(not shell-mode text-mode))
(setq font-lock-verbose t)
(setq font-lock-maximum-size '((t . 1048576) (vm-mode . 5250000)))
;; 语法高亮。除 shell-mode 和 text-mode 之外的模式中使用语法高亮。

(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))
;; hippie-expand 所使用的补全函数及使用的顺序。

(setq ido-enable-tramp-completion t)
;; ido 模式中,使用 tramp 的补全方式。
(setq ido-save-directory-list-file nil)
;; ido 模式中不保存目录列表。

(setq tramp-unified-filenames t)
(setq ange-ftp-generate-anonymous-password "user@cyber.net")
(setq ange-ftp-default-user t)
;; 用于编辑远程文件的 tramp 和 ange-ftp 的设置。

(setq quack-default-program "guile")
(setq quack-fontify-style nil)
;;【quack.el】scheme 的交互环境。

(setq bbdb-file "~/.emacs.d/.bbdb")
;;【bbdb】一个很好用的地址簿,保存你的联系人信息。

(setq-default kill-whole-line t)
;; 在行首 C-k 时,同时删除该行。

(set-register ?e '(file . "~/.emacs.d/.emacs.el"))
(set-register ?g '(file . "~/.emacs.d/.gnus.el"))
;; C-x r j e 就打开了我的 .emacs 配置文件。

(setenv "DISPLAY" "chunyu:0")
;; 设置显示变量,到我的 Windwos 机器,上面装了 X-Win32,用来显示 Linux 机器
;; 上的 X 程序。

(set-language-environment 'Chinese-GB)
;; 默认的语言。
(set-keyboard-coding-system 'chinese-iso-8bit)
;; 键盘输入,用于输入法。
(set-terminal-coding-system 'chinese-iso-8bit)
;; 终端显示的编码方式。
(set-clipboard-coding-system 'chinese-iso-8bit)
;; 剪切板,用于和其他程序之间复制内容

(fset 'yes-or-no-p 'y-or-n-p)
;; 改变 Emacs 固执的要你回答 yes 的行为。按 y 或空格键表示 yes,n 表示 no。

(minibuffer-electric-default-mode 1)

(partial-completion-mode 1)
;; M-x t-t-l RET 就可以执行 M-x toggle-truncate-lines。其中的 "-" 除按空格键
;; 就可以。

(global-font-lock-mode 1)               ; 开启语法高亮。
(auto-compression-mode 1)               ; 打开压缩文件时自动解压缩。
(column-number-mode 1)                  ; 显示列号。
(blink-cursor-mode -1)                  ; 光标不要闪烁。
(display-time-mode 1)                   ; 显示时间。
(show-paren-mode 1)                     ; 高亮显示匹配的括号。
(menu-bar-mode -1)                      ; 不要 menu-bar。
(icomplete-mode 1)            ; 给出用 M-x foo-bar-COMMAND 输入命令的提示。
(ido-mode 1)                           ; 打开文件和转换 buffer 的方便模式。

(add-hook 'diary-hook 'appt-make-list)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;; shell 中打开 ansi-color 支持。

(add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt)

(add-hook 'write-file-hooks 'time-stamp)
;; 自动更新 time-stamp。

(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
;; Dired 中 C-c C-a 作为附件发送。

(add-hook 'dired-load-hook
          (lambda ()
            (load "dired-x")
            (setq dired-view-command-alist
                  '(("[.]\\(ps\\|ps_pages\\|eps\\)\\'" . "gv -spartan -color -watch %s")
                    ("[.]pdf\\'" . "xpdf %s")
                    ("[.]\\(jpe?g\\|gif\\|png\\)\\'" . "ee %s")
                    ("[.]dvi\\'" . "xdvi -sidemargin 0.5 -topmargin 1 %s")))))
;; 开启 Dired-x 所提供的新功能,设置 Dired 中 v 使用的相应程序。

(add-hook 'message-setup-hook
          (lambda ()
            (define-key message-mode-map "\M-/" 'chunyu-message-expand)))
(defun chunyu-message-expand (&optional arg)
  "message mode expand."
  (interactive)
  (if (message-point-in-header-p)
      (bbdb-complete-name arg)
    (hippie-expand arg)))
;; Message buffer 中的 M-/ 使用自己定义的补全方法 chunyu-message-expand。
;; 当在邮件头中的时候,使用 bbdb-complete-name 补全;而在其他地方,使用缺省
;; 的 hippie-expand 补全。
(add-hook 'ido-define-mode-map-hook
          (lambda ()
            (define-key ido-mode-map "\M-\d" 'ido-delete-backward-updir)))
;; 由于使用 ido 之前的习惯,经常用 M-Backspace 来删除 mini-buffer 中的文件名,
;; 而 ido 的绑定中虽然有却不好用,索性从新绑定一下。

(add-hook 'c-mode-common-hook
          (lambda ()
            (c-toggle-auto-hungry-state 1)
            (which-func-mode 1)))
;; auto-newline  子模式,自动换行缩进;
;; hungry-delete 子模式,一个 Backspace 删除尽可能多的空白;
;; which-func-mode 在模式行中显示当前行在哪个函数中。

(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))))

      ((eq window-system 'x)
       ;; 如果在 X Window 中
       (global-set-key (kbd "C--") 'undo)
       ;; Console 中习惯了 C-_ 作为 Undo,不妨把这个也改过来。

       (setq visible-bell t)
       ;; X Window 中的 visible-bell 还是很好看的。

       (setq x-stretch-cursor nil)
       ;; 如果设置为 t,光标在 TAB 字符上会显示为一个大方块 :)。

       (scroll-bar-mode -1)
       (tool-bar-mode -1)
       ;; 不要 tool-bar 和 scroll-bar。

       (setq default-frame-alist
             ;; 缺省的颜色设置。
             `((vertical-scroll-bars)
               (top . 0) (left . 0) (width . 111) (height . 48)
               (background-color . "DarkSlateGrey")
               (foreground-color . "Wheat")
               (cursor-color     . "gold1")
               (mouse-color      . "gold1")
               (font . "9x15")))

       ;; 其他颜色设置。
       (if (facep 'mode-line)
           (set-face-attribute 'mode-line nil :foreground "DarkSlateGrey" :background "Wheat"))
       (if (facep 'fringe)
           (set-face-attribute 'fringe nil :foreground "limegreen" :background "gray30"))
       (if (facep 'tool-bar)
           (set-face-background 'tool-bar "DarkSlateGrey"))
       (if (facep 'menu)
           (face-spec-set 'menu '((t (:foreground "Wheat" :background "DarkSlateGrey")))))
       (if (facep 'trailing-whitespace)
           (set-face-background 'trailing-whitespace "SeaGreen1"))
       (if (facep 'minibuffer-prompt)
           (face-spec-set 'minibuffer-prompt '((t (:foreground "cyan")))))))
(autoload 'big5togb-region "big5togb" "Big5 to GB2312" t)
;;【big5togb.el】ZSH 写的将 big5 文本转为 gb2312 的包。

(autoload 'css-mode "css-mode" "CSS editing mode" t)
;;【css-mode.el】编辑 css 文件。

(autoload 'python-mode "python-mode" "Python editing mode." t)
(autoload 'py-shell "python-mode" "Python shell" t)
;;【python-mode.el】www.python.org 上面的 python-mode

(autoload 'run-scheme "quack" "Quack scheme editing mode" t)
(autoload 'scheme-mode "quack" "Quack scheme editing mode" t)
;;【quack.el】scheme 模式和交互模式。

(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;;【html-helper-mode.el】一个不错的 html 编辑模式。

(autoload 'htmlize-buffer "htmlize" "HTMLize mode" t)
;;【htmlize.el】把 buffer 中的内容连同颜色转为 html 格式。

(autoload 'browse-kill-ring "browse-kill-ring" "Browse kill ring" t)
;;【browse-kill-ring.el】查看 kill-ring,都曾经 kill 过哪些文本。

(autoload 'folding-mode          "folding" "Folding mode" t)
(autoload 'turn-off-folding-mode "folding" "Folding mode" t)
(autoload 'turn-on-folding-mode  "folding" "Folding mode" t)
;;【folding.el】编辑文本的一部分,将其他部分折叠起来。

(setq auto-mode-alist
      ;; 将文件模式和文件后缀关联起来。
      (append '(("\\.py\\'" . python-mode)
                ("\\.s?html?\\'" . html-helper-mode)
                ("\\.asp\\'" . html-helper-mode)
                ("\\.phtml\\'" . html-helper-mode)
                ("\\.css\\'" . css-mode))
              auto-mode-alist))

(add-to-list 'load-path "~/.emacs.d/elisp")
(add-to-list 'load-path "~/.emacs.d/elisp/tramp")
(add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil))
;(require 'gnus-load)
;(require 'tex-site)
;(require 'boxquote)
;(require 'compile)
;(require 'dired-tar)
;;【dired-tar.el】Dired 中用 T 就把一个目录压缩为一个 .tar.gz 文件。

(require 'uniquify)
(require 'flyspell)

(put 'dired-find-alternate-file 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'rmail 'disabled t)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值