.emacs
来源:互联网 发布:组态王与单片机modbus 编辑:程序博客网 时间:2024/06/09 20:43
在网上找资源,看Emacs的帮助文档,最终整理了一个自己的Emacs配置,用起来还可以。
(defvar first-time t
"Flag signifying this is the first time that .emacs has been evaled")
;; line number
(add-to-list 'load-path "~/.emacs.d/")
(require 'linum)
(global-linum-mode t)
;(require 'hl-line)
;(global-hl-line-mode t)
;;xcscope
(require 'xcscope)
;; template file header module
(require 'template)
(template-initialize)
(setq-default save-place t)
(require 'saveplace)
;;color-themes
(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0/")
(require 'color-theme)
(load-file "~/.emacs.d/color-theme-6.6.0/themes/color-theme-library.el")
(color-theme-tty-dark)
;;cedet
(load-file "~/.emacs.d/cedet-1.0pre7/common/cedet.el")
(global-ede-mode 1)
(semantic-load-enable-minimum-features)
;(semantic-load-enable-code-helpers)
(require 'semantic-ia)
(global-srecode-minor-mode 1)
;;ecb
(add-to-list 'load-path "~/.emacs.d/ecb-2.40/")
(require 'ecb)
(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.
'(cscope-overlay-arrow-string "")
'(cscope-stop-at-first-match-dir t)
'(delete-selection-mode nil)
'(display-time-mode t)
'(ecb-layout-name "user01")
'(ecb-methods-general-face (quote ecb-default-general-face))
'(ecb-methods-menu-sorter nil)
'(ecb-methods-separate-prototypes t)
'(ecb-options-version "2.40")
'(ecb-source-path (quote (("~/" "/"))))
'(ecb-sources-sort-ignore-case t)
'(ecb-tip-of-the-day nil)
'(ecb-use-speedbar-instead-native-tree-buffer nil)
'(ecb-windows-height 0.23)
'(ecb-windows-width 0.23)
'(global-visual-line-mode nil)
'(gud-tooltip-mode t)
'(linum-format "%5d ")
'(locate-ls-subdir-switches "")
'(mark-even-if-inactive t)
'(next-line-add-newlines t)
'(semantic-complete-inline-analyzer-displayor-class (quote semantic-displayor-tooltip))
'(semanticdb-project-roots (quote ("/")))
'(transient-mark-mode 1))
(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.
'(cscope-file-face ((((class color) (background light)) (:foreground "cyan"))))
'(cscope-line-face ((t (:foreground "cyan"))))
'(hl-line ((t (:inherit highlight :foreground "white"))))
'(linum ((t (:inherit (shadow default) :background "black" :foreground "magenta")))))
(setq auto-update-methods-after-save t)
(setq semantic-idle-scheduler-idle-time 432000)
(setq semanticdb-default-save-directory
(expand-file-name "~/.emacs.d/semanticdb"))
(setq semanticdb-project-roots
(list (expand-file-name "~/")))
(setq semanticdb-search-system-databases t)
(add-hook 'c-mode-common-hook
(lambda ()
(setq semanticdb-project-system-databases
(list (semanticdb-create-database
semanticdb-new-database-class
"/usr/include")))))
(defun my-cedet-hook ()
(local-set-key (kbd "M-/") 'semantic-ia-complete-symbol)
(local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
(local-set-key "\C-c>" 'semantic-complete-analyze-inline)
(local-set-key "\C-cp" 'semantic-analyze-proto-impl-toggle)
)
(add-hook 'c-mode-common-hook 'my-cedet-hook)
(add-hook 'c++-mode-hook 'my-cedet-hook)
(setq backup-by-copying-when-mismatch t)
;; Treat 'y' or <CR> as yes, 'n' as no.
(fset 'yes-or-no-p 'y-or-n-p)
(define-key query-replace-map [return] 'act)
(define-key query-replace-map [?\C-m] 'act)
;; Pretty diff mode
(autoload 'ediff-buffers "ediff" "Intelligent Emacs interface to diff" t)
(autoload 'ediff-files "ediff" "Intelligent Emacs interface to diff" t)
(autoload 'ediff-files-remote "ediff" "Intelligent Emacs interface to diff")
(if first-time
(setq auto-mode-alist
(append '(("\\.cpp$" . c++-mode)
("\\.cc$" . c++-mode)
("\\.hpp$" . c++-mode)
("\\.def$" . c++-mode)
("\\.he$" . c++-mode)
("\\.h*$" . c-mode)
("\\.lsp$" . lisp-mode)
("\\.scm$" . scheme-mode)
("\\.pl$" . perl-mode)
("\\.py$" . python-mode)
("\\.php$" . php-mode)) auto-mode-alist)))
;; Auto font lock mode
(defvar font-lock-auto-mode-list
(list 'c-mode 'c++-mode 'c++-c-mode 'emacs-lisp-mode 'lisp-mode 'perl-mode 'scheme-mode'python-mode'php-mode)
"List of modes to always start in font-lock-mode")
(defvar font-lock-mode-keyword-alist
'((c++-c-mode . c-font-lock-keywords)
(perl-mode . perl-font-lock-keywords))
"Associations between modes and keywords")
(defun font-lock-auto-mode-select ()
"Automatically select font-lock-mode if the current major mode is in font-lock-auto-mode-list"
(if (memq major-mode font-lock-auto-mode-list)
(progn
(font-lock-mode t))
)
)
;; New dabbrev stuff
;(require 'new-dabbrev)
(setq dabbrev-always-check-other-buffers t)
(setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_")
(add-hook 'emacs-lisp-mode-hook
'(lambda ()
(set (make-local-variable 'dabbrev-case-fold-search) nil)
(set (make-local-variable 'dabbrev-case-replace) nil)))
(add-hook 'c-mode-hook
'(lambda ()
(set (make-local-variable 'dabbrev-case-fold-search) nil)
(set (make-local-variable 'dabbrev-case-replace) nil)))
(add-hook 'text-mode-hook
'(lambda ()
(set (make-local-variable 'dabbrev-case-fold-search) t)
(set (make-local-variable 'dabbrev-case-replace) t)))
;;自定义风格
(defconst my-style
'("stroustrup" ;;基于现有的代码风格进行修改。
(c-offsets-alist . ((access-label . -)
(inclass . ++)
(case-label . +)
(statement-cont . 0)
(inline-open . 0)
(topmost-intro . -)
(statement-case-intro . +))))
"My Programming Style")
;; 将自定义的代码风格加入到列表中
(c-add-style "my" my-style)
;; 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)
)
(add-hook 'c-mode-hook 'my-c-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-c-mode-auto-pair)
(add-hook 'c-mode-hook (lambda () (local-set-key [(return)] 'newline-and-indent) ))
(add-hook 'c-mode-hook (lambda () (setq comment-column 48) ))
(add-hook 'c++-mode-hook (lambda () (local-set-key [(return)] 'newline-and-indent) ))
(add-hook 'c++-mode-hook (lambda () (setq comment-column 48) ))
;; C++ and C mode...
(defun my-c++-mode-hook ()
(setq tab-width 4)
(setq c-auto-hungry-initial-state 'none)
(setq c-delete-function 'backward-delete-char)
(setq c-tab-always-indent t)
(c-set-style "my")
)
(defun my-c-mode-hook ()
(setq tab-width 4)
(setq c-auto-hungry-initial-state 'none)
(setq c-delete-function 'backward-delete-char)
(setq c-tab-always-indent t)
(define-key c-mode-map "\C-m" 'reindent-then-newline-and-indent)
(c-set-style "my")
)
;; Emacs-Lisp mode...
(defun my-lisp-mode-hook ()
(define-key lisp-mode-map "\C-m" 'reindent-then-newline-and-indent)
(define-key lisp-mode-map "\C-i" 'lisp-indent-line)
(define-key lisp-mode-map "\C-j" 'eval-print-last-sexp)
(setq tab-width 4))
;; Add all of the hooks...
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook)
(add-hook 'lisp-mode-hook 'my-lisp-mode-hook)
;; Complement to next-error
(defun previous-error (n)
"Visit previous compilation error message and corresponding source code."
(interactive "p")
(next-error (- n))
)
;; X11 or PC using direct screen writes
(if window-system
(progn
;; (global-set-key [M-f1] 'hilit-repaint-command)
;; (global-set-key [M-f2] [?\C-u M-f1])
(setq hilit-mode-enable-list
'(not text-mode c-mode c++-mode emacs-lisp-mode lisp-mode
scheme-mode)
hilit-auto-highlight nil
hilit-auto-rehighlight 'visible
hilit-inhibit-hooks nil
hilit-inhibit-rebinding t)
(require 'paren))
(setq baud-rate 2400) ; For slow serial connections
)
;; Under UNIX
;(if (not (equal system-type 'ms-dos))
; (progn
; (if first-time
; (server-start))))
;; Indicate that this file has been read at least once
;(setq first-time nil)
;; No need to debug anything now
(setq debug-on-error nil)
(setq auto-mode-alist
(cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
(cons '("python" . python-mode)
interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)
;(global-font-lock-mode t)
(setq transient-mark-mode t)
(setq mark-even-if-inactive t)
(setq visible-bell nil)
(setq compile-command "make")
(setq suggest-key-bindings nil)
;;括号自动匹配
(show-paren-mode t)
(setq show-paren-style 'parentheses)
(mouse-avoidance-mode 'animate)
(auto-image-file-mode)
;; Hide the toolbar
(tool-bar-mode nil)
;; Hide the scroll bar
(scroll-bar-mode nil)
(setq inhibit-startup-message t)
(setq gdb-many-windows t)
(setq frame-title-format "emacs@%b %f")
(defvar my-isearch-string nil)
(setq my-isearch-string "")
(defun my-isearch-region-forward ()
"isearch region if mark is acktive"
(interactive)
(if mark-active
(let ((beg (region-beginning))
(end (region-end)))
(setq my-isearch-string (filter-buffer-substring beg end nil))
(deactivate-mark)
(if (> (length my-isearch-string) 0)
(progn
(goto-char beg)
(isearch-update-ring my-isearch-string)
(add-hook 'isearch-mode-end-hook 'my-isearch-end-hook)
(isearch-mode t) ;hack isearch-forward
(isearch-repeat 'forward)
(message "%s" isearch-string)))) ;print debug msg
(if (> (length my-isearch-string) 0)
(progn
(isearch-repeat 'forward))
(message "no region selected")
)))
(defun my-isearch-end-hook ()
(remove-hook 'isearch-mode-end-hook 'my-isearch-end-hook)
(setq my-isearch-string ""))
(defvar my-isearch-word "")
(defun my-isearch-word ()
(interactive)
(when (not mark-active)
(let (word-beg word-end)
(unless (looking-at "\\<")
(if (eq (char-syntax (char-after)) ?w)
(backward-word)
(and (forward-word) (backward-word)))
)
(setq word-beg (point))
(forward-word)
(setq word-end (point))
(setq my-isearch-word (filter-buffer-substring word-beg word-end nil t))
(backward-word)
)
(when (> (length my-isearch-word) 0)
(setq my-isearch-word (concat "\\<" my-isearch-word "\\>"))
(isearch-update-ring my-isearch-word t)
(add-hook 'isearch-mode-end-hook 'my-isearch-word-end-hook)
(isearch-mode t t)
(isearch-repeat 'forward)
(message "%s" isearch-string))))
(defun my-isearch-word-end-hook ()
(remove-hook 'isearch-mode-end-hook 'my-isearch-word-end-hook)
(setq my-isearch-word ""))
;; do not make tmp file
(setq-default make-backup-files nil)
;; for code templates
(global-set-key (kbd "<M-S>") 'my-isearch-region-forward)
(global-set-key (kbd "<M-s>") 'my-isearch-word)
;; some new function keyboard combined
(global-set-key [(f1)] 'semantic-symref-symbol)
(global-set-key [(f2)] 'other-window)
(global-set-key [(f3)] 'semantic-ia-show-summary)
(global-set-key [(f4)] 'buffer-menu-other-window)
(global-set-key [(f5)] 'compile)
(global-set-key [(f6)] 'gdb)
(global-set-key [(f7)] 'previous-error)
(global-set-key [(f8)] 'next-error)
(global-set-key [(f9)] 'comment-or-uncomment-region)
(global-set-key [(f11)] 'ecb-activate)
(global-set-key [(f12)] 'ecb-deactivate)
(global-set-key (kbd "C-2") 'set-mark-command)
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "M-g") 'goto-line)
(global-set-key "\M-\C-r" 'query-replace)
(global-set-key (kbd "M-m") 'bookmark-set)
(global-set-key (kbd "M-j") 'bookmark-jump)
;(global-set-key (kbd "C-0") 'cscope-show-entry-other-window)
(global-set-key (kbd "C-\\") 'srecode-document-insert-function-comment)
;; Maximize the windows
(defun my-max-window()
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
(x-send-client-message nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0))
)
(run-with-idle-timer 1 nil 'my-max-window)
;; Configure the doxygen
(add-to-list 'load-path "~/.emacs.d/doxymacs")
(require 'doxymacs) ;; 启动doxymacs
;;注释高亮,针对C和C++程序
(defun my-doxymacs-font-lock-hook ()
(if (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
(doxymacs-font-lock)))
(add-hook 'font-lock-mode-hook 'my-doxymacs-font-lock-hook)
(doxymacs-mode) ;;doxymacs-mode常true
(add-hook 'c-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode
(add-hook 'c++-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode
;;---C-c d i
;(xterm-mouse-mode t)
;(mouse-wheel-mode t)
;(mouse-sel-mode t)
(setq display-time-world t)
(setq display-time-use-mail-icon t)
(setq display-time-interval 5)
(display-time-mode t)
(message " ******* All done ******** , %s%s" (user-login-name) ".")
- emacs...
- emacs
- ~/.emacs
- .emacs
- emacs
- emacs
- emacs
- Emacs
- emacs
- emacs
- Emacs
- Emacs
- .emacs
- Emacs
- Emacs
- emacs
- emacs
- Emacs
- Deep Learning 学习随记(四)自学习和非监督特征学习
- ABAP--动态创建局部类型的变量
- JVM 回收流程图
- jQuery 下拉菜单操作大全
- jQuery拖拽效果和切割效果
- .emacs
- cocos2dx-CCMenu菜单
- DeepLearning学习随记(五)Deepnetwork深度网络
- Android 中Parcelable的作用
- 解决eclipse编辑python程序的SyntaxError: Non-ASCII character错误
- 美国政府悬赏500万美元缉拿中国军火商李方伟
- UIViewKeyframeAnimation
- 轻松找到本地3D打印馆/ 2D快印店和相关产品/设备/展会/学习/创业平台
- HttpUrlConnection post方法传递中文乱码问题