]> git.neil.brown.name Git - edlib.git/blob - README.md
Add COPYING file and GPLv2 notices.
[edlib.git] / README.md
1 <!--
2 # Copyright Neil Brown <neil@brown.name> 2015
3 # May be distrubuted under terms of GPLv2 - see file:COPYING
4 -->
5
6 edlib - library for building a document editor
7 ==============================================
8
9 edlib is an extensible document editor.  It is inspired in part by
10 emacs, both by its strengths and its weaknesses.
11
12 emacs provides a programming language - E-lisp - for configuring and
13 extending the editor.  edlib doesn't.  It allows various pre-existing
14 languages to be used to configure and extend the editor.  It does
15 this by providing a library of core editing tools and providing
16 bindings to various languages.
17
18 At least, that is the plan.  At time if writing, edlib is just a
19 demonstration of some of those tools and has no binding yet.
20
21 The particular value-add of edlib over emacs (apart from the obvious
22 "NIH" issues) is that document rendering will be fully extensible.  A
23 buffer can have multiple views, and each view can show very different
24 things, scriptable code is run whenever text rendering is required.
25 This should make implementing documents with non-trivial structures a
26 lot easier.  I hope.
27
28 edlib is designed to have well defined abstractions that can be
29 exported to various languages for them to manipulate.  They include
30 attributes, text buffers, marks and points, panes, displays, events,
31 and keymaps.
32
33 attributes
34 ----------
35
36 An attribute is a simple name/value pair, both being strings.
37 Attributes can be associated with various other objects, but
38 particularly with characters in a text buffer.  Parsing code can
39 annotate a buffer with attributes, and rendering code can use these
40 attributes to guide rendering.  e.g. parsing code can attach
41 "spelling=wrong" or "spelling=doubtful" and rendering can underline in
42 red or whatever.
43
44 text buffer
45 -----------
46
47 A text buffer (sometimes just a "text") stores a string of characters
48 and an edit history.  The characters can be read from a file, or
49 manipulated by code.  The edit history allows indefinite undo and
50 redo.
51
52 It is expected that every document will be represented as a text.
53 Some views of the document would just display the text, others might
54 display the result of parsing the text, still others might just
55 display some of the attributes attached to the text.
56
57 A text will often be read from and saved to a file in external
58 storage.  However an extension module might fetch a text over the
59 network using some protocol, or might generate it entirely
60 algorithmically.
61
62 marks and points
63 ----------------
64
65 A "mark" identifies a location in a text buffer.  The location is
66 between two characters (or at the start or end), and the mark remains
67 at that location despite any edits that do not affect neighbouring
68 characters.
69
70 A mark can have a 'type'.  All marks of a particular type are linked
71 together in text-order so moving among marks of a type is easy.
72
73 "Points" are a special sort of mark which have linkage to nearby marks
74 of all different types.  All modification to the text happen at a
75 point.
76
77 When a modification happens, the preceding mark of each type is
78 "notified".  This allows it (or its owner) to adjust to the change,
79 such as by reparsing the text.
80
81 An example use is to have a type of marks which are used to track line
82 numbers.  "line-count" marks are places every 500 lines (or so) with
83 an attribute recording exactly how many lines between this and the
84 next "line-count" mark.  When a change happens, the recorded line
85 count is cleared.  When a line count or line number is needed, the
86 list of "line-count" marks is walked from the start.  If any has its
87 count cleared, the lines in that section are counted and the record is
88 updated.  Otherwise all that is required is simply adding up a few
89 numbers.
90
91 Note: the notification of marks on a change is not yet implemented.
92
93 Marks could be used by a parser to identify key locations which would
94 allow a renderer to find the important content quickly if it was only
95 rendering a partial view - such as the headings in outline mode.
96
97 Each mark (and point) has a unique sequence number ordered by position
98 in the text.  This makes it easy to determine relative order of two marks.
99
100 Each view of a buffer will have its own point.
101
102 displays
103 --------
104
105 A "display" displays rendered content and accepts keyboard and mouse
106 input.   Currently only a single 'ncurses' display is supported, but
107 I intend to support multiple 'ncurses' displays and also X11 displays
108 and maybe other display/input technologies.
109
110 panes
111 -----
112
113 A pane is a rectangular area of a display.  It may receive input from
114 the display and may render content.  Panes are arranged in an
115 hierarchy with parents generally responsible for their children.
116
117 Each pane can have a 'focus' child.  Keyboard input from the display
118 goes to the final pane found when following these 'focus' links from the
119 root. Mouse input goes to the pane under the mouse which has no
120 children also under the mouse.
121
122 Panes can have a 'z' depth - higher 'z' numbers are in front of lower
123 numbers.  This allows for pop-ups and floating windows.  For example a
124 list of filename completions might appear in a floating window, which
125 then disappears when the selection has been made.
126
127 Each pane must know how to refresh itself, unless the parent does
128 that.  Various amounts of 'damage' may have happened which lead to
129 different amounts of work in refreshing.  The design for this is not
130 completely clear yet.  It currently understand damage to "Size",
131 "Content" and "Cursor position".
132
133 events
134 ------
135
136 Events happen at panes and propagate up parent linkages until a
137 handler is found.  The handler may invoke further events, which
138 typically start at the original pane and themselves propagate up.
139
140 Events include:
141
142 - keystrokes.  These go to the focus pane.  They can include
143   modifiers (e.g. C-x or META) which cause subsequent keystrokes
144   to be reported differently.
145 - mouse clicks.  These go to the pane under the mouse.  Mouse
146   movement will eventually be included.  Possibly a 'grab' mechanism
147   will be needed to direct motion and button release events.
148 - text-replace.  This requests that a range of text be replaced by
149   another range (either can be empty).  When a keystroke implies
150   a text change, it is not performed directly but instead causes a
151   "text-replace" event to be sent.  This allows a module to easily
152   capture and validate all changes to text without having to capture
153   all relevant key strokes and mouse actions.
154 - movement.  This identifies a unit of text (char, word, line, etc)
155   and a count and allows each pane to interpret it in a local context.
156   This is similar to "text-replace" in that it allows handlers to
157   capture functionality rather than just keystrokes.
158 - search.  I haven't really thought this through, but it seem like
159   useful functionality to specifically delegate.
160
161
162 keymaps
163 -------
164
165 A keymap maps keystrokes to commands. It should really be "eventmap"
166 as all events are included: key, mouse, replace, movement etc.
167 The full unicode character space can be mapped as well as multiple
168 mouse clicks and assorted auxiliary functions.
169
170 An event in mapped to a "command".   Commands can be provided by
171 different modules or language bindings.  A command receives the target
172 pane, the event, and a structure of auxiliary information such as x/y
173 co-ordinate for mouse events or a text string to insert.
174
175
176 bindings
177 --------
178
179 This is totally unimplemented so the details are probably all wrong,
180 but it something thing that will be needed.
181
182 A "binding" is a connection between the library and some language
183 and/or runtime.  To load an extension module a binding to the language
184 will need to be established, and used to load the module.  The binding
185 will need access to some global objects such as the global keymap and
186 buffer list.
187
188 I'm hoping to support multiple threads so that extension modules
189 can run in parallel with editing code.  For example an extension
190 module might start a thread to talk to an IMAP server to keep some
191 local buffers up-to-date with arriving mail, and to handle slow
192 requests.   I imaging threading being closely related to bindings, but
193 maybe not.
194
195 The first binding types I hope to implement are "C" - which is really
196 just loadable shared objects - and Python.
197
198
199 Core Extensions
200 ===============
201
202 These are the basic common objects which can (I hope) be used to build
203 a rich document editor.  There need to be lots of extensions of course
204 to make them useful.  Some of these "Extensions" are so intrinsic that
205 they are part of edlib, not attached through any binding.
206
207 tile
208 ----
209
210 The "tile" handler takes a pane (typically the root pane of a display)
211 and divides it up into 1 or more non-overlapping tiles.  Tiles are
212 grouped in horizonal and vertical stacks.  Tiles can be split, can be
213 discarded or can be resized.  Any of these operations may affect other
214 tiles.
215
216 The leaves of the tile tree need to have other handlers attached.  The
217 tiler doesn't render anything itself, not even borders.  That is left
218 to the children.
219
220 view
221 ----
222
223 A "view" connects a text to a pane.  It holds the text and the point
224 and draws borders.  A horizontal border at the bottom can report
225 the name of the text and possibly other information.  A vertical
226 border acts largely to separate panes but also serves as a scroll
227 bar.  The text manager can set attributes on the text identifying
228 scroll-bar position, and the "view" will render them and handle mouse
229 events to request movement.
230
231 text-render
232 -----------
233
234 Basic text rendering is a core extension.  It will probably grow a lot
235 of optional features such as wrapping or truncation of long lines,
236 mapping attributes to colours etc though a provided mapping, and maybe
237 centering or filling based on attributes.
238
239 Simple views will probably use text-render.  More complex views won't.
240
241
242 TO-DO
243 =====
244
245 There is so very much to do.  At time of writing most of the core
246 infrastructure is in place, but it isn't all connected and is not at
247 all polished. It is certainly possible to start writing simple
248 commands to test out functionality and explore interfaces.  As
249 functionality is added I expect lots of details to be refine.
250
251 Below is a very rough list, which serves to highlight how little
252 really works.  Some of these should be easy to write.  Others will
253 requires careful design though and possibly deep changes.
254
255 - movement: char, word, line, vertical, paragraph, page, start/end
256 - text entry
257 - delete
258 - notifications of change to marks
259 - search
260 - number prefix
261 - choose file name - with floating pane
262 - open file
263 - save file
264 - file names in status line
265 - autosave
266 - cut/copy
267 - paste
268 - undo/redo
269 - auto-indent
270 - auto-wrap
271 - c-mode parsing
272 - color highlights
273 - line/word count
274 - scroll bar
275 - spell check - async?
276
277 Some Ideas
278 ==========
279
280 I have big dreams for edlib.  How much will ever be reality is an open
281 question, but dreams are nice.  Here are some, big an little.
282
283 email with notmuch
284 ------------------
285
286 I loved using emacs for reading mail, but it became too clumsy.  I
287 want to go back to using the one editor for everything.
288
289 I imagine using notmuch as an indexing backend and viewing everything
290 via edlib.  Viewing HTML would certainly be an interesting challenge
291 but I can probably live without that if everything else works well.
292
293 Attached images, including PDF, is important.  I would certainly like
294 to be able to show images in a pane but have not designed anything for
295 that yet.
296
297 Text mode server
298 ----------------
299
300 I only recently discovered "emacsclient -t".  I think I like it.  I
301 certainly want edlib to have a "server" mode and to be able to perform
302 editing in arbitrary terminal windows where I do other work.
303
304 calculator in floating pane
305 ---------------------------
306
307 I very often use 'bc' for hex/decimal conversion etc.  But it is a
308 little clumsy.  I want an easy calculator on my desktop with base
309 conversion.  I'd like to use edlib.  I imagine a small pop-up
310 appearing which automatically converts whatever I type.
311
312 spread sheet
313 ------------
314
315 Many years ago I started writing a spreadsheet program in emacs-lisp.
316 The document was a 'LaTeX' document with specially marked "tabular"
317 sections.  Each cell was on a line by itself.  It consisted of the
318 current appearance of the text, and then a comment containing the
319 formula and formatting rules.
320
321 The e-lisp code would hide the comment and the newlines so that it
322 looked like a table.  When the focus entered a cell, it would switch
323 to displaying the formula, or optionally the formatting.  Any change
324 to formula would propagate around the table.
325
326 It never worked very well.  I felt I spent most of my time fighting
327 with emacs rather than writing useful code.
328
329 If I can make a spreadsheet work at least reasonably well with edlib,
330 then edlib will be a success.
331
332 mark-right
333 ----------
334
335 Markdown?  Commonmark?  Some sort of markup is useful and there are
336 few if any that are both easy to write and highly functional.
337
338 I like writing with markdown, but it is far from complete.  So I'd
339 like to create a mark-down mode that format as I type and which can
340 render to PDF.  Then I would start extending it.  Some extensions like
341 table are fairly standard - maybe ASCII-Math too.
342
343 Description-lists are an obvious (to me) omission.  Anchors for links,
344 structure tags (author, title), foot notes, insets for
345 table/figure/equation etc, with labeling.  Index, contents...
346
347 Figure Drawings?  There are lots of drawing languages.  It would be
348 nice to find a simple but versatile one to embed in markright.
349
350
351 Outline code rendering.
352 -----------------------
353
354 I like the principle of outlines and only showing the heading of
355 nearby sections, but the detail of the current section.  I've always
356 found them a bit clumsy to use.  I want the rendering to automatically
357 do what I want, partly depending on where the cursor is, partly
358 depending on space.
359
360 So when I am editing I want to see a lot of immediately surrounding
361 text, but I also want to see nearby minor headings and all major
362 headings.
363 If headings are short enough and there are enough of them, the having
364 several to a line would be a good idea - maybe even abbreviated.  If I
365 click on an abbreviated heading in the middle of a line at the top of
366 the screen, then that section should open up, and the nearby sections
367 should get a bit more space.
368
369 When searching, I probably don't need as much context of the current
370 point, so less of the current section would be displayed, more of
371 surrounding sections.  If those surrounding sections also contained
372 matches, then that would be the part of those sections that was shown.
373
374 I would like to implement this sort of view for markright mode, but
375 more importantly I want to implement it for C-mode.  When editing C
376 code (which I do a lot) I want the few lines at the top and bottom of
377 the view to just list some function names.  Then maybe a few lines
378 with function signature one the whole line.
379
380 Certainly the start of the current function would appear somewhere no
381 matter where in the function I am editing, and as many of the
382 variables as possible.  If I am in an 'if' statement in a 'for' look,
383 then the loop header and the if condition would be displayed if at all
384 possible.
385
386 hexedit
387 -------
388
389 This is something that is very clumsy with emacs, and should be very
390 easy with edlib.  A 'hexedit' view shows the hex value of each byte in
391 the file in a nice regular pattern.  For ASCII chars, it also shows
392 the character separately.
393
394 terminal emulator
395 -----------------
396
397 I never quite got into using shell-mode in emacs - it never felt quite
398 as raw as an xterm.  And the infinite history bothered me - possibly
399 irrationally.
400
401 Still, a shell mode for edlib  might be a useful thing, though having
402 edlib easily available in any terminal window might be just as good.
403
404 If I did a shell mode, I would capture the output of each command into
405 a separate buffer, and display all those buffers in the one view.
406 Sufficiently old buffers would be discarded.  Output from any recent
407 command could easily be saved or piped.  It would be possible to
408 arrange for some interactive commands to also send output of each
409 command to a separate buffer.
410
411 Auto paging would be disabled (where possible) and edlib would page
412 output as needed.  This means that `cat bigfile` could move the whole
413 file into a buffer, which wouldn't be good.  If a 'less' command could
414 give the filename to edlib and let it display, that might be nice.