欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

emacs配置

程序员文章站 2022-03-24 17:13:45
...

直接给出配置,发邮件的配置没有给出。

;; 显示括号匹配 
(show-paren-mode t)
(setq show-paren-style 'parentheses)


;; 指针颜色设置为白色
(set-cursor-color "orange")

;;代码提示
;;-----------------------------auto-complete--------------------------------------------
;;auto-complete  
(add-to-list 'load-path "~/.emacs.d/lisp/auto-complete-1.3.1")    
(require 'auto-complete)  
(require 'auto-complete-config)
(defun prefix-list-elements (list prefix)
  (let (value)
    (nreverse
     (dolist (element list value)
       (setq value (cons (format "%s%s" prefix element) value))))))

(defvar ac-source-rope
  '((candidates
     . (lambda ()
         (prefix-list-elements (rope-completions) ac-target))))
  "Source for Rope")

(defun ac-python-find ()
  "Python `ac-find-function'."
  (require 'thingatpt)
  (let ((symbol (car-safe (bounds-of-thing-at-point 'symbol))))
    (if (null symbol)
        (if (string= "." (buffer-substring (- (point) 1) (point)))
            (point)
          nil)
      symbol)))

(defun ac-python-candidate ()
  "Python `ac-candidates-function'"
  (let (candidates)
    (dolist (source ac-sources)
      (if (symbolp source)
          (setq source (symbol-value source)))
      (let* ((ac-limit (or (cdr-safe (assq 'limit source)) ac-limit))
             (requires (cdr-safe (assq 'requires source)))
             cand)
        (if (or (null requires)
                (>= (length ac-target) requires))
            (setq cand
                  (delq nil
                        (mapcar (lambda (candidate)
                                  (propertize candidate 'source source))
                                (funcall (cdr (assq 'candidates source)))))))
        (if (and (> ac-limit 1)
                 (> (length cand) ac-limit))
            (setcdr (nthcdr (1- ac-limit) cand) nil))
        (setq candidates (append candidates cand))))
    (delete-dups candidates)))

(add-hook 'python-mode-hook
          (lambda ()
            (set (make-local-variable 'ac-sources)
                 (append ac-sources '(ac-source-rope) '(ac-source-yasnippet)))
            (rope-open-project "~/.emacs.d/database/python/")
            ))  
  
(add-to-list 'ac-dictionary-directories "~/.emacs.d/lisp/auto-complete-1.3.1/dict")    
(ac-config-default)  
  
(global-auto-complete-mode t)  
  
;(setq-default ac-sources '(ac-source-words-in-same-mode-buffers))  
(setq-default ac-sources '(ac-source-yasnippet    
                 ac-source-semantic  
                 ac-source-ropemacs  
                 ac-source-imenu    
                 ac-source-words-in-buffer  
                 ac-source-dictionary  
                 ac-source-abbrev    
                 ac-source-words-in-buffer    
                 ac-source-files-in-current-dir    
                 ac-source-filename))   
  
(add-hook 'emacs-lisp-mode-hook    (lambda () (add-to-list 'ac-sources 'ac-source-symbols)))  
(add-hook 'auto-complete-mode-hook (lambda () (add-to-list 'ac-sources 'ac-source-filename)))  
;;下面这句是从auto-complete-config.el中翻出来的  
;;加上这句,在python中输入类的 . 就可以提示里面的方法了  
(add-hook 'python-mode-hook        (lambda () (add-to-list 'ac-omni-completion-sources (cons "\\." '(ac-source-ropemacs)))  ))    
  
  
(set-face-background 'ac-candidate-face "lightgray")  
(set-face-underline 'ac-candidate-face "darkgray")  
(set-face-background 'ac-selection-face "steelblue")   
  
(setq ac-auto-start 2)  
(setq ac-dwim t) 
;;重构功能以及函数提示
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
    ;;      Cedet 1.0  
    ;;  
    (load-file "~/.emacs.d/lisp/cedet-1.1/common/cedet.el")  
         ;;;; 具体说明可参考源码包下的INSTALL文件,或《A Gentle introduction to Cedet》

;; Enabling Semantic (code-parsing, smart completion) features

;; Select one of the following:

;;(semantic-load-enable-minimum-features)

;;(semantic-load-enable-code-helpers)

;;(semantic-load-enable-gaudy-code-helpers)

(semantic-load-enable-excessive-code-helpers)

;;(semantic-load-enable-semantic-debugging-helpers)

 

;;;; 使函数体能够折叠或展开

;; Enable source code folding

(global-semantic-tag-folding-mode 1)

 

;; Key bindings

(defun my-cedet-hook ()

  (local-set-key [(control return)] 'semantic-ia-complete-symbol)

  (local-set-key "/C-c?" 'semantic-ia-complete-symbol-menu)

  (local-set-key "/C-cd" 'semantic-ia-fast-jump)

  (local-set-key "/C-cr" 'semantic-symref-symbol)

  (local-set-key "/C-cR" 'semantic-symref))

(add-hook 'c-mode-common-hook 'my-cedet-hook)

 

;;;; 当输入"."或">"时,在另一个窗口中列出结构体或类的成员

(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)
    ;;  
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    
   ;;工程目录 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
    ;;      ECB 2.40  
    ;;  
      
    (add-to-list 'load-path  
                        "~/.emacs.d/lisp/ecb-2.40")  
      
    (require 'ecb)  
    (require 'ecb-autoloads) 
    ;;;; 自动启动ecb,并且不显示每日提示

    (setq ecb-auto-activate t

      ecb-tip-of-the-day nil)
      
      (ecb-layout-define "my-cscope-layout" left nil
                   (ecb-set-methods-buffer)
                   (ecb-split-ver 0.5 t)
                   (other-window 1)
                   (ecb-set-history-buffer)
                   (ecb-split-ver 0.5 t) ;我改成了0.5 
                   (other-window 1)
                   (ecb-set-cscope-buffer))

(defecb-window-dedicator ecb-set-cscope-buffer " *ECB cscope-buf*"
                         (switch-to-buffer "*cscope*"))

(setq ecb-layout-name "my-cscope-layout")

;; Disable buckets so that history buffer can display more entries
(setq ecb-history-make-buckets 'never)
      
    ;; ;;;;窗口间切换  
    (global-set-key [M-left]  'windmove-left)  
    (global-set-key [M-right] 'windmove-right)  
    (global-set-key [M-up]    'windmove-up)  
    (global-set-key [M-down]  'windmove-down)  
      
     ;;;;show&hide window  
    (global-set-key [C-f1] 'ecb-hide-ecb-windows)  
    (global-set-key [C-f2] 'ecb-show-ecb-windows)  
      
      
    ;; ;;;; 使某一ecb窗口最大化  
    (global-set-key (kbd "C-c 1") 'ecb-maximize-window-directories)  
    (global-set-key (kbd "C-c 2") 'ecb-maximize-window-sources)  
    (global-set-key (kbd "C-c 3") 'ecb-maximize-window-methods)  
    (global-set-key (kbd "C-c 4") 'ecb-maximize-window-history)  
      
    ;; ;;;;恢复原始窗口布局  
    (global-set-key (kbd "C-c 0") 'ecb-restore-default-window-sizes)  
      
    ;;  
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
(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.
 )
(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 "green" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans Mono")))))
                          
;;------------------------pymacs-----------------------------------
(load "~/.emacs.d/pymacs.el")
;; Python mode hook
(defun my-python-hook-mode ()
  (interactive)
  ;(setq ropemacs-enable-shortcuts nil)
  ;(setq ropemacs-local-prefix "C-c C-p")
  (require 'pymacs)
  (autoload 'pymacs-apply "pymacs")
  (autoload 'pymacs-call "pymacs")
  (autoload 'pymacs-eval "pymacs" nil t)
  (autoload 'pymacs-exec "pymacs" nil t)
  (autoload 'pymacs-load "pymacs" nil t)
  (ac-ropemacs-setup)
  ;(pymacs-load "ropemacs" "rope-")
  ;; Automatically save project python buffers before refactorings
  (setq ropemacs-confirm-saving 'nil)
  (ropemacs-mode t)
  (define-key python-mode-map "\C-m" 'newline-and-indent)
  ;(setq ac-sources (append ac-sources '(ac-source-ropemacs)))
 )
 (add-hook 'python-mode-hook 'my-python-hook-mode)
 
;;------------------------查看词典----------------------------------
(defun yodao-dict-search-wordap (&optional word)

"Use python script dict to look up word under point"

(interactive)

(or word (setq word (current-word)))

(shell-command (format "python ~/.emacs.d/dict.py %s" word)))

(global-set-key [f7] 'yodao-dict-search-wordap)

;;---------------------------挂载文档----------------------------
(setq pylookup-dir "~/.emacs.d/plugins/pylookup")
(add-to-list 'load-path pylookup-dir)
(require 'pylookup)

;; load pylookup when compile time
(eval-when-compile (require 'pylookup))

;; set executable file and db file
(setq pylookup-program (concat pylookup-dir "/pylookup.py"))
(setq pylookup-db-file (concat pylookup-dir "/pylookup.db"))

;; set search option if you want
;; (setq pylookup-search-options '("--insensitive" "0" "--desc" "0"))

;; to speedup, just load it on demand
(autoload 'pylookup-lookup "pylookup"
  "Lookup SEARCH-TERM in the Python HTML indexes." t)

(autoload 'pylookup-update "pylookup" 
  "Run pylookup-update and create the database at `pylookup-db-file'." t)
(global-set-key (kbd "C-c h") 'pylookup-lookup)


 记录一下,防止以后再其他机子上需要配置,下面把所用的插件也上传上来.只需要下载并且解压到你的目录下,把emacs.d改成.emacs.d,覆盖你原来的.emacs.d,然后拷贝上面的的配置文件到你的.emacs下,就可以生效了。

好了,体验emcas来了,以后有新的功能会及时更新。