       (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"))
+              (when (file-exists-p (expand-file-name ".tern-project" cur))
                 (return (setf project-dir cur))))
         (setf tern-project-dir project-dir))))
 

  (with-current-buffer (find-file-noselect file)
    (let* ((start (1+ (cdr (assq 'start data))))
           (cx-start (- start (cdr (assq 'contextOffset data))))
           (cx (cdr (assq 'context data))))
      (if (equal (buffer-substring-no-properties cx-start (+ cx-start (length cx))) cx)
          start
        (let (nearest nearest-dist)
          (save-excursion

            (push change (cdr found))))
    (loop for (file . changes) in per-file do
          (setf changes (sort changes (lambda (a b) (> (cdr (assq 'start a)) (cdr (assq 'start b))))))
          (find-file (expand-file-name file (tern-project-dir)))
          (loop for change in changes do
                (let ((start (1+ (cdr (assq 'start change))))
                      (end (1+ (cdr (assq 'end change)))))
