Emacs as my UE4 IDE with intellisense

Hi, any other emacs users here?

As an emacs-user, being forced to work in an IDE like Visual Studio or Xcode can be quite… demotivating. I mean, the IDEs themselves are not bad, but text-editing, switching to other files and so on is just sooooo painfully slow, mouse-based and confusing.
(If you are a programmer and don’t know emacs, you should take a look: GNU Emacs - GNU Project)

So, what we need is emacs to be capable of working with the UE4 code-base, ideally with intelli-sense and auto-completion. This turned out by far more complicated than I had hoped for.

First off, this is not supposed to be a pure instruction thread, but a discussion on how to improve working with emacs and UE4. I can only provide my current state of a kind-of (some problems persist, see end of the post) working solution for OSX using rtags. Getting this working on Linux shouldn’t be a big problem. Getting it working on Windows is probably impossible (because rtags doesn’t work on windows and I guess UBT forces you to use VC compiler anyway. No clang, no rtags!) so, if you’re programming on Windows, you might want to consider getting a mac :wink:


Using (rtags-find-references-at-point), [C-x r ,] to show all uses of the symbol “NAME_INDEX” that rtags could find.

emacs intellisense options
I’m using rtags, but there are other possible solutions. Maybe you can get them to work, or are already using one of them? If so, please tell us.

When searching for “emacs intellisense” the first hit will probably be CEDET and its Semantic Analyzer. The UE4 code base is too complicated, making heavy use of macros and C++11 stuff, semantic will fail parsing buffers half-through and never be able to find symbols.
Then there is etags (for semantic), I can’t remember what exactly went wrong with that, but I couldn’t get it to work.
I did not try ctags, because etags is supposed to be better.
I also did not try gnu-global, because we are not using gcc and due to how the GNU-guys tick, it probably won’t work with clang.

btw:
I tried to compile rtags on windows, but it won’t work. And then Windows complained about my PATH envvar beeing too long… oh, Windows, you are so cool, really.

rtgas
rtags is made for clang and uses clangs features to analyze the code while actually compiling, so if clang is able to understand and compile the codebase, it should be able to output the correct information for Intellisense to work (I guess that is the way xcode gets its Intellisense under the hood, but I’m not sure, it might use ctags though it doesn’t create TAGS files in the source directories).

-a note on xcrun -
I compiled rtags without much of a problem and got it working with a simple project (the rtags codebase). The problem now was, that UBT kinda explicitly calls the clang that is included with xcode by calling xcrun.

I tried to use a non-xcode clang but it won’t work. It simply never finished compiling one of the first Core cpp files. So there seems to be something about the xcode clang that is necessary for UE4 compilation, at least in the context of xcrun. I didn’t try to edit the Mac-Toolchain UBT file to not call xcrun anymore, maybe that would work too, but you would have to rebuilt UBT then.

-a note on memory -
rtags will create an in-memory database of tags. So it will use even more memory when compiling your project. If your machine barely keeps up compiling UE4 the normal way, you will probably run into out-of-memory problems here.

get and install rtags
go to GitHub - Andersbakken/rtags: A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
install rtags as explained on the website. You will need to install a llvm/clang as told, using the provided homebrew formula or macports.

piping the xcrun call to clang through the rtags wrapper
UBT will call xcrun to call the clang++ that comes with xcode. To intercept the build commands, we need to put a symlink to the wrapper there. First get the path to the current xcode clang++ by using


xcrun -f clang++

the result should be something like this


/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

now this is only a symlink to the file called clang in the same directory but we don’t care, you could delete the file, or rename it, using


sudo mv /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/__clang++

now to create the symlink to the wrapper file


sudo ln -s ~/rtags/bin/gcc-rtags-wrapper.sh /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

now everytime UBT invokes the xcode clang++ to compile something, it will be run through the rtags wrapper file instead.

using rtags rdm
now start the rdm in a new shell by calling (i installed rtags to ~/rtags, so if you installed it somewhere else, change the path accordingly)


cd ~/rtags/bin
./rdm

Now, when compiling the Editor for example, the rdm shell should be doing stuff (namely indexing/tagging files)
To build UE, run in a different shell:



cd path/to/UnrealEngine
source Engine/Build/BatchFiles/Mac/SetupMono.sh Engine/Build/BatchFiles/Mac
mono Engine/Binaries/DotNET/UnrealBuildTool.exe UE4Editor Mac Debug -deploy


You might want to remove anything from previous builds first using the -clean flag. Then -deploy will do a full rebuild of the engine.


mono Engine/Binaries/DotNET/UnrealBuildTool.exe UE4Editor Mac Debug -clean

please note that since we replaced the official xcode clang++, even a compile through the xcode interface should start indexing the files for rtags.

using rtags in emacs
This is also stated on the rtags website, but if you’re using your emacs also on windows, you might want to narrow the initialization to the mac only, put this to your emacs initialization scripts:



