CSDN Summer of Code 2014 Report #2: Setup C/GTK+ development environment with Emacs

Setup C/GTK+ development environment with Emacs

Warning: be careful with my broken English, I got only about 450 in CET 6.

1 Introduction

I'm a beginner at programming in C/GTK+ so I want to my development tools to give me more help like:

  1. auto complete function name / type name
  2. function parameter hint
  3. quick look API document
  4. jump to definition and back
  5. compile && run && edit or debug cycle
  6. and of course some basic editor feature e.g. syntax highlight, code style, search / replace

As you can see I actually should use an IDE for GTK+, but I do not find one even meets a half of my requirements. I have tried both Anjuta and geany, the former is a heavyweight IDE for development using GNOME techniques. It has a very handy tools to create classes but many features which I list above are missing or do not work out of box. The latter is a lightweight IDE, I think it maybe suitable for develop small project.

I do not know if that is possible GTK+/GNOME has an IDE like kdevelop and QT Create of QT/KDE?

For now, I have to use GNU Emacs to get start to develop my C/GTK+ project although I am not a Emacs master or even loyal fan.

2 General configuration

I fork emacs24-start-kit and customize to suit my need. It is a good starter for me because of literate way to embed code in document. I install many color themes and change everyday since I can not decide which one is my favorite.

I also taste many packages and find some of them are quiet useful:

  • projectile, can manager project base on git repository and provide some handy functions like search within project via many external tools like ag or ack
  • git-gutter, show current changes in frame's left in real time, so I do not need to use git diff to check what I have done

I am also using Helmorg-mode and maybe many not built-in package, they looks awesome but I do not know much about them.

3 C/GTK+ configuration

Emacs itself has many features with program mode, for example, code style, it has many rules not only indent as 4 space, setting up a suitable code style is necessary for editing and format code.

3.1 on-the fly Syntax check

I use clang as the syntax check back-end. To make it works, I add GTK+ include path to Flycheck Clang Include Path via "M-x customize".

3.2 Code complete

Auto-Complete (in short AC) is my choice for this task. AC is an intelligent auto-completion extension for Emacs1. It needs Source to complete the task, there are some built-in ones like words-in-buffer, dictionaries and TAGS etc.

auto-complete-clang is The AC sources for Clang. It is the most valuable source.

Here is my configurations according to related user manuals:

(require 'auto-complete-config)
(ac-config-default)

(require 'auto-complete-clang)

(setq ac-quick-help-delay 0.5)
(defun my-ac-config ()
  (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))
  (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)
  (global-auto-complete-mode t))

(defun my-ac-cc-mode-setup ()
  (setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))

(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)

(my-ac-config)

(setq ac-clang-flags
      (mapcar (lambda (item)(concat "-I" item))
              (split-string
               "
 /usr/lib/gcc/x86_64-redhat-linux/4.8.3/include
 /usr/local/include
 /usr/include
 /usr/include/gio-unix-2.0/
 /usr/lib64/glib-2.0/include
/usr/include/glib-2.0
")))

3.3 Code browse

C-s*/*C-r and occur are quit easy and intimate way to move around within a source file. Helm has a search base directory named helm-do-grep which shows result when you are typing.

I use GNU global and its emacs front ggtags instead of cscope, no special reason for it, just since I'd like to try new things.

3.4 lookup GTK+ API

I always need to read the API document when I read / write code. After some search, I do find two solutions: gtklookup and devhelp-index, but both are not work for me.

So I write a small function to meet my needs partly:

(defun devhelp()
  "Search current symbol in devhelp"
  (interactive)
  (shell-command (format "devhelp -s %s" (thing-at-point 'symbol))))
(global-set-key [f1] 'devhelp)

At least I do not need copy-paste text between Emacs and devhelp. it is better if the API document (in html) can be shown within Emacs.

Date: 2014-08-11T02:34+0800

Author: Chunyang Xu

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看rEADME.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看rEADME.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值