       (return (funcall c tern-known-port)))
     (unless (buffer-file-name)
       (return (funcall c nil)))
-    (let ((port-file (concat (tern-project-dir) ".tern-port")))
+    (let ((port-file (expand-file-name ".tern-port" (tern-project-dir))))
       (when (file-exists-p port-file)
         (let ((port (string-to-number (with-temp-buffer
                                         (insert-file-contents port-file)

      (let ((project-dir (file-name-directory (buffer-file-name))))
        (loop for cur = project-dir then (file-name-directory (substring cur 0 (1- (length cur))))
              while cur do
              (when (file-exists-p (concat cur ".tern-project"))
                (return (setf project-dir cur))))
        (setf tern-project-dir project-dir))))


  (interactive)
  (tern-run-query (lambda (data _offset)
                    (let* ((file (cdr (assq 'file data)))
                           (found (and file (setf file (expand-file-name (cdr (assq 'file data)) (tern-project-dir)))
                                       (tern-find-position file data))))
                      (if found
                          (progn
