mercredi 9 juin 2010

.emacs 20100610

(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.
'(blink-cursor-mode nil)
)
(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.
)

;;-----------------------------------------------------------------------------
;; to enable highlighting when searching
(setq search-highlight t)
;;to highlight matches when using serch-and-replace
(setq query-replace-highlight t)
;;用win+space为set-mark键,留出ctrl+space热键作为输入法
(global-set-key (kbd "C-SPC") 'nil)
(global-set-key (kbd "s-SPC") 'set-mark-command)
;;设置字体大小
(set-default-font "DejaVu Sans Mono-8")
;;在窗口左侧显示行号
(global-linum-mode t)
;;在状态栏(mode line)上显示行号
(setq column-number-mode t)
(setq line-number-mode t)
;;鼠标自动避开指针,如当你输入的时候,指针到了鼠标的位置,鼠标有点挡住视线了
(mouse-avoidance-mode 'animate)
;;指针不要闪
(blink-cursor-mode -1)
(transient-mark-mode 1)
;;当指针到一个括号时,自动显示所匹配的另一个括号
(show-paren-mode 1)
;;去掉烦人的警告铃声
(setq visible-bell nil)
;;去掉Emacs和gnus启动时的引导界面
(setq inhibit-startup-message t)
(setq gnus-inhibit-startup-message t)
;; 显示时间
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)
;;当前行高亮
(require 'hl-line)
(global-hl-line-mode t)
;;滚动条在窗口右侧
'(scroll-bar-mode (quote right))
;;在窗口的标题栏上显示文件名称
(setq frame-title-format "%n%F/%b")
;;允许emacs和外部其他程序的粘
(setq x-select-enable-clipboard t)
;;支持中键粘贴
(setq mouse-yank-at-point t)
;;所有的问题用y/n方式,不用yes/no方式
(fset 'yes-or-no-p 'y-or-n-p)
;;go-line快捷键
(global-set-key (kbd "M-g") 'goto-line)
;; 在行首 C-k 时,同时删除该行。
(setq-default kill-whole-line t)
;;保存前,删除当前buffer中行尾空格和TAB等whitespace
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;(setq ansi-color-for-comint-mode t)使用shell,shell中没有乱码
(ansi-color-for-comint-mode-on)
;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;; Add the directories to your load path
(add-to-list 'load-path "~/.emacs.d/")
;;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
;;------------------------------------------------------------------------------
;; 启动时的屏幕大小
;;第一种方法,需要根据不同的电脑屏幕大小进行修正
;;第二种方法,思路很好,但是垂直方向(vert)超过了显示范围,需要修正
;;------------------------------------------------------------------------------
;;第一种方法
(setq default-frame-alist
(append '((top . 0)(left . 0)(width . 175)(height . 45))
default-frame-alist))
;;第二种方法
;(defun my-maximized-horz ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0)))
;(defun my-maximized-vert ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
;(defun my-maximized ()
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
; (interactive)
; (x-send-client-message
; nil 0 nil "_NET_WM_STATE" 32
; '(1 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
;(my-maximized)
;;-----------------------------------------------------------------------------
;; cursor-chg.el
;;-----------------------------------------------------------------------------
(require 'cursor-chg) ; Load this library
(change-cursor-mode 1) ; On for overwrite/read-only/input mode
(toggle-cursor-type-when-idle 1) ; On when idle
;;-----------------------------------------------------------------------------
;;调用smart-compile
;;-----------------------------------------------------------------------------
(require 'smart-compile)
(global-set-key [f7] 'smart-compile)
;;-----------------------------------------------------------------------------
;; add emacs-wiki
;;-----------------------------------------------------------------------------
;; Add the directories to your load path
;(add-to-list 'load-path "~/.emacs.d/emacs-wiki-2.72")
;;调用emacs-wiki
;(require 'emacs-wiki)
;(require 'emacs-wiki-menu)
;(load "emacs-wiki")
;;----------------------------------------------------------------------------
;; 调用tabbar,在head中显示打开文件列表
;;-----------------------------------------------------------------------------
(require 'tabbar)
(tabbar-mode t)
;;全部分在同一组
(setq tabbar-buffer-groups-function
(lambda ()
(list "All")))
;;----------------------------------------------------------------
;; add a buffer modification state indicator in the tab label,
;; and place a space around the label to make it looks less crowd
;;----------------------------------------------------------------
(defadvice tabbar-buffer-tab-label (after fixup_tab_label_space_and_flag activate)
(setq ad-return-value
(if (and (buffer-modified-p (tabbar-tab-value tab))
(buffer-file-name (tabbar-tab-value tab)))
(concat " + " (concat ad-return-value " "))
(concat " " (concat ad-return-value " ")))))
;; called each time the modification state of the buffer changed
(defun ztl-modification-state-change ()
(tabbar-set-template tabbar-current-tabset nil)
(tabbar-display-update))
;; first-change-hook is called BEFORE the change is made
(defun ztl-on-buffer-modification ()
(set-buffer-modified-p t)
(ztl-modification-state-change))
(add-hook 'after-save-hook 'ztl-modification-state-change)
;; this doesn't work for revert, I don't know
;;(add-hook 'after-revert-hook 'ztl-modification-state-change)
(add-hook 'first-change-hook 'ztl-on-buffer-modification)
;;----------------------------------------------------------------------------
;; 使用一个简单的 Elisp 函数
;;:如果选定了区域,那么按 M-w 就复制这个区域;如果没有选定区域,那么 M-w 就复制一行
;;-----------------------------------------------------------------------------
(defun huangq-kill-ring-save (&optional n)
"If region is active, copy region. Otherwise, copy line."
(interactive "p")
(if mark-active
(kill-ring-save (region-beginning) (region-end))
(if (> n 0)
(kill-ring-save (line-beginning-position) (line-end-position n))
(kill-ring-save (line-beginning-position n) (line-end-position)))))

(global-set-key (kbd "M-w") 'huangq-kill-ring-save)

;;-----------------------------------------------------------------------------
;;备份设置
;;-----------------------------------------------------------------------------
;;emacs还有一个自动保存功能,默认在~/.emacs.d/auto-save-list里,
;;这个非常有用,具体可以参见Sams teach yourself emacs in 24hours(我简称为sams24)
;;启用版本控制,即可以备份多次
(setq version-control t)
;;备份最原始的版本两次,记第一次编辑前的文档,和第二次编辑前的文档
(setq kept-old-versions 2)
;;备份最新的版本五次,理解同上
(setq kept-new-versions 5)
;;删掉不属于以上7中版本的版本
(setq delete-old-versions t)
;;设置备份文件的路径
(setq backup-directory-alist '(("." . "~/.emacs.tmp")))
;;备份设置方法,直接拷贝
(setq backup-by-copying t)
;;-----------------------------------------------------------------------------
;; 快速在另外一个buffer中打开shell并cd 到当前 buffer 所在的目录
;;-----------------------------------------------------------------------------
(defun kid-switch-to-shell ()
(interactive)
(when (null (cdr (window-list)))
(split-window-horizontally))
(let ((file buffer-file-name))
(other-window 1)
(shell)
(when file
(end-of-buffer)
(when (looking-back shell-prompt-pattern)
(insert "cd " (file-name-directory file))
(call-interactively 'comint-send-input)))))
(global-set-key (kbd "") 'kid-switch-to-shell)
;;-----------------------------------------------------------------------------
;; occur
;;-----------------------------------------------------------------------------
(defun occur-fortran ()
(interactive )
(setq mawei "\\(?:\\\\|\\\\|\\\\|\\\\|\\\\|\\\\)")
(occur mawei)
;(occur (regexp-opt '("program""subroutine""function""call")))
)
(global-set-key (kbd "") 'occur-fortran)
;;-----------------------------------------------------------------------------
;; 每当我在 M-x shell启动shell,然后执行 exit 退出 shell 之后,buffer 并不自动关闭,很不爽,
;; 下面的指令,可以让其自动关闭。
;;-----------------------------------------------------------------------------
(add-hook 'shell-mode-hook 'wcy-shell-mode-hook-func)
(defun wcy-shell-mode-hook-func ()
(set-process-sentinel (get-buffer-process (current-buffer))
#'wcy-shell-mode-kill-buffer-on-exit)
)
(defun wcy-shell-mode-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))))
(kill-buffer-and-window )))
;;-----------------------------------------------------------------------------
;; 当前buffer的文件名,前加“./”,后去掉后面4位数字,输入到minibuffer
;;-----------------------------------------------------------------------------
;(define-key minibuffer-local-map [f8]
;(lambda ()
;(interactive)
;(insert (concat "./") )
;(insert (substring (buffer-name (current-buffer-not-mini)) 0 -4 ))
;(insert (concat ".exe") )
;)
;)
;
;(defun current-buffer-not-mini ()
;"Return current-buffer if current buffer is not the *mini-buffer*
;else return buffer before minibuf is activated."
;(not (window-minibuffer-p)) (current-buffer)
;(if (eq (get-lru-window) (next-window))
;(window-buffer (previous-window)) (window-buffer (next-window))))

;;------------------------------------------------------------------------------
;; auto-complete
;; -----------------------------------------------------------------------------
;; Add the directories to your load path
(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete)
;;(global-auto-complete-mode t)
;; if only use the line above, auto-complete-mode does not work in a lot of modes
;; for example LaTeX-mode
(add-hook 'f90-mode-hook 'auto-complete-mode)
(add-hook 'emacs-lisp-mode-hook 'auto-complete-mode)
(add-hook 'LaTeX-mode-hook 'auto-complete-mode)
(add-hook 'latex-mode-hook 'auto-complete-mode)
;; Use C-n/C-p to select candidates
;;(define-key ac-complete-mode-map "\M-n" 'ac-next)
;;(define-key ac-complete-mode-map "\M-p" 'ac-previous)
;; you can stop completion by pressing M-/.
;;(define-key ac-complete-mode-map "\M-TAB" 'ac-stop)
;; Completion by TAB
;;
;; Add following code to your .emacs.
;;
(define-key ac-complete-mode-map "\t" 'ac-complete)
(define-key ac-complete-mode-map "\r" nil)

;; Do What I Mean mode
;; -------------------
;;
;; If DWIM (Do What I Mean) mode is enabled,
;; the following features is available:
;;
;; a. TAB (ac-expand) behave as completion (ac-complete)
;; when only one candidate is left
;; b. TAB (ac-expand) behave as completion (ac-complete)
;; after you select candidate
;; c. Disapear automatically when you
;; complete a candidate.
;;
;; DWIM mode is enabled by default.
;; You can enable this feature by
;; setting `ac-dwim' to t.
;;
(setq ac-dwim t)
;;------------------------------------------------------------------------------
;; quit a frame the same way no matter what kind of frame you are on"
;;------------------------------------------------------------------------------
;;This method, when bound to C-x C-c, allows you to close an emacs frame the
;;same way, whether it's the sole window you have open, or whether it's
;;a "child" frame of a "parent" frame. If you're like me, and use emacs in
;;a windowing environment, you probably have lots of frames open at any given
;;time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child
;;frame, and to remember to do C-x C-x to close the main frame (and if you're
;;not careful, doing so will take all the child frames away with it). This
;;is my solution to that: an intelligent close-frame operation that works in
;;all cases (even in an emacs -nw session).
;;(global-set-key "\C-x\C-c" 'ic) ;forward reference
(defun ic ()
"quit a frame the same way no matter what kind of frame you are on"
(interactive)
(if (eq (car (visible-frame-list)) (selected-frame))
;;for parent/master frame...
(if (> (length (visible-frame-list)) 1)
;;close a parent with children present
(delete-frame (selected-frame))
;;close a parent with no children present
(save-buffers-kill-emacs))
;;close a child frame
(delete-frame (selected-frame))))
;;------------------------------------------------------------------------------
;; hithlight-80+:
;;------------------------------------------------------------------------------
;;(add-to-list 'load-path "~/.emacs.d/")
;;(global-highlight-80+-mode t)
(require 'highlight-80+)
(add-hook 'f90-mode-hook 'highlight-80+-mode)
;;------------------------------------------------------------------------------
;; 自动补全括号
;; 输入左边的括号,就会自动补全右边的部分.包括(), "", [] , {} , 等等。
;;------------------------------------------------------------------------------
(defun auto-pair ()
(interactive)
(make-local-variable 'skeleton-pair-alist)
(setq skeleton-pair-alist '(
(\"_"\"")
(\'_"'")
(\(")")
(\[_"]")
(\{_"}")
;(?\{?_"}")
))
(setq skeleton-pair t)
(local-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "'") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'f90-mode-hook 'auto-pair)
(add-hook 'latex-mode-hook 'auto-pair)
(add-hook 'LaTeX-mode-hook 'auto-pair)
;;------------------------------------------------------------------------------
;; redo/undo
;;------------------------------------------------------------------------------
(require 'redo)
(global-set-key (kbd "C-/") 'undo)
(global-set-key (kbd "M-/") 'redo)

;;------------------------------------------------------------------------------
;; flyspell.el
;;
;; flyspell is an Emacs package that highlights misspelld words as you type;
;; Remark:
;; `flyspell-mode' uses `ispell-mode'. Thus all Ispell options are
;; valid. For instance, a personal dictionary can be used by
;; invoking `ispell-change-dictionary'.
;;
;; ispell-program-name = "aspell"
;; ispell-aspell-dict-dir = "/usr/lib/aspell"
;;------------------------------------------------------------------------------
;; enable flyspell-mode (minor mode) in latex-mode (major mode)
(add-hook 'latex-mode-hook 'flyspell-mode) ;; for latex
(add-hook 'LaTeX-mode-hook 'flyspell-mode) ;;for AUCtex
;; enable flyspell-prog-mode (minor mode) in f90-mode (major mode)
;; (add-hook 'f90-mode-hook 'flyspell-prog-mode)
(setq ispell-local-dictionary "american")
;;(setq ispell-local-dictionary "french")


;;------------------------------------------------------------------------------
;; for LaTeX-mode-hook, both latex and AUCtex
;;------------------------------------------------------------------------------

;; If you want to make AUCTeX aware of style files and multi-file
;; documents right away, insert the following in your `.emacs' file.
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)

;; To turn RefTeX Mode on and off in a particular buffer, use `M-x
;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the
;; following lines to your `.emacs' file:
(add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
(add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
(add-hook 'LaTeX-mode-hook 'outline-minor-mode) ; with Emacs latex mode

Aucun commentaire:

Enregistrer un commentaire