 (require 'url)
 (require 'url-http)
 
+(defvar tern-known-port nil)
+(defvar tern-server nil)
+(defvar tern-explicit-port nil)
+(defvar tern-project-dir nil)
+
 (defun tern-message (fmt &rest objects)
   (apply 'message fmt objects))
 
 (defun tern-req (port doc c)
-  (declare (special url-mime-charset-string url-request-method url-request-data url-show-status))
   (let* ((url-mime-charset-string nil) ; Suppress huge, useless header
          (url-request-method "POST")
          (deactivate-mark nil) ; Prevents json-encode from interfering with shift-selection-mode

         (url (url-parse-make-urlobj "http" nil nil tern-server port "/" nil nil nil)))
    (url-http url #'tern-req-finished (list c))))

;; This is necessary to force proper dynamic binding below, for some reason.
(defvar url-callback-function)

(defun tern-req-finished (c)
  (declare (special url-http-process url-callback-function))
  (let ((is-error (and (consp c) (eq (car c) :error)))
        (found-body (search-forward "\n\n" nil t))
        (deactivate-mark nil))

                   (forward-char 1)))))))

(defun tern-show-argument-hints ()
  (cl-destructuring-bind (paren . type) tern-last-argument-hints
    (let ((parts ())
          (current-arg (tern-find-current-arg paren)))
