免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5426 | 回复: 11
打印 上一主题 下一主题

[C++] 借C++版块为下关于emacs的事情 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-25 17:55 |只看该作者 |倒序浏览
在咱们C++版块混的时间也不短了,一直没有发过贴子,今天发个,不过就关于emacs的,前几天一时冲动想从vim转到emacs,可以发现emacs的用户太少了,在我的几个QQ群了问了都不会用,想请教也不行,郁闷,在网上拼凑了一个.emacs文件,现在贴出来希望大家看看哪里不妥的地方指出来,或者分享下您的emacs配置也行(主要是针对程序员的使用方便),先谢谢大家了。。。
//.emacs

  1. ;;;;自动保存关闭前的环境变量
  2. (require 'session)
  3.   (add-hook 'after-init-hook 'session-initialize)
  4. ;;;;打开上次的文件
  5. (load "desktop")
  6. (desktop-load-default)
  7. (desktop-read)
  8. ;;;;buffer选项
  9. (require 'ibuffer)
  10. (global-set-key (kbd "C-x C-b") 'ibuffer)
  11. ;;;;方便在kill-ring里寻找需要的东西
  12. (require 'browse-kill-ring)
  13. (global-set-key [(control c)(k)] 'browse-kill-ring)
  14. (browse-kill-ring-default-keybindings)
  15. ;;;;切换buffer
  16. (require 'ido)
  17. (ido-mode t)
  18. ;;;;最近buffer切换
  19. (require 'swbuff)
  20. (global-set-key (kbd "") 'swbuff-switch-to-previous-buffer)
  21. (global-set-key (kbd "") 'swbuff-switch-to-next-buffer)
  22. (setq swbuff-exclude-buffer-regexps
  23.      '("^ " "\\*.*\\*"))

  24. (setq swbuff-status-window-layout 'scroll)
  25. (setq swbuff-clear-delay 1)
  26. (setq swbuff-separator "|")
  27. (setq swbuff-window-min-text-height 1)
  28. ;;;;标签
  29. (require 'tabbar)
  30. (tabbar-mode)
  31. (global-set-key (kbd "") 'tabbar-backward-group)
  32. (global-set-key (kbd "") 'tabbar-forward-group)
  33. (global-set-key (kbd "") 'tabbar-backward)
  34. (global-set-key (kbd "") 'tabbar-forward)

  35. (setq tabbar-buffer-groups-function 'tabbar-buffer-ignore-groups)

  36. (defun tabbar-buffer-ignore-groups (buffer)
  37.   "Return the list of group names BUFFER belongs to.
  38. Return only one group for each buffer."
  39.   (with-current-buffer (get-buffer buffer)
  40.     (cond
  41.      ((or (get-buffer-process (current-buffer))
  42.           (memq major-mode
  43.                 '(comint-mode compilation-mode)))
  44.       '("Process")
  45.       )
  46.      ((member (buffer-name)
  47.               '("*scratch*" "*Messages*"))
  48.       '("Common")
  49. )
  50.      ((eq major-mode 'dired-mode)
  51.       '("Dired")
  52.       )
  53.      ((memq major-mode
  54.             '(help-mode apropos-mode Info-mode Man-mode))
  55.       '("Help")
  56.       )
  57.      ((memq major-mode
  58.             '(rmail-mode
  59.               rmail-edit-mode vm-summary-mode vm-mode mail-mode
  60.               mh-letter-mode mh-show-mode mh-folder-mode
  61.               gnus-summary-mode message-mode gnus-group-mode
  62.               gnus-article-mode score-mode gnus-browse-killed-mode))
  63.       '("Mail")
  64.       )
  65.      (t
  66.       (list
  67.        "default"  ;; no-grouping
  68.        (if (and (stringp mode-name) (string-match "[^ ]" mode-name))
  69.            mode-name
  70.          (symbol-name major-mode)))
  71.       )
  72.      
  73.      )))

  74. ;;;;插入表格
  75. (autoload 'table-insert "table" "WYGIWYS table editor")
  76. ;;;;保存最近打开的文件的列表
  77. (require 'recentf)
  78. (recentf-mode 1)

  79. (defun recentf-open-files-compl ()
  80.   (interactive)
  81.   (let* ((all-files recentf-list)
  82.          (tocpl (mapcar (function
  83.                          (lambda (x) (cons (file-name-nondirectory x) x))) all-files))
  84.          (prompt (append '("File name: ") tocpl))
  85.          (fname (completing-read (car prompt) (cdr prompt) nil nil)))
  86.     (find-file (cdr (assoc-ignore-representation fname tocpl)))))

  87. (global-set-key [(control x)(control r)] 'recentf-open-files-compl)
  88. ;;;;自动补全
  89. (global-set-key [(meta ?/)] 'hippie-expand)

  90. (setq hippie-expand-try-functions-list
  91.      '(try-expand-dabbrev
  92.         try-expand-dabbrev-visible
  93.         try-expand-dabbrev-all-buffers
  94.         try-expand-dabbrev-from-kill
  95.         try-complete-file-name-partially
  96.         try-complete-file-name
  97.         try-expand-all-abbrevs
  98.         try-expand-list
  99.         try-expand-line
  100.         try-complete-lisp-symbol-partially
  101.         try-complete-lisp-symbol))
  102. ;;;;括号匹配
  103. (global-set-key "%" 'match-paren)
  104.          
  105. (defun match-paren (arg)
  106.   "Go to the matching paren if on a paren; otherwise insert %."
  107.   (interactive "p")
  108.   (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
  109.         ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
  110.         (t (self-insert-command (or arg 1)))))
  111. ;;;;临时标记
  112. (global-set-key [(control ?\.)] 'ska-point-to-register)
  113. (global-set-key [(control ?\,)] 'ska-jump-to-register)
  114. (defun ska-point-to-register()
  115.   "Store cursorposition _fast_ in a register.
  116. Use ska-jump-to-register to jump back to the stored
  117. position."
  118.   (interactive)
  119.   (setq zmacs-region-stays t)
  120.   (point-to-register 8))

  121. (defun ska-jump-to-register()
  122.   "Switches between current cursorposition and position
  123. that was stored with ska-point-to-register."
  124.   (interactive)
  125.   (setq zmacs-region-stays t)
  126.   (let ((tmp (point-marker)))
  127.         (jump-to-register 8)
  128.         (set-register 8 tmp)))
  129. ;;;;C+c+a+字符,移动到下一个字符
  130. (defun wy-go-to-char (n char)
  131.   "Move forward to Nth occurence of CHAR.
  132. Typing `wy-go-to-char-key' again will move forwad to the next Nth
  133. occurence of CHAR."
  134.   (interactive "p\ncGo to char: ")
  135.   (search-forward (string char) nil nil n)
  136.   (while (char-equal (read-char)
  137.                      char)
  138.     (search-forward (string char) nil nil n))
  139.   (setq unread-command-events (list last-input-event)))

  140. (define-key global-map (kbd "C-c a") 'wy-go-to-char)
  141. ;;;;隐藏行
  142. ;;hide region
  143. (require 'hide-region)
  144. (global-set-key (kbd "C-c r") 'hide-region-hide)
  145. (global-set-key (kbd "C-c R") 'hide-region-unhide)


  146. ;; hide lines
  147. (require 'hide-lines)
  148. (global-set-key (kbd "C-c l") 'hide-lines)
  149. (global-set-key (kbd "C-c L") 'show-all-invisible)
  150. ;;;;代码折叠
  151. (load-library  "folding")
  152. (declare (special fold-fold-on-startup
  153.                   fold-keys-already-setup
  154.                   ))
  155.    
  156. (setq fold-fold-on-startup t)
  157. (folding-mode-add-find-file-hook)

  158. (setq fold-keys-already-setup nil)
  159. (add-hook 'folding-mode-hook
  160.           (function (lambda()
  161.                       (unless fold-keys-already-setup
  162.                         (setq fold-keys-already-setup t)
  163.                         (define-prefix-command 'ctl-f-folding-mode-prefix)
  164.                         (define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
  165.                         (define-key  'ctl-f-folding-mode-prefix "e" 'fold-enter)
  166.                         (define-key 'ctl-f-folding-mode-prefix "x" 'fold-exit)
  167.                         (define-key  'ctl-f-folding-mode-prefix "b" 'fold-whole-buffer)
  168.                         (define-key 'ctl-f-folding-mode-prefix "o" 'fold-open-buffer)
  169.                         (define-key 'ctl-f-folding-mode-prefix "h" 'fold-hide)
  170.                         (define-key 'ctl-f-folding-mode-prefix "s" 'fold-show)
  171.                         (define-key 'ctl-f-folding-mode-prefix "t" 'fold-top-level)
  172.                         (define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
  173.                         )
  174.                       (local-set-key "\C-f" 'ctl-f-folding-mode-prefix))))

  175. (fold-add-to-marks-list 'sgml-mode
  176.                         "<!-- {"
  177.                         "<!-- } -->" " --> ")
  178. (fold-add-to-marks-list 'c-mode "/* <" "/* > */" "*/")
  179. (fold-add-to-marks-list 'c++-mode
  180.                         "//<" "//>" "")
  181. (fold-add-to-marks-list 'LaTeX-mode "%%% {{{" "%%% }}}" " ")
  182. (fold-add-to-marks-list 'latex2e-mode "%%% {{{" "%%% }}}" " ")
  183. (fold-add-to-marks-list 'latex-mode "%%%% {{{" "%%%% }}}" " ")
  184. (fold-add-to-marks-list 'BibTeX-mode "%%% {{{" "%%% }}}" " ")
  185. (fold-add-to-marks-list 'lisp-mode ";;; {" ";;; }" "")
  186. (fold-add-to-marks-list 'lex-mode" /* {{{ " " /* }}} */ " "*/")
  187. (fold-add-to-marks-list 'html-mode "<!-- { " "<!-- } -->" "-->")
  188. (fold-add-to-marks-list 'shell-script-mode "# {{{" "# }}}" nil)
  189. (fold-add-to-marks-list 'sh-mode "# {{{ " "# }}}" nil)
  190. ;;;;主题
  191. (require 'color-theme)
  192. ;;;;模式自动选择
  193. (autoload 'mmm-mode "mmm-mode" "Multiple Major Modes" t)
  194. (autoload 'mmm-parse-buffer "mmm-mode" "Automatic MMM-ification" t)
  195. ;;;;typedef 自定义命名高亮
  196. (require 'ctypes)
  197. (ctypes-auto-parse-mode 1)
  198. ;;;;文泉驿字体
  199. (set-fontset-font "fontset-default" 'gb18030 '("文泉驿正黑" . "unicode-bmp"))
  200. ;;;; 显示行号:
  201. (add-to-list 'load-path "/usr/share/emacs/site-lisp")
  202. (require 'linum)
  203. (global-linum-mode t)


  204. ;;;;杂项
  205. (setq mouse-yank-at-point t);支持中键粘贴
  206. (show-paren-mode t);显示匹配括号
  207. (setq show-paren-style 'parentheses)
  208. (set-scroll-bar-mode 'right);滚动条在右侧

  209. ;;滚动页面时比较舒服,不要整页的滚动
  210. (setq scroll-step 1
  211. scroll-margin 3
  212. scroll-conservatively 10000)
  213. ;;;;快捷键
  214. (global-set-key [f5] 'eshell)
  215. (global-set-key [f7] 'compile)
  216. (global-set-key (kbd "C-z") 'undo);撤消
  217. ;;设置缩进长度
  218. (define-key c-mode-map [return] 'newline-and-indent)
  219. (setq c-basic-offset 4)
复制代码

论坛徽章:
0
2 [报告]
发表于 2010-05-25 18:33 |只看该作者
看到那么多圆括号头都大了,呼叫LISP强人出手。

论坛徽章:
0
3 [报告]
发表于 2010-05-26 08:48 |只看该作者
为什么要从vim-》emacs?

论坛徽章:
0
4 [报告]
发表于 2010-05-26 11:43 |只看该作者
回复 3# rain_fish


    无语,找不到用emacs的,我还是老老实实用我的vim吧,想转emacs的原因是感觉写的程序文件一多用vim开的太多,照顾不过来了

论坛徽章:
0
5 [报告]
发表于 2010-05-26 11:46 |只看该作者
用vim的插件啊,NERD_tree

论坛徽章:
0
6 [报告]
发表于 2010-05-26 13:02 |只看该作者
回复 4# wzlxx_


    不想vim多窗口可以用 :tabnew 开tab标签。

论坛徽章:
0
7 [报告]
发表于 2010-05-26 14:23 |只看该作者
emacs 就是gdb 时方便。

论坛徽章:
0
8 [报告]
发表于 2010-05-26 14:47 |只看该作者
回复 6# 没本


   多谢没本 ,我也没本,以后有钱了一起买哈

论坛徽章:
0
9 [报告]
发表于 2010-05-26 14:48 |只看该作者
回复 7# p4apple


    嗯,不转了,还是vim吧,按照没本说的再加上代码折叠效果还不错

论坛徽章:
0
10 [报告]
发表于 2010-05-26 16:00 |只看该作者
vim 有象emacs autocomplete那种自动提示么??
比如 有个变量 fifoConditionImpl 当你开始输入fxxx开始就自动的提示所有fxx打头的变量名称,
包括fifoConditionImpl
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP