                               (with-current-buffer buffer
                                 (emdocs-after-change-function
                                  buffer beg end prev-length))))
+                (setq-local emdocs-before-change-lambda
+                            (lambda (beg end)
+                              (with-current-buffer buffer
+                                (emdocs-before-change-function
+                                 buffer beg end))))
                 (setq-local after-change-functions
                             (cons emdocs-after-change-lambda
                                   after-change-functions))
+                (setq-local before-change-functions
+                            (cons emdocs-before-change-lambda
+                                  before-change-functions))
+                (setq-local emdocs-undo-list nil)
+                ;; TODO: add removable lambda as with after-change-functions
                 (add-hook 'kill-buffer-hook
                           (lambda ()
                             (when (string-equal

  "docstring")

(defvar-local emdocs-after-change-lambda nil
  "docstring")

;;; classes

                     *emdocs-incoming-clients*))
    (setq-local after-change-functions
                (remove emdocs-after-change-lambda after-change-functions))
    (setq-local emdocs-after-change-lambda nil)
    (setq-local emdocs-undo-list nil)
    (setq-local before-change-functions
                (remove emdocs-before-change-lambda before-change-functions))
    (setq-local emdocs-before-change-lambda nil)))

(defun emdocs-kill-server ()
  "docstring"
