Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1259672
  • 博文数量: 264
  • 博客积分: 10772
  • 博客等级: 上将
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-25 11:54
文章分类

全部博文(264)

文章存档

2012年(4)

2011年(51)

2010年(31)

2009年(57)

2008年(51)

2007年(70)

分类: LINUX

2007-11-29 00:58:05

source insight是windows环境下用于代码开发和阅读的利器,功能强大,对于大规模代码的维护和开发几乎不可或缺(这里
指它提供的功能,类似的商业工具还有很多)。使用emacs替代source insight原因有:a,si是商业软件,使用需要付费,虽然可以从网上
找到破解版本;b,对于unix/linux爱好者或者需要同时工作于unix和windows环境下的开发人员,emacs是通用工具;emacs其它的强大
功能暂且不表。
下面是基于windows xp平台的安装方法,其中大部分步骤和unix环境下的一样,只有cscope的有所不同。

1)准备工作
首先,你得下载一下一些工具(扩展),emacs,cscope,ecb,cedet是必须的,session,doxymacs不是必要的,但是装上会
更方便。下载这些东西的网址链接如下:(当然,下面这些东西都可以从google找到下载链接,下面提供的网址都是google出来的,如果
下面提供的链接不可用了,大家可以自己google一把)
i)emacs:
从gnu的ftp网站上下载windows版本,最新的版本是emacs-22.1。下面的设置都是在这个版本上进行的。

ii)cscope:cscope的主页,其中有一个download的链接,从那里可以下载到编译好的压缩包。
win32版本的下载地址:,压缩包中有两个编译好的exe文件:cscope.exe, sort.exe

iii)ecb:主页地址,download页面中还有一个Xemcas的安装程序setup.exe,可以试试,我没有使用这个。
sourceforg下载地址

iv)cedet:主页,下载release压缩包1.0pre4.tar.gz,这个包中已经包含了semantic,ede,eieio,
speedbar,因此下载了这个大包后不用分别下载这些扩展插件。

v)session:sf下载地址

vi)doxymacs:地址,
下载

vii)下载windows下的bash工具,主要是用到其中的find工具,用来手工生成cscope.files。如果安装了cygwin则不用安装这个了。
地址:

2)安装
安装emacs:这个很简单,只要将压缩包解开,放到你想放的位置就可以用了,如果要在windows的开始菜单中添加菜单项,点击bin目录下
的addpm运行,就会在菜单中加入gnu菜单项。

安装cscope:a,解压平台不相关的那个tar.gz包,将/contrib/xscope/xscope.el拷贝到emacs-22.1/site-lisp目录下(emacs-22.1是
你安装emacs的目录);b,解压win32版本的cscope,将cscope.ext sort.exe拷贝到emacs-22.1/bin目录下(这个路径不是必要的,因为
cscope在windows下要用起来还得费点劲,4)点会讲到)

安装ecb:解压,将解压后的ecb目录拷贝到site-lisp目录下。

安装cedet:解压,将解压后的cedet目录拷贝到site-lisp目录下。

安装session:解压,将解压后的session目录拷贝到site-lisp目录下。

安装doxymacs:解压,将解压后的doxymacs目录拷贝到site-lisp目录下。

安装win32bash:点击user.exe安装文件一步步点到最后就行了。
到此安装工作完成。

