Function: diff-post-command-hook

diff-post-command-hook is a byte-compiled function defined in diff-mode.el.gz.

Signature

(diff-post-command-hook)

Documentation

Fixup hunk headers if necessary.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/diff-mode.el.gz
(defun diff-post-command-hook ()
  "Fixup hunk headers if necessary."
  (when (consp diff-unhandled-changes)
    (ignore-errors
      (save-excursion
	(goto-char (car diff-unhandled-changes))
	;; Maybe we've cut the end of the hunk before point.
	(if (and (bolp) (not (bobp))) (backward-char 1))
	;; We used to fixup modifs on all the changes, but it turns out that
	;; it's safer not to do it on big changes, e.g. when yanking a big
	;; diff, or when the user edits the header, since we might then
	;; screw up perfectly correct values.  --Stef
	(diff-beginning-of-hunk t)
        (let* ((style (if (looking-at "\\*\\*\\*") 'context))
               (start (line-beginning-position (if (eq style 'context) 3 2)))
               (mid (if (eq style 'context)
                        (save-excursion
                          (re-search-forward diff-context-mid-hunk-header-re
                                             nil t)))))
          (when (and ;; Don't try to fixup changes in the hunk header.
                 (>= (car diff-unhandled-changes) start)
                 ;; Don't try to fixup changes in the mid-hunk header either.
                 (or (not mid)
                     (< (cdr diff-unhandled-changes) (match-beginning 0))
                     (> (car diff-unhandled-changes) (match-end 0)))
                 (save-excursion
		(diff-end-of-hunk nil 'donttrustheader)
                   ;; Don't try to fixup changes past the end of the hunk.
                   (>= (point) (cdr diff-unhandled-changes))))
	  (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
      (setq diff-unhandled-changes nil))))