我的Emacs配置文件 (windows版)


文件可以去我的资源里面下载。参考http://blog.csdn.net/pfanaya/article/details/6674336

越来越发现Emacs之伟大,现在终于明白为什么这个编辑器历经40年了仍旧这么受欢迎!

谢谢Richard Stallman,你永远是黑客中的传奇!


(setq default-directory "D:/")

(setq default-buffer-file-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

;;Emacs chinese environment
(set-language-environment 'Chinese-GB)
(set-keyboard-coding-system 'euc-cn)
(set-clipboard-coding-system 'euc-cn)
(set-terminal-coding-system 'euc-cn)
(set-buffer-file-coding-system 'euc-cn)
(set-selection-coding-system 'euc-cn)
(modify-coding-system-alist 'process "*" 'euc-cn)
(setq default-process-coding-system '(euc-cn . euc-cn)) ;;从网上抄来时,.两边没有空格,这是不对的。;;在执行命令时会提示 出错。


(add-to-list 'load-path "~/.emacs.d")
;;;session.el用来记录以打开过的文件 命令 寄存器 修改过的文件 最后修改的位置
;;把缺省的 major mode 设置为 text-mode, 而不是几乎什么功能也 没有的 fundamental-mode.
(show-paren-mode t)
(setq show-paren-style 'parentheses)
;;括号匹配时显示另外一边的括号,而不是烦人的跳到另一个括号。
(mouse-avoidance-mode 'animate)
;;进行语法加亮。
(global-font-lock-mode t)
;;设置有用的个人信息
(setq user-full-name "visaya fan")
(setq user-mail-address "visayafan[AT]gmail.com or visayafan[AT]163.com")
;;让 dired 可以递归的拷贝和删除目录。
(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)
(setq visible-bell t)
;; 高亮显示选择区域
(setq transient-mark-mode t)
;; 设置tab为4个空格的宽度,而不是原来的2
(setq c-basic-offset 4)
(setq default-tab-width 4)
(setq-default indent-tabs-mode nil)
;; 不产生备份文件,临时文件
(setq make-backup-files nil)
(setq-default make-backup-files nil)
;; 打开图片显示功能
(auto-image-file-mode t)

;;==========================================================
;; 高亮当前行:hi-line.el,emacs自己带的
;;==========================================================
(require 'hl-line)
(global-hl-line-mode t)

;;页面平滑滚动, scroll-margin 3 靠近屏幕边沿3行时开始滚动,可以很好的看到上下文。
(setq scroll-margin 3
      scroll-conservatively 10000)

(require 'session)
(add-hook 'after-init-hook 'session-initialize)

(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)


;;; browse-kill-ring
(require 'browse-kill-ring)
(global-set-key [(control c)(k)] 'browse-kill-ring)
(browse-kill-ring-default-keybindings)

(require 'ido)
(ido-mode t)



;;; hippie-expand

(global-set-key [(meta ?/)] 'hippie-expand)

(setq hippie-expand-try-functions-list

      '(try-expand-dabbrev

        try-expand-dabbrev-visible

        try-expand-dabbrev-all-buffers

        try-expand-dabbrev-from-kill

        try-complete-file-name-partially

        try-complete-file-name

        try-expand-all-abbrevs

        try-expand-list

        try-expand-line

        try-complete-lisp-symbol-partially

        try-complete-lisp-symbol))





(autoload 'thumbs "thumbs" "Preview images in a directory." t)

(auto-image-file-mode t)

(global-set-key [f9] 'ecb-activate)

(global-set-key (kbd "M-g") 'goto-line)

(tool-bar-mode nil)
;(menu-bar-mode nil)
                                        ;(scroll-bar-mode nil)

(require 'linum)

(global-linum-mode 1)

(require 'yasnippet-bundle)

(fset 'yes-or-no-p 'y-or-n-p)

(setq-default make-backup-files nil)

(setq column-number-mode t)

(setq default-fill-column 110)

;;(global-set-key [f6] 'eshell);F1??è?Shell

(global-set-key [f5] 'gdb);F5μ÷ê?3ìDò

(defadvice kill-ring-save (before slickcopy activate compile)

  "When called interactively with no active region, copy a single line instead."

  (interactive

   (if mark-active (list (region-beginning) (region-end))

     (list (line-beginning-position)

           (line-beginning-position 2)))))

(defadvice kill-region (before slickcut activate compile)

  "When called interactively with no active region, kill a single line instead."

  (interactive

   (if mark-active (list (region-beginning) (region-end))

     (list (line-beginning-position)

           (line-beginning-position 2)))))

(require 'xcscope)

;; 指针颜色
(set-cursor-color "blue")
;; 鼠标颜色
(set-mouse-color "yellow")

;; Load CEDET.

;; See cedet/common/cedet.info for configuration details.

(load-file "~/.emacs.d/cedet/common/cedet.el")

;; (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)
;; Enable EDE (Project Management) features
(global-ede-mode 1)

;; Enable EDE (Project Management) features

(global-ede-mode 1)

(global-set-key [(control f4)] 'speedbar)

;; Enable source code folding

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

;;;;ECB

(add-to-list 'load-path

             "~/.emacs.d/ecb")
(require 'ecb)

(setq ecb-tip-o/-the-day nil)

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

(setq ecb-tip-of-the-day nil)

;;;;隐藏和显示ECB窗口
;;(define-key global-map [(control f1)] 'ecb-hide-ecb-windows)
;;(define-key global-map [(control f2)] 'ecb-show-ecb-windows)
;;
;;;;使某一ecb窗口最大化
;;(define-key global-map "\C-c1" 'ecb-maximize-window-directories)
;;(define-key global-map "\C-c2" 'ecb-maximize-window-sources)
;;(define-key global-map "\C-c3" 'ecb-maximize-window-methods)
;;(define-key global-map "\C-c4" 'ecb-maximize-window-history)
;;
;;;;恢复原始窗口布局
;;(define-key global-map "\C-c0" 'ecb-restore-default-window-sizes)
;;

                                        ; compile-command (concat "C:/DEV-CPP/bin/g++ -g " "\"" buffer-file-name "\""))
                                        ;
                                        ;y (kbd "<f7>") 'smart-compile)
                                        ;
                                        ;ompile()
                                        ;
                                        ;)
                                        ;
                                        ;efile
                                        ;
                                        ;date-make-file-name '("makefile" "Makefile" "GNUmakefile"))
                                        ;
                                        ;nd nil))
                                        ;
                                        ;null
                                        ;
                                        ;(find t candidate-make-file-name :key
                                        ;
                                        ;      '(lambda (f) (file-readable-p f)))))
                                        ;
                                        ;command "make -k ")
                                        ;
                                        ;D?òμ? Makefile £?2é?′μ±?° mode ê?·?ê?ò??aμ??é±àò?μ??£ê?
                                        ;
                                        ;ull (buffer-file-name (current-buffer)))
                                        ;
                                        ;essage "Buffer not attached to a file, won't compile!")
                                        ;
                                        ;f (eq major-mode 'c-mode)
                                        ;
                                        ;  (setq command
                                        ;
                                        ;        (concat "D:/DEV-CPP/bin/gcc.exe -Wall -o "      ;;??òa?÷è·?aμà×??oμ?±àò??÷?ú??à?,
                                        ;
                                        ;                (file-name-sans-extension                          ;;?a?ù,ó???μ?gcc.exeμ?μ??·′úì??aà?μ?D:/Dev-Cpp/bin/gcc.exe
                                        ;
                                        ;                 (file-name-nondirectory buffer-file-name)) ;;×¢òa,?aà?μ??·??μ?D±?üoívistaμ??°1??à·′,??òa×¢òaDT??
                                        ;
                                        ;                " "
                                        ;
                                        ;                (file-name-nondirectory buffer-file-name)
                                        ;
                                        ;                " -g -lm "))
                                        ;
                                        ;(if (eq major-mode 'c++-mode)
                                        ;
                                        ;    (setq command
                                        ;
                                        ;          (concat "D:/DEV-CPP/bin/g++.exe -Wall -o " ;;?1óD?aà?μ?g++,ò2í?gccò??ù...
                                        ;
                                        ;                  (file-name-sans-extension
                                        ;
                                        ;                   (file-name-nondirectory buffer-file-name))
                                        ;
                                        ;                  " "
                                        ;
                                        ;                  (file-name-nondirectory buffer-file-name)
                                        ;
                                        ;                  " -g -lm "))
                                        ;
                                        ;  (message "Unknow mode, won't compile!")))))
                                        ;
                                        ;null command))
                                        ;
                                        ;(command (read-from-minibuffer "Compile command: " command)))
                                        ;
                                        ;pile command)))))

(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.
 '(ecb-layout-window-sizes (quote (("left8" (0.23214285714285715 . 0.27906976744186046) (0.23214285714285715 . 0.23255813953488372) (0.23214285714285715 . 0.27906976744186046) (0.23214285714285715 . 0.18604651162790697)))))
 '(ecb-options-version "2.40")
 '(matlab-shell-command "C:/Program Files/MATLAB/R2010b/bin/matlab.exe")
 '(preview-dvips-command "C:/CTEX/MiKTeX/miktex/bin/dvips -Pwww -i -E %d -o %m/preview.000")
 '(preview-fast-dvips-command "C:/CTEX/MiKTeX/miktex/bin/dvips -Pwww %d -o %m/preview.ps")
 '(preview-gs-command "gswin32c.exe"))

(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.
 )






;;color theme

(add-to-list 'load-path "~/.emacs.d/color-theme-6.6.0")
(require 'color-theme)
(eval-after-load "color-theme"
  '(progn
     (color-theme-initialize)))
;(color-theme-gnome2)))





(add-to-list 'load-path "~/.emacs.d/auctex/site-lisp/site-start.d")
;;;; .configure make sudo make install
(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)
(if (string-equal system-type "windows-nt")
    (require 'tex-mik))
(setq TeX-save-query nil)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
                                        ;(setq-default TeX-master nil)
(setq preview-scale-function 1.3)
(setq LaTeX-math-menu-unicode t)
(setq TeX-insert-braces nil)
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

;;Auctex for Latex
(add-hook 'LaTeX-mode-hook 'LaTeX-install-toolbar)
(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)

(add-hook 'LaTeX-mode-hook (lambda()
                             ;;调用latex命令
                             (add-to-list 'TeX-command-list (list "LaTeX" "latex %s.tex" 'TeX-run-command nil t))
                             ;;调用dvipdfmx命令
                             (add-to-list 'TeX-command-list (list "dvi2pdf" "dvipdfmx %s.dvi" 'TeX-run-command nil t))
                             ;;调用pdflatex命令;;调用pdflatex命令;;调用pdflatex命令
                             (add-to-list 'TeX-command-list (list "pdf Latex" "pdflatex %s.tex" 'TeX-run-command nil t))
                                        ; View PDF
                             (add-to-list 'TeX-command-list (list "View pdf" "start .\\\"%s.pdf\""'TeX-run-command nil t))
                             ;;设置环境为xelatex
                             ;;(add-to-list 'TeX-command-list '("XeLaTeX" "%`xelatex%(mode)%' %t" TeX-run-TeX nil t))
                             ;;(setq TeX-command-default "XeLaTeX")
                             ;;(setq TeX-save-query nil )
                             ;;(setq TeX-show-compilation t)
                             ))
;;=================================================
;;;+     latex-math-mode
;;=================================================

;; latex-math-mode (add math symbols to menu and shortcuts)
;; So that you can use, e.g., `a, to input \alpha. You may also define
;; your own customized shortcuts by setting the variable
;; LaTeX-math-list before loading LaTeX-math-mode.
;; to enable maths support

(setq LaTeX-math-mode t)
(setq TeX-electric-escape t) ;; you may like it or dislike it. I found it useful when inputting repeated commands -- you just need to type \ and ENTER to repeat the last latex command.

(add-hook 'LaTeX-mode-hook 'latex-math-mode)   ; with AUCTeX LaTeX mode

(add-hook 'latex-mode-hook 'latex-math-mode)   ; with Emacs latex mode

(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)

;;=================================================
;;;+     reftex-mode
;;=================================================

(autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
(autoload 'reftex-citation "reftex-cite" "Make citation" nil)
(autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode

                                        ;(Global-set-key (kbd "<f11>") 'v_latex_compile)
                                        ;(fset 'v_latex_compile
                                        ;   (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([3 3 return] 0 "%d")) arg)))





(global-set-key "\C-ccc" 'color-theme-gnome2)
(global-set-key "\C-ccb" 'color-theme-blue-sea)
(global-set-key "\C-ccg" 'color-theme-gray30)
(global-set-key "\C-ccd" 'color-theme-euphoria)
(require 'tabbar)
(tabbar-mode)
(global-set-key (kbd "M-P") 'tabbar-backward-group)   0
(global-set-key (kbd "M-N") 'tabbar-forward-group)
(global-set-key (kbd "M-p") 'tabbar-backward)
(global-set-key (kbd "M-n") 'tabbar-forward)

(global-set-key "\C-cds" 'desktop-save)
(global-set-key "\C-cdc" 'desktop-change-dir)

(setq x-select-enable-clipboard t);支持emacs和外部程序的粘贴
(setq frame-title-format '("" buffer-file-name ));在标题栏显示buffer名

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



(add-hook 'c-mode-hook 'hs-minor-mode)
(add-hook 'C++-mode-hook 'hs-minor-mode)
(add-hook 'lisp-mode-hook 'hs-minor-mode)
(add-hook 'html-mode-hook 'hs-minor-mode)
(global-set-key "\C-cha" 'hs-hide-all)
(global-set-key "\C-cas" 'hs-show-all)
(global-set-key "\C-chb" 'hs-hide-block)
(global-set-key "\C-cbs" 'hs-show-block)
(global-set-key "\C-chl" 'hs-hide-level)

;;hide region
(require 'hide-region)
(global-set-key (kbd "C-c h r") 'hide-region-hide)
(global-set-key (kbd "C-c s r") 'hide-region-unhide)
;; hide lines
(require 'hide-lines)
(global-set-key (kbd "C-c h L") 'hide-lines)
(global-set-key (kbd "C-c s l") 'show-all-invisible)
(global-set-key (kbd "C-c m l") 'list-matching-lines)

;;===================================
;;设置编译器==========================
;;===================================
;;(setq compile-command (concat "C:/Dev-Cpp/bin/g++ -g " "\"" buffer-file-name "\""))
                                        ;(global-set-key (kbd "<f7>") 'smart-compile)
;; (defun smart-compile()

;;   ;;  "比较智能的C/C++编译命令
;;   ;;如果当前目录有makefile则用make -k编译,否则,如果是
;;   ;;处于c-mode,就用gcc -Wall编译,如果是c++-mode就用 g++ -Wall编译"
;;   (interactive)
;;   ;; 查找 Makefile
;;   (let ((candidate-make-file-name '("makefile" "Makefile" "GNUmakefile"))
;;         (command nil))
;;     (if (not (null
;;               (find t candidate-make-file-name :key
;;                     '(lambda (f) (file-readable-p f)))))
;;         (setq command "make -k ")
;;       ;; 没有找到 Makefile ,查看当前 mode 是否是已知的可编译的模式
;;       (if (null (buffer-file-name (current-buffer)))
;;           (message "Buffer not attached to a file, won't compile!")
;;         (if (eq major-mode 'c-mode)
;;             (setq command
;;                   (concat "c:/study/CodeBlocks/MinGW/bin/gcc.exe -Wall -o "      ;;你要明确知道自己的编译器在哪里,
;;                           (file-name-sans-extension                          ;;这样,用你的gcc.exe的地址代替这里的D:/Dev-Cpp/bin/gcc.exe
;;                            (file-name-nondirectory buffer-file-name)) ;;注意,这里的路径的斜杠和vista的习惯相反,你要注意修改
;;                           " "
;;                           (file-name-nondirectory buffer-file-name)
;;                           " -g -lm "))
;;           (if (eq major-mode 'c++-mode)
;;               (setq command
;;                     (concat " C:/study/CodeBlocks/MinGW/bin/g++.exe -Wall -o " ;;还有这里的g++,也同gcc一样...
;;                             (file-name-sans-extension
;;                              (file-name-nondirectory buffer-file-name))
;;                             " "
;;                             (file-name-nondirectory buffer-file-name)
;;                             " -g -lm "))
;;             (message "Unknow mode, won't compile!")))))
;;     (if (not (null command))
;;         (let ((command (read-from-minibuffer "Compile command: " command)))
;;           (compile command)))))




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



(add-to-list 'load-path "~/.emacs.d/auto-complete-1.3.1")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete-1.3.1/ac-dict")
(ac-config-default)



;;禁用启动画面

(setq inhibit-startup-message t)

;;尺寸
;;(setq initial-frame-alist '( (width . 93) (height . 36)))


(require 'unicad)

(load "desktop")
(desktop-load-default)
(desktop-read)

(menu-bar-left-scroll-bar)


(put 'narrow-to-page 'disabled nil)
(put 'narrow-to-region 'disabled nil)



(global-set-key (kbd "M-@") 'set-mark-command)
(global-set-key (kbd "C-@") 'mark-word)

                                        ;(add-to-list 'load-path "~/.emacs.d/icicles")
                                        ;(require 'icicles)
                                        ;(icy-mode 1)

(require 'edit-server)
(edit-server-start)


                                        ;(global-set-key [(f9)] 'touming)  ;;注意这行中的F8 , 可以改成你想要的按键
(setq alpha-list '((85 55) (100 100)))
(defun touming ()
  (interactive)
  (let ((h (car alpha-list)))
    ((lambda (a ab)
       (set-frame-parameter (selected-frame) 'alpha (list a ab))
       (add-to-list 'default-frame-alist (cons 'alpha (list a ab)))
       ) (car h) (car (cdr h)))
    (setq alpha-list (cdr (append alpha-list (list h))))
    )
  )



                                        ;(add-to-list 'load-path "~/.emacs.d/matlab-emacs")
                                        ;(require 'matlab-load)
                                        ;(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
                                        ;(setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
                                        ;(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
                                        ;(setq matlab-verify-on-save-flag nil) ; turn off auto-verify on save
                                        ;(defun my-matlab-mode-hook ()
                                        ;  (setq fill-column 76)) ; where auto-fill should wrap
                                        ;(add-hook 'matlab-mode-hook 'my-matlab-mode-hook)
                                        ;(defun my-matlab-shell-mode-hook ()
                                        ;  '())
                                        ;(add-hook 'matlab-shell-mode-hook 'my-matlab-shell-mode-hook)
(global-font-lock-mode t)
                                        ;(matlab-mode-hilit)
(autoload 'tlc-mode "tlc" "tlc Editing Mode" t)
(add-to-list 'auto-mode-alist '("\\.tlc{1}quot; . tlc-mode))
(setq tlc-indent-function t)

(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)


;; 使用cperl-mode代替默认的perl-mode
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))

;; 缩进相关
(add-hook 'cperl-mode-hook 'n-cperl-mode-hook t)
(defun n-cperl-mode-hook ()
  (setq cperl-indent-level 4)
  (setq cperl-continued-statement-offset 0)
  (setq cperl-extra-newline-before-brace t)
  (set-face-background 'cperl-array-face "wheat")
  (set-face-background 'cperl-hash-face "wheat")
  )

(global-set-key (kbd "C-c l") 'tex-comment-current-line)
(fset 'tex-comment-current-line
      "\C-e   %")

;(require 'autopair)
;(autopair-global-mode) ;; to enable in all buffers

(require 'htmlize)

(require 'goto-last-change)
(global-set-key "\C-c l" 'goto-last-change)

                                        ;org-mode
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(setq org-todo-keywords
      '((sequence "TODO(t)" "|" "DONE(d)")
        (sequence "REPORT(r)" "BUG(b)" "KNOWNCAUSE(k)" "|" "FIXED(f)")))
(setq org-log-done 'time)
(setq org-log-done 'note)

                                        ;当所有子项目都标记为Done的时候,父项目也被标记为Done
(defun org-summary-todo (n-done n-not-done)
  "Swith entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging.
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(setq org-tag-alist '(("@STL" . ?s) ("@OJ" . ?o) ("@Python" . ?p) ("@English" . ?e)))


;;abbrev
(setq abbrev-mode t)
(setq abbrev-file-name             ;; tell emacs where to read abbrev
      "~/.emacs.d/abbrev_defs")    ;; definitions from...
(setq save-abbrevs t)              ;; save abbrevs when files are saved
;; you will be asked before the abbreviations are saved
(quietly-read-abbrev-file)       ;; reads the abbreviations file on startup
(if (file-exists-p abbrev-file-name)
    (quietly-read-abbrev-file))

;;(require 'calendar)
(setq calendar-latitude +30.15)
(setq calendar-longitude +120.10)
(setq calendar-location-name "Hangzhou")
;; 设置阴历显示,在 calendar 上用 pC 显示阴历
(setq chinese-calendar-celestial-stem
      ["甲" "乙" "丙" "丁" "戊" "己" "庚" "辛" "壬" "癸"])
(setq chinese-calendar-terrestrial-branch
      ["子" "丑" "寅" "卯" "辰" "巳" "戊" "未" "申" "酉" "戌" "亥"])
(setq calendar-remove-frame-by-deleting t)
(setq calendar-week-start-day 1)
(setq mark-diary-entries-in-calendar t)
(setq mark-holidays-in-calendar nil)
(setq view-calendar-holidays-initially nil)
;;(setq mark-diary-entries-in-calendar t)
;;(setq mark-holidays-in-calendar t)
;;(setq view-calendar-holidays-initially nil)
;; my advice for exit-calendar : save and close the _diray buffer
(defadvice exit-calendar (before my-advice-close-diary ())
  "save and close the _diary buffer to avoid open it when
starting emacs next time."
  (let ((bf (find-file-noselect diary-file t)))
    (and bf
         (save-excursion
           (with-current-buffer bf (save-buffer) (kill-buffer nil))))))
(ad-activate 'exit-calendar)
;;I don't care these holidays
(setq christian-holidays nil)
(setq hebrew-holidays nil)
(setq islamic-holidays nil)
(setq solar-holidays nil)
(setq general-holidays '((holiday-fixed 1 1 "元旦")
                         (holiday-fixed 2 14 "情人节")
                         (holiday-fixed 3 14 "白色情人节")
                         (holiday-fixed 4 1 "愚人节")
                         (holiday-fixed 5 1 "劳动节")
                         (holiday-float 5 0 2 "母亲节")
                         (holiday-fixed 6 1 "儿童节")
                         (holiday-float 6 0 3 "父亲节")
                         (holiday-fixed 7 1 "建党节")
                         (holiday-fixed 8 1 "建军节")
                         (holiday-fixed 9 10 "教师节")
                         (holiday-fixed 10 1 "国庆节")
                         (holiday-fixed 12 25 "圣诞节")))
;; settings for appt
(require 'appt)
;;(setq view-diary-entries-initially t)
(setq appt-issue-message t)
(setq appt-message-warning-time 3)
(setq appt-display-format 'window)
;;;planner
;(require 'planner)
;(global-set-key [(shift f1)] 'planner-create-task-from-buffer)
;(setq planner-publishing-directory "/home/godot/emacs/wiki/diary/plan")
;;;;;Start planner together with Calendar
;(planner-calendar-insinuate)
;(setq planner-calendar-show-planner-files t)
;(require 'remember-planner)
;(setq remember-handler-functions '(remember-planner-append))
;(setq remember-annotation-functions planner-annotation-functions)
;(require 'planner-accomplishments)
;(require 'planner-deadline)
;; 设置 calendar 的显示
;;(setq calendar-remove-frame-by-deleting t)
;;(setq calendar-week-start-day 1)            ; 设置星期一为每周的第一天
;;(setq mark-diary-entries-in-calendar t)     ; 标记calendar上有diary的日期
;;(setq mark-holidays-in-calendar t)        ; 为了突出有diary的日期,calendar上不标记节日
;;(setq view-calendar-holidays-initially t) ; 打开calendar的时候不显示一堆节日
;; 去掉不关心的节日,设定自己在意的节日,在 calendar 上用 h 显示节日



;;---------------------------------------c和cpp环境设定------------------------------------------
;; (setq compile-command "make")
;; ;;emacs的默认compile命令是调用make -k,我把它改成了make。你也可以把它改成其他的,比如gcc之类的.
;; ;;把c语言风格设置为k&r风格
;; (add-hook 'c-mode-hook
;;           '(lambda ()
;;              (c-set-style "k&r")))
;; ;;把C++语言风格设置为stroustrup风格
;; (add-hook 'c++-mode-hook
;;           '(lambda()
;;              (c-set-style "k&r")))
;;(global-set-key (kbd "<f7>") 'compile)
;;(setq compile-command "mingw32-make.exe")
(global-set-key (kbd "<f7>") 'smart-compile)
(add-hook 'c-mode-hook 'linux-c-mode)
(add-hook 'c++-mode-hook 'linux-cpp-mode)
(defun linux-c-mode()
  ;; 将回车代替C-j的功能,换行的同时对齐
  (define-key c-mode-map [return] 'newline-and-indent)
  (interactive)
  ;; 设置C程序的对齐风格
  (c-set-style "K&R")
  ;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
  ;(c-toggle-auto-state)
  ;; 此模式下,当按Backspace时会删除最多的空格
  ;(c-toggle-hungry-state)
  ;; TAB键的宽度设置为8
  (setq c-basic-offset 4)
  ;; 在菜单中加入当前Buffer的函数索引
  (imenu-add-menubar-index)
  ;; 在状态条上显示当前光标在哪个函数体内部
  (which-function-mode)
  )
(defun linux-cpp-mode()
  (define-key c++-mode-map [return] 'newline-and-indent)
  ;(define-key c++-mode-map [(control c) (c)] 'compile)
  (interactive)
  (c-set-style "K&R")
  ;(c-toggle-auto-state)
  ;(c-toggle-hungry-state)
  (setq c-basic-offset 4)
  (imenu-add-menubar-index)
  (which-function-mode)
  )
;;智能编译
(defun smart-compile()
  ;;  "比较智能的C/C++编译命令,如果当前目录有makefile则用make -k编译,否则,如果是
  ;;处于c-mode,就用gcc -Wall编译,如果是c++-mode就用g++ -Wall编译"
  (interactive)
  ;; 查找 Makefile
  (let ((candidate-make-file-name '("makefile" "Makefile" "GNUmakefile"))
        (command nil))
    (if (not (null
              (find t candidate-make-file-name :key
                    '(lambda (f) (file-readable-p f)))))
        (setq command "mingw32-make.exe -k ")
      ;; 没有找到 Makefile ,查看当前 mode 是否是已知的可编译的模式
      (if (null (buffer-file-name (current-buffer)))
          (message "Buffer not attached to a file, won't compile!")
        (if (eq major-mode 'c-mode)
            (setq command
                  (concat "gcc -g -Wall -o "
                          (file-name-sans-extension
                           (file-name-nondirectory buffer-file-name))
                          " "
                          (file-name-nondirectory buffer-file-name)
                          ;;               " -lm "
                          ))
          (if (eq major-mode 'c++-mode)
              (setq command
                    (concat "g++ -g -Wall -o "
                            (file-name-sans-extension
                             (file-name-nondirectory buffer-file-name))
                            " "
                            (file-name-nondirectory buffer-file-name)
                            ;;             " -lm "
                            ))
            (if (eq major-mode 'fortran-mode)
                (setq command
                      (concat "ifort "
                              ;;                (file-name-nondirectory buffer-file-name))
                              ;;                (file-name-sans-extension
                              (file-name-nondirectory buffer-file-name)
                              " -o "
                              ))
              (message "Unknow mode, won't compile!"))))))
    (if (not (null command))
        (let ((command (read-from-minibuffer "Compile command: " command)))
          (compile command)))))

;;rect-mark.el 高亮选中矩形区域 还不知道有什么用,先不用了
;;(require 'rect-mark)

;;当 % 在括号上按下时,那么匹配括号,否则输入一个 %。你只需要在 .emacs 文件里加入这些东西就可以达到目的:
;;(global-set-key "%" 'match-paren)
;; (defun match-paren (arg)
;;   "Go to the matching paren if on a paren; 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)))))

;;临时记号
;;有时你需要跳到另一个文件进行一些操作,然后很快的跳回来。你当然可以使用 bookmark 或者寄存器。但是这些实在是太慢了。你多想拥有vi那样的 ma, mb, 'a, 'b 的操作。现在你可以用几行 elisp 达到类似的目的:
(global-set-key "\C-cp" 'ska-point-to-register)
(global-set-key "\C-cn" '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)))
;;go-to-char
;;有了这段代码之后,当你按 C-c a x (x 是任意一个字符) 时,光标就会到下一个 x 处。再次按 x,光标就到下一个 x。比如 C-c a w w w w ..., C-c a b b b b b b ...
(defun wy-go-to-char (n char)
  "Move forward to Nth occurence of CHAR.
Typing `wy-go-to-char-key' again will move forwad to the next Nth
occurence of CHAR."
  (interactive "p\ncGo to char: ")
  (search-forward (string char) nil nil n)
  (while (char-equal (read-char)
                     char)
    (search-forward (string char) nil nil n))
  (setq unread-command-events (list last-input-event)))
(define-key global-map (kbd "C-c a") 'wy-go-to-char)


(global-set-key (kbd "<f6>") 'other-window)
(global-set-key (kbd "<f11>") 'ido-switch-buffer)
(global-set-key (kbd " <f5>") 'gdb)

(global-set-key (kbd "C-c h f") 'v_hide_function)
(fset 'v_hide_function
   [?\C-\M-a ?\C-  ?\C-\M-e ?\C-p ?\C-e ?\C-c ?h ?r ?\C-g])

(global-set-key (kbd "C-;") 'v_c_comment_currentline)
(fset 'v_c_comment_currentline
   "\355// ")



评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值