       (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 ((deactivate-mark nil)
-          (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)
-                                        (buffer-string)))))
-          (unless (eq port ignore-port)
-            (setf tern-known-port port)
-            (return (funcall c port nil))))))
-    (tern-start-server c)))
+    (if tern-explicit-port
+        (funcall c tern-explicit-port nil)
+      (unless (buffer-file-name)
+        (return (funcall c nil "Buffer is not associated with a file")))
+      (let ((deactivate-mark nil)
+            (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)
+                                          (buffer-string)))))
+            (unless (eq port ignore-port)
+              (setf tern-known-port port)
+              (return (funcall c port nil))))))
+      (tern-start-server c))))
 
 (defvar tern-command
   (let* ((script-file (or load-file-name

(defvar tern-last-point-pos nil)

(defvar tern-known-port nil)
(defvar tern-project-dir nil)

(defvar tern-last-completions nil)

                    (with-current-buffer (find-file-noselect (expand-file-name (cdr (assq 'name file)) tern-project-dir))
                      (setf tern-buffer-is-dirty nil))))
                (funcall f data))
               ((not (eq mode :silent)) (tern-message "Request failed: %s" err)))))
     doc)))

(defun tern-send-buffer-to-server ()
