 (defvar tern-known-port nil)
 (defvar tern-server nil)
 (defvar tern-explicit-port nil)
-(defvar tern-project-dir nil)
 
 (defun tern-message (fmt &rest objects)
   (apply 'message fmt objects))

      (when (and (not (eq buf (current-buffer)))
                 (buffer-local-value 'tern-mode buf)
                 (buffer-local-value 'tern-buffer-is-dirty buf)
                 (equal tern-project-dir (buffer-local-value 'tern-project-dir buf)))
        (with-current-buffer buf
          (push `((type . "full")
                  (name . ,(tern-project-relative-file))

        (funcall c nil json)))))

(defun tern-project-dir ()
  (or (and (not (buffer-file-name)) "")
      (let ((project-dir (file-name-directory (buffer-file-name))))
        (cl-loop for cur = project-dir then (let ((shorter (file-name-directory (directory-file-name cur))))
                                              (and (< (length shorter) (length cur)) shorter))
                 while cur do
                 (when (file-exists-p (expand-file-name ".tern-project" cur))
                   (cl-return (setf project-dir cur))))
        project-dir)))

(defun tern-find-server (c &optional ignore-port)
  (cl-block nil
