Function: line-move-1
line-move-1 is a byte-compiled function defined in simple.el.gz.
Signature
(line-move-1 ARG &optional NOERROR TO-END)
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
;; This is the guts of next-line and previous-line.
;; Arg says how many lines to move.
;; The value is t if we can move the specified number of lines.
(defun line-move-1 (arg &optional noerror _to-end)
;; Don't run any point-motion hooks, and disregard intangibility,
;; for intermediate positions.
(with-suppressed-warnings ((obsolete inhibit-point-motion-hooks))
(let ((outer-ipmh inhibit-point-motion-hooks)
(inhibit-point-motion-hooks t)
(opoint (point))
(orig-arg arg))
(if (consp temporary-goal-column)
(setq temporary-goal-column (+ (car temporary-goal-column)
(cdr temporary-goal-column))))
(unwind-protect
(progn
(if (not (memq last-command '(next-line previous-line)))
(setq temporary-goal-column
(if (and track-eol (eolp)
;; Don't count beg of empty line as end of line
;; unless we just did explicit end-of-line.
(or (not (bolp)) (eq last-command 'move-end-of-line)))
most-positive-fixnum
(current-column))))
(if (not (or (integerp selective-display)
line-move-ignore-invisible))
;; Use just newline characters.
;; Set ARG to 0 if we move as many lines as requested.
(or (if (> arg 0)
(progn (if (> arg 1) (forward-line (1- arg)))
;; This way of moving forward ARG lines
;; verifies that we have a newline after the last one.
;; It doesn't get confused by intangible text.
(end-of-line)
(if (zerop (forward-line 1))
(setq arg 0)))
(and (zerop (forward-line arg))
(bolp)
(setq arg 0)))
(unless noerror
(signal (if (< arg 0)
'beginning-of-buffer
'end-of-buffer)
nil)))
;; Move by arg lines, but ignore invisible ones.
(let (done)
(while (and (> arg 0) (not done))
;; If the following character is currently invisible,
;; skip all characters with that same `invisible' property value.
(while (and (not (eobp)) (invisible-p (point)))
(goto-char (next-char-property-change (point))))
;; Move a line.
;; We don't use `end-of-line', since we want to escape
;; from field boundaries occurring exactly at point.
(goto-char (constrain-to-field
(let ((inhibit-field-text-motion t))
(line-end-position))
(point) t t
'inhibit-line-move-field-capture))
;; If there's no invisibility here, move over the newline.
(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 (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))))
(unless done
(setq arg (1- arg))))
;; The logic of this is the same as the loop above,
;; it just goes in the other direction.
(while (and (< arg 0) (not done))
;; For completely consistency with the forward-motion
;; case, we should call beginning-of-line here.
;; However, if point is inside a field and on a
;; continued line, the call to (vertical-motion -1)
;; below won't move us back far enough; then we return
;; to the same column in line-move-finish, and point
;; gets stuck -- cyd
(forward-line 0)
(cond
((bobp)
(if (not noerror)
(signal 'beginning-of-buffer nil)
(setq done t)))
((and (< arg -1) ;; Use vertical-motion for last move
(not (integerp selective-display))
(not (invisible-p (1- (point)))))
(forward-line -1))
((zerop (vertical-motion -1))
(if (not noerror)
(signal 'beginning-of-buffer nil)
(setq done t))))
(unless done
(setq arg (1+ arg))
(while (and ;; Don't move over previous invis lines
;; if our target is the middle of this line.
(or (zerop (or goal-column temporary-goal-column))
(< arg 0))
(not (bobp)) (invisible-p (1- (point))))
(goto-char (previous-char-property-change (point))))))))
;; This is the value the function returns.
(= arg 0))
(cond ((> arg 0)
;; If we did not move down as far as desired, at least go
;; to end of line. Be sure to call point-entered and
;; point-left-hooks.
(let* ((npoint (prog1 (line-end-position)
(goto-char opoint)))
(inhibit-point-motion-hooks outer-ipmh))
(goto-char npoint)))
((< arg 0)
;; If we did not move up as far as desired,
;; at least go to beginning of line.
(let* ((npoint (prog1 (line-beginning-position)
(goto-char opoint)))
(inhibit-point-motion-hooks outer-ipmh))
(goto-char npoint)))
(t
(line-move-finish (or goal-column temporary-goal-column)
opoint (> orig-arg 0) (not outer-ipmh))))))))