                                         (buffer-string)))))
           (unless (eq port ignore-port)
             (setf tern-known-port port)
-            (return (funcall c port))))))
+            (return (funcall c port nil))))))
     (tern-start-server c)))
 
 (defvar tern-command


(defun tern-start-server (c)
  (let* ((default-directory tern-project-dir)
         (proc (apply #'start-process "Tern" nil tern-command)))
    (set-process-query-on-exit-flag proc nil)
    (set-process-sentinel proc (lambda (_proc _event)
                                 (delete-process proc)
                                 (funcall c nil)))
    (set-process-filter proc (lambda (proc output)
                               (when (string-match "Listening on port \\([0-9][0-9]*\\)" output)
                                 (setf tern-known-port (string-to-number (match-string 1 output)))
                                 (set-process-sentinel proc (lambda (proc _event)
                                                              (delete-process proc)
                                                              (setf tern-known-port nil)))
                                 (set-process-filter proc nil)
                                 (funcall c tern-known-port))))))

(defvar tern-command-generation 0)
(defvar tern-activity-since-command -1)

(defun tern-find-server (c &optional ignore-port)
  (block nil
    (when tern-known-port
      (return (if (consp tern-known-port)
                  (funcall c nil (cdr tern-known-port))
                (funcall c tern-known-port nil))))
    (unless (buffer-file-name)
      (return (funcall c nil "Buffer is not associated with a file")))
    (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
