How does it work?¶
The most important part to understand is Data structures. After that it’s easy to write code in other parts.
Serialization / Deserialization of objects¶
In Emacs we have many types of objects like:
#<marker at 3427 in tests.el>
- integers 123
- ... and other
And we have to represent them as text to save. This is done using
wg-pickel and functions defined in this var:
(defvar wg-pickel-object-serializers '((integer . identity) (float . identity) (string . identity) (symbol . wg-pickel-symbol-serializer) (cons . wg-pickel-cons-serializer) (vector . wg-pickel-vector-serializer) (hash-table . wg-pickel-hash-table-serializer) (buffer . wg-pickel-buffer-serializer) (marker . wg-pickel-marker-serializer)) "Alist mapping types to object serialization functions.")
So when you meet an object that cannot be represented as text - you:
- Add it’s type in this variable
- Write mentioned “serializer” function itself
For example for “buffer” objects:
(defun wg-pickel-buffer-serializer (buffer) "Return BUFFER's UID in workgroups buffer list." (list 'b (wg-add-buffer-to-buf-list buffer)))
‘b - is just a marker that will tell to run
wg-pickel-deserialize-buffer when restoring a buffer.
Last element is buffer UID and it is enough to restore the buffer with
(wg-restore-buffer (wg-find-buf-by-uid uid))
Loading a session file¶
It is done in
wg-open-session. First you read a
Session object from file in this line:
(let ((session (read (f-read-text filename)))) ...
Then you just switch to 1 of the saved workgroups in this object according to settings.
Writing objects to file is done in... (function stack):
- wg-pickel <– main function
So the main function to transform Lisp objects to strings is