前言
使用putty + vim + tmux, 对于大型项目的(比如20w+文件)c/cpp文件一直不能找到好的配色方式, 稍微中意的有TagHighlight,vim-cpp-enhanced-highlight。 前者对大型项目太鸡肋,后者配色是通过正则匹配,样式受限, 直到看到color_coded。这货的理念还是比较先进的,通过libclang.so的编译功能来识别c/cpp文件中的标识符,然后针对不同的标识符进行着色。
vim中使用color_coded为c/cpp文件配色
一 前置条件:
- 编译器需要支持C++14
- 需要动态的lua库。
二 准备工作:
编译lua的动态链接库:
下面以macox下为例子:
1)修改lua-5.3.5根目录下的Makefile:
-INSTALL_TOP= /usr/local
+INSTALL_TOP= /Users/liaozhicheng/Install/lua5.3.5
-TO_LIB= liblua.a
+TO_LIB= liblua.a liblua.dylib
2)修改修改lua-5.3.5根目录下的src目录的Makefile
ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)
ALL_A= $(LUA_A)
+LUA_SO= liblua.dylib
# Targets start here.
default: $(PLAT)
@@ -59,6 +60,9 @@ $(LUA_A): $(BASE_O)
$(AR) $@ $(BASE_O)
$(RANLIB) $@
+$(LUA_SO): $(CORE_O) $(LIB_O)
+ $(CC) -o $@ -shared $? -ldl -lm
+
$(LUA_T): $(LUA_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
3) 编译
(base) ~/Downloads/lua-5.3.5 >> make macosx
(base) ~/Downloads/lua-5.3.5 >> make install
三 编译color_code:
如果1: lua使用系统的liblua.dylib
(base) ~/.vim/bundle/color_coded/build >> cmake -DDOWNLOAD_CLANG=0 -DCUSTOM_CLANG=1 LLVM_CONFIG=~/Install/llvm9.0.0/bin/llvm-config -DLLVM_ROOT_DIR=~/Install/llvm9.0.0/ ..
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found 64bit system
-- Updating submodules
-- Performing Test COMPILER_SUPPORTS_CXX14
-- Performing Test COMPILER_SUPPORTS_CXX14 - Success
-- Performing Test COMPILER_SUPPORTS_CXX1Y
-- Performing Test COMPILER_SUPPORTS_CXX1Y - Success
-- Looking for Lua
-- Found Lua
-- Lua include /usr/local/include/lua5.3
-- Lua lib /usr/local/lib/liblua5.3.dylib
-- Found Curses: /usr/lib/libcurses.dylib
-- Found ZLIB: /Users/liaozhicheng/Install/anaconda2/lib/libz.dylib (found version "1.2.11")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found LLVM: /Users/liaozhicheng/Install/llvm9.0.0 (found version "9.0.0")
-- Detected that llvm-config comes from a build-tree, adding more include directories for Clang
-- Found Clang (LLVM version: 9.0.0)
-- Include dirs: /Users/liaozhicheng/Install/llvm9.0.0/include;/tools/clang/include;/tools/clang/include
-- Clang libraries: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangTooling.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangToolingCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangIndex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontendTool.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDriver.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFormat.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangCodeGen.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangParse.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSema.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangEdit.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSerialization.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCheckers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewriteFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewrite.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangARCMigrate.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAST.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDynamicASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangLex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangBasic.a
-- Libclang C library: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib
-- Generating sources
-- Checking for luajit
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CUSTOM_CLANG
(base) ~/.vim/bundle/color_coded/build >> make -j 4
Scanning dependencies of target color_coded_track_api
Scanning dependencies of target color_coded_boost
Tracking API changes ...
[ 0%] Built target color_coded_track_api
[ 7%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/codecvt_error_category.cpp.o
[ 15%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/operations.cpp.o
[ 23%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path.cpp.o
[ 30%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path_traits.cpp.o
[ 38%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/portability.cpp.o
[ 46%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/unique_path.cpp.o
[ 53%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/utf8_codecvt_facet.cpp.o
[ 61%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/system/src/error_code.cpp.o
[ 69%] Linking CXX static library libcolor_coded_boost.a
[ 69%] Built target color_coded_boost
Scanning dependencies of target color_coded
Scanning dependencies of target color_coded_config_test
[ 76%] Building CXX object CMakeFiles/color_coded.dir/src/main.cpp.o
[ 84%] Building CXX object CMakeFiles/color_coded_config_test.dir/test/src/config/main.cpp.o
[ 92%] Linking CXX shared library color_coded.so
[100%] Linking CXX executable color_coded_config_test
[100%] Built target color_coded_config_test
[100%] Built target color_coded
(base) ~/.vim/bundle/color_coded/build >>
(base) ~/.vim/bundle/color_coded/build >>
(base) ~/.vim/bundle/color_coded/build >> make install
[ 69%] Built target color_coded_boost
[ 84%] Built target color_coded_config_test
Tracking API changes ...
[ 84%] Built target color_coded_track_api
[100%] Built target color_coded
Install the project...
-- Install configuration: "RELEASE"
-- Installing: /Users/liaozhicheng/.vim/bundle/color_coded/color_coded.so
如果2: 使用自定义lua动态库
方式1:
(base) ~/.vim/bundle/color_coded/build >> cmake -DDOWNLOAD_CLANG=0 -DCUSTOM_CLANG=1 -DLUA_INCLUDE_DIR=~/Install/lua5.3.5/include/ -DLUA_LIBRARY=~/Install/lua5.3.5/lib/liblua.dylib -DLLVM_CONFIG=~/Install/llvm9.0.0/bin/llvm-config -DLLVM_ROOT_DIR=~/Install/llvm9.0.0/ ..
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found 64bit system
-- Updating submodules
-- Performing Test COMPILER_SUPPORTS_CXX14
-- Performing Test COMPILER_SUPPORTS_CXX14 - Success
-- Performing Test COMPILER_SUPPORTS_CXX1Y
-- Performing Test COMPILER_SUPPORTS_CXX1Y - Success
-- Looking for Lua
-- Found Lua
-- Lua include /Users/liaozhicheng/Install/lua5.3.5/include
-- Lua lib /Users/liaozhicheng/Install/lua5.3.5/lib/liblua.dylib
-- Found Curses: /usr/lib/libcurses.dylib
-- Found ZLIB: /Users/liaozhicheng/Install/anaconda2/lib/libz.dylib (found version "1.2.11")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found LLVM: /Users/liaozhicheng/Install/llvm9.0.0 (found version "9.0.0")
-- Detected that llvm-config comes from a build-tree, adding more include directories for Clang
-- Found Clang (LLVM version: 9.0.0)
-- Include dirs: /Users/liaozhicheng/Install/llvm9.0.0/include;/tools/clang/include;/tools/clang/include
-- Clang libraries: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangTooling.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangToolingCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangIndex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontendTool.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDriver.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFormat.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangCodeGen.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangParse.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSema.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangEdit.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSerialization.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCheckers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewriteFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewrite.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangARCMigrate.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAST.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDynamicASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangLex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangBasic.a
-- Libclang C library: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib
-- Generating sources
-- Checking for luajit
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CUSTOM_CLANG
-- Build files have been written to: /Users/liaozhicheng/.vim/bundle/color_coded/build
(base) ~/.vim/bundle/color_coded/build >>
(base) ~/.vim/bundle/color_coded/build >>
(base) ~/.vim/bundle/color_coded/build >> make
Scanning dependencies of target color_coded_boost
[ 7%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/codecvt_error_category.cpp.o
[ 15%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/operations.cpp.o
[ 23%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path.cpp.o
[ 30%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path_traits.cpp.o
[ 38%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/portability.cpp.o
[ 46%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/unique_path.cpp.o
[ 53%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/utf8_codecvt_facet.cpp.o
[ 61%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/system/src/error_code.cpp.o
[ 69%] Linking CXX static library libcolor_coded_boost.a
[ 69%] Built target color_coded_boost
Scanning dependencies of target color_coded_config_test
[ 76%] Building CXX object CMakeFiles/color_coded_config_test.dir/test/src/config/main.cpp.o
[ 84%] Linking CXX executable color_coded_config_test
[ 84%] Built target color_coded_config_test
Scanning dependencies of target color_coded_track_api
Tracking API changes ...
[ 84%] Built target color_coded_track_api
Scanning dependencies of target color_coded
[ 92%] Building CXX object CMakeFiles/color_coded.dir/src/main.cpp.o
[100%] Linking CXX shared library color_coded.so
[100%] Built target color_coded
(base) ~/.vim/bundle/color_coded/build >> make install
[ 69%] Built target color_coded_boost
[ 84%] Built target color_coded_config_test
Tracking API changes ...
[ 84%] Built target color_coded_track_api
[100%] Built target color_coded
Install the project...
-- Install configuration: "RELEASE"
-- Installing: /Users/liaozhicheng/.vim/bundle/color_coded/color_coded.so
方式2:
step1: 修改cmake/FindLua.cmake文件,加入lua动态库文件搜索路径,可以有两种方法:
方法1: 在findpath 和 findlibrary的HINTS中加入lua的include 和lib路径.
find_path(LUA_INCLUDE_DIR lua.h
HINTS
+ /Users/liaozhicheng/Install/lua5.3.5/
ENV LUA_DIR
PATH_SUFFIXES ${_lua_include_subdirs} include/lua include
PATHS
@@ -101,6 +100,7 @@ unset(_lua_include_subdirs)
find_library(LUA_LIBRARY
NAMES ${_lua_library_names} lua
HINTS
+ /Users/liaozhicheng/Install/lua5.3.5/
ENV LUA_DIR
PATH_SUFFIXES lib
PATHS
方法2: 加入CMAKEPREFIXPATH设置:
+++ b/cmake/FindLua.cmake
@@ -69,6 +69,8 @@ unset(_lua_library_names)
# this is a function only to have all the variables inside go away automatically
set(LUA_MINOR_VERSIONS 3 2 1)
+set(CMAKE_PREFIX_PATH "/Users/liaozhicheng/Install/lua5.3.5")
step2: 将编译生成的动态库liblua.dylib重名为liblua5.3.dylib 或者 liblua-5.3.dylib, 原因见color_coded/cmake/FindLua.cmake:
(base) ~/.vim/bundle/color_coded/build >> mv ~/Install/lua5.3.5/lib/liblua.dylib ~/Install/lua5.3.5/lib/liblua5.3.dylib
step3: 编译
(base) ~/.vim/bundle/color_coded/build >> cmake . -DDOWNLOAD_CLANG=0 -DCUSTOM_CLANG=1 LLVM_CONFIG=~/Install/llvm9.0.0/bin/llvm-config -DLLVM_ROOT_DIR=~/Install/llvm9.0.0/ ..
-- The C compiler identification is AppleClang 9.1.0.9020039
-- The CXX compiler identification is AppleClang 9.1.0.9020039
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found 64bit system
-- Updating submodules
-- Performing Test COMPILER_SUPPORTS_CXX14
-- Performing Test COMPILER_SUPPORTS_CXX14 - Success
-- Performing Test COMPILER_SUPPORTS_CXX1Y
-- Performing Test COMPILER_SUPPORTS_CXX1Y - Success
-- Looking for Lua
-- Found Lua
-- Lua include /Users/liaozhicheng/Install/lua5.3.5/include
-- Lua lib /Users/liaozhicheng/Install/lua5.3.5/lib/liblua5.3.dylib
-- Found Curses: /usr/lib/libcurses.dylib
-- Found ZLIB: /Users/liaozhicheng/Install/anaconda2/lib/libz.dylib (found version "1.2.11")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Found LLVM: /Users/liaozhicheng/Install/llvm9.0.0 (found version "9.0.0")
-- Detected that llvm-config comes from a build-tree, adding more include directories for Clang
-- Found Clang (LLVM version: 9.0.0)
-- Include dirs: /Users/liaozhicheng/Install/llvm9.0.0/include;/tools/clang/include;/tools/clang/include
-- Clang libraries: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangTooling.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangToolingCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangIndex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFrontendTool.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDriver.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangFormat.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangCodeGen.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangParse.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSema.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangEdit.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangSerialization.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCheckers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangStaticAnalyzerCore.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewriteFrontend.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangRewrite.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAnalysis.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangARCMigrate.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangAST.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangDynamicASTMatchers.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangLex.a;/Users/liaozhicheng/Install/llvm9.0.0/lib/libclangBasic.a
-- Libclang C library: /Users/liaozhicheng/Install/llvm9.0.0/lib/libclang.dylib
-- Generating sources
-- Checking for luajit
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CUSTOM_CLANG
-- Build files have been written to: /Users/liaozhicheng/.vim/bundle/color_coded/build
(base) ~/.vim/bundle/color_coded/build >> make
Scanning dependencies of target color_coded_boost
[ 7%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/codecvt_error_category.cpp.o
[ 15%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/operations.cpp.o
[ 23%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path.cpp.o
[ 30%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/path_traits.cpp.o
[ 38%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/portability.cpp.o
[ 46%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/unique_path.cpp.o
[ 53%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/filesystem/src/utf8_codecvt_facet.cpp.o
[ 61%] Building CXX object CMakeFiles/color_coded_boost.dir/lib/boost/system/src/error_code.cpp.o
[ 69%] Linking CXX static library libcolor_coded_boost.a
[ 69%] Built target color_coded_boost
Scanning dependencies of target color_coded_config_test
[ 76%] Building CXX object CMakeFiles/color_coded_config_test.dir/test/src/config/main.cpp.o
[ 84%] Linking CXX executable color_coded_config_test
[ 84%] Built target color_coded_config_test
Scanning dependencies of target color_coded_track_api
Tracking API changes ...
[ 84%] Built target color_coded_track_api
Scanning dependencies of target color_coded
[ 92%] Building CXX object CMakeFiles/color_coded.dir/src/main.cpp.o
[100%] Linking CXX shared library color_coded.so
[100%] Built target color_coded
(base) ~/.vim/bundle/color_coded/build >> make install
[ 69%] Built target color_coded_boost
[ 84%] Built target color_coded_config_test
Tracking API changes ...
[ 84%] Built target color_coded_track_api
[100%] Built target color_coded
Install the project...
-- Install configuration: "RELEASE"
-- Installing: /Users/liaozhicheng/.vim/bundle/color_coded/color_coded.so
四 使用color_coded
结论:如果发现颜色没有效果,一定要先检查是否正确配置了.colorcoded.
在安装过程中发现,colorcoded在 ~/.vim/bundle下面,通过scriptnames可以查看到已经加载,但是测试发现对于c/cpp文件着色笔不明显。 检查配置和CCerror都是正常。最后通过跟踪colorcoded的源码发现: colorcoded/include/vim/highlight.hpp中的highlight_group中的:
auto const mapped(clang::token::map_token_kind(kind, cursor_kind,cursor_type));
if(mapped.size())
{
//std::cout << spell.c_str() << " : " << mapped << std::endl;
emplace_back(mapped, line, column, spell.c_str());
}
else
{ /* std::cout << "unmapped: " << spell.c_str() << std::endl; */ }
mapped并没有将spell.cstr与kind映射一起来,导致colorcoded.vim不能识别colorcoded/after/syntax/colorcoded.vim中的 Member、Variable、Namespace、EnumConstant。
进一步跟踪colorcoded/include/core.hpp -> queue中找到原因: .colorcoded这个配置文件么有加入正确的头文件,下面是通过ycm-Generator生成color_coded配置文件
(base) ~/.vim/bundle/color_coded >> more ~/Workspace/global-6.6.3/.color_coded
-x
c
-DBINDIR="/usr/local/bin"
-DDATADIR="/usr/local/share"
-DHAVE_CONFIG_H
-DLIBDIR="/usr/local/lib"
-DLID="no"
-DLOCALSTATEDIR="/usr/local/var"
-DLTDL
-DLTDLOPEN=libltdlc
-DLT_CONFIG_H=<config.h>
-DPIC
-DSYSCONFDIR="/usr/local/etc"
-DUSE_EXTRA_FIELDS
-I.
-I..
-I../libdb
-I../libglibc
-I../libparser
-I../libutil
-I./libltdl
-Ilibltdl