Writing a Programmers Editor - Part 1


Since the time i learnt emacs i have toyed with the idea of writing my own programming text editor. Though emacs is a powerful tool it can be obtuse to people with no lisp/scheme knowledge, one cannot be very effective in emacs without learning elisp. When i floated the idea of writing my own text editor my fellow programmers often speculated that it is the most difficult endeavour one can undertake as a programmer, the arguments that were made varied from Emacs and vim they have been in development for over 3 decades to it is a massive untertaking for an individual since companies like IntelliJ's entire business is around the development of text editors/IDE's.

And perhaps they are right, despite these editors being touted as highly configurable or programmable, programmers regularly dive into the C code to upgrade them. It is infact a delicate exercise in the balance of power, between the C-Runtime and the scripting language of the editor.

The obvious question is how much power should an user have in a programmable editor? Some editors lend more power to the user than others. Emacs for instance is still undergoing active development in its C-Runtime, instead of fixing the issues or adding enhancements at the elisp level (The scripting language of emacs).

Perhaps elisp isnt powerful enough or the C-Runtime is dominant and doesnt lend enough power to elisp interpreter. Either way the user ends up with a power deficiency.

I wondered what percentage of emacs is written in elisp and how much in C?

emacs-percentage-repo.png

Figure 1: Emacs C/elisp percentage split.

Documentation of emacs at 16.2% is quite impressive irrespective of the power level.

What about vim how much of vim is written in C and vimscript?

vim-percentage-repo.png

Figure 2: Vim C/vimscript percentage split.

Vimscript on the other hand may very well be suited for extending the editor in but it surely is no match for a full fledged programming language like lisp, but again the question is How much power does one need in a programming editor ?.

In other words where does the sweetspot lie in the Power Continuum?

  • Are these languages equally powerful in the Power Continuum?
  • How do these existing Editors work?
  • Is there an efficiency equation that we are unaware of?
  • What if the Delicate balance in powers of the runtime and scripting exists

for a reason and has a penalty when disturbed?

Whenever i encounter subjective questions such as these, my approach is to find an objective reasoning for the thought. The approach draws its inspiration from a famous Feynman quote.

What i cannot create i do not understand. - Richard Feynman

I think what one needs is a language that is powerful enough to be both a general purpose programming language and simple enough to be an extensions language. Emacs lisp fits that bill being a lisp, though elisp has "borrowed power" and can move only so much as the runtime itself allows it.

  • What if emacs was written in 100% elisp?
  • What if we write an Editor in a lisp or scheme which gives us the power to

extend the editor in the same language as the editor itself is written in ?

A thought worthy of exploration! In the next few assays we would explore this idea further to lend 100% power to the user. We would explore concepts as broad wide as terminal buffers to datasctructures required to build an editor. We would piece together an editor for ourselves in the next few assays, to know the answer to the questions mentioned above.

Watchout for the next part of the assay till then.

Shorel'aran



Comments

comments powered by Disqus