Using Cscope as Semanticdb Backend

4 篇文章 0 订阅

CEDET 1.0终于在8月份的时候发布了,新的semanticdb实现竟然加入 了对cscope后端的支持,真是用完才觉得爽。使用auto-complete前端 加上cscope解析如图:

cscope+auto-complete
cscope+auto-complete

其实早就觉得ctags/etags对头文件的解析不够完整,这次用cscope, 基本上所有的函数和变量定义都能找到。闲话少说,上配置:

;; turn on cscope semanticdb backend
(require 'semanticdb-cscope)
(semanticdb-enable-cscope-databases)

CEDET1.0可以按照CEDET 1.0pre7的配置方法。加入上述配置就可以在 c/c++模式下打开cscope的semanticdb后端的支持。

不如意的地方是semanticdb-cscope不支持在当前目录的文件路径上递 归寻找cscope数据文件,只能在所编辑的文件的当前目录中寻找,而前者 是cscope的默认行为。

自己尝试修改了两个文件,可以支持cscope的递归搜索行为:

  • 修改 cedet-1.0/semantic/semanticdb-cscope.el
;; add the following line
(require 'xcscope)

;; ...

;; modifiy the function `semanticdb-enable-cscope-in-buffer'
(defun semanticdb-enable-cscope-in-buffer (&optional dont-err-if-not-available)
  "Enable a CScope database in the current buffer.
When CScope is not available for this directory, display a message
if optional DONT-ERR-IF-NOT-AVAILABLE is non-nil; else throw an error."
  (interactive "P")
  ;; ==> begin change
  ;; commented out - (if (cedet-cscope-support-for-directory (semantic-symref-calculate-rootdir))
  ;; changed to the following line
   (if (cedet-cscope-support-for-directory (cscope-search-directory-hierarchy default-directory))
  ;; <== end change
       (setq
       ;; Add to the system database list.
       semanticdb-project-system-databases
       (cons (semanticdb-project-database-cscope "CScope")
	     semanticdb-project-system-databases)
       ;; Apply the throttle.
       semanticdb-find-default-throttle
       (append semanticdb-find-default-throttle
	       '(omniscience))
       )
    (if dont-err-if-not-available
	nil; (message "No CScope support in %s" default-directory)
      (error "No CScope support in %s" default-directory))
    ))
  • 修改 cedet-1.0/semantic/symref/semantic-symref-cscope.el
;; add the following line
(require 'xcscope)

;; ...

;; modify the method `semantic-symref-perform-search'
(defmethod semantic-symref-perform-search ((tool semantic-symref-tool-cscope))
  "Perform a search with GNU Global."
  (let* ((rootproj (when (and (featurep 'ede) ede-minor-mode)
		     (ede-toplevel)))
	 (default-directory (if rootproj
				(ede-project-root-directory rootproj)
;; ==> begin change
;; comment out -	      default-directory))
;; change to the following line
			      (cscope-search-directory-hierarchy default-directory)))
;; <== end change

	 ;; CScope has to be run from the project root where
	 ;; cscope.out is.
	 (b (cedet-cscope-search (oref tool :searchfor)
				 (oref tool :searchtype)
				 (oref tool :resulttype)
				 (oref tool :searchscope)
				 ))
	)
    (semantic-symref-parse-tool-output tool b)
    ))

还需要修改 cedet-1.0/semantic/common/cedet-cscope.el,改变默认的cscope最小版本:

;;(defvar cedet-cscope-min-version "16.0"
(defvar cedet-cscope-min-version "15.0"
  "Minimum version of CScope required.")

多谢Kai的提醒:)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值