                         ((string-equal "delete" type)
                          (goto-char cur-point)
                          (delete-char content)))
-                     (setq emdocs-is-network-insert nil))))))
+                     (setq-local emdocs-is-network-insert nil))))))
             (buffer-contents
              (with-current-buffer buffer
                (when emdocs-mode
                  (let ((prev-point (point)))
-                   (setq emdocs-is-network-insert t)
+                   (setq-local emdocs-is-network-insert t)
                    (unwind-protect
                        (progn
                          (goto-char (point-min))
                          (erase-buffer)
                          (insert buffer-contents)
                          (goto-char prev-point))
-                     (setq emdocs-is-network-insert nil))))))))))
+                     (setq-local emdocs-is-network-insert nil)
+                     (setq-local emdocs-undo-list nil))))))))))
 
 (defun emdocs-client-filter (client sock msg)
   "docstring"

                  (equal (emdocs-get-process client) sock))
                *emdocs-incoming-clients*)))))

(defun emdocs-send-file-periodically (client sock msg)
  (when (and (get-buffer (emdocs-get-attached-buffer client))
             (process-live-p (emdocs-get-process client)))
    (with-current-buffer (emdocs-get-attached-buffer client)

             (with-current-buffer buffer
               (when emdocs-mode
                 (save-excursion
                   (setq-local emdocs-is-network-insert t)
                   (unwind-protect
                       (cond
                        ((string-equal "insert" type)
