;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;下面的这一大部分,是可以在任意只要安装了emacs的机器上面,就可以使用的,
;不会依赖于任何的外部包,也无所谓是ssh到服务器上,只要服务器安装了emacs
;下面的部分就会起作用,并且不会有额外的问题
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;---------------自己定义的光标移动---------------
(global-set-key (kbd "C-j") 'backward-char); //往上一个字符移动,就是左边移动
(global-set-key (kbd "C-l") 'forward-char); //往下一个字符移动,就是右边移动
(global-set-key (kbd "C-u") 'beginning-of-line); //到行头部,就是左边
(global-set-key (kbd "C-o") 'end-of-line); //到行尾部,就是右边
(global-set-key (kbd "M-j") 'backward-word); //往上一个单词移动
(global-set-key (kbd "M-l") 'forward-word); //往下一个单词移动
;---------------自己定义的光标移动---------------
;---------------删除字符和词---------------
(global-set-key (kbd "C-e") 'backward-delete-char); //删除光标前面的一个字符
(global-set-key (kbd "C-d") 'nil); //取消原先的快捷键
(global-set-key (kbd "C-d") 'delete-char); //删除光标后面的一个字符
(defun delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))
(defun backward-delete-word (arg)
"Delete characters backward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(delete-word (- arg)))
(global-set-key (kbd "M-e") 'backward-delete-word); //删除前一个词
(global-set-key (kbd "M-d") 'nil); //取消原先的快捷键
(global-set-key (kbd "M-d") 'delete-word); //删除后一个词
;---------------删除字符和词---------------
;---------------切换缓冲-----------------
(global-set-key (kbd "C-x C-j") 'next-buffer); //前一个buf
(global-set-key (kbd "C-x C-l") 'previous-buffer); //后一个buf
;---------------切换缓冲-----------------
;---------------设定标记--------------
(global-set-key (kbd "M-b") 'set-mark-command)
;---------------设定标记--------------
;-----------------自己定义的拷贝粘贴-----------------
(global-set-key (kbd "C-c C-c") 'kill-ring-save); //copy
(global-set-key (kbd "C-v") 'yank); //paste
(global-set-key (kbd "C-x x") 'kill-region); //cut
(global-set-key (kbd "C-z") 'undo); //udo
;-----------------自己定义的拷贝粘贴-----------------
;-----------------默认用正则搜索-----------------
(global-set-key (kbd "C-s") 'isearch-forward-regexp ); //正则搜索
;-----------------默认用正则搜索-----------------e
;----------------设置时间显示为24小时制,否则为12小时制----------------
(setq display-time-24hr-format 't); //显示时间
(setq display-time-day-and-date t); //显示日期
(display-time)
;----------------设置时间显示为24小时制,否则为12小时制----------------
;----------------------------------------有错误时,后面的不会被执行 ----------------------------------------
;(setq-default cursor-type 'bar); //设置光标为竖线
(setq-default cursor-type 'box); //设置光标为方块
;----------------------------------------有错误时,后面的不会被执行 ----------------------------------------
;-------------------------------------一些其他的功能 -----------------------------------------
(auto-image-file-mode t); //打开图片显示功能
(fset 'yes-or-no-p 'y-or-n-p); //以 y/n代表 yes/no,可能你觉得不需要,呵呵。
(mouse-avoidance-mode 'animate); //光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。很好玩阿,这个功能
(setq frame-title-format "hjz@%b"); //在标题栏提示你目前在什么位置。你要把hjz改成自己的用户名
(setq default-fill-column 256); //默认显示 256列就换行
;-------------------------------------一些其他的功能 -----------------------------------------
;------------------------外观设置------------------------------
(tool-bar-mode nil); //去掉工具栏
;(menu-bar-mode nil); //去掉菜单栏
;(scroll-bar-mode nil); //不要滚动栏,现在都用滚轴鼠标了,可以不用滚动栏了
;------------------------外观设置------------------------------
;------------------------------------自定义的F快捷键 ------------------------------------------
;自定义按键
(global-set-key [f1] 'shell); //F1进入Shell
(global-set-key [f3] 'speedbar-get-focus); //F3打开speedbar
(global-set-key (kbd "C-x C-o" ) 'other-window); //窗口间跳转
(global-set-key [f7] 'compile); //F7编译文件
;------------------------------------自定义的F快捷键 ------------------------------------------
;-------------------------关闭当前的buffer-------------------------
(global-set-key (kbd "M-c") 'kill-this-buffer)
;-------------------------关闭当前的buffer-------------------------
;----------------------------------鼠标滚轮 --------------------------------------------
;鼠标滚轮,默认的滚动太快,这里改为3行
(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)
;----------------------------------鼠标滚轮 --------------------------------------------
;-----------------------------------不要生成临时文件 -------------------------------------------
(setq-default make-backup-files nil)
;-----------------------------------不要生成临时文件 -------------------------------------------
;---------------------------------用y/n代替yes /no---------------------------------------------
(fset 'yes-or-no-p 'y-or-n-p)
;---------------------------------用y/n代替yes /no---------------------------------------------
;-------------------------关闭错误提示的Beep音--------------
(setq visible-bell t)
;-------------------------关闭错误提示的Beep音--------------
;-------------------------关闭启动时的`开机画面'------------
(setq inhibit-startup-message t)
;-------------------------关闭启动时的`开机画面'------------
;;-------------------------使用Win下的选择习惯---------------
(pc-selection-mode); //用shift+方向键进行选择
;;-------------------------使用Win下的选择习惯---------------
;;-------------------------Shell 使用 ansi color-------------
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;;-------------------------Shell 使用 ansi color-------------
;---------------------------文字间距,行距等---------------------------
;;设定行距
(setq default-line-spacing 0)
;;页宽
(setq default-fill-column 256)
;;缺省模式 text-mode
(setq default-major-mode 'text-mode)
;;锁定行高
(setq resize-mini-windows nil)
;---------------------------文字间距,行距等---------------------------
(setq kill-ring-max 512)
;用一个很大的 kill ring. 这样可以有更多的ctrl+z可以按
;-----------------------------平滑滚动-------------------------------
;VC下有两种滚动模式,一种叫做up up/down,使移动光标,当光标到达页面顶端的时候,滚动页面;
;一种是Scroll line up/down,光标所在的绝对行和列不变,滚动页面。
;Emacs下有第一种滚动方式,但是第二种滚动方式一直没有找到。于是自己写了两个函数,来实现这个功能,以方便边浏览边编辑代码的操作。
(defun hold-line-scroll-up()
"Scroll the page with the cursor in the same line"
(interactive)
(let ((next-screen-context-lines
(count-lines
(window-start) (window-end)
)
))
(scroll-up)
))
(defun hold-line-scroll-down()
"Scroll the page with the cursor in the same line"
(interactive)
(let ((next-screen-context-lines
(count-lines
(window-start) (window-end)
)
))
(scroll-down)
))
(global-set-key (kbd "M-n") 'scroll-up);//page down
(global-set-key (kbd "M-p") 'scroll-down);//page up
;-----------------------------平滑滚动-------------------------------
;---------------------------------------不折行显示 ---------------------------------------
;; dired-mode 下不折行显示
;(defun my-dired-long-lines ()
(setq truncate-lines t);)
;(add-hook 'dired-after-readin-hook 'my-dired-long-lines)
;---------------------------------------不折行显示 ---------------------------------------
;;-------------------------语法加亮--------------------------
(global-font-lock-mode 't)
;;-------------------------显示列号--------------------------
(setq column-number-mode t)
;--------------------括号跳转匹配--------------------
;就是win下按Ctrl + ]跳到对应的花括号上去,我2造成的
(global-set-key (kbd "C-]") 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert C-]."
(interactive "p")
(cond ((looking-at "//s/(") (forward-list 1) (backward-char 1))
((looking-at "//s/)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
;--------------------括号跳转匹配--------------------
;-------------------------标题拦显示buffer的名字------------
(setq frame-title-format "emacs@%b")
(setq user-full-name "Huang Jing Ze")
;-------------------------标题拦显示buffer的名字------------
;--------------------------------------shell,gdb退出后,自动关闭该 buffer----------------------------------------
(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 mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'kill-buffer-on-exit))
(add-hook 'shell-mode-hook 'mode-hook-func)
(add-hook 'gdb-mode-hook 'mode-hook-func)
;--------------------------------------shell,gdb退出后,自动关闭该 buffer----------------------------------------
;----------------------------tab设置----------------------------
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
;----------------------------tab设置----------------------------
;---------------加载ssh的支持-----------------
(require `tramp)
;---------------加载ssh的支持-----------------
;---------------设置语言环境-----------------
;; For my language code setting (UTF-8)
(setq current-language-environment "UTF-8")
(setq default-input-method "chinese-py")
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;---------------设置语言环境-----------------
;-----------------自动注释--------------
(defun qiang-comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command. If no region is selected and current line is not blank and we are not at the end of the line, then comment current line. Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key "\M-;" 'qiang-comment-dwim-line)
;-----------------自动注释--------------
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;上面的这一大部分,是可以在任意只要安装了emacs的机器上面,就可以使用的,
;不会依赖于任何的外部包,也无所谓是ssh到服务器上,只要服务器安装了emacs
;上面的部分就会起作用,并且不会有额外的问题
;简单来说:算是一个通用的配置,即使是在洗衣机上,只要洗衣机安装了emacs
;上面的配置就会起作用,也是一些最最基本的配置
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;----------------------------------C风格的对齐-----------------------------
(custom-set-variables
'(standard-indent 4)
'(inverse-video t))
(custom-set-faces)
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(substatement-open . 0)
(case-label . 4)
(block-open . 0);
(defun-block-intro . 0)
(statement-block-intro . 4)
(substatement . 4)
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t)
)
"My C Programming Style")
;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-add-style "PERSONAL" my-c-style t)
;; offset customizations not in my-c-style
(c-set-offset 'defun-block-intro' +)
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline and hungry-delete
(c-toggle-hungry-state 1)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
;(define-key c-mode-base-map "/C-m" 'newline-and-indent)
;(define-key c-mode-base-map "/C-c /C-c" 'kill-ring-save)
;(define-key c-mode-base-map "/C-v" 'yank)
;(define-key c-mode-base-map "/C-x x" 'kill-region)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;----------------------------------C风格的对齐-----------------------------
;--------------------------------传说中的施特劳斯特卢普的C++代码风格 ---------------------------------------
(add-to-list 'auto-mode-alist '("//.h//'" . c++-mode))
(require 'cl)
(defun file-in-directory-list-p (file dirlist)
"Returns true if the file specified is contained within one of the directories in the list. The directories must also exist."
(let ((dirs (mapcar 'expand-file-name dirlist))
(filedir (expand-file-name (file-name-directory file))))
(and
(file-directory-p filedir)
(member-if (lambda (x) ; Check directory prefix matches
(string-match (substring x 0 (min(length filedir) (length x))) filedir))
dirs))))
(defun buffer-standard-include-p ()
"Returns true if the current buffer is contained within one of the directories in the INCLUDE environment variable."
(and (getenv "INCLUDE")
(file-in-directory-list-p buffer-file-name (split-string (getenv "INCLUDE") path-separator))))
(add-to-list 'magic-fallback-mode-alist '(buffer-standard-include-p . c++-mode))
(c-add-style "my-style"
'("stroustrup"
(indent-tabs-mode . nil) ; use spaces rather than tabs
(c-basic-offset . 8) ; indent by four spaces
(c-offsets-alist . (
(inline-open . 0) ; custom indentation rules
(brace-list-open . 0)
(statement-case-open . +)
)
)
))
(defun my-c++-mode-hook ()
(c-set-style "my-style") ; use my-style defined above
(auto-fill-mode)
;(c-toggle-auto-hungry-state 1)
(c-toggle-electric-state 1)
;(c-toggle-auto-newline 1);这个就是遇到了{};之后,自己开新行的
(c-toggle-hungry-state 1)
;(c-toggle-syntactic-indentation 1)
;(define-key c++-mode-map (kbd ":") 'semantic-ia-complete-symbol-menu)
;(define-key c++-mode-map (kbd ".") 'semantic-ia-complete-symbol-menu)
;(define-key c++-mode-map (kbd "C-c C-c") 'kill-ring-save);copy
;(define-key c++-mode-map (kbd "C-v") 'yank);paste
;(define-key c++-mode-map (kbd "M-x") 'kill-region);cut
)
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
;--------------------------------传说中的施特劳斯特卢普的C++代码风格 ---------------------------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;-----------去网上拉下来----------------颜色主题------------------
(setq load-path (cons "/home/hjz/software/emacs/color-theme-6.6.0" load-path))
(require 'color-theme)
(color-theme-initialize)
(color-theme-subtle-hacker)
;-----------去网上拉下来----------------颜色主题------------------
;----------要自己安装一个--------------------cscope-------------------
;(load-file "/usr/share/emacs23/site-lisp/cscope/xcscope.elc")
;(require 'xcscope)
;----------要自己安装一个--------------------cscope-------------------
;---------想办法弄到----------------大名鼎鼎的cedet----------------
(setq load-path (cons "/home/hjz/software/emacs/cedet-1.0pre7/common" load-path))
(setq load-path (cons "/home/hjz/software/emacs/cedet-1.0pre7/contrib" load-path))
(require 'cedet)
(require 'semantic)
(require 'semantic-ia)
(require 'semanticdb)
(global-ede-mode t)
(require 'semantic-gcc)
(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)
(global-semantic-stickyfunc-mode -1);关掉,免得替代tabbar
(which-function-mode nil)
;-----------------------
(setq semanticdb-project-roots (list (expand-file-name "/")))
(defconst cedet-user-include-dirs
(list "/" "./"))
(defconst cedet-win32-include-dirs
(list "../"))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
(when (eq system-type 'windows-nt)
(setq include-dirs (append include-dirs cedet-win32-include-dirs)))
(mapc (lambda (dir)
(semantic-add-system-include dir 'c++-mode)
(semantic-add-system-include dir 'c-mode))
include-dirs))
;-----------------------
(global-set-key [f12] 'semantic-ia-fast-jump);F12跳转
;Shift F12跳转回来
(global-set-key [S-f12]
(lambda ()
(interactive)
(if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
(error "Semantic Bookmark ring is currently empty"))
(let* ((ring (oref semantic-mru-bookmark-ring ring))
(alist (semantic-mrub-ring-to-assoc-list ring))
(first (cdr (car alist))))
(if (semantic-equivalent-tag-p (oref first tag)
(semantic-current-tag))
(setq first (cdr (car (cdr alist)))))
(semantic-mrub-switch-tags first))))
(global-set-key (kbd "C-/") 'semantic-ia-complete-symbol-menu)
;---------想办法弄到----------------大名鼎鼎的cedet----------------
;-----------------F4.h.cpp切换------------
(require 'eassist nil 'noerror)
(global-set-key (kbd "M-o") 'eassist-switch-h-cpp);修改为F4切换.h和.cpp
;设定.h .cpp 的格式
(setq eassist-header-switches
'(("h" . ("cpp" "cxx" "c++" "CC" "cc" "C" "c" "mm" "m"))
("hh" . ("cc" "CC" "cpp" "cxx" "c++" "C"))
("hpp" . ("cpp" "cxx" "c++" "cc" "CC" "C"))
("hxx" . ("cxx" "cpp" "c++" "cc" "CC" "C"))
("h++" . ("c++" "cpp" "cxx" "cc" "CC" "C"))
("H" . ("C" "CC" "cc" "cpp" "cxx" "c++" "mm" "m"))
("HH" . ("CC" "cc" "C" "cpp" "cxx" "c++"))
("cpp" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
("cxx" . ("hxx" "hpp" "h++" "HH" "hh" "H" "h"))
("c++" . ("h++" "hpp" "hxx" "HH" "hh" "H" "h"))
("CC" . ("HH" "hh" "hpp" "hxx" "h++" "H" "h"))
("cc" . ("hh" "HH" "hpp" "hxx" "h++" "H" "h"))
("C" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
("c" . ("h"))
("m" . ("h"))
("mm" . ("h"))))
;-----------------F4.h.cpp切换------------
;----------------代码折叠----------------
(require 'semantic-tag-folding nil 'noerror)
(global-semantic-tag-folding-mode 1)
(global-set-key (kbd "C-c -") 'semantic-tag-folding-fold-block)
(global-set-key (kbd "C-c +") 'semantic-tag-folding-show-block)
;----------------代码折叠----------------
;-----------------项目工程文件------------------
(global-ede-mode t)
;-----------------项目工程文件------------------
;---------想办法弄到-----------------ecb------------------
(add-to-list 'load-path "/home/hjz/software/emacs/ecb-2.40")
(require 'ecb)
;(ecb-activate)
;---------想办法弄到-----------------ecb------------------
;-------在ubuntu下,会有gdb-ui-------------gdb的相关-----------------
;(load-file "/home/hjz/software/emacs/multi-gdb-ui.el")
(require 'gdb-ui)
(defun gdb-or-gud-go ()
"If gdb isn't running; run gdb, else call gud-go."
(interactive)
(if (and gud-comint-buffer
(buffer-name gud-comint-buffer)
(get-buffer-process gud-comint-buffer)
(with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
(gud-call (if gdb-active-process "continue" "run") "")
(gdb (gud-query-cmdline 'gdb))))
(defun gud-break-remove ()
"Set/clear breakpoin."
(interactive)
(save-excursion
(if (eq (car (fringe-bitmaps-at-pos (point))) 'breakpoint)
(gud-remove nil)
(gud-break nil))))
(defun gud-kill ()
"Kill gdb process."
(interactive)
(with-current-buffer gud-comint-buffer (comint-skip-input))
(kill-process (get-buffer-process gud-comint-buffer)))
(setq gdb-many-windows t)
;---快捷键设定---
(global-set-key [f5] 'gdb-or-gud-go); //F5启动gdb或gdb运行
(global-set-key [f8] 'gud-print); //打印当前光标所在的变量,比较省心的好东东
(global-set-key [C-f8] 'gud-pstar); //打印指针所指向的值,也是好东东
(global-set-key [f9] 'gud-break-remove); //设定或取消断点
(global-set-key [f10] 'gud-next); //下一步
(global-set-key [C-f10] 'gud-until); //执行直到
(global-set-key [S-f10] 'gud-jump); //跳转
(global-set-key [f11] 'gud-step); //单步进入的方式
(global-set-key [C-f11] 'gud-finish); //跳出函数
;--------------说明--------------
;在c/c++-mode中按f7,就会调用make编译程序。
;在c/c++-mode中按f5,就会进入gdb调试。
;打开gdb后在源代码buffer中按f9设置断点,相当于gdb中的break。
;按Ctrl+f9就可以删除断点,相当于gdb中的delete。
;在gdb buffer中,按Ctrl+f5就开始执行程序,相当于gdb中的run。
;断点之后,可以按f10单步执行,相当于gdb中的next。
;把光标移动到某处按Ctrl+f10,会一直执行光标位置,相当于gdb的until。
;把光标移动到某处按Shift+f10,会jump到光标位置,下一次会从光标处执行。
;也可以按f11单步执行,不过f11会进入函数内部,相当于gdb中的step。
;按Ctrl+f11可以跳出当前函数,相当于gdb中的finish。
;在断点处按Shift+f5继续执行程序,相当于gdb中的continue。
;在变量上按f8会输出变量的值,相当于gdb的print。
;在变量上按Ctrl+f8会打印出指针对应的值。
;--------------说明--------------
;-------在ubuntu下,会有gdb-ui-------------gdb的相关-----------------
;--------想办法弄到-------------auto complete-------------------
(add-to-list 'load-path "/home/hjz/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "/home/hjz/.emacs.d//ac-dict")
(ac-config-default)
;; Show 0.8 second later
(setq ac-auto-show-menu 0.8)
;; 20 lines
(setq ac-menu-height 20)
;; Examples
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue")
(add-hook 'c++-mode (lambda () (add-to-list 'ac-sources 'ac-source-semantic)))
;; Complete member name by C-c . for C++ mode.
;(add-hook 'c++-mode-hook
; (lambda ()
; (local-set-key (kbd "C-c .") 'ac-complete-semantic)))
;; Complete file name by C-c /
;(global-set-key (kbd "C-c /") 'ac-complete-filename)
(defun semantic-and-gtags-complete ()
(interactive)
(auto-complete '(ac-source-semantic ac-source-gtags)))
(defun auto-complete-settings ()
"Settings for `auto-complete'."
;; After do this, isearch any string, M-: (match-data) always
;; return the list whose elements is integer
(global-auto-complete-mode 1)
;; 不让回车的时候执行`ac-complete', 因为当你输入完一个
;; 单词的时候, 很有可能补全菜单还在, 这时候你要回车的话,
;; 必须要干掉补全菜单, 很麻烦, 用M-j来执行`ac-complete'
(define-key ac-complete-mode-map "/C-i" 'nil)
;(define-key ac-complete-mode-map "RET" 'nil)
;(define-key ac-complete-mode-map "M-j" 'ac-complete)
;(define-key ac-complete-mode-map "<C-return>" 'ac-complete)
(define-key ac-complete-mode-map "/C-n" 'ac-next)
(define-key ac-complete-mode-map "/C-p" 'ac-previous)
(setq ac-dwim t)
(setq ac-candidate-max ac-candidate-menu-height)
(set-default 'ac-sources
'(ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename))
;(setq ac-modes ac+-modes)
(dolist (command `(backward-delete-char-untabify delete-backward-char))
(add-to-list 'ac-trigger-commands command))
(defun ac-start-use-sources (sources)
(interactive)
(let ((ac-sources sources))
(call-interactively 'ac-start)))
(defvar ac-trigger-edit-commands
`(self-insert-command
delete-backward-char
backward-delete-char
backward-delete-char-untabify)
"*Trigger edit commands that specify whether `auto-complete' should start or not when `ac-completing'."))
(eval-after-load "auto-complete"
'(auto-complete-settings))
(eval-after-load "cc-mode"
'(progn
(dolist (command `(c-electric-backspace
c-electric-backspace-kill))
(add-to-list 'ac-trigger-commands command)
(add-to-list 'ac-trigger-edit-commands command))))
(eval-after-load "autopair"
'(progn
(dolist (command `(autopair-insert-or-skip-quote
autopair-backspace
autopair-extra-skip-close-maybe))
(add-to-list 'ac-trigger-commands command))
(defun ac-trigger-command-p ()
"Return non-nil if `this-command' is a trigger command."
(or
(and
(memq this-command ac-trigger-commands)
(let* ((autopair-emulation-alist nil)
(key (this-single-command-keys))
(beyond-autopair (or (key-binding key)
(key-binding (lookup-key local-function-key-map key)))))
(memq beyond-autopair ac-trigger-edit-commands)))
(and ac-completing
(memq this-command ac-trigger-edit-commands))))))
(defun ac-settings-4-lisp ()
"Auto complete settings for lisp mode."
(setq ac-omni-completion-sources
'(
("//<featurep/s+'" ac+-source-elisp-features)
("//<require/s+'" ac+-source-elisp-features)
("//<load/s+'" ac-source-emacs-lisp-features)
)
)
(ac+-apply-source-elisp-faces)
(setq ac-sources
'(ac-source-yasnippet
ac-source-symbols
;; ac-source-semantic
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
;; ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename)
)
)
(defun ac-settings-4-c ()
(setq ac-omni-completion-sources (list (cons "//." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-cpp ()
(setq ac-omni-completion-sources
(list (cons "//." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c++-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-text ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu))
)
(defun ac-settings-4-eshell ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename
ac-source-symbols
ac-source-imenu))
)
(defun ac-settings-4-ruby ()
(require 'rcodetools-settings)
(setq ac-omni-completion-sources
(list (cons "//." '(ac-source-rcodetools))
(cons "::" '(ac-source-rcodetools))))
)
(defun ac-settings-4-html ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-tcl ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-awk ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(provide 'auto-complete-settings)
(require 'auto-complete-settings)
;--------想办法弄到-------------auto complete-------------------
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;
;下面的部分,是确定需要有外部额外的el的支持的,如果,没有去弄个文件
;然后,写入相关的内容,然后,弄到指定的目录下
;就可以用了
;
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;-----------------如果是在ubuntu下,用这个就可以了 tabbar--------------
(load-file "/home/hjz/software/emacs/tabbar.el")
(require 'tabbar)
(tabbar-mode)
(setq tabbar-buffer-groups-function nil)
;-----------------如果是在ubuntu下,用这个就可以了 tabbar--------------
;-------------------------------------加在emacs自己带的行号工具 -----------------------------------------
(require 'linum)
(global-linum-mode 1)
;-------------------------------------加在emacs自己带的行号工具 -----------------------------------------
;---------------------------这个svn被我修改了,由svn-status修改为 ---svn---------------------------
;(load-file "/home/hjz/software/emacs/psvn.el")
;(require 'psvn)
;(define-prefix-command 'svn-map)
;(global-set-key (kbd "M-x M-c") 'svn-map)
;(define-key svn-map (kbd "c") 'svn-status-commit)
;(global-set-key (kbd "M-x 'svn commit'") 'svn-status-commit)
;顺便说几句,这个集成在emacs中的svn,不是很好用,估计要么用外部的。
;要么,找个时间,自己弄一下。
;---------------------------这个svn被我修改了,由svn-status修改为 ---svn---------------------------
;----------------------------书签,有点像win下的书签----------------------------
(load-file "/home/hjz/software/emacs/bm.el")
(require 'bm )
(global-set-key [C-f2] 'nil);//clear old fast key
(global-set-key [C-f2] 'bm-toggle);
(global-set-key [f2] 'nil);
(global-set-key [f2] 'bm-next);
;----------------------------书签,有点像win下的书签----------------------------
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;
;下面的部分,基本上是确定了,只有在ubuntu下才能正常使用的
;所以,需要区分开来
;
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;---------------使用输入法,在ubuntu下可能会需要---------------
(global-set-key (kbd "C-SPC") 'nil);用win+space为set-mark键,留出ctrl+space热键作为输入法
(require 'ibus); //Turn on ibus-mode automatically after loading .emacs
(add-hook 'after-init-hook 'ibus-mode-on); //Use C-SPC for Set Mark command
(ibus-define-common-key ?\C-\s nil); //Use C-/ for Undo command
(ibus-define-common-key ?\C-/ nil); //Change cursor color depending on IBus status
(setq ibus-cursor-color '("red" "blue" "limegreen")); //Use s-SPC to toggle input status
(global-set-key (kbd "C-SPC") 'ibus-toggle)
;---------------使用输入法,在ubuntu下可能会需要---------------
;----------------------------------------这个是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.
'(column-number-mode t)
'(delete-selection-mode nil)
'(mark-even-if-inactive t)
'(scroll-bar-mode (quote right))
'(show-paren-mode t)
'(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.
'(default ((t (:inherit nil :stipple nil :background "darkslategrey" :foreground "wheat" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 89 :width normal :foundry "unknown" :family "文泉驿等宽微米黑")))))
;----------------------------------------这个是emacs的字体 ----------------------------------------
;--------------------------------全屏--------------------------------
(defun my-fullscreen ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0)))
(global-set-key [M-return] 'my-fullscreen);//Alt+Enter全屏,切换
;--------------------------------全屏--------------------------------
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;下面的这一大部分,是可以在任意只要安装了emacs的机器上面,就可以使用的,
;不会依赖于任何的外部包,也无所谓是ssh到服务器上,只要服务器安装了emacs
;下面的部分就会起作用,并且不会有额外的问题
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;---------------自己定义的光标移动---------------
(global-set-key (kbd "C-j") 'backward-char); //往上一个字符移动,就是左边移动
(global-set-key (kbd "C-l") 'forward-char); //往下一个字符移动,就是右边移动
(global-set-key (kbd "C-u") 'beginning-of-line); //到行头部,就是左边
(global-set-key (kbd "C-o") 'end-of-line); //到行尾部,就是右边
(global-set-key (kbd "M-j") 'backward-word); //往上一个单词移动
(global-set-key (kbd "M-l") 'forward-word); //往下一个单词移动
;---------------自己定义的光标移动---------------
;---------------删除字符和词---------------
(global-set-key (kbd "C-e") 'backward-delete-char); //删除光标前面的一个字符
(global-set-key (kbd "C-d") 'nil); //取消原先的快捷键
(global-set-key (kbd "C-d") 'delete-char); //删除光标后面的一个字符
(defun delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(delete-region (point) (progn (forward-word arg) (point))))
(defun backward-delete-word (arg)
"Delete characters backward until encountering the end of a word.
With argument, do this that many times."
(interactive "p")
(delete-word (- arg)))
(global-set-key (kbd "M-e") 'backward-delete-word); //删除前一个词
(global-set-key (kbd "M-d") 'nil); //取消原先的快捷键
(global-set-key (kbd "M-d") 'delete-word); //删除后一个词
;---------------删除字符和词---------------
;---------------切换缓冲-----------------
(global-set-key (kbd "C-x C-j") 'next-buffer); //前一个buf
(global-set-key (kbd "C-x C-l") 'previous-buffer); //后一个buf
;---------------切换缓冲-----------------
;---------------设定标记--------------
(global-set-key (kbd "M-b") 'set-mark-command)
;---------------设定标记--------------
;-----------------自己定义的拷贝粘贴-----------------
(global-set-key (kbd "C-c C-c") 'kill-ring-save); //copy
(global-set-key (kbd "C-v") 'yank); //paste
(global-set-key (kbd "C-x x") 'kill-region); //cut
(global-set-key (kbd "C-z") 'undo); //udo
;-----------------自己定义的拷贝粘贴-----------------
;-----------------默认用正则搜索-----------------
(global-set-key (kbd "C-s") 'isearch-forward-regexp ); //正则搜索
;-----------------默认用正则搜索-----------------e
;----------------设置时间显示为24小时制,否则为12小时制----------------
(setq display-time-24hr-format 't); //显示时间
(setq display-time-day-and-date t); //显示日期
(display-time)
;----------------设置时间显示为24小时制,否则为12小时制----------------
;----------------------------------------有错误时,后面的不会被执行 ----------------------------------------
;(setq-default cursor-type 'bar); //设置光标为竖线
(setq-default cursor-type 'box); //设置光标为方块
;----------------------------------------有错误时,后面的不会被执行 ----------------------------------------
;-------------------------------------一些其他的功能 -----------------------------------------
(auto-image-file-mode t); //打开图片显示功能
(fset 'yes-or-no-p 'y-or-n-p); //以 y/n代表 yes/no,可能你觉得不需要,呵呵。
(mouse-avoidance-mode 'animate); //光标靠近鼠标指针时,让鼠标指针自动让开,别挡住视线。很好玩阿,这个功能
(setq frame-title-format "hjz@%b"); //在标题栏提示你目前在什么位置。你要把hjz改成自己的用户名
(setq default-fill-column 256); //默认显示 256列就换行
;-------------------------------------一些其他的功能 -----------------------------------------
;------------------------外观设置------------------------------
(tool-bar-mode nil); //去掉工具栏
;(menu-bar-mode nil); //去掉菜单栏
;(scroll-bar-mode nil); //不要滚动栏,现在都用滚轴鼠标了,可以不用滚动栏了
;------------------------外观设置------------------------------
;------------------------------------自定义的F快捷键 ------------------------------------------
;自定义按键
(global-set-key [f1] 'shell); //F1进入Shell
(global-set-key [f3] 'speedbar-get-focus); //F3打开speedbar
(global-set-key (kbd "C-x C-o" ) 'other-window); //窗口间跳转
(global-set-key [f7] 'compile); //F7编译文件
;------------------------------------自定义的F快捷键 ------------------------------------------
;-------------------------关闭当前的buffer-------------------------
(global-set-key (kbd "M-c") 'kill-this-buffer)
;-------------------------关闭当前的buffer-------------------------
;----------------------------------鼠标滚轮 --------------------------------------------
;鼠标滚轮,默认的滚动太快,这里改为3行
(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)
;----------------------------------鼠标滚轮 --------------------------------------------
;-----------------------------------不要生成临时文件 -------------------------------------------
(setq-default make-backup-files nil)
;-----------------------------------不要生成临时文件 -------------------------------------------
;---------------------------------用y/n代替yes /no---------------------------------------------
(fset 'yes-or-no-p 'y-or-n-p)
;---------------------------------用y/n代替yes /no---------------------------------------------
;-------------------------关闭错误提示的Beep音--------------
(setq visible-bell t)
;-------------------------关闭错误提示的Beep音--------------
;-------------------------关闭启动时的`开机画面'------------
(setq inhibit-startup-message t)
;-------------------------关闭启动时的`开机画面'------------
;;-------------------------使用Win下的选择习惯---------------
(pc-selection-mode); //用shift+方向键进行选择
;;-------------------------使用Win下的选择习惯---------------
;;-------------------------Shell 使用 ansi color-------------
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;;-------------------------Shell 使用 ansi color-------------
;---------------------------文字间距,行距等---------------------------
;;设定行距
(setq default-line-spacing 0)
;;页宽
(setq default-fill-column 256)
;;缺省模式 text-mode
(setq default-major-mode 'text-mode)
;;锁定行高
(setq resize-mini-windows nil)
;---------------------------文字间距,行距等---------------------------
(setq kill-ring-max 512)
;用一个很大的 kill ring. 这样可以有更多的ctrl+z可以按
;-----------------------------平滑滚动-------------------------------
;VC下有两种滚动模式,一种叫做up up/down,使移动光标,当光标到达页面顶端的时候,滚动页面;
;一种是Scroll line up/down,光标所在的绝对行和列不变,滚动页面。
;Emacs下有第一种滚动方式,但是第二种滚动方式一直没有找到。于是自己写了两个函数,来实现这个功能,以方便边浏览边编辑代码的操作。
(defun hold-line-scroll-up()
"Scroll the page with the cursor in the same line"
(interactive)
(let ((next-screen-context-lines
(count-lines
(window-start) (window-end)
)
))
(scroll-up)
))
(defun hold-line-scroll-down()
"Scroll the page with the cursor in the same line"
(interactive)
(let ((next-screen-context-lines
(count-lines
(window-start) (window-end)
)
))
(scroll-down)
))
(global-set-key (kbd "M-n") 'scroll-up);//page down
(global-set-key (kbd "M-p") 'scroll-down);//page up
;-----------------------------平滑滚动-------------------------------
;---------------------------------------不折行显示 ---------------------------------------
;; dired-mode 下不折行显示
;(defun my-dired-long-lines ()
(setq truncate-lines t);)
;(add-hook 'dired-after-readin-hook 'my-dired-long-lines)
;---------------------------------------不折行显示 ---------------------------------------
;;-------------------------语法加亮--------------------------
(global-font-lock-mode 't)
;;-------------------------显示列号--------------------------
(setq column-number-mode t)
;--------------------括号跳转匹配--------------------
;就是win下按Ctrl + ]跳到对应的花括号上去,我2造成的
(global-set-key (kbd "C-]") 'match-paren)
(defun match-paren (arg)
"Go to the matching paren if on a paren; otherwise insert C-]."
(interactive "p")
(cond ((looking-at "//s/(") (forward-list 1) (backward-char 1))
((looking-at "//s/)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
;--------------------括号跳转匹配--------------------
;-------------------------标题拦显示buffer的名字------------
(setq frame-title-format "emacs@%b")
(setq user-full-name "Huang Jing Ze")
;-------------------------标题拦显示buffer的名字------------
;--------------------------------------shell,gdb退出后,自动关闭该 buffer----------------------------------------
(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 mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'kill-buffer-on-exit))
(add-hook 'shell-mode-hook 'mode-hook-func)
(add-hook 'gdb-mode-hook 'mode-hook-func)
;--------------------------------------shell,gdb退出后,自动关闭该 buffer----------------------------------------
;----------------------------tab设置----------------------------
(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
;----------------------------tab设置----------------------------
;---------------加载ssh的支持-----------------
(require `tramp)
;---------------加载ssh的支持-----------------
;---------------设置语言环境-----------------
;; For my language code setting (UTF-8)
(setq current-language-environment "UTF-8")
(setq default-input-method "chinese-py")
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;---------------设置语言环境-----------------
;-----------------自动注释--------------
(defun qiang-comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command. If no region is selected and current line is not blank and we are not at the end of the line, then comment current line. Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key "\M-;" 'qiang-comment-dwim-line)
;-----------------自动注释--------------
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;上面的这一大部分,是可以在任意只要安装了emacs的机器上面,就可以使用的,
;不会依赖于任何的外部包,也无所谓是ssh到服务器上,只要服务器安装了emacs
;上面的部分就会起作用,并且不会有额外的问题
;简单来说:算是一个通用的配置,即使是在洗衣机上,只要洗衣机安装了emacs
;上面的配置就会起作用,也是一些最最基本的配置
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
;----------------------------------C风格的对齐-----------------------------
(custom-set-variables
'(standard-indent 4)
'(inverse-video t))
(custom-set-faces)
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(substatement-open . 0)
(case-label . 4)
(block-open . 0);
(defun-block-intro . 0)
(statement-block-intro . 4)
(substatement . 4)
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t)
)
"My C Programming Style")
;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-add-style "PERSONAL" my-c-style t)
;; offset customizations not in my-c-style
(c-set-offset 'defun-block-intro' +)
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline and hungry-delete
(c-toggle-hungry-state 1)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
;(define-key c-mode-base-map "/C-m" 'newline-and-indent)
;(define-key c-mode-base-map "/C-c /C-c" 'kill-ring-save)
;(define-key c-mode-base-map "/C-v" 'yank)
;(define-key c-mode-base-map "/C-x x" 'kill-region)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;----------------------------------C风格的对齐-----------------------------
;--------------------------------传说中的施特劳斯特卢普的C++代码风格 ---------------------------------------
(add-to-list 'auto-mode-alist '("//.h//'" . c++-mode))
(require 'cl)
(defun file-in-directory-list-p (file dirlist)
"Returns true if the file specified is contained within one of the directories in the list. The directories must also exist."
(let ((dirs (mapcar 'expand-file-name dirlist))
(filedir (expand-file-name (file-name-directory file))))
(and
(file-directory-p filedir)
(member-if (lambda (x) ; Check directory prefix matches
(string-match (substring x 0 (min(length filedir) (length x))) filedir))
dirs))))
(defun buffer-standard-include-p ()
"Returns true if the current buffer is contained within one of the directories in the INCLUDE environment variable."
(and (getenv "INCLUDE")
(file-in-directory-list-p buffer-file-name (split-string (getenv "INCLUDE") path-separator))))
(add-to-list 'magic-fallback-mode-alist '(buffer-standard-include-p . c++-mode))
(c-add-style "my-style"
'("stroustrup"
(indent-tabs-mode . nil) ; use spaces rather than tabs
(c-basic-offset . 8) ; indent by four spaces
(c-offsets-alist . (
(inline-open . 0) ; custom indentation rules
(brace-list-open . 0)
(statement-case-open . +)
)
)
))
(defun my-c++-mode-hook ()
(c-set-style "my-style") ; use my-style defined above
(auto-fill-mode)
;(c-toggle-auto-hungry-state 1)
(c-toggle-electric-state 1)
;(c-toggle-auto-newline 1);这个就是遇到了{};之后,自己开新行的
(c-toggle-hungry-state 1)
;(c-toggle-syntactic-indentation 1)
;(define-key c++-mode-map (kbd ":") 'semantic-ia-complete-symbol-menu)
;(define-key c++-mode-map (kbd ".") 'semantic-ia-complete-symbol-menu)
;(define-key c++-mode-map (kbd "C-c C-c") 'kill-ring-save);copy
;(define-key c++-mode-map (kbd "C-v") 'yank);paste
;(define-key c++-mode-map (kbd "M-x") 'kill-region);cut
)
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
;--------------------------------传说中的施特劳斯特卢普的C++代码风格 ---------------------------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;******************下面的部分是需要有额外的支持的,是需要能够有相关的匹配的---------------------
;-----------去网上拉下来----------------颜色主题------------------
(setq load-path (cons "/home/hjz/software/emacs/color-theme-6.6.0" load-path))
(require 'color-theme)
(color-theme-initialize)
(color-theme-subtle-hacker)
;-----------去网上拉下来----------------颜色主题------------------
;----------要自己安装一个--------------------cscope-------------------
;(load-file "/usr/share/emacs23/site-lisp/cscope/xcscope.elc")
;(require 'xcscope)
;----------要自己安装一个--------------------cscope-------------------
;---------想办法弄到----------------大名鼎鼎的cedet----------------
(setq load-path (cons "/home/hjz/software/emacs/cedet-1.0pre7/common" load-path))
(setq load-path (cons "/home/hjz/software/emacs/cedet-1.0pre7/contrib" load-path))
(require 'cedet)
(require 'semantic)
(require 'semantic-ia)
(require 'semanticdb)
(global-ede-mode t)
(require 'semantic-gcc)
(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)
(global-semantic-stickyfunc-mode -1);关掉,免得替代tabbar
(which-function-mode nil)
;-----------------------
(setq semanticdb-project-roots (list (expand-file-name "/")))
(defconst cedet-user-include-dirs
(list "/" "./"))
(defconst cedet-win32-include-dirs
(list "../"))
(require 'semantic-c nil 'noerror)
(let ((include-dirs cedet-user-include-dirs))
(when (eq system-type 'windows-nt)
(setq include-dirs (append include-dirs cedet-win32-include-dirs)))
(mapc (lambda (dir)
(semantic-add-system-include dir 'c++-mode)
(semantic-add-system-include dir 'c-mode))
include-dirs))
;-----------------------
(global-set-key [f12] 'semantic-ia-fast-jump);F12跳转
;Shift F12跳转回来
(global-set-key [S-f12]
(lambda ()
(interactive)
(if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
(error "Semantic Bookmark ring is currently empty"))
(let* ((ring (oref semantic-mru-bookmark-ring ring))
(alist (semantic-mrub-ring-to-assoc-list ring))
(first (cdr (car alist))))
(if (semantic-equivalent-tag-p (oref first tag)
(semantic-current-tag))
(setq first (cdr (car (cdr alist)))))
(semantic-mrub-switch-tags first))))
(global-set-key (kbd "C-/") 'semantic-ia-complete-symbol-menu)
;---------想办法弄到----------------大名鼎鼎的cedet----------------
;-----------------F4.h.cpp切换------------
(require 'eassist nil 'noerror)
(global-set-key (kbd "M-o") 'eassist-switch-h-cpp);修改为F4切换.h和.cpp
;设定.h .cpp 的格式
(setq eassist-header-switches
'(("h" . ("cpp" "cxx" "c++" "CC" "cc" "C" "c" "mm" "m"))
("hh" . ("cc" "CC" "cpp" "cxx" "c++" "C"))
("hpp" . ("cpp" "cxx" "c++" "cc" "CC" "C"))
("hxx" . ("cxx" "cpp" "c++" "cc" "CC" "C"))
("h++" . ("c++" "cpp" "cxx" "cc" "CC" "C"))
("H" . ("C" "CC" "cc" "cpp" "cxx" "c++" "mm" "m"))
("HH" . ("CC" "cc" "C" "cpp" "cxx" "c++"))
("cpp" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
("cxx" . ("hxx" "hpp" "h++" "HH" "hh" "H" "h"))
("c++" . ("h++" "hpp" "hxx" "HH" "hh" "H" "h"))
("CC" . ("HH" "hh" "hpp" "hxx" "h++" "H" "h"))
("cc" . ("hh" "HH" "hpp" "hxx" "h++" "H" "h"))
("C" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
("c" . ("h"))
("m" . ("h"))
("mm" . ("h"))))
;-----------------F4.h.cpp切换------------
;----------------代码折叠----------------
(require 'semantic-tag-folding nil 'noerror)
(global-semantic-tag-folding-mode 1)
(global-set-key (kbd "C-c -") 'semantic-tag-folding-fold-block)
(global-set-key (kbd "C-c +") 'semantic-tag-folding-show-block)
;----------------代码折叠----------------
;-----------------项目工程文件------------------
(global-ede-mode t)
;-----------------项目工程文件------------------
;---------想办法弄到-----------------ecb------------------
(add-to-list 'load-path "/home/hjz/software/emacs/ecb-2.40")
(require 'ecb)
;(ecb-activate)
;---------想办法弄到-----------------ecb------------------
;-------在ubuntu下,会有gdb-ui-------------gdb的相关-----------------
;(load-file "/home/hjz/software/emacs/multi-gdb-ui.el")
(require 'gdb-ui)
(defun gdb-or-gud-go ()
"If gdb isn't running; run gdb, else call gud-go."
(interactive)
(if (and gud-comint-buffer
(buffer-name gud-comint-buffer)
(get-buffer-process gud-comint-buffer)
(with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
(gud-call (if gdb-active-process "continue" "run") "")
(gdb (gud-query-cmdline 'gdb))))
(defun gud-break-remove ()
"Set/clear breakpoin."
(interactive)
(save-excursion
(if (eq (car (fringe-bitmaps-at-pos (point))) 'breakpoint)
(gud-remove nil)
(gud-break nil))))
(defun gud-kill ()
"Kill gdb process."
(interactive)
(with-current-buffer gud-comint-buffer (comint-skip-input))
(kill-process (get-buffer-process gud-comint-buffer)))
(setq gdb-many-windows t)
;---快捷键设定---
(global-set-key [f5] 'gdb-or-gud-go); //F5启动gdb或gdb运行
(global-set-key [f8] 'gud-print); //打印当前光标所在的变量,比较省心的好东东
(global-set-key [C-f8] 'gud-pstar); //打印指针所指向的值,也是好东东
(global-set-key [f9] 'gud-break-remove); //设定或取消断点
(global-set-key [f10] 'gud-next); //下一步
(global-set-key [C-f10] 'gud-until); //执行直到
(global-set-key [S-f10] 'gud-jump); //跳转
(global-set-key [f11] 'gud-step); //单步进入的方式
(global-set-key [C-f11] 'gud-finish); //跳出函数
;--------------说明--------------
;在c/c++-mode中按f7,就会调用make编译程序。
;在c/c++-mode中按f5,就会进入gdb调试。
;打开gdb后在源代码buffer中按f9设置断点,相当于gdb中的break。
;按Ctrl+f9就可以删除断点,相当于gdb中的delete。
;在gdb buffer中,按Ctrl+f5就开始执行程序,相当于gdb中的run。
;断点之后,可以按f10单步执行,相当于gdb中的next。
;把光标移动到某处按Ctrl+f10,会一直执行光标位置,相当于gdb的until。
;把光标移动到某处按Shift+f10,会jump到光标位置,下一次会从光标处执行。
;也可以按f11单步执行,不过f11会进入函数内部,相当于gdb中的step。
;按Ctrl+f11可以跳出当前函数,相当于gdb中的finish。
;在断点处按Shift+f5继续执行程序,相当于gdb中的continue。
;在变量上按f8会输出变量的值,相当于gdb的print。
;在变量上按Ctrl+f8会打印出指针对应的值。
;--------------说明--------------
;-------在ubuntu下,会有gdb-ui-------------gdb的相关-----------------
;--------想办法弄到-------------auto complete-------------------
(add-to-list 'load-path "/home/hjz/.emacs.d/")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "/home/hjz/.emacs.d//ac-dict")
(ac-config-default)
;; Show 0.8 second later
(setq ac-auto-show-menu 0.8)
;; 20 lines
(setq ac-menu-height 20)
;; Examples
(set-face-background 'ac-candidate-face "lightgray")
(set-face-underline 'ac-candidate-face "darkgray")
(set-face-background 'ac-selection-face "steelblue")
(add-hook 'c++-mode (lambda () (add-to-list 'ac-sources 'ac-source-semantic)))
;; Complete member name by C-c . for C++ mode.
;(add-hook 'c++-mode-hook
; (lambda ()
; (local-set-key (kbd "C-c .") 'ac-complete-semantic)))
;; Complete file name by C-c /
;(global-set-key (kbd "C-c /") 'ac-complete-filename)
(defun semantic-and-gtags-complete ()
(interactive)
(auto-complete '(ac-source-semantic ac-source-gtags)))
(defun auto-complete-settings ()
"Settings for `auto-complete'."
;; After do this, isearch any string, M-: (match-data) always
;; return the list whose elements is integer
(global-auto-complete-mode 1)
;; 不让回车的时候执行`ac-complete', 因为当你输入完一个
;; 单词的时候, 很有可能补全菜单还在, 这时候你要回车的话,
;; 必须要干掉补全菜单, 很麻烦, 用M-j来执行`ac-complete'
(define-key ac-complete-mode-map "/C-i" 'nil)
;(define-key ac-complete-mode-map "RET" 'nil)
;(define-key ac-complete-mode-map "M-j" 'ac-complete)
;(define-key ac-complete-mode-map "<C-return>" 'ac-complete)
(define-key ac-complete-mode-map "/C-n" 'ac-next)
(define-key ac-complete-mode-map "/C-p" 'ac-previous)
(setq ac-dwim t)
(setq ac-candidate-max ac-candidate-menu-height)
(set-default 'ac-sources
'(ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename))
;(setq ac-modes ac+-modes)
(dolist (command `(backward-delete-char-untabify delete-backward-char))
(add-to-list 'ac-trigger-commands command))
(defun ac-start-use-sources (sources)
(interactive)
(let ((ac-sources sources))
(call-interactively 'ac-start)))
(defvar ac-trigger-edit-commands
`(self-insert-command
delete-backward-char
backward-delete-char
backward-delete-char-untabify)
"*Trigger edit commands that specify whether `auto-complete' should start or not when `ac-completing'."))
(eval-after-load "auto-complete"
'(auto-complete-settings))
(eval-after-load "cc-mode"
'(progn
(dolist (command `(c-electric-backspace
c-electric-backspace-kill))
(add-to-list 'ac-trigger-commands command)
(add-to-list 'ac-trigger-edit-commands command))))
(eval-after-load "autopair"
'(progn
(dolist (command `(autopair-insert-or-skip-quote
autopair-backspace
autopair-extra-skip-close-maybe))
(add-to-list 'ac-trigger-commands command))
(defun ac-trigger-command-p ()
"Return non-nil if `this-command' is a trigger command."
(or
(and
(memq this-command ac-trigger-commands)
(let* ((autopair-emulation-alist nil)
(key (this-single-command-keys))
(beyond-autopair (or (key-binding key)
(key-binding (lookup-key local-function-key-map key)))))
(memq beyond-autopair ac-trigger-edit-commands)))
(and ac-completing
(memq this-command ac-trigger-edit-commands))))))
(defun ac-settings-4-lisp ()
"Auto complete settings for lisp mode."
(setq ac-omni-completion-sources
'(
("//<featurep/s+'" ac+-source-elisp-features)
("//<require/s+'" ac+-source-elisp-features)
("//<load/s+'" ac-source-emacs-lisp-features)
)
)
(ac+-apply-source-elisp-faces)
(setq ac-sources
'(ac-source-yasnippet
ac-source-symbols
;; ac-source-semantic
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
;; ac-source-imenu
ac-source-files-in-current-dir
ac-source-filename)
)
)
(defun ac-settings-4-c ()
(setq ac-omni-completion-sources (list (cons "//." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-cpp ()
(setq ac-omni-completion-sources
(list (cons "//." '(ac-source-semantic))
(cons "->" '(ac-source-semantic))))
(setq ac-sources
'(ac-source-yasnippet
ac-source-c++-keywords
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-text ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-imenu))
)
(defun ac-settings-4-eshell ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename
ac-source-symbols
ac-source-imenu))
)
(defun ac-settings-4-ruby ()
(require 'rcodetools-settings)
(setq ac-omni-completion-sources
(list (cons "//." '(ac-source-rcodetools))
(cons "::" '(ac-source-rcodetools))))
)
(defun ac-settings-4-html ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-tcl ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(defun ac-settings-4-awk ()
(setq ac-sources
'(;;ac-source-semantic
ac-source-yasnippet
ac-source-abbrev
ac-source-words-in-buffer
ac-source-words-in-all-buffer
ac-source-files-in-current-dir
ac-source-filename))
)
(provide 'auto-complete-settings)
(require 'auto-complete-settings)
;--------想办法弄到-------------auto complete-------------------
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;
;下面的部分,是确定需要有外部额外的el的支持的,如果,没有去弄个文件
;然后,写入相关的内容,然后,弄到指定的目录下
;就可以用了
;
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
;-----------------如果是在ubuntu下,用这个就可以了 tabbar--------------
(load-file "/home/hjz/software/emacs/tabbar.el")
(require 'tabbar)
(tabbar-mode)
(setq tabbar-buffer-groups-function nil)
;-----------------如果是在ubuntu下,用这个就可以了 tabbar--------------
;-------------------------------------加在emacs自己带的行号工具 -----------------------------------------
(require 'linum)
(global-linum-mode 1)
;-------------------------------------加在emacs自己带的行号工具 -----------------------------------------
;---------------------------这个svn被我修改了,由svn-status修改为 ---svn---------------------------
;(load-file "/home/hjz/software/emacs/psvn.el")
;(require 'psvn)
;(define-prefix-command 'svn-map)
;(global-set-key (kbd "M-x M-c") 'svn-map)
;(define-key svn-map (kbd "c") 'svn-status-commit)
;(global-set-key (kbd "M-x 'svn commit'") 'svn-status-commit)
;顺便说几句,这个集成在emacs中的svn,不是很好用,估计要么用外部的。
;要么,找个时间,自己弄一下。
;---------------------------这个svn被我修改了,由svn-status修改为 ---svn---------------------------
;----------------------------书签,有点像win下的书签----------------------------
(load-file "/home/hjz/software/emacs/bm.el")
(require 'bm )
(global-set-key [C-f2] 'nil);//clear old fast key
(global-set-key [C-f2] 'bm-toggle);
(global-set-key [f2] 'nil);
(global-set-key [f2] 'bm-next);
;----------------------------书签,有点像win下的书签----------------------------
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;
;下面的部分,基本上是确定了,只有在ubuntu下才能正常使用的
;所以,需要区分开来
;
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
;---------------使用输入法,在ubuntu下可能会需要---------------
(global-set-key (kbd "C-SPC") 'nil);用win+space为set-mark键,留出ctrl+space热键作为输入法
(require 'ibus); //Turn on ibus-mode automatically after loading .emacs
(add-hook 'after-init-hook 'ibus-mode-on); //Use C-SPC for Set Mark command
(ibus-define-common-key ?\C-\s nil); //Use C-/ for Undo command
(ibus-define-common-key ?\C-/ nil); //Change cursor color depending on IBus status
(setq ibus-cursor-color '("red" "blue" "limegreen")); //Use s-SPC to toggle input status
(global-set-key (kbd "C-SPC") 'ibus-toggle)
;---------------使用输入法,在ubuntu下可能会需要---------------
;----------------------------------------这个是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.
'(column-number-mode t)
'(delete-selection-mode nil)
'(mark-even-if-inactive t)
'(scroll-bar-mode (quote right))
'(show-paren-mode t)
'(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.
'(default ((t (:inherit nil :stipple nil :background "darkslategrey" :foreground "wheat" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 89 :width normal :foundry "unknown" :family "文泉驿等宽微米黑")))))
;----------------------------------------这个是emacs的字体 ----------------------------------------
;--------------------------------全屏--------------------------------
(defun my-fullscreen ()
(interactive)
(x-send-client-message
nil 0 nil "_NET_WM_STATE" 32
'(2 "_NET_WM_STATE_FULLSCREEN" 0)))
(global-set-key [M-return] 'my-fullscreen);//Alt+Enter全屏,切换
;--------------------------------全屏--------------------------------