4 ms·
> How does emacs UI work? Emacs has the idea of _buffers_ which are the actual window panes that you can view. The _buffer_ has data in the form of text which
by ywei3410 6y ago
> How does emacs UI work?
Emacs has the idea of _buffers_ which are the actual window panes that you can view. The _buffer_ has
data in the form of text which has properties in much the same way a block of html can have properties.
An emacs-lisp function has full access to do anything it wants with the buffer. For example it can insert
contents, change the font family, change the bit of text into a button with a callback. This is exactly
how syntax highlighting/semantic highlighting works in emacs, you just change the styling for bits of
text [1].
A _mode_ inside emacs is a collection of emacs-lisp functions which trigger (usually on a file extension name).
Typically they will set certain keybindings for specific mode-like behaviour. You always have a single
_major_ mode and multiple _minor_ modes - the vim emulation layer, for example is simply a minor mode
which adds the vim keybindings and emulates the vim state machine inside emacs-lisp.
> It seems like each script is registering commands it can run in context of mode
An emacs-lisp file can be _evaluated_ in the same way as a python file into emacs. It's like a REPL - you can
evaluate a file and the functions become available. There's a bit of extra behaviour which allows lazy loading
et cetera, but user defined scripts are first-class and there's no distinction between them and those which are
"native".
> updating of values
You can update a variable by simply evaluating the appropriate lisp function. If you want to update a value
in the text buffer, you just replace/rerender that chunk.
> handling async requests
A buffer can also have a _process_ running which gets events each time the buffer is updated. When you run
a command, you direct the output to a buffer and you trigger your lisp function on certain events.
This is sort of how the HTTP requests work, but there's libraries which abstract some of it for you. Buffers are
really just an abstraction for textual data.
Some of this is simplified, but I hope it gives you a vague idea of what emacs is.
[1] https://www.reddit.com/r/emacs/comments/iemo44/wysiwygified_org_mode/ https://www.reddit.com/r/emacs/comments/iemo44/wysiwygified_...
- axilmar 6y agoIn other words, Emacs has its own markup language? how does emacs know that a specific bit of text is a button, for example?
- dmortin 6y agoCharacters can have various properties set. These are either built in or you can define your own properties too.
- juxtapose 6y agoYes, Emacs supports a limited form of "rich text". See text-mode. It's supported by text properties [1] and overlays [2]. Character properties are special attributes attached to a single character, while overlays can attach attributes to a "region" and override old text properties (like div in HTML). In Emacs, > A button is essentially a set of text or overlay properties, attached to a stretch of text in a buffer. [3] The Emacs display engine is sorta like an HTML render engine. [1] https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Properties.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Te... [2] https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ov... [3] https://www.gnu.org/software/emacs/manual/html_node/elisp/Buttons.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Bu...