Show HN: C/C++ Development Environment for Emacs
tuhdo.github.io
tuhdo.github.io
Here you also have an outline tree the Emacs way, which is very efficient to use when a file contains lots of function/variable definitions: http://tuhdo.github.io/static/part3/helm-semantic-or-imenu.g...
For Arch Linux users, I made a PKGBUILD for it: https://aur.archlinux.org/packages/global-pygments-plugin-gi...
The Pygments plugin is really awesome; it should prove useful even for those who don't use Emacs. For example, gtags lets you use vim/Doxygen/bash/less/etc. to access the tags as well.
Perhaps if you change it in future, think about having a 'basic config' which one can follow?
It would also be nice to know how well these things cope with things like templates and C++11 rvalue references and lambda functions. My past experience is that tags-based tools are fine when your C++ code is basically just C code, but die horribly as soon as you start using C++11 or boost.
For C++, CEDET works pretty nicely with templates and libraries like Boost. I haven't used much C++ aside playing with lambda, so I'm not sure. I've looked at rvalue reference, and it seems to return an assignable pointer to do other thing from a function. Currently, you can jump to the function but not the pointer that the function returns.
Currently, I only work with C. But being able to jump anywhere in the Linux kernel source tree and your system include source (such as "/usr/include", "/usr/local/include" is already very useful, don't you agree?
I'm not sure how you came to that conclusion, but it is not correct. R-values don't have much to do with pointers at all. Though they sometimes do solve problems you would be tempted to use pointers for. I admit I do find it hard to explain briefly what they are though. Maybe these are helpful, though it might be hard to grasp if you don't already properly understand C++: http://www.artima.com/cppsource/rvalue.html http://thbecker.net/articles/rvalue_references/section_01.ht.... This example basically gives an idea of why they are useful: http://thisthread.blogspot.be/2011/03/what-is-rvalue-referen...
get_pointer() = 1;
assigning 1 to a pointer isn't the best idea :P so I think you mean you read int& get_reference();
get_reference() = 1;
which is about lvalue references, not rvalue references, and has existed in C++ since the beginning.None of these emacs packages (e.g. CEDET) handle modern C++ well (heavy use of generic programming, boost, c++-11 features, etc.). Even indenting this code is complicated for an editor!
I think the only way to do it is to rely on the compilers to parse the code. Clang has a nice API (and command lines tools) for this. For instance, there are some packages for auto-completition in emacs: http://www.emacswiki.org/emacs/AutoComplete
Last, it would be nice to have a brew/ubuntu package so we can easily install the "IDE" :)
Emacs also has Clang based solutions such as rtags: https://github.com/Andersbakken/rtags that can index code as you type but is complicated to setup. Or you can use Clang to generate a tag database for your source code with clang-ctags: https://github.com/drothlis/clang-ctags , but the performance for creating tag database is not so good for large source tree: it took "98 minutes and a peak memory usage of 140MB" to generate a tag database for entire LLVM source.
As for CEDET, in what way it could not handle library like Boost? Could you be specific? I tried it before with Boost, and it works pretty well (i.e. gives correct completion candidates in a namespace). I used CEDET for getting completion candidates all the time in Boost.
Basic templates are handled, but things like template specialization or default template parameters still break things. I'm currently working on fixing this; it's been in my personal branch for quite some time now, but I haven't got around to merge it into mainline.
Actually, still one of the most problematic things is preprocessor handling. If the parser doesn't work, it is often due to some preprocessor macros Semantic does not know about.
Yes, I agree with the preprocessor handling since we still have manually tell Semantic what preprocessor exists in the current project. But CEDET is still very usable for most of the things and I love it.
template<typename X> struct Test { void test(const X& x) { typename X::type_t x = x.get_something(); } };
When I type this, there is no way for the compiler to know what X will be (and even for the programmer). As a consequence, the IDE cannot help me much: no auto-completion is possible on x, no way to jump to the definition of get_something() [there are probably several implementations], no way to jump to the definition of type_t, etc.
The issue is that this kind of code is very common in modern C++ (I think 90% of my code is probably templated by something) [and look at the code of boost].
So, there is probably no issue in _using_ some boost libraries or the STL, but programming "boost-like" or "STL-like" libraries probably needs different tools.
"In this guide, I will help you to setup an efficient working C/C++ environment. Despite looking long, the setup is short and easy (mostly copy/paste Emacs Lisp code into your init.el); most of the guide are explanations and demonstrations of many useful features. "
Most of the text are just explanations to help you understand what you are doing, why you need these features.
Or, you can have a simple recipe with 42 steps for setting up a working environment with Linux kernel in Ecliplse with barely any explanation, just learn by heart: http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_... . The guide is merely for NAVIGATING the Linux kernel. Even with the first section of my guide with setting up ggtags or helm-gtags that you can do in 5 minutes, you can freely roam the linux kernel.
Nice timing this time, because of these:
1) https://tuhdo.github.io/emacs-tutor.html
2) https://www.youtube.com/watch?v=HTUE03LnaXA
Since I want to use it for navigation more than for programming these two made my day because I've found about global and how to integrate it with emacs. The rest came as a bonus. Now I can go on with my work and not worry about customization until I have to.
I've been using Emacs for about eight years but never as a power user.
EDIT: Thanks for your work. This tutorial has some new ideas I want to try.
Otherwise IDEs, since the MS-DOS/Amiga days.
For example adding function class member in the .h or .cpp file, and then adding the other part automatically. Or changing arguments, and little balloon comes up, you pres alt+enter - and gives you choices how to make the changes.
Then switch between header/cpp (right visual studio doesn't have this built-in) and few other things make Qt Creator a very good choice.
(add-hook 'c-mode-common-hook (lambda() (local-set-key (kbd "C-c o") 'ff-find-other-file)))
If the .h is in the same directory as .c/.cpp, then Emacs automatically opens. Otherwise, you prompt for the .h file. Once the .h file is opened, subsequent execution of the command switches between the two files.
This is refactoring capability another commercial Emacs plugin had in 2007: http://www.xref.sk/xrefactory/emacs.html
What's so difficult about using Elisp to configure your editor? If you know how to turn on a light switch, you already know how to configure Emacs at its basic level!!! Most of Emacs lisp configuration is like this:
(semantic-mode 1) ;; 1 means turn the feature on
If you want to turn it off:
(semantic-mode 0) ;; 0 means turn the feature off
Most of Emacs plugins work this way, with a few more Elisp code for setting key bindings and other things. Anyway, the package maintainers always give you config Elisp code. Your only work is to copy/paste into your config file and it's done.
Your IDEs appears nice at first since they hide most of the complexity in a menu item called "Options". But when you need to adjust something, and when you click the "Options" menu, things are not so nice anymore. For example, try Eclipse.
And if you mean seriously refactoring as in this article from Qt Creator: http://qt-project.org/doc/qtcreator-2.6/creator-editor-refac... that includes reformatting code, generating getter/setter or automatically detect and fix mistake for you, then no. I have never write such code in the first place that having to back later and I believe we should not fall into the use cases listed in that article.
My only use case for refactoring is to rename variable/function names.
Let's take the "rename function" refactoring. You claimed sed was sufficient. What about functions with the same name in different namespaces or different visibilities?
The same goes for move parameter. Sometimes you want to move a parameter so the order adheres to a guideline that you've accidentially forgotten or that newly emerged. Again: What about ambiguos function names?
Refactorings such as pull method up (e.g. to create an interface)/ push method down are probably not even possible with sed.
Those are small and manageable refactorings. But even a small refactoring such as rename function can mess up your code if not done correctly.
I guess you never used refactoring tools. Good luck doing all their use cases with sed.
That being said, once they release this in production, I'll be buying it on day one and won't look back at emacs.
However, my favorite C++ IDE so far has been Visual Studio with the Visual Assist X plug-in. Visual Studio by itself is not that impressive. But the folks who built Visual Assist X, have done an impressive job. It adds a lot of features to Visual Studio that take it far beyond any IDE.
To learn the basics of Emacs, start with my mini-manual: http://tuhdo.github.io/emacs-tutor.html
http://lorefnon.me/2014/02/02/configuring-emacs-for-rails.ht...
http://crypt.codemancers.com/posts/2013-09-26-setting-up-ema...
- Jonathan