
Show HN: C/C++ Development Environment for Emacs - tuhdo
http://tuhdo.github.io/c-ide.html
======
tuhdo
I added a demo on how CEDET works with Boost:
[http://tuhdo.github.io/static/c-ide/semantic-boost-
demo.gif](http://tuhdo.github.io/static/c-ide/semantic-boost-demo.gif)

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...](http://tuhdo.github.io/static/part3/helm-semantic-or-imenu.gif)

------
euid
If anyone follows this and happens to like GNU Global/ggtags (I did), there's
a Pygments plugin released earlier this year that enables it to use any
language that can be parsed by Pygments: [https://github.com/yoshizow/global-
pygments-plugin](https://github.com/yoshizow/global-pygments-plugin)

For Arch Linux users, I made a PKGBUILD for it:
[https://aur.archlinux.org/packages/global-pygments-plugin-
gi...](https://aur.archlinux.org/packages/global-pygments-plugin-git/)

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.

------
CJefferson
While it's good to see the work you put into this article, for the emacs
novice it really is far too much of an information dump, in particular it's a
little difficult to keep track of all the different things which do the same
thing.

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.

~~~
tuhdo
I think it's pretty basic. I created a demo repo for people to play with, so
they don't have to configure themselves: [https://github.com/tuhdo/emacs-c-
ide-demo](https://github.com/tuhdo/emacs-c-ide-demo)

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?

~~~
stinos
_I 've looked at rvalue reference, and it seems to return an assignable
pointer to do other thing from a function_

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://www.artima.com/cppsource/rvalue.html)
[http://thbecker.net/articles/rvalue_references/section_01.ht...](http://thbecker.net/articles/rvalue_references/section_01.html).
This example basically gives an idea of why they are useful:
[http://thisthread.blogspot.be/2011/03/what-is-rvalue-
referen...](http://thisthread.blogspot.be/2011/03/what-is-rvalue-reference-
good-for.html)

~~~
tuhdo
Well currently I only work with C not C++ anymore so my knowledge might be
outdated. I thought that the rvalue reference is something new in C++11, as I
read it here:
[http://thbecker.net/articles/rvalue_references/section_01.ht...](http://thbecker.net/articles/rvalue_references/section_01.html).
Your article seems to mention different thing from 2008? In the article I
read, a function returns a pointer that you can assign it like this:
get_pointer() = 1;

~~~
stinos
The design of C++11 started way before 2011, hence articles from 2008.

    
    
      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.

~~~
tuhdo
Thanks for the explanation.

------
sprash
This actually convinced me to never use Emacs as C/C++ IDE ever. The amount of
unnecessary complexity is astounding.

~~~
tuhdo
What's so complex? I wrote in the very beginning of the guide:

"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_...](http://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source)
. 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.

~~~
crististm
I can understand where he is coming from. At least in my case the question was
- how come there is no package that does all this by default? Install the
package and that's it... I want to be productive in my project before I get
productive in init.el customization. Nice to have but it comes second. Anyway,
I've bitten the bullet and after realizing that I'm not that smart to choose
`the` packages for C dev myself, I decided (again) to see what others do with
their setups.

Nice timing this time, because of these:

1) [https://tuhdo.github.io/emacs-tutor.html](https://tuhdo.github.io/emacs-
tutor.html)

2)
[https://www.youtube.com/watch?v=HTUE03LnaXA](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.

------
malkia
I love emacs, and use it daily for lots of text-editing, but since I've been
learning Qt, I've been using Qt Creator and seems much easier to get certain
things (which granted might be available in emacs, or visual studio but
haven't checked how).

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.

~~~
tuhdo
You can switch between .h and .cpp easily with ff-other-file. Bind it to a
key:

(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.

------
Erwin
After a few years with PyCharm I'm not excited to manually write wads of elisp
to get basic functionality. Instead I pay the JetBrains people a negligible
sum per year (and the basic functionality is open sourced now). They are
working on a C++ IDE now:
[http://www.jetbrains.com/objc/features/cpp.html](http://www.jetbrains.com/objc/features/cpp.html)

This is refactoring capability another commercial Emacs plugin had in 2007:
[http://www.xref.sk/xrefactory/emacs.html](http://www.xref.sk/xrefactory/emacs.html)

~~~
tuhdo
Because such refactoring is not really needed. You can do easily with sed.

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.

~~~
emsy
If you do that kind of refactoring with sed, I won't believe you take
refactoring seriously.

~~~
tuhdo
How do you refactor complex C code with myriad of macros? I think we should
avoid writing code that having to seriously change its structure later. If we
want to refactor, it should be minimal and manageable.

And if you mean seriously refactoring as in this article from Qt Creator:
[http://qt-project.org/doc/qtcreator-2.6/creator-editor-refac...](http://qt-
project.org/doc/qtcreator-2.6/creator-editor-refactoring.html#refactoring-c-
code) 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.

~~~
emsy
Refactorings are used to adapt your code to newly acquired knowledge and/or
changed requirements. That are things that CAN'T BE PLANNED because you simply
don't know them yet. Therefore you can't plan how minimal you'll have to
refactor.

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.

------
donniezazen
@tuhdo Are you using Emacs in terminal? Do you prefer it use the GUI version?

~~~
tuhdo
I am using both GUI and terminal. I prefer the GUI for my local use. But when
working, I have to connect to remote server only through SSH under the
terminal. Instead of using Tramp (which is not practical for the current
latency), I setup Emacs on the remote servers and use it from there when I
connect to the servers.

------
fvinci
Do any ROR devs use emacs? Are there articles on good configurations for Ruby
or Rails? I'm trying to get into emacs. I see the value, but it is REALLY
overwhelming getting started.

~~~
hvis
Here's a different couple of guides to get you started:

[http://lorefnon.me/2014/02/02/configuring-emacs-for-
rails.ht...](http://lorefnon.me/2014/02/02/configuring-emacs-for-rails.html)

[http://crypt.codemancers.com/posts/2013-09-26-setting-up-
ema...](http://crypt.codemancers.com/posts/2013-09-26-setting-up-emacs-as-
development-environment-on-osx/)

------
jonathanmarvens
I use VIM, though :( .

\- Jonathan

