现在的位置: 首页 > 综合 > 正文

emacs 配置文件

2013年10月22日 ⁄ 综合 ⁄ 共 8212字 ⁄ 字号 评论关闭
最近又捡起了 emacs。由于前段时间学过一段 Lisp/Scheme,发现配置和运用要得心应手得多,只是一些 VIM 下的习惯经常出来捣乱。在此贴一下配置文件吧,都是到处抄来的,以后慢慢增补。

-------配置文件--------

  1. ;;; The running on system stuff.
  2. (defvar running-on-windows (memq system-type '(windows-nt cygwin)))
  3. (defvar running-on-linux (not running-on-windows))
  4. (defvar running-on-x (eq window-system 'x))
  5. ;;;
  6. (setq visible-bell t)
  7. ;;;
  8. (fset 'yes-or-no-p 'y-or-n-p)
  9. ;;; Lose the menu bar
  10. ;;(if (fboundp 'menu-bar-mode) (menu-bar-mode nil))
  11. ;;; Lose the toolbar
  12. (tool-bar-mode nil)
  13. ;;; Lose the scroll bar
  14. (set-scroll-bar-mode nil)
  15. ;;(customize-set-variable 'scroll-bar-mode 'right)
  16. (set-cursor-color "steelblue")
  17. (set-mouse-color "steelblue")
  18. ;;; Time
  19. (setq display-time-day-and-date t)
  20. (display-time)
  21. ;;
  22. (display-time-mode 1)
  23. (setq display-time-24hr-format t)
  24. (setq display-time-day-and-date t)
  25. (setq display-time-use-mail-icon t)
  26. (setq display-time-interval 10)
  27. ;;Emacs@Windows maximum
  28. ;;(w32-send-sys-command #xf030)
  29. ;;; Window size for starting up
  30. (setq default-frame-alist
  31.  '((height . 35) (width . 100)))
  32. ;;; Disable startup screen
  33. (custom-set-variables
  34.  '(inhibit-startup-screen t))
  35. (custom-set-faces
  36.   ;; custom-set-faces was added by Custom.
  37.   ;; If you edit it by hand, you could mess it up, so be careful.
  38.   ;; Your init file should contain only one such instance.
  39.   ;; If there is more than one, they won't work right.
  40. )
  41. ;;; Useful key strokes
  42. ;;; goto-line --> ctrl+g
  43. (global-set-key "/C-c/C-g" 'goto-line)
  44. (global-set-key "/C-cb" 'whitespace-cleanup)
  45. (global-set-key "/M-?" 'help-command)
  46. ;;;
  47. (setq backup-directory-alist '(("" . "D:/GS/emacs_msw/backup")))
  48. (setq make-backup-files nil)
  49. (setq-default make-backup-files nil)
  50. (auto-compression-mode 1)
  51. ;;; Show trailing whitespace
  52. (setq-default show-trailing-whitespace t)
  53. ;;;
  54. (setq require-final-newline t)
  55. ;;;
  56. (setq mouse-yank-at-point t)
  57. (setq x-select-enable-clipboard t)
  58. ;;;
  59. (setq column-number-mode t)
  60. ;;
  61. (add-to-list 'load-path "D:/GS/emacs_msw/myemacs")
  62. (require 'linum)
  63. (global-linum-mode 1)
  64. (require 'xcscope)
  65. ;;
  66. (cond
  67.     (running-on-windows
  68.         (require 'color-theme)
  69.         (require 'color-theme-tango)
  70.         (color-theme-tango))
  71.     (running-on-x
  72.         (require 'color-theme)
  73.         (color-theme-gnome2))
  74. )
  75. (setq-default indent-tabs-mode nil)
  76. ;;(setq standard-indent 4)
  77. ;;(setq tab-stop-list ())
  78. (global-set-key (kbd "TAB") 'self-insert-command)
  79. (global-set-key (kbd "TAB") 'tab-to-tab-stop)
  80. (setq-default tab-width 4)
  81. (setq-default
  82.     tab-stop-list
  83.     (list 4 8 12 16 20 24 28 32 36 40
  84.           44 48 52 56 60 64 68 72 76 80
  85.           84 88 92 96 100 104 108))
  86. (setq show-paren-mode t) ;;打开括号匹配显示模式
  87. (setq show-paren-style 'parenthesis)
  88. (setq auto-image-file-mode t)
  89. (setq w32-charset-info-alist
  90.       (cons '("gbk" w32-charset-gb2312 . 936) w32-charset-info-alist))
  91. (setq default-frame-alist
  92.       (append
  93.        '((font . "fontset-gbk")) default-frame-alist))
  94. (create-fontset-from-fontset-spec
  95. "-outline-Courier New-normal-r-normal-normal-16-97-96-96-c-*-fontset-gbk")
  96. (set-fontset-font
  97. "fontset-default" nil
  98. "-outline-新宋体-normal-r-normal-*-16-*-96-96-c-*-iso10646-1" nil 'prepend)
  99. (set-fontset-font
  100. "fontset-gbk" 'kana
  101. "-outline-新宋体-normal-r-normal-*-16-*-96-96-c-*-iso10646-1" nil 'prepend)
  102. (set-fontset-font
  103. "fontset-gbk" 'han
  104. "-outline-新宋体-normal-r-normal-*-16-*-96-96-c-*-iso10646-1" nil 'prepend)
  105. (set-fontset-font
  106. "fontset-gbk" 'cjk-misc
  107. "-outline-新宋体-normal-r-normal-*-16-*-96-96-c-*-iso10646-1" nil 'prepend)
  108. (set-fontset-font
  109. "fontset-gbk" 'symbol
  110. "-outline-新宋体-normal-r-normal-*-16-*-96-96-c-*-iso10646-1" nil 'prepend)
  111. (set-default-font "fontset-gbk")
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ;;;  mode
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115. (add-hook 'c++-mode-hook
  116.    (lambda ()
  117.      (c-set-style "bsd")
  118.      (hs-minor-mode)
  119.      (local-set-key "/C-c/t" 'complete-symbol)
  120.      (local-set-key "/C-m" 'newline-and-indent)
  121.      (setq mslk-c++-key (make-keymap))
  122.      (local-set-key "/C-j" mslk-c++-key)
  123.      (define-key mslk-c++-key "/C-j" 'complete-symbol)
  124.      (define-key mslk-c++-key "/C-o" 'hs-hide-all)
  125.      (define-key mslk-c++-key "/C-p" 'hs-show-all)
  126.      (define-key mslk-c++-key "/C-h" 'hs-hide-block)
  127.      (define-key mslk-c++-key "/C-u" 'hs-show-block)
  128.      (define-key mslk-c++-key "/C-l" 'hs-hide-level)
  129.      (define-key mslk-c++-key "/C-m" 'hs-toggle-hiding)
  130.      ))
  131. (add-hook 'c-mode-hook 'c++-mode)
  132. (defun my-c-mode-common-hook()
  133.   (setq tab-width 4 indent-tabs-mode nil)
  134.   ;;; hungry-delete and auto-newline
  135.   (c-toggle-auto-hungry-state 1)
  136.   ;;按键定义
  137.   (define-key c-mode-base-map [(control /`)] 'hs-toggle-hiding)
  138.   (define-key c-mode-base-map [(return)] 'newline-and-indent)
  139.   (define-key c-mode-base-map [(f7)] 'compile)
  140.   (define-key c-mode-base-map [(meta /`)] 'c-indent-command)
  141. ;;  (define-key c-mode-base-map [(tab)] 'hippie-expand)
  142.   (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)
  143.   (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
  144.     ;;预处理设置
  145.   (setq c-macro-shrink-window-flag t)
  146.   (setq c-macro-preprocessor "cpp")
  147.   (setq c-macro-cppflags " ")
  148.   (setq c-macro-prompt-flag t)
  149.   (setq hs-minor-mode t)
  150.   (setq abbrev-mode t)
  151. )
  152. (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  153. ;;;;我的C++语言编辑策略
  154. (defun my-c++-mode-hook()
  155.   (setq tab-width 4 indent-tabs-mode nil)
  156.   (c-set-style "stroustrup")
  157. ;;  (define-key c++-mode-map [f3] 'replace-regexp)
  158. )
  159. (defun my-indent-or-complete ()
  160.    (interactive)
  161.    (if (looking-at "//>")
  162.       (hippie-expand nil)
  163.       (indent-for-tab-command))
  164.  )
  165. (global-set-key [(control tab)] 'my-indent-or-complete)
  166. (setq compile-command "make")
  167. (define-key global-map (read-kbd-macro "M-RET") 'hippie-expand)
  168. (load "completion")
  169. (initialize-completions)
  170. ;; Make actionscript-mode the default mode for .as files
  171. ;;(load "actionscript-mode")
  172. ;;(add-to-list ‘auto-mode-alist ‘(”//.as[123]?$” . actionscript-mode))
  173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  174. ;; Various functions
  175. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  176. ;; Convert DOS cr-lf to UNIX newline
  177. (defun dos-unix () (interactive) (goto-char (point-min))
  178.   (while (search-forward "/r/n" nil t) (replace-match "/n")))
  179. ;; Convert UNIX newline to DOS cr-lf
  180. (defun unix-dos () (interactive) (goto-char (point-min))
  181.   (while (search-forward "/n" nil t) (replace-match "/r/n")))
  182. ;; Replace all tab with four blank spaces
  183. (defun notab () (interactive)  (goto-char (point-min))
  184.   (while (search-forward "/t" nil t) (replace-match "    ")))
  185. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  186. ;; auto-indent
  187. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  188. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  189. (setq x-select-enable-clipboard t)
  190. for copying word
  191. (defun copy-word (&optional arg)
  192.     "Copy words at point into kill-ring"
  193.     (interactive "P")
  194.     (let ((beg (progn (if (looking-back "[a-zA-Z0-9]" 1) (backward-word 1)) (point)))
  195.         (end (progn (forward-word arg) (point))))
  196.     (copy-region-as-kill beg end))
  197. )
  198. (global-set-key (kbd "C-c w") (quote copy-word))
  199. for copying line
  200. (defun copy-line (&optional arg)
  201.     "Save current line into Kill-Ring without mark the line "
  202.     (interactive "P")
  203.     (let ((beg (line-beginning-position))
  204.           (end (line-end-position arg)))
  205.     (copy-region-as-kill beg end))
  206. )
  207. (global-set-key (kbd "C-c l") (quote copy-line))
  208. for copying paragraph
  209. (defun copy-paragraph (&optional arg)
  210.     "Copy paragraphes at point"
  211.     (interactive "P")
  212.     (let ((beg (progn (backward-paragraph 1) (point)))
  213.           (end (progn (forward-paragraph arg) (point))))
  214.     (copy-region-as-kill beg end))
  215. )
  216. (global-set-key (kbd "C-c p") (quote copy-paragraph))
  217. for copying string
  218. (defun copy-string (&optional arg)
  219.     "Copy a sequence of string into kill-ring"
  220.     (interactive)
  221.     (setq onPoint (point))
  222.     (let (
  223.             ( beg  (progn (re-search-backward "[/t ]" (line-beginning-position) 3 1)
  224.                    (if (looking-at "[/t ]") (+ (point) 1) (point) ) )
  225.             )
  226.             ( end  (progn  (goto-char onPoint) (re-search-forward "[/t ]" (line-end-position) 3 1)
  227.                    (if (looking-back "[/t ]") (- (point) 1) (point) ) )
  228.             )
  229.          )
  230.      (copy-region-as-kill beg end)
  231.      )
  232. )
  233. (global-set-key (kbd "C-c s") (quote copy-string))

Windows 下需要在注册表中设定 emacs 启动时载入配置文件的 HOME 目录,下面是注册表文件

  1. Windows Registry Editor Version 5.00
  2. [HKEY_CURRENT_USER/Software/GNU]
  3. [HKEY_CURRENT_USER/Software/GNU/Emacs]
  4. "HOME"="D://GS//emacs_msw"

【上篇】
【下篇】

抱歉!评论已关闭.