         (funcall c nil json)))))
 
 (defun tern-project-dir ()
-  (or tern-project-dir
-      (and (not (buffer-file-name)) (setf 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))))
-        (setf tern-project-dir project-dir))))
+        project-dir)))
 
 (defun tern-find-server (c &optional ignore-port)
   (cl-block nil

  (set (make-local-variable 'tern-known-port) nil)
  (set (make-local-variable 'tern-server) "127.0.0.1")
  (set (make-local-variable 'tern-explicit-port) nil)
  (set (make-local-variable 'tern-project-dir) nil)
  (set (make-local-variable 'tern-last-point-pos) nil)
  (set (make-local-variable 'tern-last-completions) nil)
  (set (make-local-variable 'tern-last-argument-hints) nil)

      (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) (with-current-buffer buf (tern-project-dir))))
        (with-current-buffer buf
          (push `((type . "full")
                  (name . ,(tern-project-relative-file))
