r/cpp • u/[deleted] • Dec 25 '24
Building a code editor in C++
I was planning to build a project in c++ during my winter break. I have a bit of knowledge and I want to be better at C++. How feasible is the idea of building a code editor in c++? Do you guys have any resources that I can follow and take help from?
Thanks
13
u/Revolutionalredstone Dec 25 '24
I've got a pretty decent code editor 🐱
I use imgui and have linting, colorization etc.
Happy to share screenshots 🙂
0
2
u/krum Dec 25 '24
I've worked on a commercial code editor product that is written in C++. There's not much to it really. Just start doing it.
1
Dec 25 '24
Where should I start from? Is there anything that I can refer to?
1
u/krum Dec 25 '24
Start from scratch. It would be easiest to make TUI and use curses. If you want a modern one like VSCode or one that runs in a browser or uses a native UI, you gotta figure all that stuff out first and it'll be a long road.
4
u/starfreakclone MSVC FE Dev Dec 25 '24
I built my editor in C++ using freetype for rasterizing glyphs and tree-sitter for syntax highlighting. My text buffer, I think, is the most interesting part, I talked about it here: https://cdacamar.github.io/data%20structures/algorithms/benchmarking/text%20editors/c++/editor-data-structures/.
I also have a short demo of the editor itself: https://youtu.be/LmINbnhfLIc?si=Zrvx1QqQk3P8Mcyt
It's a lot of work to make a quality editor though, however you learn quite a lot because the problem space is as complex as you want it to be.
1
1
u/DeadlyRedCube frequent compiler breaker 😬 Dec 26 '24
Oh the piece table idea seems neat (definitely going to read that again when it's not after 4am) but more than that, your multi-redo system looks wildly useful and I legit can't believe that I haven't seen that implemented anywhere else!
7
u/Dappster98 Dec 25 '24
I don't know much about writing a code editor, but it's probably not going to be something you'll be able to finish over just a Winter break. However this entirely depends on how "mature" you're wanting it to be.
However, for getting better at C++, I recommend going through learncpp.com, watching CPPCon talks, and watching C++ Weekly videos on YouTube.
0
Dec 25 '24
[deleted]
-2
u/Dappster98 Dec 25 '24
Telling them to ignore their motivation and go another route
Where at all did I do that?
2
u/lewispringle Dec 27 '24
The Stroika library (https://github.com/SophistSolutions/Stroika) provides a framework with most of this functionality (https://github.com/SophistSolutions/Stroika/tree/v3-Release/Library/Sources/Stroika/Frameworks/Led).
And it comes with a sample application which is a basic text editor, supporting syntax coloring (https://github.com/SophistSolutions/Stroika/tree/v3-Release/Samples/LedLineIt).
This would be a good place to start.
1
u/diegoiast Dec 25 '24
I am doing that exactly. See https://github.com/diegoiast/qtedit4
The main editor component is https://github.com/diegoiast/qutepart-cpp
1
1
-2
u/loreiva Dec 25 '24
In order to build a code editor, you need a code editor. But if you have a code editor, then you don't need to make a new code editor to begin with! Magic
4
u/lovelacedeconstruct Dec 25 '24
Imagine bootstrapping your code editor and writing it in itself to write a compiler for a programming language in the programming language you created
2
12
10
u/khedoros Dec 25 '24
I don't think I'd worry about how feasible it is for you. Having a project like "I don't know exactly how I'll do this, but I'm eager to figure it out!" can be a great attitude for learning something new and improving overall.