Guest User

Untitled

a guest
Oct 16th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. ## A web frontend for Emacs via CodeMirror
  2.  
  3. ### Motivation
  4.  
  5. Why a web frontend for Emacs?
  6.  
  7. 1. A web frontend would benefit from being cross-platform in the sense
  8. that you have one implementation, and now any web browser on any
  9. platform is capable of providing an interface for you. Currently
  10. Emacs maintains many codebases for different frontends.
  11. 2. Web browsers will support Wayland faster than Emacs will support
  12. Wayland.
  13. 3. You can embed web pages via iframes, which can be used to browse
  14. documentation, or even creating a web browser within Emacs that can
  15. display anything a fully fledged browser can.
  16. 4. You can embed graphics, animations, canvas, GL and other widgets
  17. available to a modern web browser, and put this into e.g. a REPL, a
  18. code editor (e.g. a colour picker in css-mode).
  19. 5. Thanks to Electron, you can produce a native "app" from such a web
  20. interface, that would look no less first-class than graphical Emacs
  21. itself.
  22. 6. Working over a network (e.g. websockets) would allow you to "live
  23. stream" your Emacs to other people who could view it trivially with
  24. a web browser (no installation or setup neccessary).
  25. 7. It would serve as a nice proof-of-concept/fact-finding project in
  26. order to consider more ideal implementations, such as an SDL-based
  27. Cairo/OpenGL-based implementation of Emacs.
  28.  
  29. ### Emacs background
  30.  
  31. Emacs is a Lisp engine with built-in support for buffers and
  32. windowing. It has frontends: a terminal frontend, a Gtk & X.org based
  33. frontend (capable of displaying more colours and font sizes and
  34. styles), and also Cocoa and Windows frontends.
  35.  
  36. ### Web frontend
  37.  
  38. To provide a web frontend for Emacs, you would need a web page to
  39. connect to Emacs via a websocket (for which there's a library in Emacs
  40. Lisp) which would:
  41.  
  42. 1. Emacs side: Receive incoming keyboard (text typing and commands)
  43. and mouse events (clicking, selecting, scrolling) from the client,
  44. and run them.
  45. 2. Web side: Receive updates to the windows and buffers, replacing
  46. parts of the buffer that changed along with text properties,
  47. creating and destroying overlays, and send keyboard & mouse events
  48. to the server.
  49.  
  50. There would need to be special handling for window management, and for
  51. the minibuffer which is always visible, as well as the modeline and
  52. "fringe" (which is the left-hand-side bar sometimes used by flycheck
  53. and things like that).
  54.  
  55. ### CodeMirror as a frontend
  56.  
  57. To produce a frontend, you hypothetically only need a few
  58. things. These things are provided by CodeMirror:
  59.  
  60. * `replaceRegion` - can be used to update changed text coming from Emacs,
  61. which lets us only change part of the buffer, rather than rewriting
  62. the whole document.
  63. * `markText` - can be used to set text properties, which is used for
  64. highlighting and visibility among other things in Emacs.
  65. * `addOverlay` - can be used to create overlays, just as they are done
  66. in Emacs.
  67. * `setSelection` - can be used to set the cursor position and the
  68. selection.
  69. * Capturing keyboard input in a cross-platform manner.
  70. * Capturing scrolling and other mouse input in a cross-platform
  71. manner.
  72.  
  73. Font faces would be sent from Emacs to the Web client periodically,
  74. and encoded as CSS rules, with custom face properties specified as
  75. `style` properties in the DOM.
  76.  
  77. ### Conclusions
  78.  
  79. 1. The case for a web frontend for Emacs is compelling.
  80. 2. It should not be much work to create a CodeMirror frontend to
  81. Emacs.
Add Comment
Please, Sign In to add comment