Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp standard library #86

Merged
merged 9 commits into from
Mar 1, 2017
Merged

Cpp standard library #86

merged 9 commits into from
Mar 1, 2017

Conversation

pappasam
Copy link
Contributor

C builtins / C++ standard library syntax options

This pull request resembles:

#84

However, I've put some thought into highlighting options for the C++ standard library / C language builtins. I believe this option is especially important for C++ because the standard library is 2/3 of the written standard. As usual, this pull request provides users the option to override the default behavior of no builtin highlighting, keeping with PaperColor's philosophy.

Change to global boolean evaluation function

In order to elegantly implement the syntax options for the standard library functions, I needed a way to impact both the "bold" flag and the syntax color. In order to achieve this elegantly, I changed the boolean flag function to take three values:

fun! s:value_if_global_boolean_else_other(g_bool, value_if_bool, default)

By generalizing the abstract function (eg, can choose your own default, not mentioning color specifically to enable using signals for thickness instead of color), I was able to use the derived functions to handle both color and boldness. As a result, I had to revise the functions used for Python builtins. However, to me, this makes the framework simpler and more extensible. Hopefully you agree!

@pappasam
Copy link
Contributor Author

pappasam commented Feb 27, 2017

Additionally, this specifically targets the following plugin due to its active development and up-to-date status:

https://github.com/octol/vim-cpp-enhanced-highlight

@NLKNguyen NLKNguyen merged commit d022da7 into NLKNguyen:master Mar 1, 2017
@NLKNguyen
Copy link
Owner

Great work again! 🥇

I'm thinking a different way of providing config options. We obviously don't want a separate function for each option. Below is what I'm aiming at, extending the global variable g:PaperColor_Theme_Options with options per language.

.vimrc

let g:PaperColor_Theme_Options = {
  \   'language': {
  \     'python': {
  \       'highlight_builtins' : 1
  \     },
  \     'cpp': {
  \       'highlight_standard_library': 1
  \     } 
  \   }
  \ }

Using that in PaperColor.vim will be something like:

if s:LanguageOptions('cpp.highlight_standard_library', 1)
  call s:HL("cppSTLtype", s:pink, "", s:bold)
else
  call s:HL("cppSTLtype", s:foreground, "", "")
endif

This way, I think, is shorter and easier to maintain in the future. I'll provide the function s:LanguageOptions as soon as the next commit.

@NLKNguyen
Copy link
Owner

NLKNguyen commented Mar 1, 2017

I've added that in 39a7084

The function is s:Language_Options and the sample config in .vimrc is like this:

let g:PaperColor_Theme_Options = {
  \   'language': {
  \     'python': {
  \       'highlight_builtins' : 1
  \     }
  \ }

There can be any number of languages alongside with Python in this case, and each can have multiple options. The way to check if the option is set to 1 is very simple in PaperColor.vim: s:Language_Options('python.highlight_builtins', 1). Language name and otpion name are case sensitive; the value can be number or string (case insensitive).

I refactored the Python builtins feature in the commit, please see that as example, and it would be great if you can help refactor the current C/CPP options to this new way. 😃

@pappasam pappasam mentioned this pull request Mar 1, 2017
@pappasam pappasam deleted the CPP_STANDARD_LIBRARY branch March 5, 2017 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants