                                    (buffer-name (current-buffer))
                                    buffer)
                               (emdocs-disconnect buffer))))
-                (add-hook 'kill-emacs-hook #'emdocs-kill-server)))))
+                (add-hook 'kill-emacs-hook #'emdocs-kill-server)
+                (add-hook 'change-major-mode-hook #'emdocs-mode)))))
       (message "Not connected to internet: exiting.")
       (setq emdocs-mode nil)
       (emdocs-disconnect))))

            (define-key map (kbd "C-c C-c") #'emdocs-mode)
            map)
  (if emdocs-mode
      (emdocs-connect (buffer-name))
    (emdocs-disconnect (buffer-name))))

(provide 'emdocs-mode)

                                           (emdocs-get-attached-buffer client)
                                         (buffer-string))))
          "\n"))
          (run-at-time "1 min" nil
                       #'emdocs-send-file-periodically
                       client sock msg)))))