3)配置.emacs启动文件
显示指定扩展插件的加载地址(这一步好像不是必要的,只列出一个地址,其它类似)
(add-to-list 'load-path "e:/emacs/site-lisp/ecb-2.31"
加载相应插件:
(require 'xcscope) ;;加载xcscope
(require 'cedet) ;;加载cedet
(require 'ecb) ;;加载ecb
(require 'session) ;;加载session
(add-hook 'after-init-hook 'session-initialize) ;; 启动时初始化session
(require 'doxymacs) ;; 启动doxymacs
在配置文件中加入这些语句后,保存重启emacs,重启后查看一下Message窗口中的加载信息,可以看到各个插件加载成功。
在.emacs中加入一些方便的设置就可以使用了,完整的配置文件附在后面。(这些配置都是从google上到处搜刮来的,其中王垠博士的
网页上有很多emacs设置的好东西可以参考,还有一些英文网站上贴出的配置文件中也有很多好东西,大家可以根据自己的习惯写自己的
配置)

4)问题及解决
安装进行到这里,大部分功能都没有问题了,存在的问题有:
i)cscope的创建文件列表和创建代码符号索引两个命令不可用,按下C-c s L和C-c s I后minibuffer中显示cscope-indexer找不到。在
cscope的安装包中确实有一个cscope-indexer的文件,我们安装时没有将它拷贝到emacs的安装路径中去,但是即使将它拷贝到bin目录下
也还是不能工作,用文本编辑器打开cscope-indexer会发现它其实是个shell脚本文件,从脚本中可以看到,它首先通过find,grep等工具
生成一个cscope.files的文件,然后调用cscope使用cscope.files作为输入生成cscope.out的索引文件。
因此,只要能生成一个文件列表的文件就可以使用win32版本的cscope.exe来生成cscope.out文件。到此,我们可以使用win32bash中的find
工具生成一个源代码文件列表了(与unix下一样:find /my-project-source -name "*.[chs]" -print > cscope.files,不知windows下
是否有类似find这样功能的命令,xp下的find好像不能用通配符,如果有这样的东西就可以不安装win32bash)。
生成了cscope.files源码文件列表后就可以使用它像si一样在代码间穿梭了:
C-c s a设定代码根目录,cscope.files必须放在这个设定目录下,否则cscope找不到;在第一次使用如下几条命令时cscope会自动生成
cscope.out,也可以在windows的cmd中调用cscope.exe -b -i cscope.files -f cscope.out生成cscope.out。
C-c s g查找函数(或变量)定义;
C-c s c查看调用者;
C-c s C查看函数中调用的子函数;

ii)semantic中设置的项目根目录好像不起作用,在进行tag查找时semantic只查了当前目录中的代码文件,如果引用的是其它目录中的函数
或变量,查找相应定义时就找不到。这个问题还不知道原因,可能是设置的问题,semantic的设置项太多了。遇到相同问题的朋友请解答一下。

到此,si中常用的几个动作实现了。

还有个si中类似功能的实现:跳到函数定义后如何在跳回刚才的调用函数的地方。
在王垠的网页中找到了一个实现
;;;临时记号
(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 )

(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
        (set-register 8 tmp)))
这样就可以在函数间跳来跳去,
结合cscope的pop-mark,就可以跳来跳去了,这样基本可以满足大多数情况下的使用。
还有一些有用扩展:

ecb,cedet(semantic)提供了很多功能,不过由于太多了,需要慢慢摸索,目前使用cscope已经基本上实现了si上的几个常用功能,
ecb + semantic可以实现像si中的函数/变量上下文显示功能,但是由于4)ii)中提到的问题,这个显示上下文功能有时候不起作用。
附:一个杂七杂八的配置文件
;;basic setting =============================================
(setq display-time-24hr-format t)
(display-time)
(column-number-mode t)
(transient-mark-mode t)
(tool-bar-mode -1)
(setq visible-bell t)
(setq inhibit-startup-message t)
(setq mouse-yank-at-point t)
(setq default-fill-column 60)

;(setq-default indent-tabs-mode nil)
;(setq default-tab-width
;(setq tab-stop-list ()
;     (loop for x downfrom 40 to 1 do
  ;          (setq tab-stop-list (cons (* x 4) tab-stop-list))))

(global-set-key [f3] 'repeat-complex-command)

(global-set-key [f4] 'other-window)
;; 跳转到 Emacs 的另一个buffer窗口
;; 可以从外面粘贴东西
(setq x-select-enable-clipboard t)
;; 屏蔽C-SPC的set mark功能 , 目前不必要,SCIM输入法不能用
(global-set-key (kbd "C-SPC" 'nil)
(global-set-key (kbd "M-" 'set-mark-command)
;;这样 我就不用按 C-@ 来 setmark 了, C-@ 很不好按。

(setq sentence-end "\\([。!?]\\|……\\|[.?!][]\"')}]*\\($\\|[ \t]\\)\\)[ \t\n]*"
(setq sentence-end-double-space nil)

(setq enable-recursive-minibuffers t)

(setq scroll-margin 3
      scroll-conservatively 10000)
(setq default-major-mode 'text-mode)

(show-paren-mode t)
(setq show-paren-style 'parentheses)

(mouse-avoidance-mode 'animate)
(setq frame-title-format "emacs@%b"

(auto-image-file-mode)

;;shadow password
(add-hook 'comint-output-filter-functions
            'comint-watch-for-password-prompt)

;; global font lock
(global-font-lock-mode 1)

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

;;version control
(setq version-control t)
(setq kept-new-versions 3)
(setq delete-old-versions t)
(setq kept-old-versions 2)
(setq dired-kept-versions 1)

(mapcar
(function (lambda (setting)
             (setq auto-mode-alist
                   (cons setting auto-mode-alist))))
'(("\\.xml$".  sgml-mode)
   ("\\\.bash" . sh-mode)
   ("\\.rdf$".  sgml-mode)
   ("\\.session" . emacs-lisp-mode)
   ("\\.l$" . c-mode)
   ("\\.css$" . css-mode)
   ("\\.cfm$" . html-mode)
   ("gnus" . emacs-lisp-mode)
   ("\\.idl$" . idl-mode)))

(setq dired-recursive-copies 'top)
(setq dired-recursive-deletes 'top)

;; frame customize
;(setq default-frame-alist
;     '((top . 200) (left . 400)
;        (width . 160) (height . 70)
;        (cursor-color . "green"
;        (cursor-type . box)
;        (foreground-color . "grey"
;        (background-color . "black"))
        ;(font . "-*-Courier-namorl-r-*-*-13-*-*-*-c-*-iso8859-1"))
;(setq initial-frame-alist '((top . 30) (left . 10)))

;(condition-case err
;    (progn
;      (require 'xxx))
;  (error
;   (message "Can't load xxx-mode %s" (cdr err))))

; chinese environment
(set-terminal-coding-system 'chinese-iso-8bit)
(set-keyboard-coding-system 'chinese-iso-8bit)
(setq locale-coding-system 'chinese-iso-8bit)

;;display number
(require 'setnu)
(global-set-key [f11] 'setnu-mode)
(setq-default kill-whole-line t);;删除整行时,顺便把产生的空格行也删除掉。
;(w32-send-sys-command #xf030);;窗口最大化

(setq track-eol t)
;; 当光标在行尾上下移动的时候,始终保持在行尾。
;;保存文件时在最后使用换行
(setq require-final-newline t)
(setq suggest-key-bindings 1)
;;;;设置移动窗口命令
  ;(global-set-key [M-down] 'windmove-down)
;  (global-set-key [M-up]   'windmove-up)
; (global-set-key [M-right] 'windmove-right)
  ;(global-set-key [M-left] 'windmove-left)

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

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

(require 'ido)
(ido-mode t)
;;ido绑定键
;;{{{ ido: fast switch buffers
(add-hook 'ido-define-mode-map-hook 'ido-my-keys)
(defun ido-my-keys ()
  "Set up the keymap for `ido'."
  ;; common keys
  (define-key ido-mode-map "\C-e" 'ido-edit-input)  
  (define-key ido-mode-map "\t" 'ido-complete) ;; complete partial
  (define-key ido-mode-map "\C-j" 'ido-select-text)
  (define-key ido-mode-map "\C-m" 'ido-exit-minibuffer)
  (define-key ido-mode-map "?" 'ido-completion-help) ;; list completions
  (define-key ido-mode-map [(control ? )] 'ido-restrict-to-matches)
  (define-key ido-mode-map [(control ?@)] 'ido-restrict-to-matches)

  ;; cycle through matches
  (define-key ido-mode-map "\C-r" 'ido-prev-match)
  (define-key ido-mode-map "\C-s" 'ido-next-match)
  (define-key ido-mode-map [right] 'ido-next-match)
  (define-key ido-mode-map [left] 'ido-prev-match)

  ;; toggles
  (define-key ido-mode-map "\C-t" 'ido-toggle-regexp) ;; same as in isearch
  (define-key ido-mode-map "\C-p" 'ido-toggle-prefix)
  (define-key ido-mode-map "\C-c" 'ido-toggle-case)
  (define-key ido-mode-map "\C-a" 'ido-toggle-ignore)

  ;; keys used in file and dir environment
  (when (memq ido-cur-item '(file dir))
    (define-key ido-mode-map "\C-b" 'ido-enter-switch-buffer)
    (define-key ido-mode-map "\C-d" 'ido-enter-dired)
    (define-key ido-mode-map "\C-f" 'ido-fallback-command)

    ;; cycle among directories
    ;; use [left] and [right] for matching files
    (define-key ido-mode-map [down] 'ido-next-match-dir)
    (define-key ido-mode-map [up]   'ido-prev-match-dir)

    ;; backspace functions
    (define-key ido-mode-map [backspace] 'ido-delete-backward-updir)
    (define-key ido-mode-map "\d"        'ido-delete-backward-updir)
    (define-key ido-mode-map [(meta backspace)] 'ido-delete-backward-word-updir)
    (define-key ido-mode-map [(control backspace)] 'ido-up-directory)

    ;; I can't understand this
    (define-key ido-mode-map [(meta ?d)] 'ido-wide-find-dir)
    (define-key ido-mode-map [(meta ?f)] 'ido-wide-find-file)
    (define-key ido-mode-map [(meta ?k)] 'ido-forget-work-directory)
    (define-key ido-mode-map [(meta ?m)] 'ido-make-directory)

    (define-key ido-mode-map [(meta down)] 'ido-next-work-directory)
    (define-key ido-mode-map [(meta up)] 'ido-prev-work-directory)
    (define-key ido-mode-map [(meta left)] 'ido-prev-work-file)
    (define-key ido-mode-map [(meta right)] 'ido-next-work-file)

    ;; search in the directories
    ;; use C-_ to undo this
    (define-key ido-mode-map [(meta ?s)] 'ido-merge-work-directories)
    (define-key ido-mode-map [(control ?_)] 'ido-undo-merge-work-directory)
    )

  (when (eq ido-cur-item 'file)
    (define-key ido-mode-map "\C-k" 'ido-delete-file-at-head)
    (define-key ido-mode-map "\C-l" 'ido-toggle-literal)
    (define-key ido-mode-map "\C-o" 'ido-copy-current-word)
    (define-key ido-mode-map "\C-v" 'ido-toggle-vc)
    (define-key ido-mode-map "\C-w" 'ido-copy-current-file-name)
    )

  (when (eq ido-cur-item 'buffer)
    (define-key ido-mode-map "\C-b" 'ido-fallback-command)
    (define-key ido-mode-map "\C-f" 'ido-enter-find-file)
    (define-key ido-mode-map "\C-k" 'ido-kill-buffer-at-head)
    ))

;;(ido-mode t)
;;}}}

;;使用这个,你就可以方便的在最近编辑的 buffer 之间切换了。切换的时候会出现一个小窗口显示附近的buffer,就像翻页一样.
;;默认的键是 C-f6 为 swbuff-switch-to-next-buffer。 C-S-F6为 swbuff-switch-to-previous-buffer
(require 'swbuff)
(global-set-key (kbd "" 'swbuff-switch-to-previous-buffer)
(global-set-key (kbd "") 'swbuff-switch-to-next-buffer)
(setq swbuff-exclude-buffer-regexps
     '("^ " "\\*.*\\*"))

(setq swbuff-status-window-layout 'scroll)
(setq swbuff-clear-delay 1)
(setq swbuff-separator "|")
(setq swbuff-window-min-text-height 1)

(require 'tabbar)
(tabbar-mode)
(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)
;;;表格
(autoload 'table-insert "table" "WYGIWYS table editor")
;;;将语法加量文件输出为彩色HTML文件
;;(load "htmlize")

;;;将emacs做为图片浏览器
(load "thumbs")
;;;设置c-o,这样在一行中的任何位置就可以直接新建一行了。相当于先c-e再enter
(global-set-key (kbd "C-o")
            '(lambda ()
               (interactive)
               (end-of-line 1)
               (newline-and-indent)))

(load "color-theme")
(color-theme-dark-blue2)

;;programming setting =================================================================
(require 'xcscope) ;;加载xcscope
(require 'cedet) ;;加载cedet
(require 'ecb) ;;加载ecb
(require 'session) ;;加载session
(add-hook 'after-init-hook 'session-initialize) ;; 启动时初始化session
(require 'doxymacs) ;; 启动doxymacs
(add-hook 'c-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode
(add-hook 'c++-mode-common-hook 'doxymacs-mode) ;; 启动doxymacs-mode
(desktop-load-default) ;;读取默认desktop设置
(desktop-read) ;;读取当前目录保存的desktop设置
;(set-face-background 'default "LightCyan3") ;;设置背景色为 浅青色3
;(set-face-font 'default "-outline-新宋体-normal-r-normal-normal-*-*-96-96-c-*-iso8859-1") ;;设置字体为新宋体 ( Only for windows )
;(global-set-key [f12] 'ecb-activate) ;;定义F12键为激活ecb
(global-set-key [C-f12] 'ecb-deactivate) ;;定义Ctrl+F12为停止ecb
(global-set-key [C-f11] 'delete-other-windows) ;;设置F11为删除其它窗口
(global-set-key [(meta return)] 'semantic-ia-complete-symbol-menu) ;;设置Alt+Enter为自动补全菜单
(global-set-key [(control ?\;)] 'ecb-goto-window-edit-last) ;;切换到编辑窗口
(global-set-key [(control ?\')] 'ecb-goto-window-methods) ;;切换到函数窗口
(global-set-key [(control ?\=)] 'cscope-find-global-definition-no-prompting) ;;搜索定义
(global-set-key [(control ?\/)] 'cscope-find-called-functions)
(global-set-key [(control ?\,)] 'cscope-pop-mark) ;; 跳出转向
(enable-visual-studio-bookmarks) ;; 启动VS书签子程序
(setq semanticdb-project-roots (list "g:/ob41")) ;; 设置cemanticdb的扫描根目录
(add-hook 'c-mode-common-hook ( lambda() ( c-set-style "k&r" ) ) ) ;;设置C语言默认格式
(add-hook 'c++-mode-common-hook ( lambda() ( c-set-style "k&r" ) ) ) ;;设置C++语言默认格式

;;;临时记号
(global-set-key [(control ?\.)] 'ska-point-to-register)
(global-set-key [(meta ?\,)] '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 )

(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
        (set-register 8 tmp)))

(setq speedbar-show-unknown-files t);;可以显示所有目录以及文件
(setq dframe-update-speed nil);;不自动刷新,手动 g 刷新
(setq speedbar-update-flag nil)
(setq speedbar-use-images nil);;不使用 image 的方式
(setq speedbar-verbosity-level 0)

(setq ecb-tip-of-the-day nil)
(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-auto-expand-tag-tree (quote all))
'(ecb-gzip-setup (quote cons))
'(ecb-layout-window-sizes (quote (("left8" (0.21844660194174756 . 0.288135593220339) (0.21844660194174756 . 0.23728813559322035) (0.21844660194174756 . 0.288135593220339) (0.21844660194174756 . 0.169491525423728))))
'(ecb-options-version "2.32")
'(ecb-tar-setup (quote cons))
'(ecb-type-tag-expansion (quote ((default . all-specifiers) (c-mode . all-specifiers))))
'(ecb-wget-setup (quote cons))
'(global-semantic-decoration-mode t nil (semantic-decorate-mode))
'(global-semantic-highlight-edits-mode t nil (semantic-util-modes))
'(global-semantic-idle-completions-mode t nil (semantic-idle))
'(global-semantic-show-parser-state-mode t nil (semantic-util-modes))
'(global-semantic-show-unmatched-syntax-mode t nil (semantic-util-modes))
'(global-semantic-stickyfunc-mode t nil (semantic-util-modes))
'(imenu-auto-rescan nil)
'(semantic-edits-verbose-flag t)
'(semantic-imenu-auto-rebuild-directory-indexes t)
'(semantic-imenu-index-directory t)
'(semantic-imenu-summary-function (quote semantic-format-tag-abbreviate))
'(semantic-which-function-use-color t)
'(semanticdb-default-save-directory "g:/ob41")
'(semanticdb-find-default-throttle (quote (file local project unloaded system recursive omniscience)))
'(semanticdb-project-roots (quote ("g:/ob41"))))
(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.
)

;(require 'recentf)
;(recentf-mode 1)

;(defun recentf-open-files-compl ()
;  (interactive)
;  (let* ((all-files recentf-list)
;         (tocpl (mapcar (function
;                         (lambda (x) (cons (file-name-nondirectory x) x))) all-files))
;         (prompt (append '("File name: ") tocpl))
;         (fname (completing-read (car prompt) (cdr prompt) nil nil)))
;    (find-file (cdr (assoc-ignore-representation fname tocpl)))))

;(global-set-key [(control x)(control r)] 'recentf-open-files-compl)

(setq semantic-load-turn-everything-on t)
;(add-hook 'semantic-init-hooks 'semantic-idle-completions-mode)

(autoload 'senator-try-expand-semantic "senator")

;设置 hippie-expand 的补全方式。它是一个优先列表, hippie-expand 会优先使用表最前面的函数来补全。
;;M-/ 绑定到 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))

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


;;有了这段代码之后,当你按 C-c a x (x 是任意一个字符) 时,光标就会到下一个 x 处。再次按 x,光标就到下一个 x。
(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)

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

(autoload 'mmm-mode "mmm-mode" "Multiple Major Modes" t)
(autoload 'mmm-parse-buffer "mmm-mode" "Automatic MMM-ification" t)

(require 'ctypes)
(ctypes-auto-parse-mode 1)

(load-library  "folding")
(declare (special fold-fold-on-startup
                  fold-keys-already-setup
                  ))
(setq fold-fold-on-startup t)
(folding-mode-add-find-file-hook)

(setq fold-keys-already-setup nil)
(add-hook 'folding-mode-hook
          (function (lambda()
                      (unless fold-keys-already-setup
                        (setq fold-keys-already-setup t)
                        (define-prefix-command 'ctl-f-folding-mode-prefix)
                        (define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
                        (define-key  'ctl-f-folding-mode-prefix "e" 'fold-enter)
                        (define-key 'ctl-f-folding-mode-prefix "x" 'fold-exit)
                        (define-key  'ctl-f-folding-mode-prefix "b" 'fold-whole-buffer)
                        (define-key 'ctl-f-folding-mode-prefix "o" 'fold-open-buffer)
                        (define-key 'ctl-f-folding-mode-prefix "h" 'fold-hide)
                        (define-key 'ctl-f-folding-mode-prefix "s" 'fold-show)
                        (define-key 'ctl-f-folding-mode-prefix "t" 'fold-top-level)
                        (define-key 'ctl-f-folding-mode-prefix "f" 'fold-fold-region)
                        )
                      (local-set-key "\C-f" 'ctl-f-folding-mode-prefix))))

(fold-add-to-marks-list 'sgml-mode
                        "" " --> ")
(fold-add-to-marks-list 'c-mode "/* <" "/* > */" "*/")
(fold-add-to-marks-list 'c++-mode
                        "//<" "//>" "")
(fold-add-to-marks-list 'LaTeX-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'latex2e-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'latex-mode "%%%% {{{" "%%%% }}}" " ")
(fold-add-to-marks-list 'BibTeX-mode "%%% {{{" "%%% }}}" " ")
(fold-add-to-marks-list 'lisp-mode ";;; {" ";;; }" "")
(fold-add-to-marks-list 'lex-mode" /* {{{ " " /* }}} */ " "*/")
(fold-add-to-marks-list 'html-mode "" "-->")
(fold-add-to-marks-list 'shell-script-mode "# {{{" "# }}}" nil)
(fold-add-to-marks-list 'sh-mode "# {{{ " "# }}}" nil)

(require 'emacs-wiki)

(add-hook 'emacs-wiki-mode-hook
          (lambda ()
            (define-key emacs-wiki-mode-map (kbd "C-c C-h") 'emacs-wiki-preview-html)
            (define-key emacs-wiki-mode-map (kbd "C-c C-c") 'emacs-wiki-preview-source)
            (define-key emacs-wiki-mode-map (kbd "C-c C-v") 'emacs-wiki-change-project)

))

;; (setq emacs-wiki-grep-command "glimpse -nyi \"%W\"")

(setq emacs-wiki-publishing-directory "publish")

(setq emacs-wiki-directories '("~/WiKi"))
(setq emacs-wiki-meta-charset "gb2312")
(setq emacs-wiki-style-sheet
      "")

(setq emacs-wiki-inline-relative-to 'emacs-wiki-publishing-directory)

(defun emacs-wiki-preview-source ()
  (interactive)
  (emacs-wiki-publish-this-page)
  (find-file (emacs-wiki-published-file)))

(defun emacs-wiki-preview-html ()
  (interactive)
  (emacs-wiki-publish-this-page)
  (browse-url (emacs-wiki-published-file)))

(setq emacs-wiki-projects
      `(("default" . ((emacs-wiki-directories . ("~/WiKi"))))
        ("work" . ((fill-column . 65)
                 (emacs-wiki-directories . ("~/workwiki/"))))))

(add-hook 'speedbar-timer-hook
          (lambda ()
            (speedbar-refresh)))
(setq speedbar-verbosity-level 0)
阅读(4457) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~