                  (>= current-visual-column menu-width))
             (setq menu-column (- menu-column menu-width))))
       ;; Make a room to show menu at the end of buffer
-      (when (eq (line-end-position) (point-max))
-        (end-of-line)
-        (newline))
+      (forward-line 1)
+      (if (eq line (line-number-at-pos))
+          (newline)
+        (forward-line -1))
       (setq ac-menu (ac-menu-create line menu-column menu-width height ac-menu-direction)))))
 
 (defun ac-cleanup ()


(defun ac-menu-at-wrapped-line ()
  "Return non-nil if current line is long and wrapped to next visual line."
  (eq (line-beginning-position)
      (save-excursion
        (vertical-motion 1)
        (line-beginning-position))))

(defun ac-goto-line (line)
  "Goto `LINE' regarding of narrowing."
  (goto-char (point-min))
  (forward-line (1- line)))

(defun ac-handle-pre-command ()
  (condition-case var

          (window (selected-window))
          menu-visual-column
          current-visual-column)
      (goto-line line)
      (move-to-column column)
      (setq menu-visual-column (ac-current-physical-column))
      (dotimes (i height)
