I am embarking on setting up my VIM with better autocompletion, mainly for classes. In my google research I came across omnicppcomplete and clang. I can't seem to figure out the advantage/disadvantage of the two. Does anyone know?
Also, is one easier to install on third party systems than the other?
Any feedback will help. Thanks!
Clang really 'understands' c++. That means it can tell the difference between a local variable named foo and a member function named foo. If you want to complete thisObject.fo..., it will not give you the fooContainer completion, but only the Object::fooMethod.
Also, Clang can handle all C-type languages, which ctags cannot.
Omnicppcomlete is based on ctags, which is merely a textual index of your source tree. So it will be denser, will most of the time do what you want; sometimes it will be less accurate. Which isn't a real problem.
I have not yet installed the Clang completion though :( You probably have to build clang yourself, while ctags most likely comes with your distribution.
Related
I usually develop using emacs in a linux environment (ubuntu) because I love the editor. I've been also using eclipse from time to time but I find it slow.
Since I want IDE-like features, I tried to setup cedet and it seems to be sort of doing the work.
I find that cedet never finds base class members. For example, std::vector in gcc has std::vector::size in its base class and it cannot find it.
Seems inaccurate: If I do something like "myvector." it will give me completions like size_type.
Cannot use auto from c++11, it seems not to work.
srecode-getset gives me errors even for basic usage.
My configuration does not give any error and is based in alexott cedet config.
My questions are:
The completion is that inaccurate still? (Think of "vector." giving things like "size_type".
What is the status of cedet for c++/c++11? Should auto be working? I'm doing anything wrong?
I tried to use both bundled ubuntu version and last version from bzr repository. CEDET seems an extremely useful tool, but I wonder if it needs more work.
Thanks in advance.
Instead of relying on CEDET for completion, you might want to consider an alternative completion provider in Emacs.
Auto-complete-clang and auto-complete-clang-async both work with clang to get completions and with the auto-complete package to display them. Company-clang is similar, but uses the company package to display completions.
There is another minor mode for C, C++, and ObjC called irony that uses clang to get completions and can use multiple front-ends to display completions. This might have the best documentation for getting it set up.
All of these are available on Marmalade for use with the package manager in Emacs 24.
I know that this may be a less-than-sufficient answer (and I'd prefer to mention this in the comments but I'm shy on points), but there is an Eclipse plugin for emacs functionality called emacs+. This link should be friendly to your Eclipse install manager (on Indigo I can copy and paste it into Help->Install New Software->Work With). Because Eclipse was otherwise attractive to you and therefore this can indirectly alleviate your problem...
size_type is actually a member type of vector, so that's not as crazy as it sounds. Of course, the syntax is myvector::size_type, not with a period.
I've found an odd inconsistency between Rcpp which compiled with and without -std=c++0x.
Consider the expression
Function data_frame("data.frame");
GenericVector a;
a.push_back("17");
return data_frame(a, _["stringsAsFactors"]=0);
(ed. note: coercion to DataFrame in Rcpp actually thunks down to the R function, but doesn't allow the user to set that flag.)
In "old" C++ (w/o -std=c++0x set) this code works. In modern C++ (w/ -std=c++0x set), this fails, saying "cannot coerce class "pairlist" into a data.frame".
Obviously, this isn't the end of the world: I just don't use any newer features. However, I confess to being totally at a loss as to what causes this difference, and how to work around it without throwing C++11 away. Any ideas, anyone?
Code targetting features of the new standard was written in Rcpp about 2 years ago.
But then, later we realized that CRAN did not accept the -std=c++0x flag for gcc (or equivalent flags for other compilers), and forcing the C++99 standard and therefore we cannot realistically use it.
Consequently we pretty much don't maintain the C++11 aware code. That's a shame because we'd really like to, but we prefer the exposure of being accepted in CRAN. Since we don't maintain, there are probably many things that don't work as they should.
This particular issue is probably easy to fix. And this will happen as soon as we get the green light on using C++11.
We love C++11 and cannot wait to use it. But we cannot use it in uploads to CRAN (as per a decree of the CRAN maintainers who consider C++11 "non portable" at this point -- please complain to them, not us, of that irks you).
Consequently it is currently "barred". There is a bit of detection in RcppCommon.h and we define HAS_CXX0X. But we haven't really written code for this, as we can't (yet) per the previous paragraph.
So if you found a bug, please do us the favor and report it where request follow-ups to be sent: the rcpp-devel list. Reproducible is good, patches even better :)
I have a couple of simple C++ homeworks and I know the students shared code. These are smart students and they know how to cheat moss. I'm looking for a tool that can rename variables based on their types (first variable of type int will be int1, first int array will be intptr1...), or does something similar that I cannot think of now. Do you know a quick way to do this?
edit: I'm required to use moss and report 90% match
Thanks
Yep, the tool you're looking for is called a compiler. :)
Seriously, if the programs submitted are exactly the same except for the identifier names, compiling then (without debugging info) should result in exactly the same output.
If you do this with debugging turned on, the compiler may leave meta-data in the executable that is different for each executable, hence the comment about ensuring it is off. This is also why this wont work for Java programs - that kind of info is present whether in debug mode or not (for the purposes of dynamic introspection).
EDIT: I see from the comments added to the question that you're observing some submissions that are different in more than just identifier names. If the programs are still structurally equivalent, this should still work.
EDIT: Given that the use of moss is a requirement, this probably isn't the way to go. I does seem though that moss has some support for comparing assembly - perhaps compiling to assembler and submitting that to moss is an option (depending on what compiler you're using).
You can download and try our C CloneDR duplicate code detector. It finds duplicated code even when the variable names have been changed. Multiple changes in the same chunk are treated as just one; if they rename the varaibles consistenly everywhere, you'll get back a report of "one clone" with the precise variable subsitution.
You can try Copy Paste Detector with ignoreIdentifiers turned on. You can at least use it for a first pass before going to the effort of normalizing names for moss. Or, since the source is available, maybe you can get it to spit out its internal normalization of the code.
Another way of doing this would be to compile the applications and compare their binaries, so your examination is not limited to variable/function name changing.
An HEX editor can help you with that. I just tried ExamDiff (not free $) and I was happy with the result.
When you get a third-party library (c, c++), open-source (LGPL say), that does not have good documentation, what is the best way to go about understanding it to be able to integrate into your application?
The library usually has some example programs and I end up walking through the code using gdb. Any other suggestions/best-practicies?
For an example, I just picked one from sourceforge.net, but it's just a broad engineering/programming question:
http://sourceforge.net/projects/aftp/
I frequently use a couple of tools to help me with this:
GNU Global. It generates cross-referencing databases and can produce hyperlinked HTML from source code. Clicking function calls will take you to their definitions, and you can see lists of all references to a function. Only works for C and perhaps C++.
Doxygen. It generates documentation from Javadoc-style comments. If you tell it to generate documentation for undocumented methods, it will give you nice summaries. It can also produce hyperlinked source code listings (and can link into the listings provided by htags).
These two tools, along with just reading code in Emacs and doing some searches with recursive grep, are how I do most of my source reverse-engineering.
One of the better ways to understand it is to attempt to document it yourself. By going and trying to document it yourself, it forces you to really dive in and test and test and test and make sure you know what each statement is doing at what times. Then you can really start to understand what the previous developer may have been thinking (or not thinking for that matter).
Great question. I think that this should be addressed thoroughly, so I'm going to try to make my answer as thorough as possible.
One thing that I do when approaching large projects that I've either inherited or contributing to is automatically generate their sources, UML diagrams, and anything that can ease the various amounts of A.D.D. encountered when learning a new project:)
I believe someone here already mentioned Doxygen, that's a great tool! You should look into it and write a small bash script that will automatically generate sources for the application you're developing in some tree structure you've setup.
One thing that I've haven't seen people mention is BOUML! It's fantastic and free! It automatically generates reverse UML diagrams from existing sources and it supports a variety of languages. I use this as a way to really capture the big picture of what's going on in terms of architecture and design before I start reading code.
If you've got the money to spare, look into Understand for %language-here%. It's absolutely great and has helped me in many ways when inheriting legacy code.
EDIT:
Try out ack (betterthangrep.com), it is a pretty convenient script for searching source trees:)
Familiarize yourself with the information available in the headers. The functions you call will be declared there. Then try to identify the valid arguments and pre-/post-conditions of the functions, as those are your primary guidance (even if they are not documented!). The example programs are your next bet.
If you have code completion/intellisense I like opening up the library and going '.' or 'namespace::' and seeing what comes up. I always find it helpful, you can navigate through the objects/namespaces and see what functionality they have. This is of course assuming its an OOP library with relatively good naming of functions/objects.
There really isn't a silver bullet other than just rolling up your sleeves and digging into the code.
This is where we earn our money.
Three things;
(1) try to run the test or example apps available, set low debug levels, and walk through logs.
(2) use source navigator tool / cscope ( available both on windows and linux) and browse the code to understand the flow.
(3) also in parallel use gdb to walk into code while running test/example apps.
In a nutshell, I'm searching for a working autocompletion feature for the Vim editor. I've argued before that Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion.
I know about Ctrl+N, Exuberant Ctags integration, Taglist, cppcomplete and OmniCppComplete. Alas, none of these fits my description of “working autocompletion:”
Ctrl+N works nicely (only) if you've forgotton how to spell class, or while. Oh well.
Ctags gives you the rudiments but has a lot of drawbacks.
Taglist is just a Ctags wrapper and as such, inherits most of its drawbacks (although it works well for listing declarations).
cppcomplete simply doesn't work as promised, and I can't figure out what I did wrong, or if it's “working” correctly and the limitations are by design.
OmniCppComplete seems to have the same problems as cppcomplete, i.e. auto-completion doesn't work properly. Additionally, the tags file once again needs to be updated manually.
I'm aware of the fact that not even modern, full-blown IDEs offer good C++ code completion. That's why I've accepted Vim's lack in this area until now. But I think a fundamental level of code completion isn't too much to ask, and is in fact required for productive usage. So I'm searching for something that can accomplish at least the following things.
Syntax awareness. cppcomplete promises (but doesn't deliver for me), correct, scope-aware auto-completion of the following:
variableName.abc
variableName->abc
typeName::abc
And really, anything else is completely useless.
Configurability. I need to specify (easily) where the source files are, and hence where the script gets its auto-completion information from. In fact, I've got a Makefile in my directory which specifies the required include paths. Eclipse can interpret the information found therein, why not a Vim script as well?
Up-to-dateness. As soon as I change something in my file, I want the auto-completion to reflect this. I do not want to manually trigger ctags (or something comparable). Also, changes should be incremental, i.e. when I've changed just one file it's completely unacceptable for ctags to re-parse the whole directory tree (which may be huge).
Did I forget anything? Feel free to update.
I'm comfortable with quite a lot of configuration and/or tinkering but I don't want to program a solution from scratch, and I'm not good at debugging Vim scripts.
A final note, I'd really like something similar for Java and C# but I guess that's too much to hope for: ctags only parses code files and both Java and C# have huge, precompiled frameworks that would need to be indexed. Unfortunately, developing .NET without an IDE is even more of a PITA than C++.
Try YouCompleteMe. It uses Clang through the libclang interface, offering semantic C/C++/Objective-C completion. It's much like clang_complete, but substantially faster and with fuzzy-matching.
In addition to the above, YCM also provides semantic completion for C#, Python, Go, TypeScript etc. It also provides non-semantic, identifier-based completion for languages for which it doesn't have semantic support.
There’s also clang_complete which uses the clang compiler to provide code completion for C++ projects. There’s another question with troubleshooting hints for this plugin.
The plugin seems to work fairly well as long as the project compiles, but is prohibitively slow for large projects (since it attempts a full compilation to generate the tags list).
as per requested, here is the comment I gave earlier:
have a look at this:
Vim integration to MonoDevelop
for .net stuff at least..
OmniCompletion
this link should help you if you want to use monodevelop on a MacOSX
Good luck and happy coding.
I've just found the project Eclim linked in another question. This looks quite promising, at least for Java integration.
I'm a bit late to the party but autocomplpop might be helpful.
is what you are looking for something like intellisense?
insevim seems to address the issue.
link to screenshots here
Did someone mention code_complete?
http://www.vim.org/scripts/script.php?script_id=1764
But you did not like ctags, so this is probably not what you are looking for...