|
|
发表于 2006-2-22 10:21:24
|
显示全部楼层
Post by bcjr
herberteuler兄,你能贴一下你的c编程环境的.emacs文件吗?想参考参考
下面是我的 .emacs 的全部内容(2006 年 1 月 17 日),其中用到了 Alex Schroeder 和 Jonadab the Unsightly One 的 color-theme.el 中的函数。
- ;;; default settings
- (global-set-key (kbd "M-/") 'hippie-expand)
- (global-font-lock-mode t)
- (column-number-mode t)
- (require 'generic-x)
- (auto-compression-mode t)
- (add-to-list 'load-path "~/.emacs.d")
- (put 'narrow-to-region 'disabled nil)
- (require 'color-theme)
- ;;(require 'python-mode)
- (require 'printing)
- (pr-update-menus)
- ;;; custom settings, but only involved system commands
- (cond
- ((or (eq system-type 'gnu/linux) (eq system-type 'berkeley-unix))
- (term "bash")
- (switch-to-buffer "*scratch*")))
- (defun my-c-mode-common-hook ()
- (c-toggle-hungry-state t)
- ;;(hs-minor-mode t)
- (xgp-c-define-local-variables)
- (xgp-c-load-header-files-in-current-buffer)
- (local-set-key (kbd "M-<DEL>") 'backward-kill-sexp)
- (local-set-key (kbd "M-d") 'kill-sexp)
- (local-set-key (kbd "M-n") 'c-end-of-statement)
- (local-set-key (kbd "M-p") 'c-beginning-of-statement)
- (local-set-key (kbd "C-a") 'beginning-of-line)
- (local-set-key (kbd "C-e") 'end-of-line)
- (local-set-key (kbd "M-a") 'backward-sentence)
- (local-set-key (kbd "M-e") 'forward-sentence)
- (local-set-key (kbd "M-k") 'kill-sentence)
- (local-set-key (kbd "C-k") 'kill-line)
- (local-set-key (kbd "C-M-a") 'beginning-of-defun)
- (local-set-key (kbd "C-M-e") 'end-of-defun)
- (local-set-key (kbd "M-<") 'beginning-of-buffer)
- (local-set-key (kbd "M->") 'end-of-buffer)
- (local-set-key (kbd "<f9>") 'xgp-cfsi))
- (add-hook 'c-mode-common-hook
- '(lambda ()
- (my-c-mode-common-hook)))
- (or window-system (progn (menu-bar-mode 0)
- (mouse-wheel-mode 0)))
- (setq c-default-style "bsd"
- frame-title-format "%b [%m] - GNU Emacs")
- (cond
- ((eq window-system 'w32)
- (setq printer-name "\\\\bdc\\hp1320n"
- initial-frame-alist '((width . 89) (height . 32)))
- (set-default-font "-outline-lucida sans typewriter-normal-r-normal-normal-19-142-96-96-c-*-fontset-auto2")
- (add-to-list 'default-frame-alist '(font . "-outline-lucida sans typewriter-normal-r-normal-normal-19-142-96-96-c-*-fontset-auto2")))
- ((eq window-system 'x)
- (setq xgp-x-fontset
- (create-fontset-from-fontset-spec
- "-adobe-courier-medium-r-normal--17-120-100-100-m-0-fontset-17,iso8859-1:adobe-courier-medium-r-normal--17-120-100-100-m-110-iso8859-1,chinese-gb2312:-misc-simsun-medium-r-normal--14-105-96-96-c-0-gb2312.1980-0"))
- ;; 14-105-96-96
- ;; 16-120-96-96
- ;; 12-90-96-96
- (set-default-font xgp-x-fontset)
- (add-to-list 'default-frame-alist '(font . "fontset-17"))))
- (cond
- ((<= emacs-major-version 22)
- (prefer-coding-system 'gb2312)
- (set-terminal-coding-system 'gb2312)
- (set-keyboard-coding-system 'gb2312))
- ((>= emacs-major-version 23)
- (prefer-coding-system 'gbk)
- (set-terminal-coding-system 'gbk)
- (set-keyboard-coding-system 'gbk)))
- ;;; custom commands created by myself
- (defgroup xgp-c-header-files nil
- "Group for reading C/C++ header files."
- :group 'c)
- (defcustom xgp-c-system-include-paths
- '("/usr/include"
- "/usr/local/include")
- "List of directories where C/C++ header files are found."
- :type '(repeat string)
- :group 'xgp-c-header-files)
- (defun xgp-c-define-local-variables ()
- "Make variable XGP-C-USER-INCLUDE-PATHS directory of file in the current buffer."
- (make-local-variable 'xgp-c-user-include-paths)
- (setq xgp-c-user-include-paths (list (file-name-directory (buffer-file-name)))))
- (defun xgp-c-load-header-files-in-current-buffer ()
- "Try load C/C++ header files included by file in the current buffer.
- First search in the directory relative to the directory of the file
- in the current buffer, then user defined directories, then system
- wide directory."
- (interactive)
- (save-excursion
- (goto-char (point-min))
- (let (b e f af)
- (while (and (setq b (re-search-forward "#include[ \t]+" nil t))
- (setq e (re-search-forward "\n" nil t)))
- (setq f (buffer-substring-no-properties (1+ b) (- e 2)))
- (if (eq (char-before (1- e)) ?>)
- (dotimes (n (length xgp-c-system-include-paths))
- (setq af (concat (nth n xgp-c-system-include-paths) "/" f))
- (if (file-exists-p af)
- (find-file-noselect af t)))
- (dotimes (n (length xgp-c-user-include-paths))
- (setq af (concat (nth n xgp-c-user-include-paths) "/" f))
- (if (file-exists-p af)
- (find-file-noselect af t))))))))
- (defun xgp-execute-program-region (start end program)
- "Execute external program on region in the current buffer.
- START and END specifies the region, PROGRAM specifies which
- program to be called."
- (interactive "r\nsProgram: ")
- (let ((delete (y-or-n-p "Substitute orignal content: "))
- args
- s)
- (setq s (read-string "Argument (type RET directly to finish): "))
- (while (not (equal s ""))
- (progn (setq args (append args (list s))
- s (read-string "Argument (type RET directly to finish): ")))
- (apply 'call-process-region start end program delete t nil args))))
- (global-set-key (kbd "<f7>") 'xgp-execute-program-region)
- ;; C/C++ F? Style Inputing
- (defun xgp-cfsi (style)
- "Deciding whether using CFSI."
- (interactive "sStyle: ")
- (if (equal style "bsd")
- (progn (c-toggle-auto-newline -1)
- (c-set-style "bsd")
- (setq indent-tabs-mode t)
- (local-set-key " " 'self-insert-command))
- (progn (c-toggle-auto-newline 1)
- (c-set-style style)
- (setq indent-tabs-mode nil
- c-hanging-braces-alist (quote ((defun-open) (defun-close) (brace-list-open before) (brace-entry-open) (statement-cont) (substatement-open before) (block-close) (extern-lang-open) (namespace-open before) (module-open) (composition-open) (inexpr-class-open) (inexpr-class-close before) (class-open before) (class-close)))
- c-hanging-semi&comma-criteria nil
- c-hanging-colons-alist nil)
- (local-set-key " " 'xgp-cfsi-SPC))))
- (defun xgp-cfsi-SPC ()
- (interactive)
- (if (looking-back "^[ \t]*}[ \t]*$")
- (progn
- (insert "\n")
- (c-indent-command))
- (insert " ")))
- ;;; custom commands created by others
- ;;; modified color-theme-high-contrast
- (defun color-theme-high-contrast-tty ()
- "High contrast color theme, maybe for the visually impaired.
- Watch out! This will set a very large font-size!
- If you want to modify the font as well, you should customize variable
- `color-theme-legal-frame-parameters' to "\\(color\\|mode\\|font\\|height\\|width\\)$".
- The default setting will prevent color themes from installing specific
- fonts."
- (interactive)
- (color-theme-standard)
- (let ((color-theme-is-cumulative t))
- (color-theme-install
- '(color-theme-high-contrast
- ((cursor-color . "red")
- (width . 60)
- (height . 25)
- (background . dark))
- (default ((t (:stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :height 240 :width normal :family "adobe-courier"))))
- (bold ((t (:bold t :underline t))))
- (bold-italic ((t (:bold t :underline t))))
- (font-lock-builtin-face ((t (:bold t :foreground "Red"))))
- (font-lock-comment-face ((t (:bold t :foreground "Firebrick"))))
- (font-lock-constant-face ((t (:bold t :underline t :foreground "Blue"))))
- (font-lock-function-name-face ((t (:bold t :foreground "Blue"))))
- (font-lock-keyword-face ((t (:bold t :foreground "Purple"))))
- (font-lock-string-face ((t (:bold t :foreground "DarkGreen"))))
- (font-lock-type-face ((t (:bold t :foreground "ForestGreen"))))
- (font-lock-variable-name-face ((t (:bold t :foreground "DarkGoldenrod"))))
- (font-lock-warning-face ((t (:bold t :foreground "Red"))))
- (highlight ((t (:background "black" :foreground "white" :bold 1))))
- (info-menu-5 ((t (:underline t :bold t))))
- (info-node ((t (:bold t))))
- (info-xref ((t (:bold t ))))
- (italic ((t (:bold t :underline t))))
- (modeline ((t (:background "black" :foreground "white" :bold 1))))
- (modeline-buffer-id ((t (:background "black" :foreground "white" :bold 1))))
- (modeline-mousable ((t (:background "black" :foreground "white" :bold 1))))
- (modeline-mousable-minor-mode ((t (:background "black" :foreground "white" :bold 1))))
- (region ((t (:background "black" :foreground "white" :bold 1))))
- (secondary-selection ((t (:background "black" :foreground "white" :bold 1))))
- (underline ((t (:bold t :underline t))))))))
- (defun color-theme-sitaramv-nt-modified ()
- "Black foreground on white background.
- Includes faces for font-lock, widget, custom, speedbar."
- (interactive)
- (color-theme-install
- '(color-theme-sitaramv-nt
- ((foreground-color . "black")
- (background-color . "white")
- (mouse-color . "sienna3")
- (cursor-color . "HotPink")
- (border-color . "Blue")
- (background-mode . light))
- (default ((t (nil))))
- (modeline ((t (:foreground "black" :background "gold2"))))
- (modeline-buffer-id ((t (:foreground "black" :background "gold2"))))
- (modeline-mousable ((t (:foreground "black" :background "gold2"))))
- (modeline-mousable-minor-mode ((t (:foreground "black" :background "gold2"))))
- (highlight ((t (:foreground "black" :background "darkseagreen2"))))
- (bold ((t (:bold t))))
- (italic ((t (:italic t))))
- (bold-italic ((t (:bold t :italic t))))
- (region ((t (:foreground "black" :background "snow3"))))
- (secondary-selection ((t (:background "paleturquoise"))))
- (underline ((t (:underline t))))
- (lazy-highlight-face ((t (:foreground "dark magenta" :bold t))))
- (font-lock-comment-face ((t (:foreground "ForestGreen" :italic t))))
- (font-lock-string-face ((t (:foreground "red"))))
- (font-lock-keyword-face ((t (:foreground "blue" :bold t))))
- (font-lock-builtin-face ((t (:foreground "blue"))))
- (font-lock-function-name-face ((t (:foreground "magenta" :bold t))))
- (font-lock-variable-name-face ((t (:foreground "black"))))
- (font-lock-type-face ((t (:foreground "ForestGreen" :bold t))))
- (font-lock-constant-face ((t (:foreground "blue" :underline t))))
- (font-lock-warning-face ((t (:foreground "Red" :bold t))))
- (widget-documentation-face ((t (:foreground "dark green"))))
- (widget-button-face ((t (:bold t))))
- (widget-field-face ((t (:background "gray85"))))
- (widget-single-line-field-face ((t (:background "gray85"))))
- (widget-inactive-face ((t (:foreground "dim gray"))))
- (widget-button-pressed-face ((t (:foreground "red"))))
- (custom-invalid-face ((t (:foreground "yellow" :background "red"))))
- (custom-rogue-face ((t (:foreground "pink" :background "black"))))
- (custom-modified-face ((t (:foreground "white" :background "blue"))))
- (custom-set-face ((t (:foreground "blue" :background "white"))))
- (custom-changed-face ((t (:foreground "white" :background "blue"))))
- (custom-saved-face ((t (:underline t))))
- (custom-button-face ((t (nil))))
- (custom-documentation-face ((t (nil))))
- (custom-state-face ((t (:foreground "dark green"))))
- (custom-variable-tag-face ((t (:foreground "blue" :underline t))))
- (custom-variable-button-face ((t (:bold t :underline t))))
- (custom-face-tag-face ((t (:underline t))))
- (custom-group-tag-face-1 ((t (:foreground "red" :underline t))))
- (custom-group-tag-face ((t (:foreground "blue" :underline t))))
- (speedbar-button-face ((t (:foreground "green4"))))
- (speedbar-file-face ((t (:foreground "cyan4"))))
- (speedbar-directory-face ((t (:foreground "blue4"))))
- (speedbar-tag-face ((t (:foreground "brown"))))
- (speedbar-selected-face ((t (:foreground "red" :underline t))))
- (speedbar-highlight-face ((t (:background "green"))))
- (ff-paths-non-existant-file-face ((t (:foreground "NavyBlue" :bold t))))
- (show-paren-match-face ((t (:background "light blue"))))
- (show-paren-mismatch-face ((t (:foreground "white" :background "purple")))))))
- (if window-system
- (color-theme-sitaramv-nt-modified)
- (color-theme-high-contrast-tty))
- ;;; finally, customization by Emacs
- (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.
- '(c-offsets-alist (quote ((block-open . 0) (block-close . 0) (statement-block-intro . +) (substatement . +) (substatement-open . 0) (substatement-label . 0) (case-label . 0) (do-while-closure . 0) (else-clause . 0) (catch-clause . 0) (case-label . 0) (access-label . -) (namespace-open . 0) (class-open . 0) (class-close . 0))))
- '(dired-recursive-copies (quote always))
- '(dired-recursive-deletes (quote top))
- '(ps-font-size (quote (8.5 . 10)))
- '(tab-width 8)
- '(undo-limit 200000))
- (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.
- )
复制代码
我是一个传统的 UNIX C 程序员,所以大多数内容都和 C 编程有关。无论何时,请注意每个人的背景和所处的环境不同,因此他的需要也不一样。所以,请针对自己的需要对配置作出修改。 |
|