emacs 配置.emacs

emacs 配置.emacs

(setq url-proxy-services
   '(("http" . "10.4.47.114:8080")
     ("https" . "10.4.47.114:8080")
     ))

(setq package-archives '(("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
                         ("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(package-initialize)

;;启动自动补齐
(require 'auto-complete-config)
(ac-config-default)

;;当打开c,c++文件后,自动启动ggtags-mode
(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1))))
;;从函数定义处,跳回函数调用处
(global-set-key (kbd "M-,")
		'ggtags-prev-mark)

;;语法检查
;;(add-hook 'after-init-hook #'global-flycheck-mode)

;;启动自动补齐
(require 'auto-complete-config)
(ac-config-default)

;;启动semantic功能
(semantic-mode 1)
;;当光标移到到某个函数调用的地方,或者变量使用的地方的时候,
;;函数的原型(返回值,参数),变量的类型,会显示在emacs最下面的辅助入力区
(global-semantic-idle-summary-mode)
;;启动代码补齐的功能
(global-semantic-idle-completions-mode)

;;启动Sticky Function mode
;;Sticky Function mode:在emacs的最上面一行显示类名,方法名等
;;(global-semantic-stickyfunc-mode)

;;启动bookmark功能,为了函数semantic-mrub-switch-tags可以被使用。
;;进而实现当跳转到函数/变量定义的地方后,还能跳回来
(global-semantic-mru-bookmark-mode)
;;ctrl-回车,绑定自动补全
(add-hook 'semantic-after-idle-scheduler-reparse-hook
	    (lambda ()
	          (message "after parse done!")
		      (local-set-key (kbd "C-<return>")
				         'semantic-complete-analyze-inline-idle)))

;;让speedbar使用由semantic解析出来的tags,semantic解析出来的tags里的信息比speedbar自己的tags要详细
(add-hook 'speedbar-load-hook
	    (lambda () (require 'semantic/sb)))
;;speedbar和buffer间的切换
(add-hook 'speedbar-load-hook
	    (lambda ()
	          (local-set-key (kbd "C-q")
				    'speedbar-get-focus)))

;;跳转到函数/变量定义的地方
(global-set-key [f12] 'semantic-ia-fast-jump)
;;为了跳回去,要使用函数semantic-mrub-switch-tags,但老是报出【Semantic Bookmark ring is currently empty】错误。原因是函数semantic-ia-fast-jump调用了函数push-mark,而函数push-mark里面没有做push bookmark的操作,所以要修改函数push-mark,把bookmark放入semantic-mru-bookmark-ring里。放入后再执行semantic-mrub-switch-tags就不会出错了
(defadvice push-mark (around semantic-mru-bookmark activate)
  "Push a mark at LOCATION with NOMSG and ACTIVATE passed to `push-mark'.
If `semantic-mru-bookmark-mode' is active, also push a tag onto
the mru bookmark stack."
  (semantic-mrub-push semantic-mru-bookmark-ring
                      (point)
                      'mark)
  ad-do-it)

;;跳转后再跳回原来的地方
(global-set-key [f11]
      (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))))

;;To enable more advanced functionality for name completion, etc.
;;(require 'semantic/ia)
;;If you're using GCC for programming in C & C++, then Semantic can automatically find directory, where system include files are stored. Just load semantic/bovine/gcc package with following command
;;(require 'semantic/bovine/gcc)
;;当输入【.】或者【>】后,自动提示出结构体或者类里的成员变量和函数
(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;;当使用外部的库时,下面的命令可以把外部库的头文件所在目录告诉给semantic,
;;然后semantic就可以解析这些头文件,从而提供代码补齐,跳转等
;;(semantic-add-system-include "~/exp/include/boost_1_37" 'c++-mode)

;;语法高亮
(require 'symbol-overlay)
(global-set-key (kbd "M-i") 'symbol-overlay-put)
(global-set-key (kbd "M-n") 'symbol-overlay-switch-forward)
(global-set-key (kbd "M-p") 'symbol-overlay-switch-backward)
(global-set-key (kbd "<f7>") 'symbol-overlay-mode)
(global-set-key (kbd "<f8>") 'symbol-overlay-remove-all)

;;gdb
(add-hook 'gdb-mode-hook
	  (lambda ()
	    (gdb-many-windows);;M-x gdb 后,是多窗口显示
	    (local-set-key [f4] 'gdb-restore-windows);;恢复gdb多窗口
	    (local-set-key [f5] 'gud-step);;进入函数
	    (local-set-key [f6] 'gud-next);;不进入函数
	    (local-set-key [f7] 'gud-finish);;跳出函数
	    (local-set-key [f8] 'gud-until)));;继续执行

;;关闭自动备份功能
(setq make-backup-files nil)
;;打开emacs时,不显示工具条
(tool-bar-mode 0)
;;打开emacs时,不显示菜单
(menu-bar-mode 0)
;;高亮当前行
;;(global-hl-line-mode 1)
(global-set-key (kbd "C-z") 'undo)

;;打开自动换行和饥饿删除功能
(add-hook 'c-mode-common-hook
	    (lambda ()
	          (c-set-offset 'substatement-open 0)
		       (c-toggle-auto-hungry-state)))

;;save
(define-key global-map "\C-s" 'save-buffer)
;;search
(global-set-key (kbd "\C-x s") 'isearch-forward)



;;这一条语句的作用是让 windmove 在边缘的窗口也能正常运作。举个例子,当前窗口已经是最左端的窗口了,如果使用 ctrl+left ,将仍会停留在当前窗口——因为已经到边缘了,左边没有窗口可供选择。但在添加了上面这句后,ctrl+left 将会跳到最右边的窗口中。垂直方向上的窗口切换同理。 
(setq windmove-wrap-around t)
(global-set-key (kbd "C-x <left>")  'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <up>")    'windmove-up)
(global-set-key (kbd "C-x <down>")  'windmove-down)

;;启动后,c-c left是undo 窗口;c-c right是redo窗口
(winner-mode t)

;;每打开一个文件都输入ggtags-mode,太麻烦了,所以在.emacs文件里加一个钩子,当打开c,c++,java的源文件时,自动启动ggtags-mode
(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1))))

18.04

(require 'package)
  (package-initialize)
  (add-to-list'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)

;;启动自动补齐
(require 'auto-complete-config)
(ac-config-default)

;;启动semantic功能
(semantic-mode 1)
;;当光标移到到某个函数调用的地方,或者变量使用的地方的时候,
;;函数的原型(返回值,参数),变量的类型,会显示在emacs最下面的辅助入力区
(global-semantic-idle-summary-mode)
;;启动代码补齐的功能
(global-semantic-idle-completions-mode)
;;启动Sticky Function mode
;;Sticky Function mode:在emacs的最上面一行显示类名,方法名等
;;(global-semantic-stickyfunc-mode)
;;启动bookmark功能,为了函数semantic-mrub-switch-tags可以被使用。
;;进而实现当跳转到函数/变量定义的地方后,还能跳回来
(global-semantic-mru-bookmark-mode)
;;ctrl-回车,绑定自动补全
(add-hook 'semantic-after-idle-scheduler-reparse-hook
	  (lambda ()
	    (message "after parse done!")
	    (local-set-key (kbd "C-<return>")
			    'semantic-complete-analyze-inline-idle)))
;;让speedbar使用由semantic解析出来的tags,semantic解析出来的tags里的信息比speedbar自己的tags要详细
(add-hook 'speedbar-load-hook
	  (lambda () (require 'semantic/sb)))

;;跳转到函数/变量定义的地方
(global-set-key [f12] 'semantic-ia-fast-jump)
;;为了跳回去,要使用函数semantic-mrub-switch-tags,但老是报出【Semantic Bookmark ring is currently empty】错误。原因是函数semantic-ia-fast-jump调用了函数push-mark,而函数push-mark里面没有做push bookmark的操作,所以要修改函数push-mark,把bookmark放入semantic-mru-bookmark-ring里。放入后再执行semantic-mrub-switch-tags就不会出错了
(defadvice push-mark (around semantic-mru-bookmark activate)
  "Push a mark at LOCATION with NOMSG and ACTIVATE passed to `push-mark'.
If `semantic-mru-bookmark-mode' is active, also push a tag onto
the mru bookmark stack."
  (semantic-mrub-push semantic-mru-bookmark-ring
                      (point)
                      'mark)
  ad-do-it)

;;跳转后再跳回原来的地方
(global-set-key [f11]
      (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))))

;;To enable more advanced functionality for name completion, etc.
;;(require 'semantic/ia)
;;If you're using GCC for programming in C & C++, then Semantic can automatically find directory, where system include files are stored. Just load semantic/bovine/gcc package with following command
;;(require 'semantic/bovine/gcc)
;;当输入【.】或者【>】后,自动提示出结构体或者类里的成员变量和函数
(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;;当使用外部的库时,下面的命令可以把外部库的头文件所在目录告诉给semantic,
;;然后semantic就可以解析这些头文件,从而提供代码补齐,跳转等
;;(semantic-add-system-include "~/exp/include/boost_1_37" 'c++-mode)

;;speedbar和buffer间的切换
(add-hook 'speedbar-load-hook
	  (lambda ()
	    (local-set-key (kbd "C-q")
			   'speedbar-get-focus)))

;;gdb
(add-hook 'gdb-mode-hook
	  (lambda ()
	    (gdb-many-windows);;M-x gdb 后,是多窗口显示
	    (local-set-key [f4] 'gdb-restore-windows);;恢复gdb多窗口
	    (local-set-key [f5] 'gud-step);;进入函数
	    (local-set-key [f6] 'gud-next);;不进入函数
	    (local-set-key [f7] 'gud-finish);;跳出函数
	    (local-set-key [f8] 'gud-until)));;继续执行

;;关闭自动备份功能
(setq make-backup-files nil)
;;打开emacs时,不显示工具条
(tool-bar-mode 0)
;;打开emacs时,不显示菜单
(menu-bar-mode 0)
;;高亮当前行
;;(global-hl-line-mode 1)
(global-set-key (kbd "C-z") 'undo)

;;打开自动换行和饥饿删除功能
(add-hook 'c-mode-common-hook
	  (lambda ()
	    (c-set-offset 'substatement-open 0)
	     (c-toggle-auto-hungry-state)))

;;save
(define-key global-map "\C-s" 'save-buffer)
;;search
(global-set-key (kbd "\C-x s") 'isearch-forward)



;;这一条语句的作用是让 windmove 在边缘的窗口也能正常运作。举个例子,当前窗口已经是最左端的窗口了,如果使用 ctrl+left ,将仍会停留在当前窗口——因为已经到边缘了,左边没有窗口可供选择。但在添加了上面这句后,ctrl+left 将会跳到最右边的窗口中。垂直方向上的窗口切换同理。 
(setq windmove-wrap-around t)
(global-set-key (kbd "C-x <left>")  'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <up>")    'windmove-up)
(global-set-key (kbd "C-x <down>")  'windmove-down)

;;启动后,c-c left是undo 窗口;c-c right是redo窗口
(winner-mode t)

;;每打开一个文件都输入ggtags-mode,太麻烦了,所以在.emacs文件里加一个钩子,当打开c,c++,java的源文件时,自动启动ggtags-mode
(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1))))
;;当代码需要补齐的时候,让补齐代码的显示方式是在tooltip里
(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.
 '(gdb-use-colon-colon-notation t)
 '(package-selected-packages
   (quote
    (phi-rectangle highlight-symbol ggtags auto-complete)))
 '(semantic-complete-inline-analyzer-idle-displayor-class (quote semantic-displayor-tooltip)))

;;设置face:default的背景色为黑色,前景色为白色,字体大小为218
(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 "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 200 :width normal :foundry "DAMA" :family "Ubuntu Mono"))))
 '(tooltip ((t (:background "steel blue" :foreground "white" :weight normal :height 190 :width normal :foundry "DAMA" :family "Ubuntu Mono")))))

14.04(有mark down)

(require 'package)
  (package-initialize)
  (add-to-list'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)

;;启动ggtags
(setq load-path (append load-path (list "/home/ys/.emacs.d/elpa/ggtags-0.8.11")))
(load "ggtags.elc")
;;当打开c,c++文件后,自动启动ggtags-mode
(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1))))
;;从函数定义处,跳回函数调用处
(global-set-key (kbd "M-,")
		'ggtags-prev-mark)

;;语法检查
;;(add-hook 'after-init-hook #'global-flycheck-mode)

;;启动自动补齐
(require 'auto-complete-config)
(ac-config-default)

;;启动semantic功能
(semantic-mode 1)
;;当光标移到到某个函数调用的地方,或者变量使用的地方的时候,
;;函数的原型(返回值,参数),变量的类型,会显示在emacs最下面的辅助入力区
(global-semantic-idle-summary-mode)
;;启动代码补齐的功能
(global-semantic-idle-completions-mode)

;;启动Sticky Function mode
;;Sticky Function mode:在emacs的最上面一行显示类名,方法名等
;;(global-semantic-stickyfunc-mode)

;;启动bookmark功能,为了函数semantic-mrub-switch-tags可以被使用。
;;进而实现当跳转到函数/变量定义的地方后,还能跳回来
(global-semantic-mru-bookmark-mode)
;;ctrl-回车,绑定自动补全
(add-hook 'semantic-after-idle-scheduler-reparse-hook
	    (lambda ()
	          (message "after parse done!")
		      (local-set-key (kbd "C-<return>")
				         'semantic-complete-analyze-inline-idle)))

;;让speedbar使用由semantic解析出来的tags,semantic解析出来的tags里的信息比speedbar自己的tags要详细
(add-hook 'speedbar-load-hook
	    (lambda () (require 'semantic/sb)))
;;speedbar和buffer间的切换
(add-hook 'speedbar-load-hook
	    (lambda ()
	          (local-set-key (kbd "C-q")
				    'speedbar-get-focus)))

;;跳转到函数/变量定义的地方
(global-set-key [f12] 'semantic-ia-fast-jump)
;;为了跳回去,要使用函数semantic-mrub-switch-tags,但老是报出【Semantic Bookmark ring is currently empty】错误。原因是函数semantic-ia-fast-jump调用了函数push-mark,而函数push-mark里面没有做push bookmark的操作,所以要修改函数push-mark,把bookmark放入semantic-mru-bookmark-ring里。放入后再执行semantic-mrub-switch-tags就不会出错了
(defadvice push-mark (around semantic-mru-bookmark activate)
  "Push a mark at LOCATION with NOMSG and ACTIVATE passed to `push-mark'.
If `semantic-mru-bookmark-mode' is active, also push a tag onto
the mru bookmark stack."
  (semantic-mrub-push semantic-mru-bookmark-ring
                      (point)
                      'mark)
  ad-do-it)

;;跳转后再跳回原来的地方
(global-set-key [f11]
      (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))))

;;To enable more advanced functionality for name completion, etc.
;;(require 'semantic/ia)
;;If you're using GCC for programming in C & C++, then Semantic can automatically find directory, where system include files are stored. Just load semantic/bovine/gcc package with following command
;;(require 'semantic/bovine/gcc)
;;当输入【.】或者【>】后,自动提示出结构体或者类里的成员变量和函数
(defun my-c-mode-cedet-hook ()
 (local-set-key "." 'semantic-complete-self-insert)
 (local-set-key ">" 'semantic-complete-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;;当使用外部的库时,下面的命令可以把外部库的头文件所在目录告诉给semantic,
;;然后semantic就可以解析这些头文件,从而提供代码补齐,跳转等
;;(semantic-add-system-include "~/exp/include/boost_1_37" 'c++-mode)

;;语法高亮
(require 'symbol-overlay)
(global-set-key (kbd "M-i") 'symbol-overlay-put)
(global-set-key (kbd "M-n") 'symbol-overlay-switch-forward)
(global-set-key (kbd "M-p") 'symbol-overlay-switch-backward)
(global-set-key (kbd "<f7>") 'symbol-overlay-mode)
(global-set-key (kbd "<f8>") 'symbol-overlay-remove-all)

;;gdb
(add-hook 'gdb-mode-hook
	  (lambda ()
	    (gdb-many-windows);;M-x gdb 后,是多窗口显示
	    (local-set-key [f4] 'gdb-restore-windows);;恢复gdb多窗口
	    (local-set-key [f5] 'gud-step);;进入函数
	    (local-set-key [f6] 'gud-next);;不进入函数
	    (local-set-key [f7] 'gud-finish);;跳出函数
	    (local-set-key [f8] 'gud-until)));;继续执行

;;关闭自动备份功能
(setq make-backup-files nil)
;;打开emacs时,不显示工具条
(tool-bar-mode 0)
;;打开emacs时,不显示菜单
(menu-bar-mode 0)
;;高亮当前行
;;(global-hl-line-mode 1)
(global-set-key (kbd "C-z") 'undo)

;;打开自动换行和饥饿删除功能
(add-hook 'c-mode-common-hook
	    (lambda ()
	          (c-set-offset 'substatement-open 0)
		       (c-toggle-auto-hungry-state)))

;;save
(define-key global-map "\C-s" 'save-buffer)
;;search
(global-set-key (kbd "\C-x s") 'isearch-forward)



;;这一条语句的作用是让 windmove 在边缘的窗口也能正常运作。举个例子,当前窗口已经是最左端的窗口了,如果使用 ctrl+left ,将仍会停留在当前窗口——因为已经到边缘了,左边没有窗口可供选择。但在添加了上面这句后,ctrl+left 将会跳到最右边的窗口中。垂直方向上的窗口切换同理。 
(setq windmove-wrap-around t)
(global-set-key (kbd "C-x <left>")  'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <up>")    'windmove-up)
(global-set-key (kbd "C-x <down>")  'windmove-down)

;;启动后,c-c left是undo 窗口;c-c right是redo窗口
(winner-mode t)

;;markdown设置
;;设置markdown.el文件的所在路径
(add-to-list 'load-path "~/.emacs.d/my/")
(autoload 'markdown-mode "markdown-mode"
  "Major mode for editing Markdown files" t)
;;当打开下面文件时,自动启动markdown-mode
(add-to-list 'auto-mode-alist '("\\.text\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;;markdown模式和gfm模式都不会当输入回车时,真正换行,设置钩子函数,实现回车换行。
(defun my-gfm-mode-hook ()
  (visual-line-mode 1))
(add-hook 'gfm-mode-hook 'my-gfm-mode-hook)
(add-hook 'markdown-mode 'my-gfm-mode-hook)
;;预览markdown文件需要安装pandoc(sudo apt install pandoc)
(setq markdown-command "/usr/bin/pandoc")

;;当代码需要补齐的时候,让补齐代码的显示方式是在tooltip里
(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.
 '(gdb-use-colon-colon-notation t)
 '(package-selected-packages
   (quote
    (phi-rectangle highlight-symbol ggtags auto-complete)))
 '(semantic-complete-inline-analyzer-idle-displayor-class (quote semantic-displayor-tooltip)))

;;设置face:default的背景色为黑色,前景色为白色,字体大小为218
;;(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 "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 200 :width normal :foundry "DAMA" :family "Ubuntu Mono"))))
;; '(tooltip ((t (:background "steel blue" :foreground "white" :weight normal :height 190 :width normal :foundry "DAMA" :family "Ubuntu Mono")))))

posted @ 2018-10-06 11:51  小石王  阅读(556)  评论(0编辑  收藏  举报