CppCon 2015: Atila Neves "Emacs as a C++ IDE"

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

OP and speaker here. AMA.

👍︎︎ 20 👤︎︎ u/atilaneves 📅︎︎ Oct 21 2015 🗫︎ replies

I just installed Rtags again after last giving it a shot about six months ago. It has advanced tremendously, lightning fast, and with it Emacs becomes better than other IDEs at "jump to definition"/"jump to uses" type tasks. I am thrilled by the helpful new buffer highlighting.

The recent lengthy discussion on emacs-devel about enhancing IDE features is makes me very optimistic for the tooling to advance even further.

👍︎︎ 7 👤︎︎ u/pzone 📅︎︎ Oct 22 2015 🗫︎ replies

Your cmake-ide project sounds very similar to my own ede-compdb project. Have you ever looked at that? If so did you have any feedback?

👍︎︎ 7 👤︎︎ u/randomphr4se 📅︎︎ Oct 22 2015 🗫︎ replies

Great talk! I've been using emacs for more than a decade! One of the many great things about emacs is there is very little version fatigue. This is important.

I look forward to investigating the packages mentioned and seeing if I integrate some of the tools mentioned. I do use cscope but as he says, it is not the greatest.

👍︎︎ 6 👤︎︎ u/funkiestj 📅︎︎ Oct 22 2015 🗫︎ replies
Captions
so we have four brave volunteers today and I'm hoping that all for them will be with us soon but Attila is here and an X physicist okay a recovering physicist mean yeah I'm never denied who works for a Cisco and has been writing C++ for 16 years and he's going to show you how to use Emacs as a C++ IDE alright so there's my name and my handle on Twitter I also have a blog which I ramble about things she might be interested in reading that or not was a case may be okay um so a few years ago I was using Emacs and when I got my job at Cisco I ended up using Eclipse EDT for about two years I'm not entirely sure why now I don't remember I think it's because I was a new kid on the block and everybody else was using it I just wanted to say um and the experience is a bit you know bitter I left a sour taste in my mouth but I have to admit there were certain features that I enjoyed and that made me more productive as a C++ programmer and I've listed the ones that premiere important in actual descending order of importance at the top the most important thing for me what I use the most is jump to the definition can't live without to need to know where a struct is define a function a macro whatever got my cursor on top I want to go to it and I want to go to it fast auto completion saves a lot of time if you don't know the API that well you can hit dot and then things pop up and you can kind of fumble your way around on the fly syntax highlighting this means that when you're typing your code you don't wait for it to compile things are happening in the background you get squiggly line it'll tell you what you're doing wrong and maybe even some static analysis going on there fine felon project I don't care what directory things are that's for the computer to know and me to find out I just want to tell it here's my name here's the name of the fellow one go find it don't care I get funny looks at work when people keep telling me where things are I kind of what is it called compiled onkeypress not a big deal but important for some people and graphical debugger that's been in Emacs forever but I heard anybody uses it for some reason so I wanted to go back to you max but I don't know how because I didn't want to give up these features and I think for about a year I was mostly said to myself if I could only get this in Emacs I would switch but I I was lazy and didn't until I did so the whole thing is I'll show you how to get all of this in Emacs now why would you want to use Emacs well first of all it's lightweight it doesn't take that much RAM or CPU I once had the windows XP VM running Visual Studio and that took less Ram that eclipse which is ridiculous it's incredibly powerful and a lot of people don't know how or why and to be fair there aren't that many examples of the kind of things you can get done with it but if you start doing macros are compiling within Emacs and then using the error messages for the compiler to then generate new code this is a kind of thing I'm talking about tried in DES in Eclipse and let me know how that works out for you it doesn't require the mouse to be productive you can still use it so how's menus you can click on but you don't have to when that for me is very good because the mouse is slow its extensible you can make it do whatever you want because it's a programmable platform so the abotu changes are comedy your habits instead of you having to change to accommodate to somebody's idea of what ide should do and B there's a rich collection of packages which means that somebody out there's probably written code to do what you want it to do and if they haven't you can write that code yourself where code is that's what we're using the editor for and obviously if it's going to make you more productive that's a good investment of time and because the the extensible language is list we can just version control your editor configuration which I do that means I get it for free everywhere I go every computer I use has exact same Emacs configuration and also you know your power user when you have to do git bisect to figure out why you screwed up multiple times why not Emacs Emacs is for tinker's if you want something that just works that not the editor for you it's not gonna happen I told the co-worker just use eclipse if that's what you want you have to tinker with it you have to customize it or else you're not going to get the benefits that they provide to make things worse the out the box experience is dreadful if you just install your Max and run it it basically doesn't do anything or do it well nearly everything is optional you need to turn it on and of course if you're a beginner you don't know where to begin if you go look at somebody else's config it's going to be ginormous and you don't know which parts you're going to like or not there's too many options there's more than one way to do things and more than one package may be providing similar functionality so that can cause decision fatigue you have to go try out all these things and figure out which ones you like and which ones you don't don't use emacs if you just like typing five closing parenthesis in a row because there will be a lot of that an e Lisp and your colleagues will probably think you're weird might do but I don't think he works is the only reason why now there are several packages for an ID like experience the Emacs some of them have been there for a very long time you can get tagging with those three C scopes probably the best one out of those and it works by just tagging where things are in source code and then you can jump to them the problem is they don't work that well and for any project that you're likely to be paid to work on your projects too big for these things to work so you're going to get a lot of false positives you're going to jump to wrong parts of the code it can be annoying and I've tried all three for syntax checking needs to be the single fly make there's a new one called flightcheck that i recommend wholeheartedly and it will give you the squiggly lines we need typing and it works with several several different languages not just seen C++ with Python Perl you name it people keep adding things to that all the time Emacs actually ships now since I think version 23 but not sure a package called semantic it's not on by default you have to turn it on and it also supposed to understand the language you're working on so you can jump the definition all to complete that kind of thing but there's a problem with that which I'll come to shortly for auto-completion you have to made packages once called autocomplete and the other ones company mode for complete any they both also have backends so that you can have different sources of information for the autocompletion engine to work with both of them have engines for clang this is a good I think but doesn't always work I'll come back to that as well and miscellaneous are tags are tax is awesome I didn't write it something else did don't know the guy but I'm using it now foreseeable sports because work soil what it does is it leverages lib clang and there's a server and a client and the server will cache results a compilation with Lib clang and then it can give you information where things are defined and all sorts of other things now the good thing about so flightcheck has a thing for clang as well the good thing about that is it's using a compiler the problem with C scope and those things is they're not compilers so they don't understand the language that well when you have crazy if thefts and compiler directives and dash D flags and - includes none of these packages work because they can't if you're right in one file and you try semantic on it or if all the files on the same directory it will work or we'll know where to find things because we need to include it's from that directory but of course any non-trivial project has include paths has - DS maybe some configuration at Build time that will happen and things depend maybe you're building on Windows and Linux and you have if thefts and things don't work that way so that's the common problem - always packages so where the solutions a really bad one is using Mac's directory variables that's when you write a file - directory and when you open a file in Emacs and any of its sub directories it will apply those variables so you have to manually keep track of your compiler flags for every file in your project this doesn't sound like a good thing to do a better solution is to use a package like projectile that this project management for you so you don't have to handle this thing so you specify in this package you do some command in Emacs so you tell it what the project name is and what the directories are and all of these things compiler flags etc okay fine but the thing is if you're working on your own project then you can use projectile but if you're in a team of people and they're using eclipse or Visual Studio wherever and you just happen to be one to use Emacs you don't have that there is a build system in place and the most common one these days is probably Simic I use it for all of my C and C++ project and I don't want to be duplicating information that C make already knows C mix already building my project it knows what the compiler flags are so would it be great if I could just take that information from C make instead and pass it on to the packages that need of course they all have their own idiosyncratic ways doing this right so my contribution is to write a package called CMake ID it does what it says on the tin I try to make a zero config possible so what it does is when you open a file in Emacs it will search up that's and if it's a siient or C++ file it will look up the directory tree trying to find a see make lips txt now I can't stop with the first one because C make can use embedded stuff so it keeps going up the directory tree until I can't find another one and that one's the root now that it knows you're in a C make project because if you're not then it doesn't do anything because there's nothing to do it will run C make for you because this is another beauty of image you can just launch processes you can open a socket you can do whatever you want so it will run C make for you see Michael generate a compilation database in JSON with all the files in the system and all of the compiler flags and then this package that I wrote will set the variables used by autocomplete company flightcheck and we'll talk to the our tags demon until it oh by the way it's this directory over here go fetch the compilation database and do your magic and all of this all we have to do is install the packages all happens automatically all you do is open a file you open a file and then these things get set and now you have compiler assisted ID features compiler assisted by client using the exact same Flags you're actually using to build so this is no way you can get wrong definition because or else it wouldn't compile okay and that's how it's automatic so let's look at how this works now I've already got this open because it's a lightning talk and I don't have a lot of time but if if I just open a max in this file these things will work so there's already squiggly lines here because I have a CPP checker Clank is complaining about those headers I'm not sure what's going on there this project is ancient I would not write code like this anymore so there's that and I hope you believe if I just put the cursor over here no jump to the definition that thing just works I go straight to the where the micro wrist doesn't even take any time because it's cached if I put it here I'll see where this class is defined well actually that's the thing there it's a 4 declaration okay in this case the soil gets there's all sorts of things this is all being powered by our tech if I wanted to do I don't know here's the M weapon something right so if I try to do this and try to complete I get the demo effect and it's not working okay but normally the autocomplete believe me just just trust me with all right okay just took a while sometimes it does because they need to catch yourself yeah I don't know how it's taken so long it's got smooth yep so one of the back into ended ups reply and then you get all of these which are all methods define on that thing I'm kind of experiments in my configuration as well but it does some pretty cool stuff as well this is a different project here oh wait um so this is some some of the Google test source code I just picked it because it's it's open source and I won't get to trouble but maybe I'm gonna fall be better now this is the one I was trying to show I think this microwave yeah right so see how this thing to get grayed out that's because if the compiler definitions so it already knows 516 it's magic now our talks can do appear some pretty cool stuff as well here's a completely stupid project all I'm doing is with the macro defining a struct and the reason why I'm showing this is because I want to show the results of pre-processing that file and then on the other buffer on the Left you get the results of running the preprocessor on the entire file now of course that includes string there already gives me a lot of output because this is a standard library include so what if I just want to do this region here not a problem there you go boom pre-processed that's courtesy of our tags I'm just setting flags I'm just telling it where to get the stuff so you can know what to do the other kind of stuff that our tags does which is really cool as well is well let me jump to this header so these are all virtual functions right okay what if I ask the compiler to find every single virtue in plantation to that virtual function done and this is an eMac how many of you thought that Emacs could do that before getting into this room today that's what I thought but it can do anything so if it doesn't do what you need write some code than it will but chances are you don't have to because somebody else like me a package to do it so hopes I'll convince you that this is a good investment to make because you get all the part of Emacs with every idea feature you may want the autocomplete stuff I was showing here I've had problems with lots of complete recently so Strang company for a little while so I've changed my configure a little bit so and the reason why it wasn't because it wasn't working it was actually just because it was being slow because compiling C++ is slow and so when you're depending on clang to compile that structure to give you it takes a while um so I'm so you know mocking a part of it you can install this package from Mel but you don't have to clone it from github or anything like that and unless you have question with me it's that so there's actually a standalone server and a client that you need to compile I'm not running them so that that would be too much setup Emacs is running them for me the only thing I have to do is compile them and make sure they're in the path that's it but as soon as it recognizes as a seam a project it'll start our tags in the background for you and then tell the client to connect and say take the compiler flags from here so I I i use the the debugger inside Emacs as well with multiple windows actually shows you all the local variables and stuff like that I just didn't think I'd have time to put it up well so I'd have to pick up binary now so I'm definitely on time I had a lot of time on my hands two years ago and I changed everything about my development environment including operating system shell and ID I just went on a quest and I obsessed easily and I'm obsessed about my productivity and I did nothing else for six months I spent two hours once picking a programming foot thank you thank you very much thank you
Info
Channel: CppCon
Views: 95,466
Rating: undefined out of 5
Keywords: Atila Neves, CppCon 2015, Computer Science (Field), Bash Films, Conference Video Recording, Event Video Recording, Video Conferencing, Video Services, C (Programming Language), Programming Language (Software Genre)
Id: 5FQwQ0QWBTU
Channel Id: undefined
Length: 16min 18sec (978 seconds)
Published: Wed Oct 21 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.