程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Emacs as C++ IDE

Emacs as C++ IDE

編輯:C++入門知識

1.1 auto-completion (require 'auto-complete) (require 'auto-complete-config) (ac-config_default) Auto-completion is a basic plugin. When you input the existed string in a file, emacs will give your some tips.   1.2 yasnippet (require 'yasnippet) (yas-global-mode 1) Yasnnipet is used to complete your code with code-fragments. For example, when you input "for" and press tab in a cpp file, code will be automatically completed as below:   for (i = 0; i < N; i++) {     } 1.3 auto-complete-c-headers (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/include/c++/4.8") ("/usr/include/x86_64-linux-gnu/c++/4.8") ("/usr/include/c++/4.8/backward") ("/usr/lib/gcc/x86_64-linux-gnu/4.8/include") ("/usr/local/include") ("/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed") ("/usr/include")))) (add-hook 'c++-mode-hook 'my:ac-c-header-init) (add-hook 'c-mode-hook 'my:ac-c-header-init) The "achead:include-directories" are my configuration. The include-directories vary with different systems. In terminal you can check include-directories as below command:   gcc -xc++ -E -v - Use this plugins, when you press "#include <f", emacs will give your some tips, such as "float.h", "fstream.h" and so on.   2 google style   2.1 google-cpplint Some tools are required in your system   sudo apt-get install python-pip python-dev build-essential sudo pip install cpplint Then your can configure your emacs.   (defun my:flymake-google-init()   (require 'flymake-google-cpplint)   (custom-set-variables    '(flymake-google-cpplint-command "/usr/local/bin/cpplint"))   (flymake-google-cpplint-load)) (add-hook 'c-mode-hook 'my:flymake-google-init) (add-hook 'c++-mode-hook 'my:flymake-google-init)   (require 'google-c-style) (add-hook 'c-mode-common-hook 'google-set-c-style) (add-hook 'c-mode-common-hook 'google-make-newline-indent) This is my configure and maybe your cpplint-command directory isn't "/usr/local/bin/cpplint". you can set the directory as below command.   whereis cpplint Using cpplint, you will see some "!, ?" at the begging of line in your .cpp or .h file, because your code isn't fit with google style.   2.2 clang sudo apt-get install clang3.5 libclang-dev git clone https://github.com/Sarcasm/irony-mode.git git clone https://github.com/MJPA/SimpleJSON.git mv irony-mode* irony-mode mv SimpleJSon* SimpleJSon mv SimpleJSon  irony-mode/lib mv SimpleJSon ~/.emacs.d/ cd ~/.emacs.d/SimpleJSon/build cmake .. make sudo make install The clang version varies with diffrent systems. you can check the package version in your system as the below command:   sudo apptitude search clang Then you can configure your emacs as below:   (setenv "LD_LIBRARY_PATH" "/usr/lib/llvm-3.5/lib/") (add-to-list 'load-path (expand-file-name "~/.emacs.d/irony-mode/elisp/")) (require 'irony) (irony-enable 'ac) (defun my:irony-enable()   (when (member major-mode irony-known-modes) (irony-mode 1))) (add-hook 'c++-mode-hook 'my:irony-enable) (add-hook 'c-mode-hook 'my:irony-enable) Maybe the llvm-lib directory isn't "usr/lib/llvm-3.5/lib". you can search llvm-lib directory as below:   find / -name "llvm" In reality, We setenv llv-lib because of iron's run is dependent on llvm-lib and it equals with adding llvm-lib in "/etc/ld.so.conf" file.   3 project manager   3.1 projectile (require 'projectile)   ;; 默認全局使用 (projectile-global-mode) ;; 默認打開緩存 (setq projectile-enable-caching t) ;; 使用f5鍵打開默認文件搜索 (global-set-key [f5] 'projectile-find-file)

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved