vim-cpp-auto-include
vim-cpp-auto-include copied to clipboard
Detect usage of std:: and avoid using namespace
E.g. goole code style tells you not to do so.
To be honest, the current change makes the code harder to read. $1 is discouraged in Ruby and names like regexp and rex confuses people.
Let's do this instead: If std:: is found, do not add using namespace std;
diff --git a/cpp_auto_include.vim b/cpp_auto_include.vim
index 6bcfa34..e593250 100644
--- a/cpp_auto_include.vim
+++ b/cpp_auto_include.vim
@@ -111,6 +111,7 @@ module CppAutoInclude
]
USING_STD = 'using namespace std;'
+ USING_STD_REGEX = /using namespace std;|std::/
# do nothing if lines.count > LINES_THRESHOLD
LINES_THRESHOLD = 1000
@@ -164,7 +165,7 @@ module CppAutoInclude
end
# add / remove 'using namespace std'
- has_std = content[USING_STD]
+ has_std = content[USING_STD_REGEX]
if use_std && !has_std && !includes.empty?
VIM::append(includes.last.last+1, USING_STD)
Ok, i haven't thought about that Solution. Well to be honest I haven't really taken care of the variable names. Thanks.
Am 17.12.2015 um 22:31 schrieb Jun Wu <[email protected] mailto:[email protected] >:
To be honest, the current change make the code hard to read. $1 is discouraged in Ruby and names like regexp and rex confuses people.
Let's do this instead: If std:: is found, do not add using namespace std;
diff --git a/cpp_auto_include.vim b/cpp_auto_include.vim index 6bcfa34..e593250 100644 --- a/cpp_auto_include.vim +++ b/cpp_auto_include.vim @@ -111,6 +111,7 @@ module CppAutoInclude ]
USING_STD = 'using namespace std;'
- USING_STD_REGEX = /using namespace std;|std::/
do nothing if lines.count > LINES_THRESHOLD
LINES_THRESHOLD = 1000 @@ -164,7 +165,7 @@ module CppAutoInclude end
# add / remove 'using namespace std'
-
has_std = content[USING_STD] -
has_std = content[USING_STD_REGEX] if use_std && !has_std && !includes.empty? VIM::append(includes.last.last+1, USING_STD)
— Reply to this email directly or view it on GitHub.
Fixed it