Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1170|回复: 0
打印 上一主题 下一主题

emacs24 配置c++ 开发环境

[复制链接]

165

主题

269

帖子

957

积分

认证用户组

Rank: 5Rank: 5

积分
957
跳转到指定楼层
楼主
发表于 2017-9-12 21:17:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
配置emacs包管理的源

; start package.el with emacs                                                                                                                                                                  
(require 'package)

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.milkbox.net/packages/")))
; initial package.el
(package-initialize)

安装auto-complete插件

在emacs中运行package-list-packages
选择

auto-complete
选择安装 i 然后执行安装 x
安装完之后配置.emacs 文件

; start auto-complete with emacs                                                                                                                                                               
(require 'auto-complete)
; default config                                                                                                                                                                              
(require 'auto-complete-config)
(ac-config-default)
安装yasnippet

在emacs中运行package-list-packages
选择

yasnippet
选择安装 i 然后执行安装 x
安装完之后配置.emacs 文件

; start yasnippet with emacs                                                                                                                                                                  
(require 'yasnippet)
(yas-global-mode 1)
安装auto-complete-c-headers

首先看看系统的head的搜索路径

gcc -xc++ -E -v -
本例中使用

/usr/lib/gcc/x86_64-linux-gnu/4.8/include
在emacs中运行package-list-packages
选择

auto-complete-c-headers   (可以搜索c/c++ header files)
选择安装 i 然后执行安装 x

安装完之后配置.emacs 文件

; define a function which initializes auto-complete-c-headers and gets called for c/c++ hooks                                                                                                  
(defun my:ac-c-header-init ()
  (require 'auto-complete-c-headers)
  (add-to-list 'ac-sources 'ac-source-c-headers)
  (add-to-list 'achead:include-directories '"/usr/lib/gcc/x86_64-linux-gnu/4.8/include")
)

; now let's call this function from c/c++ hooks                                                                                                                                                
(add-hook 'c++-mode-hook 'my:ac-c-header-init)
(add-hook 'c-mode-hook 'my:ac-c-header-init)

安装索引文件
能在 emacs 中使用的 cscope 叫做 xcscope,安装很简单:
apt-get install xcscope-el
安装完成后,只需要在 .emacs 文件中加入下面的配置:
(require 'xcscope)
;;(cscope-setup)

生成代码数据库
        通常,一个项目的代码都在一个文件夹(包括其子文件夹)下,在搜索代码中的某个变量或函数时,我们希望搜索的范围是该项目的所有代码。为此,首先在项目的最高层目录下执行下面的命令生成代码数据库:
$ cscope-indexer -r
其中的 -r 选项代表递归扫面各个子目录。该命令执行完后会在当前目录下生成 cscope-files 和 cscope.out 两个文件,其中包含着项目中的文件名、变量函数名等信息,供检索时使用。

工程的根目录运行
cscope-index -r
生成索引文件
快捷键都绑定在
Ctrl-c s-x
Ctrl-c s-u 返回

使用方法——快捷键
C-c s s         Find symbol.
C-c s d         Find global definition.
C-c s g         Find global definition (alternate binding).
C-c s G         Find global definition without prompting.
C-c s c         Find functions calling a function.
C-c s C         Find called functions.
C-c s t         Find text string.
C-c s e         Find egrep pattern.
C-c s f         Find a file.
C-c s i         Find files #including a file.
搜索出的结果会显示在一个叫做 cscope 的 buffer 中,包含文件名、行号和相应行的具体内容。当光标在某一条目上时回车可以直接跳转到相应位置。在列出的结果间可以通过 n 和 p 两个键跳转:
n         下一个 symbol。
p         上一个 symbol。
N         下一个文件。
P         上一个文件。


emacs增加行号

在配置.emacs文件中加上

(global-linum-mode t)

启动emacs后按
m-x global-linum-mode
就可以显示行号

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-3 17:58 , Processed in 0.053829 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表