(when (eq system-type 'darwin) ; only if on mac
  (require 'cl-lib)
  (add-to-list 'load-path "~/rtags/src")
  (require 'rtags)			
  (rtags-enable-standard-keybindings c-mode-base-map)
  ;;(require 'rtags-ac)
  ;;(add-to-list 'ac-sources 'ac-source-rtags)
  ;;(add-to-list 'ac-sources 'ac-source-yasnippet))
  (require 'company-rtags))


note: you can use the company-rtags or the rtags-ac integration, depending on which mode you use when editing c++ files.
I personally found ac being much to slow because it tends to provide lists of text of “anything” you have lying around, which is quite useful in python, but like hell in c++. The problem with both modes is nonetheless, that they don’t provide the logical completion-lists in UE4 most of the time. I’m not sure what is the problem, either rtags, company or something on my personal setup, but I currently find company as well as ac pretty useless in c++.

Also, rtags won’t always be able to find symbols. This generally happens when a file you are in, or where the symbol is used in, is not indexed by rtags. Not sure why this happens, because technically everything that runs through the clang compiler should be indexed, so I blame UBT :smiley:

To help with those cases, I make heavy use of another tool called ag (the silver searcher, GitHub - ggreer/the_silver_searcher: A code-searching tool similar to ack, but faster.), it is a much better alternative to grep. So whenever a file is not indexed or so, searching with ag (ag-project) will find every location of a certain string and list them in a new buffer with a ‘click to show in other window’ fashion to quickly browse through the results.
So when you know you are looking for the implementation of DoSomething in a class called SomethingClass, and rtags can’t find it, you can tell ag to search for the string “SomethingClass::DoSomething” and you will most likely find the file you are looking for within the results listed by ag.

So, I hope I could get any potential emacs users started to use emacs for UE4 and I even more so hope that I am not the only one using emacs around here and that we can share whatever information and experience we come across while trying to improve that setup.

Wow, it’s a little sad to me that no one has replied to you since you posted this. I also am an emacs user and would very much prefer to work in it if possible too. Did you ever do more work on this? My goal is to work linux native.

This is great.

Personally I prefer Sublime and for intellisense, I generally just refer to the header like a good little C slave. That said, I just checked and there is an RTags plugin so I might try and get this working in Sublime.

Thanks!

I’m currently setting up my emacs for a UnrealEngine 4 configuration, would be nice if someone has some nice way of adding intellisense for UE4 code! Haven’t tried rtags yet, which I’m gonna try now, but I would love to get some discussion going on different configs.

I’m using Emacs on Windows. At the moment nothing special going on other than I have a couple of batch files to run exhuberant ctags to keep an updated TAGS database. This let’s me find symbol and at point and so on. Occasionally company will give me some options using that tags database but generally I haven’t gotten the intellisense-ish stuff working yet. I just keep the API.chm handy and I lean on projectile-ripgrep a lot

Oh yeah, I also just have some batch files to run the build as well as the editor (unless I need to use the debugger). Projectile keeps this all handy to run. Workflow wise it has been fast and light. When I need to debug I just created an empty solution with an exe project pointed at the editor. All of this saves me a ton of time so far and I’m pretty happy with it.

Thanks!! I learned a lot from this.

I’ve encountered one obstacle when trying to “man in the middle” Clang, described here: https://stackoverflow.com/questions/44212242/rtags-clang-wrapper-for-generating-tags

If you have any advice I’d appreciate it.

what i want is just a emacs emulation extension for vs 2017…

For those on linux, as of UE4.16, rtags works pretty much out of the box. I’m using the script in the middle for clang++3.9, otherwise everything just works after a rebuild using the Epic supplied build tools and make.

Hi,
Another UE4 & Emacs user on Linux here.
Although I wrote my UE plugin for a long while,
but missing auto-completion is quite a pain.
Really appreciate your sharing.

lol, encouraged to find this thread and I’ll add my 2 cents to keep it alive. @alfalfasprossen I appreciate your effort here and that you documented what your setup was. Do you have any updates as to where things are at now?
I am new to UE4 and game dev (and LOVING it), but my background is more than a decade in a linux environment with emacs and using misc open source compilers.

VS does lots of powerful things, and I’m fighting with trying to use it because of all the obviously critical completion and integration with UE4. But yeah, ultimately hate working with visual studio. It’s bulky and a nightmare for basic text editing, and I’ve been finding myself just editing in emacs, compiling in UE4 editor and finding myself confused why Visual Studio keeps launching monstrously large processes in the middle of this workflow to crash my once elegant development party

Much love to all the developers working on Unreal Engine, and I think Blueprints and making things more accessible is great, but getting locked into an editor like VS when coming from emacs/vim land… it’s def jarring. One particular strength of Unity seems to be the decoupling here, because emacs integrations looks to be a lot further along.

I wish I was more of an emacs wizard to start hacking on something, but unfortunately my emacs kung fu is entry level.

For everyone landing here in the future

You also might be interested in this project.

1 Like