- (if (and (not (integerp selective-display))
- (not (line-move-invisible-p (point))))
- ;; We avoid vertical-motion when possible
- ;; because that has to fontify.
- (if (eobp)
- (if (not noerror)
- (signal 'end-of-buffer nil)
- (setq done t))
- (forward-line 1))
- ;; Otherwise move a more sophisticated way.
- ;; (What's the logic behind this code?)
- (and (zerop (vertical-motion 1))
- (if (not noerror)
- (signal 'end-of-buffer nil)
- (setq done t))))
+ (cond
+ ((eobp)
+ (if (not noerror)
+ (signal 'end-of-buffer nil)
+ (setq done t)))
+ ((and (> arg 1) ;; Use vertical-motion for last move
+ (not (integerp selective-display))
+ (not (line-move-invisible-p (point))))
+ ;; We avoid vertical-motion when possible
+ ;; because that has to fontify.
+ (forward-line 1))
+ ;; Otherwise move a more sophisticated way.
+ ((zerop (vertical-motion 1))
+ (if (not noerror)
+ (signal 'end-of-buffer nil)
+ (setq done t))))