Emacs 配置文件管理

 

在emacs配置文件都写在一个.emacs 文件中 管理很麻烦,我们可以用provide 关键词把配置文件中的内容分好类,写到不同的配置文件中

如我的插件文件为/root/emacs

配置文件为/root/.emacs

分类后的文件目录在 /root/.emacs.d/目录下

具体看下配置文件

 这个是效果图

Emacs欣赏

Emacs自动补全

1.这个是emacs加载的.emacs文件

(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
;----------------------------------------------------
;;;;;一般总体设置
(require 'general)
;----------------------------------------------------
;----------------------------------------------------
;;;;    c++配置
(require 'c++conf)
;----------------------------------------------------
;----------------------------------------------------
;;;;   插件配置
(require 'myplugin)
;----------------------------------------------------
;----------------------------------------------------
;;;一些有用的设置
(require 'skills)
;---------------------------------------------------

2.下面几个分别是.emacs 加载的几个文件

general.el;; 

(add-to-list 'load-path "/root/emacs")
;; 括号匹配时显示另外一边的括号,而不是烦人的跳到另一个括号
(show-paren-mode t)
(setq show-paren-style 'parentheses)
;关闭开机画面
(setq inhibit-startup-message t)
;; 不备份文件,不推荐
(setq make-backup-files nil)
;设置光标为竖线
(setq-default cursor-type 'bar)
;;标记开始
(global-set-key (kbd "C-j") 'set-mark-command);;
(tool-bar-mode 0)
;;不要总是没完没了的问yes or no, 为什么不能用 y/n 
(fset 'yes-or-no-p 'y-or-n-p) 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;   显示时间设置   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(display-time-mode 1);;启用时间显示设置,在minibuffer上面的那个杠上
(setq display-time-24hr-format t);;时间使用24小时制
(setq display-time-day-and-date t);;时间显示包括日期和具体时间
(setq display-time-use-mail-icon t);;时间栏旁边启用邮件设置
(setq display-time-interval 10);;时间的变化频率,单位多少来着?
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;  显示时间设置结束  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
(customize-set-variable 'scroll-bar-mode 'right) 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END常规设置;;;;;;;;;;;;;;;

;;-------------------------------------------------------------
;;                  ;;显示行号
;;-------------------------------------------------------------
(global-linum-mode 1)
(require 'setnu)
(setnu-mode t)
;;-------------------------------------------------------------
;;                  Tabbar 设置
;;-------------------------------------------------------------

(require 'tabbar)
(tabbar-mode)
(global-set-key [(meta j)] 'tabbar-backward)  
(global-set-key [(meta k)] 'tabbar-forward)
;;;; 设置tabbar外观 
;; 设置默认主题: 字体, 背景和前景颜色,大小 
(set-face-attribute 'tabbar-default nil
                    :family "Vera Sans YuanTi Mono"
                    :background "gray80"
                    :foreground "gray30"
                    :height 1.0 
                    ) 
;; 设置左边按钮外观:外框框边大小和颜色 
(set-face-attribute 'tabbar-button nil
                    :inherit 'tabbar-default
                    :box '(:line-width 1 :color "gray30") 
                    ) 
;; 设置当前tab外观:颜色,字体,外框大小和颜色 
(set-face-attribute 'tabbar-selected nil
                    :inherit 'tabbar-default
                    :foreground "DarkGreen"
                    :background "LightGoldenrod"
                    :box '(:line-width 2 :color "DarkGoldenrod") 
                    ;; :overline "black" 
                    ;; :underline "black" 
                    :weight 'bold
                    ) 
;; 设置非当前tab外观:外框大小和颜色 
(set-face-attribute 'tabbar-unselected nil
                    :inherit 'tabbar-default
                    :box '(:line-width 2 :color "gray70") 
                    )

(provide 'general)


 

 

 

c++conf.el

(add-to-list 'load-path "/root/emacs")
;;;;;;;;;;;;;缩进设置;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun my-c-mode-hook ()
    (setq c-basic-offset 2
          c-label-offset 0
          indent-tabs-mode nil
         ; compile-command "cd ~/projects/myproject; mvn compile"
          require-final-newline nil)
    (lambda () (auto-fill-mode 1))
;    (define-key c-mode-base-map "C-m" 'c-context-line-break)
  (c-set-offset 'substatement-open 0))
  (add-hook 'c-mode-common-hook 'my-c-mode-hook)
;;;;;;;;;;;;;缩进设置;;;;;;;;;;;;;;;;;;;;;;;;;

;;改变默认的注释方式
(defun my-c-comment ()
      (interactive)
      (insert "/**/")
      (backward-char 2))
(global-set-key (kbd "M-;") 'my-c-comment)

;;-------------------------------------------------------------
;;                      Cscope设置
;;-------------------------------------------------------------
(require 'xcscope)
(add-hook 'c-mode-common-hook
	  '(lambda ()
	       (require 'xcscope) )
	  )
(setq cscope-do-not-update-database t)
;(define-key global-map (kbd "C-a")  'cscope-set-initial-directory)
(define-key global-map [(control f4)]  'cscope-unset-initial-directory)
(define-key global-map (kbd "M-f")  'cscope-find-this-symbol)
(define-key global-map (kbd "M-g")  'cscope-find-global-definition)
(define-key global-map (kbd "M-d")  'cscope-find-global-definition-no-prompting)
(define-key global-map (kbd "M-p")  'cscope-pop-mark)
(define-key global-map (kbd "M-n")  'cscope-next-symbol)
(define-key global-map [(control f10)] 'cscope-next-file)
(define-key global-map [(control f11)] 'cscope-prev-symbol)
(define-key global-map [(control f12)] 'cscope-prev-file)
(define-key global-map [(meta f9)]     'cscope-display-buffer)
(define-key global-map [(meta f10)]    'cscope-display-buffer-toggle)

;非交互式编译
(defun do-compile ()
  "Save buffers and start compile"
  (interactive)
  (save-some-buffers t)
  (setq compilation-read-command nil)
  (compile compile-command)
  (setq compilation-read-command t))



;;-------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;;;;GDB设置;;;;;;;;;;;;;;;;;;;;;;  
;;命令 功能 
;gdb 启动gdb进行调试 
;gdb-many-windows 切换单窗格/多窗格模式 
;gdb-restore-windows 恢复窗格布局 

;功能 命令 默认快捷键 
;添加断点 gud-break C-x C-a C-b 或 C-x <SPC> 
;删除断点 gud-remove C-x C-a C-d 
;运行/继续程序 gud-go 无 
;单步执行,无视函数 gud-next C-x C-a C-n 
;单步执行,进入函数 gud-step C-x C-a C-s 
;跳出当前函数 gud-finish C-x C-a C-f 
;运行到光标所在语句 gud-until C-x C-a C-u 
;继续运行程序 gud-cont C-x C-a C-r 

;功能 命令 默认快捷键 
;观察变量 gud-watch C-x C-a C-w 
;展开/收缩变量  <SPC> 
;开启/关闭工具提示 gud-tooltip-mode 

(global-set-key [f5] 'make-frame-command);;另外开启一个窗口进行gdb调试  
(setq gdb-many-windows t)  
(require 'gud)   
(global-set-key [f6] 'gdb)  
;;F5设置为在Emacs中调用gdb   

;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))))

;;;;;;;;;;;;;;;;;;;;;END  GDB设置;;;;;;;;;;;;;;;;;;  

(provide 'c++conf)


 

 

 myplugin.el

;;--------------------------------------
;;;;yasnippet-bundlesh设置
(add-to-list 'load-path "/root/emacs")
(require 'yasnippet-bundle)
(setq yas/root-directory "/root/.emacs.d/plugins")
;;--加入下面一段话会使加载时候很慢,可以Emacs启动后手动加载  M -x yas/load-director
;;自己新建模板的话用yas/new-snippet
;(yas/load-directory yas/root-directory)
;;--------------------------------------
;;-------------------------------------------------------------
;;                  Auto complete
;;-------------------------------------------------------------
(add-to-list 'load-path "/root/emacs/auto-complete-1.3.1")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "/root/emacs/auto-complete-1.3.1/ac-dict")
(ac-config-default)
(add-to-list 'load-path "/root/emacs/")
(require 'gccsense)
(global-set-key "\257" (quote ac-complete-gccsense))

(add-hook 'c-mode-common-hook
          (lambda ()
            (flymake-mode)
            (gccsense-flymake-setup)))

(defun ac-complete-gccsense-self-insert (arg)
  (interactive "p")
  (self-insert-command arg)
  (ac-complete-gccsense))
(defun my-c-mode-ac-complete-hook ()
  (local-set-key "." 'ac-complete-gccsense-self-insert)
  (local-set-key ">" 'ac-complete-gccsense-self-insert))
(add-hook 'c-mode-common-hook 'my-c-mode-ac-complete-hook)


;;-----------------------------------------------------------------------
;;加载主题插件;;;
;;;M-x color-theme-select 回车  选择颜色
;;-----------------------------------------------------------------------
;(add-to-list 'load-path (expand-file-name "/root/.emacs.d/plugins"))    
;(require 'color-theme)  
;(color-theme-initialize)  
;(color-theme-gnome2)  
;(color-theme-billw)  
;(color-theme-gray30)  
;(color-theme-kingsajz)  
;(color-theme-tty-dark);;彩色黑色  
;(color-theme-midnight)  

(provide 'myplugin)


 


    skills.el 

;;-------------------------------------------------------------
;自动添加括号
;;-------------------------------------------------------------
(add-hook 'c-mode-hook 'my-c-mode-hook)
 (add-hook 'c++-mode-hook 'my-c-mode-hook)
 (defun my-c-mode-hook ()
     ;;; .... 其他配置功能
     (local-set-key (kbd "{") 'skeleton-c-mode-left-brace)
     ;;; .... 其他配置功能
     )
 (defun skeleton-c-mode-left-brace (arg)
   (interactive "*P")
   (if  (c-in-literal (c-most-enclosing-brace (c-parse-state)))
       (self-insert-command 1)
     ;; auto insert complex things.
     (let* ((current-line (delete-and-extract-region (line-beginning-position) (line-end-position)))
            (lines (and arg (mark t) (delete-and-extract-region (mark t) (point))))
            (after-point (make-marker)))
       ;;; delete extra blank begin and after the LINES
       (setq lines (and lines
                        (with-temp-buffer
                          (insert lines)
                          (beginning-of-buffer)
                          (delete-blank-lines)
                          (delete-blank-lines)
                          (end-of-buffer)
                          (delete-blank-lines)
                          (delete-blank-lines)
                          (buffer-string))))
       (save-excursion
         (let* ((old-point (point)))
           (insert (if current-line current-line "")  "{\n")
           (and lines (insert lines))
           (move-marker after-point (point))
           (insert "\n}\n")
           (indent-region old-point (point) nil)))
       (goto-char after-point)
       (c-indent-line)
       )))



;;;;;;;;;;;;;;;;;;;;;;;;智能跳转;;;;;;;;;;;;;;;;;;;;;  
;;;C-.来在当前位置做个标记  
;;用C-,就回到刚才做标记的地方A,再用C-,又会回到B   
(global-set-key (kbd "M-.") 'ska-point-to-register)   
(global-set-key (kbd "M-;") 'ska-jump-to-register)   
(defun ska-point-to-register()   
"Store cursorposition _fast_ in a register.   
Use ska-jump-to-register to jump back to the stored   
position."   
(interactive)   
  (setq zmacs-region-stays t)   
     (point-to-register 8))   
(defun ska-jump-to-register()   
"Switches between current cursorposition and position   
that was stored with ska-point-to-register."   
(interactive)   
(setq zmacs-region-stays t)   
(let ((tmp (point-marker)))   
(jump-to-register 8)   
(set-register 8 tmp)))   
;;;;;;;;;;;;;;;;;;;;;;;;智能跳转;;;;;;;;;;;;;;;;;;;;;  


;;;;;;;;;;;;;;;;;;shell设置;;;;;;;;;;;;;;;;;;  
(global-set-key [f1] 'shell);F1进入Shell  
(defun open-eshell-other-buffer ()  
"Open eshell in other buffer"  
(interactive)  
(split-window-vertically)  
(eshell))  
(global-set-key [C-f8]  'open-eshell-other-buffer)  
(global-set-key [(f8)] 'eshell)  
;;目的是开一个shell的小buffer,用于更方便地测试程序(也就是运行程序了),我经常会用到  
;;f8就是另开一个buffer然后打开shell,C-f8则是在当前的buffer打开shell  
;;;;;;;;;;;;;;;;;;shell设置;;;;;;;;;;;;;;;;;;  


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
;; Highlight   
;面我来讲讲highlight-symbol的使用.
;C-c M-H高亮当前光标下的单词,
; C-c M-R取消所有单词的高亮,
; C-c M-N移到下一个高亮,
; C-c M-P则移到上一个高亮(这两个命令和vi中的*和#命令功能一样,当激活了emaci-mode后,按n和p即可,这样用起来更方便了
;具体参见强大的文件阅读器 - Emaci),
; C-c M-n在函数内移到下一个高亮,
; C-c M-p在函数内移到上一个高亮,
; C-c r对当前光标下的单词进行替换. 使用;很简单吧.
;注意:highlight-symbol与color moccur以及w3m冲突,当启用了`highlight-symbol-mode’后,moccur和w3m自己的颜色高亮就没了。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
;; highlight symbol   
(require 'highlight-symbol)

;(require 'session)
;(add-hook 'after-init-hook 'session-initialize)
;(load "desktop")
;(desktop-load-default)
;(desktop-read);



;括号匹配
;也是从Vi来的酷功能。当光标在括号上是,输入%光标自动跳到匹配的另一个括号上。
(local-set-key "%" 'match-paren)
(defun match-paren (arg)
 "Go to the matching parenthesis if on parenthesis otherwise insert %."
 (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)))))




;;全屏
(defun my-fullscreen ()
  (interactive)
  (x-send-client-message
   nil 0 nil "_NET_WM_STATE" 32
   '(2 "_NET_WM_STATE_FULLSCREEN" 0))
)
;最大化
(defun my-maximized ()
  (interactive)
  (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))
)
;启动时最大化
(my-maximized)



(provide 'skills)

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值