 (defun tern-mode-enable ()
   (set (make-local-variable 'tern-known-port) nil)
   (set (make-local-variable 'tern-project-dir) nil)
+  (set (make-local-variable 'tern-last-point-pos) nil)
   (set (make-local-variable 'tern-last-completions) nil)
+  (set (make-local-variable 'tern-last-argument-hints) nil)
   (set (make-local-variable 'tern-buffer-is-dirty) (buffer-modified-p))
   (make-local-variable 'completion-at-point-functions)
   (push 'tern-completion-at-point completion-at-point-functions)
-  (add-hook 'after-change-functions 'tern-after-change-function t t))
+  (add-hook 'after-change-functions 'tern-after-change t t)
+  (add-hook 'post-command-hook 'tern-post-command t t))
 
 (defun tern-mode-disable ()
   (setf completion-at-point-functions
         (remove 'tern-completion-at-point completion-at-point-functions))
-  (remove-hook 'after-change-functions 'tern-after-change-function t))
+  (remove-hook 'after-change-functions 'tern-after-change t)
+  (remove-hook 'post-command-hook 'tern-post-command t))

                            (file . ,(tern-local-filepath))
                            (end . ,(1- (point))))))))

;; Mode

(defun tern-after-change-function (_start _end _len)
  (setf tern-buffer-is-dirty t))

(defvar tern-mode-keymap (make-sparse-keymap))


                     (setf retrying t)
                     (setf tern-known-port nil)
                     (tern-find-server callback t))
                    ((not silent) (message "Request failed: %s" (cdr err)))))))
    (tern-find-server callback)))

(defun tern-do-complete (data)
