Function: diff-beginning-of-hunk

diff-beginning-of-hunk is a byte-compiled function defined in diff-mode.el.gz.

Signature

(diff-beginning-of-hunk &optional TRY-HARDER)

Documentation

Move back to the previous hunk beginning, and return its position.

If point is in a file header rather than a hunk, advance to the next hunk if TRY-HARDER is non-nil; otherwise signal an error.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defun diff-beginning-of-hunk (&optional try-harder)
  "Move back to the previous hunk beginning, and return its position.
If point is in a file header rather than a hunk, advance to the
next hunk if TRY-HARDER is non-nil; otherwise signal an error."
  (beginning-of-line)
  (if (looking-at diff-hunk-header-re) ; At hunk header.
      (point)
    (let ((pos (diff--at-diff-header-p))
          (regexp diff-hunk-header-re))
      (cond (pos ; At junk diff header.
             (if try-harder
                 (goto-char pos)
               (error "Can't find the beginning of the hunk")))
            ((re-search-backward regexp nil t)) ; In the middle of a hunk.
            ((re-search-forward regexp nil t) ; At first hunk header.
             (forward-line 0)
             (point))
            (t (error "Can't find the beginning of the hunk"))))))