Function: emerge-position-region

emerge-position-region is a byte-compiled function defined in emerge.el.gz.

Signature

(emerge-position-region BEG END POS)

Documentation

Attempt to show the region nicely.

If there are min-lines lines above and below the region, then don't do anything. If not, recenter the region to make it so. If that isn't possible, remove context lines evenly from top and bottom so the entire region shows. If that isn't possible, show the top of the region. BEG must be at the beginning of a line.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/emerge.el.gz
(defun emerge-position-region (beg end pos)
  "Attempt to show the region nicely.
If there are min-lines lines above and below the region, then don't do
anything.
If not, recenter the region to make it so.
If that isn't possible, remove context lines evenly from top and bottom
so the entire region shows.
If that isn't possible, show the top of the region.
BEG must be at the beginning of a line."
  ;; First test whether the entire region is visible with
  ;; emerge-min-visible-lines above and below it
  (if (not (and (<= (progn
		      (move-to-window-line emerge-min-visible-lines)
		      (point))
		    beg)
		(<= end (progn
			  (move-to-window-line
			   (- (1+ emerge-min-visible-lines)))
			  (point)))))
      ;; We failed that test, see if it fits at all
      ;; Meanwhile positioning it correctly in case it doesn't fit
      (progn
	(set-window-start (selected-window) beg)
	(if (pos-visible-in-window-p end)
	    ;; Determine the number of lines that the region occupies
	    (let ((lines 0))
	      (while (> end (progn
			      (move-to-window-line lines)
			      (point)))
		(setq lines (1+ lines)))
	      ;; And position the beginning on the right line
	      (goto-char beg)
	      (recenter (/ (1+ (- (1- (window-height))
				  lines))
			   2))))))
  (goto-char pos))