本文来自多方查询,目前我还是第一次使用emacs,所以有很多问题在emacs高手看来可能会比较幼稚,但是这并不影响我把这个神之编辑器以及怎样用这个神之编辑器写CMakeLists.txt的方法分享出来
一、安装
此处不现说明
二、禁止备份+行号显示
刚刚安装好的emacs会自动创建备份文件,可以在家目录中新建一个.emacs 文件,加入以下内容
;;禁止备份
(setq make-backup-files nil)
参考自:http://blog.csdn.net/flytomysky/article/details/7096561
行号:
;; 显示行号
(require 'linum)
(setq linum-format "%3d ")
;对所有文件生效
(add-hook 'find-file-hooks (lambda () (linum-mode 1)))
PS:根据我在网上查的资料看来,emacs显示行号这个功能,在22版本之前好像要下载插件,我的版本是24.4.1,在加入上面的配置后,重启emacs,显示行号没有问题
参考自:http://samson7b.iteye.com/blog/1522473
三、添加CMakeLists.txt语法高亮
其实cmake的源码包中就已经自带了emacs和vim的插件,路径在源码包中的Auxiliary文件夹中
➜ cmake-3.3.1 ls
Auxiliary CMakeLogo.gif CTestConfig.cmake Modules
bootstrap cmake_uninstall.cmake.in CTestCustom.cmake.in README.rst
CMakeCPack.cmake CompileFlags.cmake DartConfig.cmake Source
CMakeCPackOptions.cmake.in configure doxygen.config Templates
CMakeGraphVizOptions.cmake CONTRIBUTING.rst Help Tests
CMakeLists.txt Copyright.txt Licenses Utilities
➜ cmake-3.3.1 ls Auxiliary
bash-completion cmake-indent.vim cmake.m4 cmake-syntax.vim
cmake-help.vim CMakeLists.txt cmake-mode.el
➜ cmake-3.3.1
将其中的cmake-mode.el复制到~/.emacs.d/plugins/cmake中,在.emacs中添加如下配置
;; cmake 自带的emacs插件,可以语法高亮
(setq load-path (cons (expand-file-name "/home/laolang/.emacs.d/plugins/cmake") load-path))
(require 'cmake-mode)
(setq auto-mode-alist
(append '(("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode))
auto-mode-alist))
参考自:http://blog.csdn.net/csfreebird/article/details/7197392
四、安装company
使emacs可以自动提示[PS:这里的自动提示其实需要开启company的功能,由于我是emacs新手,所以不知道如何修改]
company的github地址:https://github.com/company-mode/company-mode
我将其放在:~/.emacs.d/plugin/company
在.emacs中添加如下配置
;company,ctrl+tab启动,可以自动提示CMakeLists.txt,同时c-mode,c++mode下也有自动提示
(add-to-list 'load-path "~/.emacs.d/plugins/company")
(autoload 'company-mode "company" nil t)
(setq company-idle-delay nil)
(add-hook 'c-mode-hook '(lambda () (company-mode)))
(add-hook 'c++-mode-hook '(lambda () (company-mode)))
(global-set-key [(control tab)] 'company-complete-common)
在使用company的自动提示功能之前,需要M-x company-mode,看到Company mode enabled之后,就可以使用Ctrl + Table使用其自动提示功能了,当然前提是你要输入至少一个字符才行
效果:
参考自:http://blog.chinaunix.net/uid-20263484-id-110157.html