Function: ediff-other-buffer

ediff-other-buffer is a byte-compiled function defined in ediff-util.el.gz.

Signature

(ediff-other-buffer EXCL-BUFF-LST)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/ediff-util.el.gz
;; Like other-buffer, but prefers visible buffers and ignores temporary or
;; other insignificant buffers (those beginning with "^[ *]").
;; Gets one arg--buffer name or a list of buffer names (it won't return
;; these buffers).
;; EXCL-BUFF-LIST is an exclusion list.
(defun ediff-other-buffer (excl-buff-lst)
  (setq excl-buff-lst (ensure-list excl-buff-lst))
  (let* ((all-buffers (nconc (ediff-get-selected-buffers) (buffer-list)))
	 ;; we compute this the second time because we need to do memq on it
	 ;; later, and nconc above will break it. Either this or use slow
	 ;; append instead of nconc
	 (selected-buffers (ediff-get-selected-buffers))
	 (preferred-buffer (car all-buffers))
	 visible-dired-buffers
	 (excl-buff-name-list
	  (mapcar
	   (lambda (b) (cond ((stringp b) b)
			     ((bufferp b) (buffer-name b))))
	   excl-buff-lst))
	 ;; if at least one buffer on the exclusion list is dired, then force
	 ;; all others to be dired. This is because this means that the user
	 ;; has already chosen a dired buffer before
	 (use-dired-major-mode
	  (cond ((null (ediff-buffer-live-p (car excl-buff-lst))) 'unknown)
		((eq (ediff-with-current-buffer (car excl-buff-lst) major-mode)
		     'dired-mode)
		 'yes)
		(t 'no)))
	 ;; significant-buffers must be visible and not belong
	 ;; to the exclusion list `buff-list'
	 ;; We also exclude temporary buffers, but keep mail and gnus buffers
	 ;; Furthermore, we exclude dired buffers, unless they are the only
	 ;; ones visible (and there are at least two of them).
	 ;; Also, any visible window not on the exclusion list that is first in
	 ;; the buffer list is chosen regardless. (This is because the user
	 ;; clicked on it or did something to distinguish it).
	 (significant-buffers
	  (mapcar
	   (lambda (x)
	     (cond ((member (buffer-name x) excl-buff-name-list) nil)
		   ((memq x selected-buffers) x)
		   ((not (ediff-get-visible-buffer-window x)) nil)
		   ((eq x preferred-buffer) x)
		   ;; if prev selected buffer is dired, look only at
		   ;; dired.
		   ((eq use-dired-major-mode 'yes)
		    (if (eq (ediff-with-current-buffer x major-mode)
			    'dired-mode)
			x nil))
		   ((eq (ediff-with-current-buffer x major-mode)
			'dired-mode)
		    (if (null use-dired-major-mode)
			;; don't know if we must enforce dired.
			;; Remember this buffer in case
			;; dired buffs are the only ones visible.
			(setq visible-dired-buffers
			      (cons x visible-dired-buffers)))
		    ;; skip, if dired is not forced
		    nil)
		   ((memq (ediff-with-current-buffer x major-mode)
			  '(rmail-mode
			    vm-mode
			    gnus-article-mode
			    mh-show-mode))
		    x)
		   ((string-match "^[ *]" (buffer-name x)) nil)
		   ((string= "*scratch*" (buffer-name x)) nil)
		   (t x)))
	   all-buffers))
	 (clean-significant-buffers (delq nil significant-buffers))
	 less-significant-buffers)

    (if (and (null clean-significant-buffers)
	     (> (length visible-dired-buffers) 0))
	(setq clean-significant-buffers visible-dired-buffers))

    (cond (clean-significant-buffers (car clean-significant-buffers))
	  ;; try also buffers that are not displayed in windows
	  ((setq less-significant-buffers
		 (delq nil
		       (mapcar
			(lambda (x)
			  (cond ((member (buffer-name x) excl-buff-name-list)
				 nil)
				((eq use-dired-major-mode 'yes)
				 (if (eq (ediff-with-current-buffer
					     x major-mode)
					 'dired-mode)
				     x nil))
				((eq (ediff-with-current-buffer x major-mode)
				     'dired-mode)
				 nil)
				((string-match "^[ *]" (buffer-name x)) nil)
				((string= "*scratch*" (buffer-name x)) nil)
				(t x)))
			all-buffers)))
	   (car less-significant-buffers))
	  (t "*scratch*"))
    ))