   :group 'auto-complete
   (if auto-complete-mode
       (progn
-        (add-hook 'post-command-hook 'ac-on-post-command nil t)
-        (add-hook 'pre-command-hook 'ac-on-pre-command nil t)
+        (funcall ac-setup-function)
+        (add-hook 'post-command-hook 'ac-handle-post-command nil t)
+        (add-hook 'pre-command-hook 'ac-handle-pre-command nil t)
         (run-hooks 'auto-complete-mode-hook))
-    (remove-hook 'post-command-hook 'ac-on-post-command t)
-    (remove-hook 'pre-command-hook 'ac-on-pre-command t)
+    (remove-hook 'post-command-hook 'ac-handle-post-command t)
+    (remove-hook 'pre-command-hook 'ac-handle-pre-command t)
     (ac-abort)))
 
 (define-global-minor-mode global-auto-complete-mode


(defun ac-current-physical-column ()
  "Current physical column. (not logical column)"
  (- (point) (save-excursion (vertical-motion 0) (point))))

(defun ac-on-pre-command ()
  (progn                                ; ignore-errors
    (if (and (not (ac-trigger-command-p))
             (or (not (symbolp this-command))
                 (not (string-match "^ac-" (symbol-name this-command)))))
        (ac-abort))))

(defun ac-on-post-command ()
  (progn                                ; ignore-errors
    (if (and (or ac-auto-start
                 ac-completing)
             (not isearch-mode)
             (ac-trigger-command-p))
        (ac-start))))

(defun auto-complete-mode-maybe ()
  "What buffer `auto-complete-mode' prefers."

                         (overlay-put overlay
                                      'after-string
                                      (concat (overlay-get overlay 'prefix)
                                              (propertize (ac-menu-create-line-string menu string) 'face face)
                                              (overlay-get overlay 'postfix)))))
          (aset overlays
		(if (> direction 0)
		    i
		  (- height i 1))
		overlay)))
      (let ((i 100))
        (mapc (lambda (overlay)
                (overlay-put overlay 'priority i)
