            do (lean-server-send-cmd-async (lean-cmd-replace n (lean-grab-line n)))
            finally (setq lean-changed-lines nil)))
 
-(defun lean-server-visit-current-buffer ()
-  "Send VISIT for the current buffer"
-  (cond ((and (buffer-modified-p)
-              (not lean-global-server-current-file-name))
-         (lean-server-handle-modified-buffer))
-        (t (lean-server-send-cmd-async (lean-cmd-visit)))))
-
 (defun lean-server-check-current-file (&optional file-name)
   "Check lean-global-server-current-file-name
 


(defun lean-server-handle-modified-buffer ()
  "Handle modified buffer when lean-mode start"
  (interactive)
  (when (buffer-file-name)
    (let* ((current-file-name (buffer-file-name))
           (current-directory (file-name-directory current-file-name))
           (temp-prefix (concat (file-name-as-directory current-directory)
                                "lean-temp"))
           (temp-file (lean-server-save-buffer-to-temp-file temp-prefix)))
      (lean-debug "lean-server-handle-modified-buffer: %s => %s"
                         current-file-name
                         temp-file)
      (lean-server-send-cmd-async (lean-cmd-visit temp-file))
      (setq lean-global-server-current-file-name current-file-name)
      (lean-server-send-cmd-async (lean-cmd-wait)
                                  (lambda () (delete-file temp-file))))))

(provide 'lean-server)

  (let ((current-file-name (or file-name (buffer-file-name))))
    (unless (string= lean-global-server-current-file-name
                     current-file-name)
      (lean-server-send-cmd-async (lean-cmd-visit)))))

(defun lean-server-before-send-cmd (cmd)
  "Operations to perform before sending a command."
