;; -*- Emacs-Lisp -*- (defconst my-emacs-path "~/emacs/" "我的emacs相关配置文件的路径") (defconst my-emacs-my-lisps-path (concat my-emacs-path "my-lisps/") "我自己写的emacs lisp包的路径") (defconst my-emacs-lisps-path (concat my-emacs-path "lisps/") "我下载的emacs lisp包的路径") (defconst my-emacs-templates-path (concat my-emacs-path "templates/") "Path for templates") ;;添加子目录的函数 (defun my-add-subdirs-to-load-path (dir) (let ((default-directory (concat dir "/"))) (setq load-path (cons dir load-path)) (normal-top-level-add-subdirs-to-load-path))) ;; 把`my-emacs-lisps-path'的所有子目录都加到`load-path'里面 (my-add-subdirs-to-load-path my-emacs-lisps-path) (my-add-subdirs-to-load-path my-emacs-my-lisps-path) (tool-bar-mode -1) ;关闭工具栏 (scroll-bar-mode -1) ;关闭左边滚动条 (delete-selection-mode 1) ;删除选定区域 (setq frame-title-format '("" buffer-file-name "@emacs23" ));在标题栏显示buffer名称 (fset 'yes-or-no-p 'y-or-n-p);以 y/n代表 yes/no (column-number-mode t);显示列号 ;(show-paren-mode t);显示括号匹配 (display-time-mode 1);显示时间,格式如下 (setq display-time-24hr-format t) (setq display-time-day-and-date t) ;(set-default-font "-unknown-文泉驿等宽微米黑-normal-normal-normal-*-*-*-*-*-*-0-iso10646-1") ;;显示行号 (require 'linum+) (global-linum-mode t) ;;设置窗口大小 (setq default-frame-alist '((height . 70) (width . 180) (menu-bar-lines . 20) (tool-bar-lines . 0))) ;;设置字体 (set-default-font "Menlo 12 14") ;自定义按键 (global-set-key [f1] 'shell);F1进入Shell ;(global-set-key [f4] 'speedbar-get-focus);cedet's speed (global-set-key [f5] 'onekey-compile); (global-set-key [f6] 'gdb); (global-set-key [f7] 'compile); (setq compile-command "make -f Makefile") ;(global-set-key [f7] 'do-compile);F7编译文件 ;(global-set-key [f8] 'other-window);F8窗口间跳转 (global-set-key [C-return] 'kill-this-buffer);C-return关闭当前buffer ;(global-set-key [f10] 'split-window-vertically);F10分割窗口 ;(global-set-key [f11] 'delete-other-windows);F11 关闭其它窗口 (global-set-key [f11] 'calculator);计算器 (global-set-key [f12] 'py-execute-buffer);直接运行脚本 ;(global-set-key [f12] 'fullscreen);F12 全屏 ;(global-set-key (kbd "C-,") 'backward-page);文件首 ;(global-set-key (kbd "C-.") 'forward-page);文件尾 ;(global-set-key (kbd "C-[") 'Previous-buffer);上一个buffer ;(global-set-key (kbd "C-]") 'next-buffer);下一个buffer ;鼠标滚轮,默认的滚动太快,这里改为3行 ;(defun smooth-scroll (increment) ; (scroll-up increment) (sit-for 0.05) ;; (scroll-up increment) (sit-for 0.02) ;; (scroll-up increment) (sit-for 0.02) ;; (scroll-up increment) (sit-for 0.05) ;; (scroll-up increment) (sit-for 0.06) ;; (scroll-up increment)) ;(global-set-key [C-/[] '(lambda () (interactive) (smooth-scroll 1))) ;(global-set-key [C-/]] '(lambda () (interactive) (smooth-scroll -1))) ;(defun up-slightly () (interactive) (scroll-up 3)) ;(defun down-slightly () (interactive) (scroll-down 3)) ;(global-set-key [mouse-4] 'down-slightly) ;(global-set-key [mouse-5] 'up-slightly) ;; ---------- cuda mode ---------- (add-to-list 'auto-mode-alist '("//.cu$" . c-mode)) ;; (require 'cuda-mode) ;; (autoload 'cuda-mode "cuda-mode.el" "Cuda mode." t) ;; (setq auto-mode-alist (append '(("/*./.cu$" . cuda-mode)) auto-mode-alist)) ;; ---------- c style ---------- (add-to-list 'auto-mode-alist '("//.c$" . linux-c-mode)) (defun linux-c-mode() "C mode with adjusted defaults for use with the Linux Kernel." (interactive) (c-mode) (c-set-style "K&R") (setq c-basic-offset 4)) ;; ---------- 传说中的高亮的尾巴? ---------- (require 'highlight-tail) (setq highlight-tail-colors '(("black" . 0) ("#bc2525" . 25) ; ("Cyan" . 25) ("black" . 66))) (highlight-tail-mode 1) ;; ---------- pause ----------传说中的淡入淡出当前行(需要cedet支持) (require 'pulse) (defadvice exchange-point-and-mark-nomark (after pulse-advice activate) "Cause the line that is `goto'd to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p) (> (abs (- (point) (mark))) 400)) (pulse-momentary-highlight-one-line (point)))) (defadvice switch-to-buffer (after pulse-advice activate) "Cause the current line of new buffer to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p)) (pulse-momentary-highlight-one-line (point)))) (defadvice ido-switch-buffer (after pulse-advice activate) "Cause the current line of new buffer to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p)) (pulse-momentary-highlight-one-line (point)))) (defadvice switch-to-other-buffer (after pulse-advice activate) "Cause the current line of new buffer to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p)) (pulse-momentary-highlight-one-line (point)))) (defadvice visit-.emacs (after pulse-advice activate) "Cause the current line of .emacs buffer to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p)) (pulse-momentary-highlight-one-line (point)))) (defadvice beginning-of-buffer (after pulse-advice activate) "Cause the current line of buffer to pulse when the cursor gets there." (when (and pulse-command-advice-flag (interactive-p)) (pulse-momentary-highlight-one-line (point)))) (pulse-toggle-integration-advice (if window-system 1 -1)) ;shell,gdb退出后,自动关闭该buffer (add-hook 'shell-mode-hook 'mode-hook-func) (add-hook 'gdb-mode-hook 'mode-hook-func) (defun mode-hook-func () (set-process-sentinel (get-buffer-process (current-buffer)) #'kill-buffer-on-exit)) (defun kill-buffer-on-exit (process state) (message "%s" state) (if (or (string-match "exited abnormally with code.*" state) (string-match "finished" state)) (kill-buffer (current-buffer)))) ;全屏 (defun fullscreen () (interactive) (set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen) nil 'fullboth))) (defun my-fullscreen () (interactive) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_FULLSCREEN" 0))) ;最大化 (defun my-maximized-horz () (interactive) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))) (defun my-maximized-vert () (interactive) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0))) (defun my-maximized () (interactive) (X-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)) (interactive) (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0))) ;;一键编译单个文件! (defun onekey-compile () "Compile current buffer" (interactive) (let (filename suffix progname compiler) (setq filename (file-name-nondirectory buffer-file-name)) (setq progname (file-name-sans-extension filename)) (setq suffix (file-name-extension filename)) (if (string= suffix "c") (setq compiler (concat "gcc -g -o " progname " "))) (if (or (string= suffix "cc") (string= suffix "cpp")) (setq compiler (concat "g++ -g -o " progname " "))) (if (string= suffix "tex") (setq compiler "latex ")) (compile (concat compiler filename)))) (require 'color-theme) (color-theme-initialize) (color-theme-calm-forest) ;;---------- php (require 'php-mode) ;;---------- mmm-mode (add-hook 'php-mode-user-hook 'turn-on-font-lock) (require 'mmm-mode) (setq mmm-global-mode 'maybe) (mmm-add-mode-ext-class nil "//.php3?//'" 'html-php) (mmm-add-classes '((html-php :submode php-mode :front "<//?//(php//)?" :back "//?>"))) (set-face-background 'mmm-default-submode-face "Blank") (autoload 'php-mode "php-mode" "PHP editing mode" t) (add-to-list 'auto-mode-alist '("//.php3?//'" . html-mode)) ;; *************************** Python Settings **************************** ;;;; Python Settings ;(require 'auto-complete) ;(require 'pysmell) (require 'python-mode) (autoload 'python-mode "python-mode" "Python Mode." t) (autoload 'jython-mode "python-mode" "Python editing mode." t) (autoload 'py-shell "python-mode" "Start interpreter in another window." t) (autoload 'pymacs-apply "pymacs") (autoload 'pymacs-call "pymacs") (autoload 'pymacs-eval "pymacs" nil t) (autoload 'pymacs-exec "pymacs" nil t) (autoload 'pymacs-load "pymacs" nil t) ;(pymacs-load "pycomplete") ;(pymacs-load "ropemacs" "rope-") (add-to-list 'auto-mode-alist '("//.py$" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)) (setq auto-mode-alist (cons '("//.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) ;(setq ropemacs-enable-autoimport t) ;;-------------- yasnippet -------------- (require 'yasnippet) (yas/initialize) (yas/load-directory "~/emacs/lisps/yasnippet-0.6.1c/snippets") ;;-------------- auto-complete -------------- (require 'auto-complete) (require 'auto-complete-config) (global-auto-complete-mode t) (setq-default ac-sources '(ac-source-words-in-same-mode-buffers)) (add-hook 'emacs-lisp-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-symbols))) (add-hook 'auto-complete-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-filename))) (set-face-background 'ac-candidate-face "lightgray") (set-face-underline 'ac-candidate-face "darkgray") (set-face-background 'ac-selection-face "steelblue") ;;; 设置比上面截图中更好看的背景颜色 (define-key ac-completing-map "/M-n" 'ac-next) ;;; 列表中通过按M-n来向下移动 (define-key ac-completing-map "/M-p" 'ac-previous) (setq ac-auto-start 2) (setq ac-dwim t) (define-key ac-mode-map (kbd "M-TAB") 'auto-complete) (require 'pycomplete) (setq auto-mode-alist (cons '("//.py$" . python-mode) auto-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t) (setq interpreter-mode-alist(cons '("python" . python-mode) interpreter-mode-alist)) ;; -------------- 括号自动补全 -------------- ;; C mode (add-hook 'c-mode-hook 'hs-minor-mode) (defun my-c-mode-auto-pair () (interactive) (make-local-variable 'skeleton-pair-alist) (setq skeleton-pair-alist '( (?` _ "`") (?/( _ ")") (?/[ _ "]") (?/" _ "/"") (?/' _ "/'") (?{ /n > _ /n ?} >))) (setq skeleton-pair t) (local-set-key (kbd "(") 'skeleton-pair-insert-maybe) (local-set-key (kbd "{") 'skeleton-pair-insert-maybe) (local-set-key (kbd "`") 'skeleton-pair-insert-maybe) (local-set-key (kbd "/"") 'skeleton-pair-insert-maybe) (local-set-key (kbd "/'") 'skeleton-pair-insert-maybe) (local-set-key (kbd "[") 'skeleton-pair-insert-maybe)) (add-hook 'c-mode-hook 'my-c-mode-auto-pair) ;; -------------- CEDET -------------- (add-to-list 'load-path "path-of-cedet/common") (require 'cedet) (require 'semantic-ia) ;; Enable EDE (Project Management) features (global-ede-mode 1) ;; Enable SRecode (Template management) minor-mode. (global-srecode-minor-mode 1) (semantic-load-enable-minimum-features) (semantic-load-enable-code-helpers) (semantic-load-enable-guady-code-helpers) (semantic-load-enable-excessive-code-helpers) (semantic-load-enable-semantic-debugging-helpers) (setq semantic-idle-scheduler-idle-time 5) ;; -------------- code folding -------------- (require 'semantic-tag-folding nil 'noerror) (global-semantic-tag-folding-mode 1) ;; -------------- 多窗口调试 -------------- (setq gdb-many-windows t) (load-library "multi-gud.el") (load-library "multi-gdb-ui.el")