 (defun tern-find-server (c &optional ignore-port)
   (block nil
     (when tern-known-port
-      (return (funcall c 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)))
+      (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

            (cdr tern-buffer-is-dirty) (max (cdr tern-buffer-is-dirty) end))
    (setf tern-buffer-is-dirty (cons start end)))
  (when (> (- (cdr tern-buffer-is-dirty) (car tern-buffer-is-dirty)) 4000)
    (run-at-time "200 millisec" nil (lambda ()
                                      (when tern-buffer-is-dirty
                                        (setf tern-buffer-is-dirty nil)
                                        (tern-send-buffer-to-server)))))
  (setf tern-last-point-pos nil)
  (when (and tern-last-argument-hints (<= (point) (car tern-last-argument-hints)))
    (setf tern-last-argument-hints nil)))

(defun tern-run-request (f doc)
  (let ((buffer (current-buffer))
        (retrying nil))
    (labels ((callback (port err)
               (if port
                   (tern-req port doc #'runner)
                 (funcall f err nil)))
             (runner (err data)
               (with-current-buffer buffer
                 (cond ((and err (eq (cadar err) 'connection-failed) (not retrying))
