- 论坛徽章:
- 0
|
;; .emacs
;;-----------------------------------------中文设定----------------------------------------------
;; Setup GBK environment
(require 'mule-gbk)
(set-terminal-coding-system 'chinese-gbk)
(set-keyboard-coding-system 'chinese-gbk)
(set-language-environment 'chinese-gbk)
(setq locale-coding-system 'chinese-gbk)
(setq current-language-environment "Chinese-GBK")
;; Setup X Selection for mule-gbk
(mule-gbk-selection-setup)
(prefer-coding-system 'gbk)
;;向其他X程序粘贴中文
(when (fboundp 'utf-translate-cjk-mode)
;; Load modified utf-translate-cjk-mode
(require 'gbk-utf-mode)
;; Turn on utf-translate-cjk-mode
(utf-translate-cjk-mode 1)
;; Setup X selection for unicode encoding
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
;;----------------------------------------基本设置-----------------------------------------------
;;; uncomment this line to disable loading of "default.el" at startup
(setq inhibit-default-init t)
;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
;; enable visual feedback on selections
(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" system-name))
(setq inhibit-startup-message t)
(fset 'yes-or-no-p 'y-or-n-p)
;; 设置imenu的排序方式为按名称排序
(setq imenu-sort-function 'imenu--sort-by-name)
(setq mouse-yank-at-point t)
(setq kill-ring-max 200)
;;不用 TAB 字符来indent, 这会引起很多奇怪的错误。编辑 Makefile 的时候也不用担心,因为 makefile-mode 会把 TAB 键设置成真正的 TAB 字符,并且加亮显示的。
(setq-default indent-tabs-mode nil)
(setq default-tab-width 8)
(setq tab-stop-list ())
(loop for x downfrom 40 to 1 do
(setq tab-stop-list (cons (* x 4) tab-stop-list)))
(setq sentence-end "\\([不要滚动栏,现在都用滚轴鼠标了,可以不用滚动栏了
;;(scroll-bar-mode nil)
;;不要工具栏
(tool-bar-mode -1)
;;启用部分补全功能,如输入M-x q r r相当于M-x query-replace-regexp
(partial-completion-mode 1)
;;在minibuffer里启用自动补全函数和变量
(icomplete-mode 1)
;;允许minibuffer自由变化其大小(指宽度)
(setq resize-mini-windows t)
;;当寻找一个同名的文件,自动关联上那个文件?
(setq uniquify-buffer-name-style 'forward)
;;允许自动打开图片,如wiki里面
(auto-image-file-mode)
;;可以操作压缩文档
(auto-compression-mode 1)
;;在minibuffer上面可以显示列号
(column-number-mode t)
;;显示默认的文档的宽度,看起来比较舒服?
(setq default-fill-column 60)
;;是用滚轴鼠标
(mouse-wheel-mode t)
(setq search-highlight t)
(setq query-replace-highlight t)
;;括号匹配
(show-paren-mode t)
(setq show-paren-style 'parentheses)
;; Automatically load abbreviations table
;; Note that emacs chooses, by default, the filename
;; "~/.abbrev_defs", so don't try to be too clever
;; by changing its name
(setq-default abbrev-mode t)
(read-abbrev-file "/home/godot/.abbrev_defs")
(setq save-abbrevs t)
;;使用Win下的选择习惯
;;用shift+方向键进行选择
(pc-selection-mode)
(set-variable 'jit-lock-stealth-time 0)
(setq user-full-name "Your name")
(setq user-mail-address "your address")
;; C-k 删除整行包括回车
;;(setq-default kill-whole-line t)
(blink-cursor-mode -1)
;; 存盘的时候,要求最后一个字符时换行符。
(setq require-final-newline t)
;; 当光标在行尾上下移动的时候,始终保持在行尾。
(setq track-eol t)
;; 当浏览 man page 时,直接跳转到 man buffer。
(setq Man-notify-method 'pushy)
;; 当使用 M-x COMMAND 后,过 1 秒钟显示该 COMMAND 绑定的键
(setq suggest-key-bindings 1)
;; M-x apropos 时多查询些结果,但需要更多的 CPU。
(setq apropos-do-all nil)
;; 设置时间戳,标识出最后一次保存文件的时间。
(setq time-stamp-active t)
(setq time-stamp-warn-inactive t)
(setq time-stamp-format "%:y-%02m-%02d %3a %02H:%02M:%02S godot")
;;把这些缺省禁用的功能打开。
(put 'set-goal-column 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'LaTeX-hide-environment 'disabled nil)
;;Shell 使用 ansi color
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
;; 刷新功能,重新打开当前文件,用于文件在外部被修改了的情况
(global-set-key (kbd "") 'kid-reopen-file)
(defun kid-reopen-file ()
"reopen current buffer"
(interactive)
(if (null (buffer-file-name (current-buffer)))
(message "buffer not attached to a file.")
(let ((file-name (buffer-file-name (current-buffer)))
(current-point (point)))
(kill-buffer (current-buffer))
(find-file file-name)
(if (") 'smart-compile)
(global-set-key [f8] 'compile)
(global-set-key [f12] 'gdb)
(global-set-key [f9] 'next-error)
(global-set-key [(s f11)] 'cscope-set-initial-directory)
(global-set-key [(s f12)] 'cscope-index-files)
(global-set-key [(shift f3)] 'list-bookmarks)
(global-set-key [(shift f2)] 'calendar)
(global-set-key [(s r)]'point-to-register)
(global-set-key [(s j)]'jump-to-register)
(global-set-key [(s g)]'define-global-abbrev)
(global-set-key [(s m)]'define-mode-abbrev )
(global-set-key (kbd "s-p") 'plan)
(global-set-key (kbd "C-x k") 'kill-this-buffer)
(global-set-key (kbd "C-x t")'insert-now-time)
;;---------------------------------------calendar settings-------------------------------------
;; diary
(setq diary-file "~/emacs/diary")
(setq diary-mail-addr "your email address")
(add-hook 'diary-hook 'appt-make-list)
;; Emacs TODO
(setq todo-file-do "~/emacs/todo-do")
(setq todo-file-done "~/emacs/todo-done")
(setq todo-file-top "~/emacs/todo-top")
;;(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 显示节日
;;------------------------------------------dired文件浏览----------------------------------------
(setq dired-recursive-deletes t) ; 可以递归的删除目录
(setq dired-recursive-copies t) ; 可以递归的进行拷贝
(require 'dired-x) ; 有些特殊的功能
(setq dired-guess-shell-alist-user
(list
(list "\\.chm$" "xchm")
(list "\\.pdf$" "acroread")
(list "\\.rm$" "totem")
(list "\\.rmvb$" "totem")
(list "\\.avi$" "totem")
(list "\\.asf$" "totem")
(list "\\.wmv$" "totem")
(list "\\.htm$" "w3m")
(list "\\.html$" "w3m")
(list "\\.mpg$" "totem")
(list "\\.agr$" "xmgrace")
(list "\\.dat$" "xmgrace")))
; 设置一些文件的默认打开方式,此功能必须在(require 'dired-x)之后
(add-hook 'dired-load-hook
(lambda ()
(load "dired-x")
;; Set dired-x global variables here. For example:
;; (setq dired-guess-shell-gnutar "gtar")
;; (setq dired-x-hands-off-my-keys nil)
(setq dired-omit-files
(concat dired-omit-files "\\|^\\..+$"))
))
(add-hook 'dired-mode-hook
(lambda ()
;; Set dired-x buffer-local variables here. For example:
(setq dired-omit-files-p t)
; (setq dired-omit-files
; (concat dired-omit-files "\\|^emacs$\\|,v$"))
))
;;---------------------------------------c和cpp环境设定------------------------------------------
(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 8)
;; 在菜单中加入当前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 8)
(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 "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 "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)))))
;;----------------------------------------extentions-------------------------------------------
(setq load-path (append load-path (list "~/emacs/extension/")))
;;color-theme
;; 如果是在图形界面下就加载颜色主题库
(if window-system
(progn
(require 'color-theme)
;;(color-theme-robin-hood) ;; 使用robin hood这款配色方案,我很喜欢的一款方案
;;(color-theme-deep-blue)
(color-theme-dark-blue2)
;;(color-theme-gnome2)
;; (color-theme-gnome)
;; (color-theme-subtle-hacker)
;;(color-theme-sitaramv-nt)
))
;;;;speedbar
;;(add-to-list 'load-path "e:/emacs/site-lisp/cedet-1.0beta3b/speedbar")
(autoload 'speedbar-frame-mode "speedbar" "Popup a speedbar frame" t)
(autoload 'speedbar-get-focus "speedbar" "Jump to speedbar frame" t)
(global-set-key [(f4)] 'speedbar-get-focus)
;;menu
;;(define-key-after (lookup-key global-map [menu-bar tools])
;;[speedbar] '("Speedbar" . speedbar-frame-mode) [calendar])
;;(setq speedbar-update-speed 3)
;;(setq speedbar-use-images nil) ;; clean face, :)
;;让Emacs拥有tabs
;;http://learn.tsinghua.edu.cn/homepage/2001315450/emacs_elisp.html
;;到上面的网页下载tabbar.el 保存到/usr/share/emacs/site-lisp/
(require 'tabbar)
(tabbar-mode)
(define-prefix-command 'lwindow-map)
;;(global-set-key (kbd "") 'lwindow-map)
;;这儿的设定王垠的主页显示有问题,
(global-set-key (kbd "") 'tabbar-backward-group)
(global-set-key (kbd "") 'tabbar-forward-group)
(global-set-key (kbd "") 'tabbar-backward)
(global-set-key (kbd "") 'tabbar-forward)
;;使用Win+方向键在tabbed buffer之间切换
;;加载了 session 之后菜单上会多两项:最近访问过的文件和最近修改过的文件 /usr/share/emacs/site-lisp/session.el
(require 'session)
(add-hook 'after-init-hook 'session-initialize)
;;保存上次打开的文件记录
(load "desktop")
(desktop-load-default)
(desktop-read)
;;如果session跟desktop配合,下次启动Emacs 的时候,就像根本没有关闭 Emacs 一样
;;把这几行加入 .emacs 就可以把 C-x C-b 那个普通的 buffer menu 换成非常方便的 ibuffer 啦
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
;;最方便的切换buffer,寻找文件的扩展
(require 'ido)
(ido-mode t)
;;使用这个,你就可以方便的在最近编辑的 buffer 之间切换了。切换的时候会出现一个小窗口显示附近的buffer,就像翻页一样
(require 'swbuff)
(global-set-key (kbd "s-") 'swbuff-switch-to-previous-buffer)
(global-set-key (kbd "s-") 'swbuff-switch-to-next-buffer)
(setq swbuff-exclude-buffer-regexps
'("^ " "\*.*\*"))
(setq swbuff-status-window-layout 'scroll)
(setq swbuff-clear-delay 2)
(setq swbuff-separator "|")
(setq swbuff-window-min-text-height 1)
;;ecb
;;(add-to-list 'load-path "/usr/share/emacs/site-lisp/ecb")
;;(require 'ecb)
;;browse-kill-ring.el
;; C-c k: kill-ring 里的内容都可以方便的浏览,粘贴。具体操作请在这个 buffer 里 C-h m 或者 ?.
(require 'browse-kill-ring)
(global-set-key [(control c)(k)] 'browse-kill-ring)
(browse-kill-ring-default-keybindings)
;;table.el
;;非常酷的一个扩展。可以“所见即所得”的编辑一个文本模式的表格。就跟很多字处理程序那样操作,可以识别文本文件里本来就存在的表格,而且可以把表格输出为 HTML 和 TeX。看看我的抓图吧。
(autoload 'table-insert "table" "WYGIWYS table editor")
;;recentf.el
;;这个扩展可以帮你保存一个“最近打开的文件”列表。在 .emacs 文件里加入:
;; (require 'recentf)
;; (recentf-mode 1)
;;这个是 Emacs 自带的功能,可是知道它的人不多。很多人用的是M-/ (dabbrev-expand) 这样的东西。 hippie-expand 要强大的多。因为它可以使用扩展函数任意扩充!你可以把你的 M-/ 绑定到 hippie-expand,马上就可以体会到它的方便。
;;你可以设置以下 hippie-expand 的补全方式。它是一个优先列表, 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))
;;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 [(control ?\.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] '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)
;; to automatically turn on line numbering when enterting text-mode.
;;(add-hook 'text-mode-hook 'turn-on-setnu-mode)
;;hide-region.el hide-lines.el
;;这两个函数可以分别把一个区域和匹配某个regexp的行都藏起来,就跟不存在一样……这样你就可以对某些内容进行任意的操作而不会影响到其它的部分。
;;hide-lines 在操作某些行的时候用起来特别方便。加一个前缀参数可以把不匹配的行都藏起来,只看到匹配的!看看我只显示这个文件里含有global-set-key 的行:
;;hide region
(require 'hide-region)
(global-set-key (kbd "C-c r") 'hide-region-hide)
(global-set-key (kbd "C-c R") 'hide-region-unhide)
;; hide lines
(require 'hide-lines)
(global-set-key (kbd "C-c l") 'hide-lines)
(global-set-key (kbd "C-c L") 'show-all-invisible)
(global-set-key (kbd "C-c o") 'hide-non-matching-lines)
;;ctypes.el
;;ctypes 可以识别你的 C 文件里的类型定义 (typedef)。自动对它们进行语法加亮。
(require 'ctypes)
(ctypes-auto-parse-mode 1)
;;mmm
;;你想过一个 buffer 里同时存在很多个 major mode 吗?现在用 MMM 就可以办到了。在不同的区域拥有对应键绑定,变量,缩进 ……
;;HTML, Emacs Lisp, Perl, C 和 LaTeX 全都都在同一个 buffer 里被正确的语法加亮了!而且TAB在不同的区域都可以进行正确缩进。在 LaTeX 的区域还可以使用 AUC TeX 来处理某个部分。
(autoload 'mmm-mode "mmm-mode" "Multiple Major Modes" t)
(autoload 'mmm-parse-buffer "mmm-mode" "Automatic MMM-ification" t)
;;tramp
(setq tramp-default-method "scp")
(setq tramp-auto-save-directory "/tmp")
(setq auto-save-file-name-transforms
'(("\\`/[^/]*:\\(.+/\\)*\\(.*\\)" "/tmp/\\2")))
(setq tramp-chunksize 328)
(require 'ange-ftp)
(require 'tramp)
;;----------------------------------------extentions ends---------------------------------------
;;(plan)
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(auto-compression-mode t nil (jka-compr))
'(case-fold-search t)
'(current-language-environment "Chinese-GBK")
'(default-input-method "chinese-py")
'(global-font-lock-mode t nil (font-lock))
'(show-paren-mode t nil (paren))
'(tex-alt-dvi-print-command "dvips")
'(tex-dvi-print-command "dvipdf")
'(tex-dvi-view-command "xdvi")
;; '(tex-dvi-view-command "evince")
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
'(transient-mark-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)
(ispell-change-dictionary "american")
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22301/showart_147109.html |
|