Function: ediff-diff-at-point

ediff-diff-at-point is a byte-compiled function defined in ediff-util.el.gz.

Signature

(ediff-diff-at-point BUF-TYPE &optional POS WHICH-DIFF)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/ediff-util.el.gz
;; find region most related to the current point position (or POS, if given)
;; returns diff number as seen by the user (i.e., 1+ the internal
;; representation)
;; The optional argument WHICH-DIFF can be `after' or `before'.  If `after',
;; find the diff after the point.  If `before', find the diff before the
;; point.  If the point is inside a diff, return that diff.
(defun ediff-diff-at-point (buf-type &optional pos which-diff)
  (let ((buffer (ediff-get-buffer buf-type))
	(ctl-buffer ediff-control-buffer)
	(max-dif-num (1- ediff-number-of-differences))
	(diff-no -1)
	(prev-beg 0)
	(prev-end 0)
	(beg 0)
	(end 0))

    (ediff-with-current-buffer buffer
      (setq pos (or pos (point)))
      (while (and (or (< pos prev-beg) (> pos beg))
		  (< diff-no max-dif-num))
	(setq diff-no (1+ diff-no))
	(setq prev-beg beg
	      prev-end end)
	(setq beg (ediff-get-diff-posn buf-type 'beg diff-no ctl-buffer)
	      end (ediff-get-diff-posn buf-type 'end diff-no ctl-buffer))
	)

      ;; boost diff-no by 1, if past the last diff region
      (if (and (memq which-diff '(after before))
	       (> pos beg) (= diff-no max-dif-num))
	  (setq diff-no (1+ diff-no)))

      (cond ((eq which-diff 'after) (1+ diff-no))
	    ((eq which-diff 'before) diff-no)
	    ((< (abs (count-lines pos (max (point-min) prev-end)))
		(abs (count-lines pos (max (point-min) beg))))
	     diff-no)       ; choose prev difference
	    (t
	     (1+ diff-no))) ; choose next difference
     )))