ediff-wind.el 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. ;;; ediff-wind.el --- window manipulation utilities
  2. ;; Copyright (C) 1994-1997, 2000-2012 Free Software Foundation, Inc.
  3. ;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
  4. ;; Package: ediff
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;; Code:
  18. ;; Compiler pacifier
  19. (defvar icon-title-format)
  20. (defvar top-toolbar-height)
  21. (defvar bottom-toolbar-height)
  22. (defvar left-toolbar-height)
  23. (defvar right-toolbar-height)
  24. (defvar left-toolbar-width)
  25. (defvar right-toolbar-width)
  26. (defvar default-menubar)
  27. (defvar top-gutter)
  28. (defvar frame-icon-title-format)
  29. (defvar ediff-diff-status)
  30. ;; declare-function does not exist in XEmacs
  31. (eval-and-compile
  32. (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
  33. (eval-when-compile
  34. (require 'ediff-util)
  35. (require 'ediff-help))
  36. ;; end pacifier
  37. (require 'ediff-init)
  38. ;; be careful with ediff-tbar
  39. (if (featurep 'xemacs)
  40. (require 'ediff-tbar)
  41. (defun ediff-compute-toolbar-width () 0))
  42. (defgroup ediff-window nil
  43. "Ediff window manipulation."
  44. :prefix "ediff-"
  45. :group 'ediff
  46. :group 'frames)
  47. ;; Determine which window setup function to use based on current window system.
  48. (defun ediff-choose-window-setup-function-automatically ()
  49. (if (ediff-window-display-p)
  50. 'ediff-setup-windows-multiframe
  51. 'ediff-setup-windows-plain))
  52. (defcustom ediff-window-setup-function (ediff-choose-window-setup-function-automatically)
  53. "Function called to set up windows.
  54. Ediff provides a choice of two functions: `ediff-setup-windows-plain', for
  55. doing everything in one frame and `ediff-setup-windows-multiframe', which sets
  56. the control panel in a separate frame. By default, the appropriate function is
  57. chosen automatically depending on the current window system.
  58. However, `ediff-toggle-multiframe' can be used to toggle between the multiframe
  59. display and the single frame display.
  60. If the multiframe function detects that one of the buffers A/B is seen in some
  61. other frame, it will try to keep that buffer in that frame.
  62. If you don't like any of the two provided functions, write your own one.
  63. The basic guidelines:
  64. 1. It should leave the control buffer current and the control window
  65. selected.
  66. 2. It should set `ediff-window-A', `ediff-window-B', `ediff-window-C',
  67. and `ediff-control-window' to contain window objects that display
  68. the corresponding buffers.
  69. 3. It should accept the following arguments:
  70. buffer-A, buffer-B, buffer-C, control-buffer
  71. Buffer C may not be used in jobs that compare only two buffers.
  72. If you plan to do something fancy, take a close look at how the two
  73. provided functions are written."
  74. :type '(choice (const :tag "Multi Frame" ediff-setup-windows-multiframe)
  75. (const :tag "Single Frame" ediff-setup-windows-plain)
  76. (function :tag "Other function"))
  77. :group 'ediff-window)
  78. ;; indicates if we are in a multiframe setup
  79. (ediff-defvar-local ediff-multiframe nil "")
  80. ;; Share of the frame occupied by the merge window (buffer C)
  81. (ediff-defvar-local ediff-merge-window-share 0.45 "")
  82. ;; The control window.
  83. (ediff-defvar-local ediff-control-window nil "")
  84. ;; Official window for buffer A
  85. (ediff-defvar-local ediff-window-A nil "")
  86. ;; Official window for buffer B
  87. (ediff-defvar-local ediff-window-B nil "")
  88. ;; Official window for buffer C
  89. (ediff-defvar-local ediff-window-C nil "")
  90. ;; Ediff's window configuration.
  91. ;; Used to minimize the need to rearrange windows.
  92. (ediff-defvar-local ediff-window-config-saved "" "")
  93. ;; Association between buff-type and ediff-window-*
  94. (defconst ediff-window-alist
  95. '((A . ediff-window-A)
  96. (?A . ediff-window-A)
  97. (B . ediff-window-B)
  98. (?B . ediff-window-B)
  99. (C . ediff-window-C)
  100. (?C . ediff-window-C)))
  101. (defcustom ediff-split-window-function 'split-window-vertically
  102. "The function used to split the main window between buffer-A and buffer-B.
  103. You can set it to a horizontal split instead of the default vertical split
  104. by setting this variable to `split-window-horizontally'.
  105. You can also have your own function to do fancy splits.
  106. This variable has no effect when buffer-A/B are shown in different frames.
  107. In this case, Ediff will use those frames to display these buffers."
  108. :type '(choice
  109. (const :tag "Split vertically" split-window-vertically)
  110. (const :tag "Split horizontally" split-window-horizontally)
  111. function)
  112. :group 'ediff-window)
  113. (defcustom ediff-merge-split-window-function 'split-window-horizontally
  114. "The function used to split the main window between buffer-A and buffer-B.
  115. You can set it to a vertical split instead of the default horizontal split
  116. by setting this variable to `split-window-vertically'.
  117. You can also have your own function to do fancy splits.
  118. This variable has no effect when buffer-A/B/C are shown in different frames.
  119. In this case, Ediff will use those frames to display these buffers."
  120. :type '(choice
  121. (const :tag "Split vertically" split-window-vertically)
  122. (const :tag "Split horizontally" split-window-horizontally)
  123. function)
  124. :group 'ediff-window)
  125. ;; Definitions hidden from the compiler by compat wrappers.
  126. (declare-function ediff-display-pixel-width "ediff-init")
  127. (declare-function ediff-display-pixel-height "ediff-init")
  128. (defconst ediff-control-frame-parameters
  129. (list
  130. '(name . "Ediff")
  131. ;;'(unsplittable . t)
  132. '(minibuffer . nil)
  133. '(user-position . t) ; Emacs only
  134. '(vertical-scroll-bars . nil) ; Emacs only
  135. '(scrollbar-width . 0) ; XEmacs only
  136. '(scrollbar-height . 0) ; XEmacs only
  137. '(menu-bar-lines . 0) ; Emacs only
  138. '(tool-bar-lines . 0) ; Emacs 21+ only
  139. '(left-fringe . 0)
  140. '(right-fringe . 0)
  141. ;; don't lower but auto-raise
  142. '(auto-lower . nil)
  143. '(auto-raise . t)
  144. '(visibility . nil)
  145. ;; make initial frame small to avoid distraction
  146. '(width . 1) '(height . 1)
  147. ;; this blocks queries from window manager as to where to put
  148. ;; ediff's control frame. we put the frame outside the display,
  149. ;; so the initial frame won't jump all over the screen
  150. (cons 'top (if (fboundp 'ediff-display-pixel-height)
  151. (1+ (ediff-display-pixel-height))
  152. 3000))
  153. (cons 'left (if (fboundp 'ediff-display-pixel-width)
  154. (1+ (ediff-display-pixel-width))
  155. 3000))
  156. )
  157. "Frame parameters for displaying Ediff Control Panel.
  158. Used internally---not a user option.")
  159. ;; position of the mouse; used to decide whether to warp the mouse into ctl
  160. ;; frame
  161. (ediff-defvar-local ediff-mouse-pixel-position nil "")
  162. ;; not used for now
  163. (defvar ediff-mouse-pixel-threshold 30
  164. "If the user moves mouse more than this many pixels, Ediff won't warp mouse into control window.")
  165. (defcustom ediff-grab-mouse t
  166. "If t, Ediff will always grab the mouse and put it in the control frame.
  167. If 'maybe, Ediff will do it sometimes, but not after operations that require
  168. relatively long time. If nil, the mouse will be entirely user's
  169. responsibility."
  170. :type 'boolean
  171. :group 'ediff-window)
  172. (defcustom ediff-control-frame-position-function 'ediff-make-frame-position
  173. "Function to call to determine the desired location for the control panel.
  174. Expects three parameters: the control buffer, the desired width and height
  175. of the control frame. It returns an association list
  176. of the form \(\(top . <position>\) \(left . <position>\)\)"
  177. :type 'function
  178. :group 'ediff-window)
  179. (defcustom ediff-control-frame-upward-shift 42
  180. "The upward shift of control frame from the top of buffer A's frame.
  181. Measured in pixels.
  182. This is used by the default control frame positioning function,
  183. `ediff-make-frame-position'. This variable is provided for easy
  184. customization of the default control frame positioning."
  185. :type 'integer
  186. :group 'ediff-window)
  187. (defcustom ediff-narrow-control-frame-leftward-shift (if (featurep 'xemacs) 7 3)
  188. "The leftward shift of control frame from the right edge of buf A's frame.
  189. Measured in characters.
  190. This is used by the default control frame positioning function,
  191. `ediff-make-frame-position' to adjust the position of the control frame
  192. when it shows the short menu. This variable is provided for easy
  193. customization of the default."
  194. :type 'integer
  195. :group 'ediff-window)
  196. (defcustom ediff-wide-control-frame-rightward-shift 7
  197. "The rightward shift of control frame from the left edge of buf A's frame.
  198. Measured in characters.
  199. This is used by the default control frame positioning function,
  200. `ediff-make-frame-position' to adjust the position of the control frame
  201. when it shows the full menu. This variable is provided for easy
  202. customization of the default."
  203. :type 'integer
  204. :group 'ediff-window)
  205. ;; Wide frame display
  206. ;; t means Ediff is using wide display
  207. (ediff-defvar-local ediff-wide-display-p nil "")
  208. ;; keeps frame config for toggling wide display
  209. (ediff-defvar-local ediff-wide-display-orig-parameters nil
  210. "Frame parameters to be restored when the user wants to toggle the wide
  211. display off.")
  212. (ediff-defvar-local ediff-wide-display-frame nil
  213. "Frame to be used for wide display.")
  214. (ediff-defvar-local ediff-make-wide-display-function 'ediff-make-wide-display
  215. "The value is a function that is called to create a wide display.
  216. The function is called without arguments. It should resize the frame in
  217. which buffers A, B, and C are to be displayed, and it should save the old
  218. frame parameters in `ediff-wide-display-orig-parameters'.
  219. The variable `ediff-wide-display-frame' should be set to contain
  220. the frame used for the wide display.")
  221. ;; Frame used for the control panel in a windowing system.
  222. (ediff-defvar-local ediff-control-frame nil "")
  223. (defcustom ediff-prefer-iconified-control-frame nil
  224. "If t, keep control panel iconified when help message is off.
  225. This has effect only on a windowing system.
  226. If t, hitting `?' to toggle control panel off iconifies it.
  227. This is only useful in Emacs and only for certain kinds of window managers,
  228. such as TWM and its derivatives, since the window manager must permit
  229. keyboard input to go into icons. XEmacs completely ignores keyboard input
  230. into icons, regardless of the window manager."
  231. :type 'boolean
  232. :group 'ediff-window)
  233. ;;; Functions
  234. (defun ediff-get-window-by-clicking (wind prev-wind wind-number)
  235. (let (event)
  236. (message
  237. "Select windows by clicking. Please click on Window %d " wind-number)
  238. (while (not (ediff-mouse-event-p (setq event (ediff-read-event))))
  239. (if (sit-for 1) ; if sequence of events, wait till the final word
  240. (beep 1))
  241. (message "Please click on Window %d " wind-number))
  242. (ediff-read-event) ; discard event
  243. (setq wind (if (featurep 'xemacs)
  244. (event-window event)
  245. (posn-window (event-start event))))))
  246. ;; Select the lowest window on the frame.
  247. (defun ediff-select-lowest-window ()
  248. (if (featurep 'xemacs)
  249. (select-window (frame-lowest-window))
  250. (let* ((lowest-window (selected-window))
  251. (bottom-edge (car (cdr (cdr (cdr (window-edges))))))
  252. (last-window (save-excursion
  253. (other-window -1) (selected-window)))
  254. (window-search t))
  255. (while window-search
  256. (let* ((this-window (next-window))
  257. (next-bottom-edge
  258. (car (cdr (cdr (cdr (window-edges this-window)))))))
  259. (if (< bottom-edge next-bottom-edge)
  260. (setq bottom-edge next-bottom-edge
  261. lowest-window this-window))
  262. (select-window this-window)
  263. (when (eq last-window this-window)
  264. (select-window lowest-window)
  265. (setq window-search nil)))))))
  266. ;;; Common window setup routines
  267. ;; Set up the window configuration. If POS is given, set the points to
  268. ;; the beginnings of the buffers.
  269. ;; When 3way comparison is added, this will have to choose the appropriate
  270. ;; setup function based on ediff-job-name
  271. (defun ediff-setup-windows (buffer-A buffer-B buffer-C control-buffer)
  272. ;; Make sure we are not in the minibuffer window when we try to delete
  273. ;; all other windows.
  274. (run-hooks 'ediff-before-setup-windows-hook)
  275. (if (eq (selected-window) (minibuffer-window))
  276. (other-window 1))
  277. ;; in case user did a no-no on a tty
  278. (or (ediff-window-display-p)
  279. (setq ediff-window-setup-function 'ediff-setup-windows-plain))
  280. (or (ediff-keep-window-config control-buffer)
  281. (funcall
  282. (ediff-with-current-buffer control-buffer ediff-window-setup-function)
  283. buffer-A buffer-B buffer-C control-buffer))
  284. (run-hooks 'ediff-after-setup-windows-hook))
  285. ;; Just set up 3 windows.
  286. ;; Usually used without windowing systems
  287. ;; With windowing, we want to use dedicated frames.
  288. (defun ediff-setup-windows-plain (buffer-A buffer-B buffer-C control-buffer)
  289. (ediff-with-current-buffer control-buffer
  290. (setq ediff-multiframe nil))
  291. (if ediff-merge-job
  292. (ediff-setup-windows-plain-merge
  293. buffer-A buffer-B buffer-C control-buffer)
  294. (ediff-setup-windows-plain-compare
  295. buffer-A buffer-B buffer-C control-buffer)))
  296. (defun ediff-setup-windows-plain-merge (buf-A buf-B buf-C control-buffer)
  297. ;; skip dedicated and unsplittable frames
  298. (ediff-destroy-control-frame control-buffer)
  299. (let ((window-min-height 1)
  300. split-window-function
  301. merge-window-share merge-window-lines
  302. wind-A wind-B wind-C)
  303. (ediff-with-current-buffer control-buffer
  304. (setq merge-window-share ediff-merge-window-share
  305. ;; this lets us have local versions of ediff-split-window-function
  306. split-window-function ediff-split-window-function))
  307. (delete-other-windows)
  308. (set-window-dedicated-p (selected-window) nil)
  309. (split-window-vertically)
  310. (ediff-select-lowest-window)
  311. (ediff-setup-control-buffer control-buffer)
  312. ;; go to the upper window and split it betw A, B, and possibly C
  313. (other-window 1)
  314. (setq merge-window-lines
  315. (max 2 (round (* (window-height) merge-window-share))))
  316. (switch-to-buffer buf-A)
  317. (setq wind-A (selected-window))
  318. ;; XEmacs used to have a lot of trouble with display
  319. ;; It did't set things right unless we tell it to sit still
  320. ;; 19.12 seems ok.
  321. ;;(if (featurep 'xemacs) (sit-for 0))
  322. (split-window-vertically (max 2 (- (window-height) merge-window-lines)))
  323. (if (eq (selected-window) wind-A)
  324. (other-window 1))
  325. (setq wind-C (selected-window))
  326. (switch-to-buffer buf-C)
  327. (select-window wind-A)
  328. (funcall split-window-function)
  329. (if (eq (selected-window) wind-A)
  330. (other-window 1))
  331. (switch-to-buffer buf-B)
  332. (setq wind-B (selected-window))
  333. (ediff-with-current-buffer control-buffer
  334. (setq ediff-window-A wind-A
  335. ediff-window-B wind-B
  336. ediff-window-C wind-C))
  337. (ediff-select-lowest-window)
  338. (ediff-setup-control-buffer control-buffer)
  339. ))
  340. ;; This function handles all comparison jobs, including 3way jobs
  341. (defun ediff-setup-windows-plain-compare (buf-A buf-B buf-C control-buffer)
  342. ;; skip dedicated and unsplittable frames
  343. (ediff-destroy-control-frame control-buffer)
  344. (let ((window-min-height 1)
  345. split-window-function wind-width-or-height
  346. three-way-comparison
  347. wind-A-start wind-B-start wind-A wind-B wind-C)
  348. (ediff-with-current-buffer control-buffer
  349. (setq wind-A-start (ediff-overlay-start
  350. (ediff-get-value-according-to-buffer-type
  351. 'A ediff-narrow-bounds))
  352. wind-B-start (ediff-overlay-start
  353. (ediff-get-value-according-to-buffer-type
  354. 'B ediff-narrow-bounds))
  355. ;; this lets us have local versions of ediff-split-window-function
  356. split-window-function ediff-split-window-function
  357. three-way-comparison ediff-3way-comparison-job))
  358. ;; if in minibuffer go somewhere else
  359. (if (save-match-data
  360. (string-match "\*Minibuf-" (buffer-name (window-buffer))))
  361. (select-window (next-window nil 'ignore-minibuf)))
  362. (delete-other-windows)
  363. (set-window-dedicated-p (selected-window) nil)
  364. (split-window-vertically)
  365. (ediff-select-lowest-window)
  366. (ediff-setup-control-buffer control-buffer)
  367. ;; go to the upper window and split it betw A, B, and possibly C
  368. (other-window 1)
  369. (switch-to-buffer buf-A)
  370. (setq wind-A (selected-window))
  371. (if three-way-comparison
  372. (setq wind-width-or-height
  373. (/ (if (eq split-window-function 'split-window-vertically)
  374. (window-height wind-A)
  375. (window-width wind-A))
  376. 3)))
  377. ;; XEmacs used to have a lot of trouble with display
  378. ;; It did't set things right unless we told it to sit still
  379. ;; 19.12 seems ok.
  380. ;;(if (featurep 'xemacs) (sit-for 0))
  381. (funcall split-window-function wind-width-or-height)
  382. (if (eq (selected-window) wind-A)
  383. (other-window 1))
  384. (switch-to-buffer buf-B)
  385. (setq wind-B (selected-window))
  386. (if three-way-comparison
  387. (progn
  388. (funcall split-window-function) ; equally
  389. (if (eq (selected-window) wind-B)
  390. (other-window 1))
  391. (switch-to-buffer buf-C)
  392. (setq wind-C (selected-window))))
  393. (ediff-with-current-buffer control-buffer
  394. (setq ediff-window-A wind-A
  395. ediff-window-B wind-B
  396. ediff-window-C wind-C))
  397. ;; It is unlikely that we will want to implement 3way window comparison.
  398. ;; So, only buffers A and B are used here.
  399. (if ediff-windows-job
  400. (progn
  401. (set-window-start wind-A wind-A-start)
  402. (set-window-start wind-B wind-B-start)))
  403. (ediff-select-lowest-window)
  404. (ediff-setup-control-buffer control-buffer)
  405. ))
  406. ;; dispatch an appropriate window setup function
  407. (defun ediff-setup-windows-multiframe (buf-A buf-B buf-C control-buf)
  408. (ediff-with-current-buffer control-buf
  409. (setq ediff-multiframe t))
  410. (if ediff-merge-job
  411. (ediff-setup-windows-multiframe-merge buf-A buf-B buf-C control-buf)
  412. (ediff-setup-windows-multiframe-compare buf-A buf-B buf-C control-buf)))
  413. (defun ediff-setup-windows-multiframe-merge (buf-A buf-B buf-C control-buf)
  414. ;;; Algorithm:
  415. ;;; 1. Never use frames that have dedicated windows in them---it is bad to
  416. ;;; destroy dedicated windows.
  417. ;;; 2. If A and B are in the same frame but C's frame is different--- use one
  418. ;;; frame for A and B and use a separate frame for C.
  419. ;;; 3. If C's frame is non-existent, then: if the first suitable
  420. ;;; non-dedicated frame is different from A&B's, then use it for C.
  421. ;;; Otherwise, put A,B, and C in one frame.
  422. ;;; 4. If buffers A, B, C are is separate frames, use them to display these
  423. ;;; buffers.
  424. ;; Skip dedicated or iconified frames.
  425. ;; Unsplittable frames are taken care of later.
  426. (ediff-skip-unsuitable-frames 'ok-unsplittable)
  427. (let* ((window-min-height 1)
  428. (wind-A (ediff-get-visible-buffer-window buf-A))
  429. (wind-B (ediff-get-visible-buffer-window buf-B))
  430. (wind-C (ediff-get-visible-buffer-window buf-C))
  431. (frame-A (if wind-A (window-frame wind-A)))
  432. (frame-B (if wind-B (window-frame wind-B)))
  433. (frame-C (if wind-C (window-frame wind-C)))
  434. ;; on wide display, do things in one frame
  435. (force-one-frame
  436. (ediff-with-current-buffer control-buf ediff-wide-display-p))
  437. ;; this lets us have local versions of ediff-split-window-function
  438. (split-window-function
  439. (ediff-with-current-buffer control-buf ediff-split-window-function))
  440. (orig-wind (selected-window))
  441. (orig-frame (selected-frame))
  442. (use-same-frame (or force-one-frame
  443. ;; A and C must be in one frame
  444. (eq frame-A (or frame-C orig-frame))
  445. ;; B and C must be in one frame
  446. (eq frame-B (or frame-C orig-frame))
  447. ;; A or B is not visible
  448. (not (frame-live-p frame-A))
  449. (not (frame-live-p frame-B))
  450. ;; A or B is not suitable for display
  451. (not (ediff-window-ok-for-display wind-A))
  452. (not (ediff-window-ok-for-display wind-B))
  453. ;; A and B in the same frame, and no good frame
  454. ;; for C
  455. (and (eq frame-A frame-B)
  456. (not (frame-live-p frame-C)))
  457. ))
  458. ;; use-same-frame-for-AB implies wind A and B are ok for display
  459. (use-same-frame-for-AB (and (not use-same-frame)
  460. (eq frame-A frame-B)))
  461. (merge-window-share (ediff-with-current-buffer control-buf
  462. ediff-merge-window-share))
  463. merge-window-lines
  464. designated-minibuffer-frame
  465. done-A done-B done-C)
  466. ;; buf-A on its own
  467. (if (and (window-live-p wind-A)
  468. (null use-same-frame) ; implies wind-A is suitable
  469. (null use-same-frame-for-AB))
  470. (progn ; bug A on its own
  471. ;; buffer buf-A is seen in live wind-A
  472. (select-window wind-A)
  473. (delete-other-windows)
  474. (setq wind-A (selected-window))
  475. (setq done-A t)))
  476. ;; buf-B on its own
  477. (if (and (window-live-p wind-B)
  478. (null use-same-frame) ; implies wind-B is suitable
  479. (null use-same-frame-for-AB))
  480. (progn ; buf B on its own
  481. ;; buffer buf-B is seen in live wind-B
  482. (select-window wind-B)
  483. (delete-other-windows)
  484. (setq wind-B (selected-window))
  485. (setq done-B t)))
  486. ;; buf-C on its own
  487. (if (and (window-live-p wind-C)
  488. (ediff-window-ok-for-display wind-C)
  489. (null use-same-frame)) ; buf C on its own
  490. (progn
  491. ;; buffer buf-C is seen in live wind-C
  492. (select-window wind-C)
  493. (delete-other-windows)
  494. (setq wind-C (selected-window))
  495. (setq done-C t)))
  496. (if (and use-same-frame-for-AB ; implies wind A and B are suitable
  497. (window-live-p wind-A))
  498. (progn
  499. ;; wind-A must already be displaying buf-A
  500. (select-window wind-A)
  501. (delete-other-windows)
  502. (setq wind-A (selected-window))
  503. (funcall split-window-function)
  504. (if (eq (selected-window) wind-A)
  505. (other-window 1))
  506. (switch-to-buffer buf-B)
  507. (setq wind-B (selected-window))
  508. (setq done-A t
  509. done-B t)))
  510. (if use-same-frame
  511. (let ((window-min-height 1))
  512. (if (and (eq frame-A frame-B)
  513. (eq frame-B frame-C)
  514. (frame-live-p frame-A))
  515. (select-frame frame-A)
  516. ;; avoid dedicated and non-splittable windows
  517. (ediff-skip-unsuitable-frames))
  518. (delete-other-windows)
  519. (setq merge-window-lines
  520. (max 2 (round (* (window-height) merge-window-share))))
  521. (switch-to-buffer buf-A)
  522. (setq wind-A (selected-window))
  523. (split-window-vertically
  524. (max 2 (- (window-height) merge-window-lines)))
  525. (if (eq (selected-window) wind-A)
  526. (other-window 1))
  527. (setq wind-C (selected-window))
  528. (switch-to-buffer buf-C)
  529. (select-window wind-A)
  530. (funcall split-window-function)
  531. (if (eq (selected-window) wind-A)
  532. (other-window 1))
  533. (switch-to-buffer buf-B)
  534. (setq wind-B (selected-window))
  535. (setq done-A t
  536. done-B t
  537. done-C t)
  538. ))
  539. (or done-A ; Buf A to be set in its own frame,
  540. ;;; or it was set before because use-same-frame = 1
  541. (progn
  542. ;; Buf-A was not set up yet as it wasn't visible,
  543. ;; and use-same-frame = nil, use-same-frame-for-AB = nil
  544. (select-window orig-wind)
  545. (delete-other-windows)
  546. (switch-to-buffer buf-A)
  547. (setq wind-A (selected-window))
  548. ))
  549. (or done-B ; Buf B to be set in its own frame,
  550. ;;; or it was set before because use-same-frame = 1
  551. (progn
  552. ;; Buf-B was not set up yet as it wasn't visible
  553. ;; and use-same-frame = nil, use-same-frame-for-AB = nil
  554. (select-window orig-wind)
  555. (delete-other-windows)
  556. (switch-to-buffer buf-B)
  557. (setq wind-B (selected-window))
  558. ))
  559. (or done-C ; Buf C to be set in its own frame,
  560. ;;; or it was set before because use-same-frame = 1
  561. (progn
  562. ;; Buf-C was not set up yet as it wasn't visible
  563. ;; and use-same-frame = nil
  564. (select-window orig-wind)
  565. (delete-other-windows)
  566. (switch-to-buffer buf-C)
  567. (setq wind-C (selected-window))
  568. ))
  569. (ediff-with-current-buffer control-buf
  570. (setq ediff-window-A wind-A
  571. ediff-window-B wind-B
  572. ediff-window-C wind-C)
  573. (setq frame-A (window-frame ediff-window-A)
  574. designated-minibuffer-frame
  575. (window-frame (minibuffer-window frame-A))))
  576. (ediff-setup-control-frame control-buf designated-minibuffer-frame)
  577. ))
  578. ;; Window setup for all comparison jobs, including 3way comparisons
  579. (defun ediff-setup-windows-multiframe-compare (buf-A buf-B buf-C control-buf)
  580. ;;; Algorithm:
  581. ;;; If a buffer is seen in a frame, use that frame for that buffer.
  582. ;;; If it is not seen, use the current frame.
  583. ;;; If both buffers are not seen, they share the current frame. If one
  584. ;;; of the buffers is not seen, it is placed in the current frame (where
  585. ;;; ediff started). If that frame is displaying the other buffer, it is
  586. ;;; shared between the two buffers.
  587. ;;; However, if we decide to put both buffers in one frame
  588. ;;; and the selected frame isn't splittable, we create a new frame and
  589. ;;; put both buffers there, event if one of this buffers is visible in
  590. ;;; another frame.
  591. ;; Skip dedicated or iconified frames.
  592. ;; Unsplittable frames are taken care of later.
  593. (ediff-skip-unsuitable-frames 'ok-unsplittable)
  594. (let* ((window-min-height 1)
  595. (wind-A (ediff-get-visible-buffer-window buf-A))
  596. (wind-B (ediff-get-visible-buffer-window buf-B))
  597. (wind-C (ediff-get-visible-buffer-window buf-C))
  598. (frame-A (if wind-A (window-frame wind-A)))
  599. (frame-B (if wind-B (window-frame wind-B)))
  600. (frame-C (if wind-C (window-frame wind-C)))
  601. (ctl-frame-exists-p (ediff-with-current-buffer control-buf
  602. (frame-live-p ediff-control-frame)))
  603. ;; on wide display, do things in one frame
  604. (force-one-frame
  605. (ediff-with-current-buffer control-buf ediff-wide-display-p))
  606. ;; this lets us have local versions of ediff-split-window-function
  607. (split-window-function
  608. (ediff-with-current-buffer control-buf ediff-split-window-function))
  609. (three-way-comparison
  610. (ediff-with-current-buffer control-buf ediff-3way-comparison-job))
  611. (orig-wind (selected-window))
  612. (use-same-frame (or force-one-frame
  613. (eq frame-A frame-B)
  614. (not (ediff-window-ok-for-display wind-A))
  615. (not (ediff-window-ok-for-display wind-B))
  616. (if three-way-comparison
  617. (or (eq frame-A frame-C)
  618. (eq frame-B frame-C)
  619. (not (ediff-window-ok-for-display wind-C))
  620. (not (frame-live-p frame-A))
  621. (not (frame-live-p frame-B))
  622. (not (frame-live-p frame-C))))
  623. (and (not (frame-live-p frame-B))
  624. (or ctl-frame-exists-p
  625. (eq frame-A (selected-frame))))
  626. (and (not (frame-live-p frame-A))
  627. (or ctl-frame-exists-p
  628. (eq frame-B (selected-frame))))))
  629. wind-A-start wind-B-start
  630. designated-minibuffer-frame
  631. done-A done-B done-C)
  632. (ediff-with-current-buffer control-buf
  633. (setq wind-A-start (ediff-overlay-start
  634. (ediff-get-value-according-to-buffer-type
  635. 'A ediff-narrow-bounds))
  636. wind-B-start (ediff-overlay-start
  637. (ediff-get-value-according-to-buffer-type
  638. 'B ediff-narrow-bounds))))
  639. (if (and (window-live-p wind-A) (null use-same-frame)) ; buf-A on its own
  640. (progn
  641. ;; buffer buf-A is seen in live wind-A
  642. (select-window wind-A) ; must be displaying buf-A
  643. (delete-other-windows)
  644. (setq wind-A (selected-window))
  645. (setq done-A t)))
  646. (if (and (window-live-p wind-B) (null use-same-frame)) ; buf B on its own
  647. (progn
  648. ;; buffer buf-B is seen in live wind-B
  649. (select-window wind-B) ; must be displaying buf-B
  650. (delete-other-windows)
  651. (setq wind-B (selected-window))
  652. (setq done-B t)))
  653. (if (and (window-live-p wind-C) (null use-same-frame)) ; buf C on its own
  654. (progn
  655. ;; buffer buf-C is seen in live wind-C
  656. (select-window wind-C) ; must be displaying buf-C
  657. (delete-other-windows)
  658. (setq wind-C (selected-window))
  659. (setq done-C t)))
  660. (if use-same-frame
  661. (let (wind-width-or-height) ; this affects 3way setups only
  662. (if (and (eq frame-A frame-B) (frame-live-p frame-A))
  663. (select-frame frame-A)
  664. ;; avoid dedicated and non-splittable windows
  665. (ediff-skip-unsuitable-frames))
  666. (delete-other-windows)
  667. (switch-to-buffer buf-A)
  668. (setq wind-A (selected-window))
  669. (if three-way-comparison
  670. (setq wind-width-or-height
  671. (/
  672. (if (eq split-window-function 'split-window-vertically)
  673. (window-height wind-A)
  674. (window-width wind-A))
  675. 3)))
  676. (funcall split-window-function wind-width-or-height)
  677. (if (eq (selected-window) wind-A)
  678. (other-window 1))
  679. (switch-to-buffer buf-B)
  680. (setq wind-B (selected-window))
  681. (if three-way-comparison
  682. (progn
  683. (funcall split-window-function) ; equally
  684. (if (memq (selected-window) (list wind-A wind-B))
  685. (other-window 1))
  686. (switch-to-buffer buf-C)
  687. (setq wind-C (selected-window))))
  688. (setq done-A t
  689. done-B t
  690. done-C t)
  691. ))
  692. (or done-A ; Buf A to be set in its own frame
  693. ;;; or it was set before because use-same-frame = 1
  694. (progn
  695. ;; Buf-A was not set up yet as it wasn't visible,
  696. ;; and use-same-frame = nil
  697. (select-window orig-wind)
  698. (delete-other-windows)
  699. (switch-to-buffer buf-A)
  700. (setq wind-A (selected-window))
  701. ))
  702. (or done-B ; Buf B to be set in its own frame
  703. ;;; or it was set before because use-same-frame = 1
  704. (progn
  705. ;; Buf-B was not set up yet as it wasn't visible,
  706. ;; and use-same-frame = nil
  707. (select-window orig-wind)
  708. (delete-other-windows)
  709. (switch-to-buffer buf-B)
  710. (setq wind-B (selected-window))
  711. ))
  712. (if three-way-comparison
  713. (or done-C ; Buf C to be set in its own frame
  714. ;;; or it was set before because use-same-frame = 1
  715. (progn
  716. ;; Buf-C was not set up yet as it wasn't visible,
  717. ;; and use-same-frame = nil
  718. (select-window orig-wind)
  719. (delete-other-windows)
  720. (switch-to-buffer buf-C)
  721. (setq wind-C (selected-window))
  722. )))
  723. (ediff-with-current-buffer control-buf
  724. (setq ediff-window-A wind-A
  725. ediff-window-B wind-B
  726. ediff-window-C wind-C)
  727. (setq frame-A (window-frame ediff-window-A)
  728. designated-minibuffer-frame
  729. (window-frame (minibuffer-window frame-A))))
  730. ;; It is unlikely that we'll implement a version of ediff-windows that
  731. ;; would compare 3 windows at once. So, we don't use buffer C here.
  732. (if ediff-windows-job
  733. (progn
  734. (set-window-start wind-A wind-A-start)
  735. (set-window-start wind-B wind-B-start)))
  736. (ediff-setup-control-frame control-buf designated-minibuffer-frame)
  737. ))
  738. ;; skip unsplittable frames and frames that have dedicated windows.
  739. ;; create a new splittable frame if none is found
  740. (defun ediff-skip-unsuitable-frames (&optional ok-unsplittable)
  741. (if (ediff-window-display-p)
  742. (let ((wind-frame (window-frame (selected-window)))
  743. seen-windows)
  744. (while (and (not (memq (selected-window) seen-windows))
  745. (or
  746. (ediff-frame-has-dedicated-windows wind-frame)
  747. (ediff-frame-iconified-p wind-frame)
  748. ;; skip small windows
  749. (< (frame-height wind-frame)
  750. (* 3 window-min-height))
  751. (if ok-unsplittable
  752. nil
  753. (ediff-frame-unsplittable-p wind-frame))))
  754. ;; remember history
  755. (setq seen-windows (cons (selected-window) seen-windows))
  756. ;; try new window
  757. (other-window 1 t)
  758. (setq wind-frame (window-frame (selected-window)))
  759. )
  760. (if (memq (selected-window) seen-windows)
  761. ;; fed up, no appropriate frames
  762. (setq wind-frame (make-frame '((unsplittable)))))
  763. (select-frame wind-frame)
  764. )))
  765. (defun ediff-frame-has-dedicated-windows (frame)
  766. (let (ans)
  767. (walk-windows
  768. (lambda (wind) (if (window-dedicated-p wind)
  769. (setq ans t)))
  770. 'ignore-minibuffer
  771. frame)
  772. ans))
  773. ;; window is ok, if it is only one window on the frame, not counting the
  774. ;; minibuffer, or none of the frame's windows is dedicated.
  775. ;; The idea is that it is bad to destroy dedicated windows while creating an
  776. ;; ediff window setup
  777. (defun ediff-window-ok-for-display (wind)
  778. (and
  779. (window-live-p wind)
  780. (or
  781. ;; only one window
  782. (eq wind (next-window wind 'ignore-minibuffer (window-frame wind)))
  783. ;; none is dedicated (in multiframe setup)
  784. (not (ediff-frame-has-dedicated-windows (window-frame wind)))
  785. )))
  786. ;; Prepare or refresh control frame
  787. (defun ediff-setup-control-frame (ctl-buffer designated-minibuffer-frame)
  788. (let ((window-min-height 1)
  789. ctl-frame-iconified-p dont-iconify-ctl-frame deiconify-ctl-frame
  790. ctl-frame old-ctl-frame lines
  791. ;; user-grabbed-mouse
  792. fheight fwidth adjusted-parameters)
  793. (ediff-with-current-buffer ctl-buffer
  794. (if (and (featurep 'xemacs) (featurep 'menubar))
  795. (set-buffer-menubar nil))
  796. ;;(setq user-grabbed-mouse (ediff-user-grabbed-mouse))
  797. (run-hooks 'ediff-before-setup-control-frame-hook))
  798. (setq old-ctl-frame (ediff-with-current-buffer ctl-buffer ediff-control-frame))
  799. (ediff-with-current-buffer ctl-buffer
  800. (setq ctl-frame (if (frame-live-p old-ctl-frame)
  801. old-ctl-frame
  802. (make-frame ediff-control-frame-parameters))
  803. ediff-control-frame ctl-frame)
  804. ;; protect against undefined face-attribute
  805. (condition-case nil
  806. (if (and (featurep 'emacs) (face-attribute 'mode-line :box))
  807. (set-face-attribute 'mode-line ctl-frame :box nil))
  808. (error)))
  809. (setq ctl-frame-iconified-p (ediff-frame-iconified-p ctl-frame))
  810. (select-frame ctl-frame)
  811. (if (window-dedicated-p (selected-window))
  812. ()
  813. (delete-other-windows)
  814. (switch-to-buffer ctl-buffer))
  815. ;; must be before ediff-setup-control-buffer
  816. ;; just a precaution--we should be in ctl-buffer already
  817. (ediff-with-current-buffer ctl-buffer
  818. (make-local-variable 'frame-title-format)
  819. (make-local-variable 'frame-icon-title-format) ; XEmacs
  820. (make-local-variable 'icon-title-format)) ; Emacs
  821. (ediff-setup-control-buffer ctl-buffer)
  822. (setq dont-iconify-ctl-frame
  823. (not (string= ediff-help-message ediff-brief-help-message)))
  824. (setq deiconify-ctl-frame
  825. (and (eq this-command 'ediff-toggle-help)
  826. dont-iconify-ctl-frame))
  827. ;; 1 more line for the modeline
  828. (setq lines (1+ (count-lines (point-min) (point-max)))
  829. fheight lines
  830. fwidth (max (+ (ediff-help-message-line-length) 2)
  831. (ediff-compute-toolbar-width))
  832. adjusted-parameters
  833. (list
  834. ;; possibly change surrogate minibuffer
  835. (cons 'minibuffer
  836. (minibuffer-window
  837. designated-minibuffer-frame))
  838. (cons 'width fwidth)
  839. (cons 'height fheight)
  840. (cons 'user-position t)
  841. ))
  842. ;; adjust autoraise
  843. (setq adjusted-parameters
  844. (cons (if ediff-use-long-help-message
  845. '(auto-raise . nil)
  846. '(auto-raise . t))
  847. adjusted-parameters))
  848. ;; In XEmacs, buffer menubar needs to be killed before frame parameters
  849. ;; are changed.
  850. (if (ediff-has-toolbar-support-p)
  851. (when (featurep 'xemacs)
  852. (if (ediff-has-gutter-support-p)
  853. (set-specifier top-gutter (list ctl-frame nil)))
  854. (sit-for 0)
  855. (set-specifier top-toolbar-height (list ctl-frame 0))
  856. ;;(set-specifier bottom-toolbar-height (list ctl-frame 0))
  857. (set-specifier left-toolbar-width (list ctl-frame 0))
  858. (set-specifier right-toolbar-width (list ctl-frame 0))))
  859. ;; As a precaution, we call modify frame parameters twice, in
  860. ;; order to make sure that at least once we do it for
  861. ;; a non-iconified frame. (It appears that in the Windows port of
  862. ;; Emacs, one can't modify frame parameters of iconified frames.)
  863. (if (eq system-type 'windows-nt)
  864. (modify-frame-parameters ctl-frame adjusted-parameters))
  865. ;; make or zap toolbar (if not requested)
  866. (ediff-make-bottom-toolbar ctl-frame)
  867. (goto-char (point-min))
  868. (modify-frame-parameters ctl-frame adjusted-parameters)
  869. (make-frame-visible ctl-frame)
  870. ;; This works around a bug in 19.25 and earlier. There, if frame gets
  871. ;; iconified, the current buffer changes to that of the frame that
  872. ;; becomes exposed as a result of this iconification.
  873. ;; So, we make sure the current buffer doesn't change.
  874. (select-frame ctl-frame)
  875. (ediff-refresh-control-frame)
  876. (cond ((and ediff-prefer-iconified-control-frame
  877. (not ctl-frame-iconified-p) (not dont-iconify-ctl-frame))
  878. (iconify-frame ctl-frame))
  879. ((or deiconify-ctl-frame (not ctl-frame-iconified-p))
  880. (raise-frame ctl-frame)))
  881. (set-window-dedicated-p (selected-window) t)
  882. ;; Now move the frame. We must do it separately due to an obscure bug in
  883. ;; XEmacs
  884. (modify-frame-parameters
  885. ctl-frame
  886. (funcall ediff-control-frame-position-function ctl-buffer fwidth fheight))
  887. ;; synchronize so the cursor will move to control frame
  888. ;; per RMS suggestion
  889. (if (ediff-window-display-p)
  890. (let ((count 7))
  891. (sit-for .1)
  892. (while (and (not (frame-visible-p ctl-frame)) (> count 0))
  893. (setq count (1- count))
  894. (sit-for .3))))
  895. (or (ediff-frame-iconified-p ctl-frame)
  896. ;; don't warp the mouse, unless ediff-grab-mouse = t
  897. (ediff-reset-mouse ctl-frame
  898. (or (eq this-command 'ediff-quit)
  899. (not (eq ediff-grab-mouse t)))))
  900. (when (featurep 'xemacs)
  901. (ediff-with-current-buffer ctl-buffer
  902. (make-local-hook 'select-frame-hook)
  903. (add-hook 'select-frame-hook
  904. 'ediff-xemacs-select-frame-hook nil 'local)))
  905. (ediff-with-current-buffer ctl-buffer
  906. (run-hooks 'ediff-after-setup-control-frame-hook))))
  907. (defun ediff-destroy-control-frame (ctl-buffer)
  908. (ediff-with-current-buffer ctl-buffer
  909. (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
  910. (let ((ctl-frame ediff-control-frame))
  911. (if (and (featurep 'xemacs) (featurep 'menubar))
  912. (set-buffer-menubar default-menubar))
  913. (setq ediff-control-frame nil)
  914. (delete-frame ctl-frame))))
  915. (if ediff-multiframe
  916. (ediff-skip-unsuitable-frames))
  917. ;;(ediff-reset-mouse nil)
  918. )
  919. ;; finds a good place to clip control frame
  920. (defun ediff-make-frame-position (ctl-buffer ctl-frame-width ctl-frame-height)
  921. (ediff-with-current-buffer ctl-buffer
  922. (let* ((frame-A (window-frame ediff-window-A))
  923. (frame-A-parameters (frame-parameters frame-A))
  924. (frame-A-top (eval (cdr (assoc 'top frame-A-parameters))))
  925. (frame-A-left (eval (cdr (assoc 'left frame-A-parameters))))
  926. (frame-A-width (frame-width frame-A))
  927. (ctl-frame ediff-control-frame)
  928. horizontal-adjustment upward-adjustment
  929. ctl-frame-top ctl-frame-left)
  930. ;; Multiple control frames are clipped based on the value of
  931. ;; ediff-control-buffer-number. This is done in order not to obscure
  932. ;; other active control panels.
  933. (setq horizontal-adjustment (* 2 ediff-control-buffer-number)
  934. upward-adjustment (* -14 ediff-control-buffer-number))
  935. (setq ctl-frame-top
  936. (- frame-A-top upward-adjustment ediff-control-frame-upward-shift)
  937. ctl-frame-left
  938. (+ frame-A-left
  939. (if ediff-use-long-help-message
  940. (* (ediff-frame-char-width ctl-frame)
  941. (+ ediff-wide-control-frame-rightward-shift
  942. horizontal-adjustment))
  943. (- (* frame-A-width (ediff-frame-char-width frame-A))
  944. (* (ediff-frame-char-width ctl-frame)
  945. (+ ctl-frame-width
  946. ediff-narrow-control-frame-leftward-shift
  947. horizontal-adjustment))))))
  948. (setq ctl-frame-top
  949. (min ctl-frame-top
  950. (- (ediff-display-pixel-height)
  951. (* 2 ctl-frame-height
  952. (ediff-frame-char-height ctl-frame))))
  953. ctl-frame-left
  954. (min ctl-frame-left
  955. (- (ediff-display-pixel-width)
  956. (* ctl-frame-width (ediff-frame-char-width ctl-frame)))))
  957. ;; keep ctl frame within the visible bounds
  958. (setq ctl-frame-top (max ctl-frame-top 1)
  959. ctl-frame-left (max ctl-frame-left 1))
  960. (list (cons 'top ctl-frame-top)
  961. (cons 'left ctl-frame-left))
  962. )))
  963. (defun ediff-xemacs-select-frame-hook ()
  964. (if (and (equal (selected-frame) ediff-control-frame)
  965. (not ediff-use-long-help-message))
  966. (raise-frame ediff-control-frame)))
  967. (defun ediff-make-wide-display ()
  968. "Construct an alist of parameters for the wide display.
  969. Saves the old frame parameters in `ediff-wide-display-orig-parameters'.
  970. The frame to be resized is kept in `ediff-wide-display-frame'.
  971. This function modifies only the left margin and the width of the display.
  972. It assumes that it is called from within the control buffer."
  973. (if (not (fboundp 'ediff-display-pixel-width))
  974. (error "Can't determine display width"))
  975. (let* ((frame-A (window-frame ediff-window-A))
  976. (frame-A-params (frame-parameters frame-A))
  977. (cw (ediff-frame-char-width frame-A))
  978. (wd (- (/ (ediff-display-pixel-width) cw) 5)))
  979. (setq ediff-wide-display-orig-parameters
  980. (list (cons 'left (max 0 (eval (cdr (assoc 'left frame-A-params)))))
  981. (cons 'width (cdr (assoc 'width frame-A-params))))
  982. ediff-wide-display-frame frame-A)
  983. (modify-frame-parameters
  984. frame-A `((left . ,cw) (width . ,wd) (user-position . t)))))
  985. ;; Revise the mode line to display which difference we have selected
  986. ;; Also resets modelines of buffers A/B, since they may be clobbered by
  987. ;; other invocations of Ediff.
  988. (defun ediff-refresh-mode-lines ()
  989. (let (buf-A-state-diff buf-B-state-diff buf-C-state-diff buf-C-state-merge)
  990. (if (ediff-valid-difference-p)
  991. (setq
  992. buf-C-state-diff (ediff-get-state-of-diff ediff-current-difference 'C)
  993. buf-C-state-merge (ediff-get-state-of-merge ediff-current-difference)
  994. buf-A-state-diff (ediff-get-state-of-diff ediff-current-difference 'A)
  995. buf-B-state-diff (ediff-get-state-of-diff ediff-current-difference 'B)
  996. buf-A-state-diff (if buf-A-state-diff
  997. (format "[%s] " buf-A-state-diff)
  998. "")
  999. buf-B-state-diff (if buf-B-state-diff
  1000. (format "[%s] " buf-B-state-diff)
  1001. "")
  1002. buf-C-state-diff (if (and (ediff-buffer-live-p ediff-buffer-C)
  1003. (or buf-C-state-diff buf-C-state-merge))
  1004. (format "[%s%s%s] "
  1005. (or buf-C-state-diff "")
  1006. (if buf-C-state-merge
  1007. (concat " " buf-C-state-merge)
  1008. "")
  1009. (if (ediff-get-state-of-ancestor
  1010. ediff-current-difference)
  1011. " AncestorEmpty"
  1012. "")
  1013. )
  1014. ""))
  1015. (setq buf-A-state-diff ""
  1016. buf-B-state-diff ""
  1017. buf-C-state-diff ""))
  1018. ;; control buffer format
  1019. (setq mode-line-format
  1020. (if (ediff-narrow-control-frame-p)
  1021. (list " " mode-line-buffer-identification)
  1022. (list "-- " mode-line-buffer-identification " Quick Help")))
  1023. ;; control buffer id
  1024. (setq mode-line-buffer-identification
  1025. (if (ediff-narrow-control-frame-p)
  1026. (ediff-make-narrow-control-buffer-id 'skip-name)
  1027. (ediff-make-wide-control-buffer-id)))
  1028. ;; Force mode-line redisplay
  1029. (force-mode-line-update)
  1030. (if (and (ediff-window-display-p) (frame-live-p ediff-control-frame))
  1031. (ediff-refresh-control-frame))
  1032. (ediff-with-current-buffer ediff-buffer-A
  1033. (setq ediff-diff-status buf-A-state-diff)
  1034. (ediff-strip-mode-line-format)
  1035. (setq mode-line-format
  1036. (list " A: " 'ediff-diff-status mode-line-format))
  1037. (force-mode-line-update))
  1038. (ediff-with-current-buffer ediff-buffer-B
  1039. (setq ediff-diff-status buf-B-state-diff)
  1040. (ediff-strip-mode-line-format)
  1041. (setq mode-line-format
  1042. (list " B: " 'ediff-diff-status mode-line-format))
  1043. (force-mode-line-update))
  1044. (if ediff-3way-job
  1045. (ediff-with-current-buffer ediff-buffer-C
  1046. (setq ediff-diff-status buf-C-state-diff)
  1047. (ediff-strip-mode-line-format)
  1048. (setq mode-line-format
  1049. (list " C: " 'ediff-diff-status mode-line-format))
  1050. (force-mode-line-update)))
  1051. (if (ediff-buffer-live-p ediff-ancestor-buffer)
  1052. (ediff-with-current-buffer ediff-ancestor-buffer
  1053. (ediff-strip-mode-line-format)
  1054. ;; we keep the second dummy string in the mode line format of the
  1055. ;; ancestor, since for other buffers Ediff prepends 2 strings and
  1056. ;; ediff-strip-mode-line-format expects that.
  1057. (setq mode-line-format
  1058. (list " Ancestor: "
  1059. (cond ((not (stringp buf-C-state-merge))
  1060. "")
  1061. ((string-match "prefer-A" buf-C-state-merge)
  1062. "[=diff(B)] ")
  1063. ((string-match "prefer-B" buf-C-state-merge)
  1064. "[=diff(A)] ")
  1065. (t ""))
  1066. mode-line-format))))
  1067. ))
  1068. (defun ediff-refresh-control-frame ()
  1069. (if (featurep 'emacs)
  1070. ;; set frame/icon titles for Emacs
  1071. (modify-frame-parameters
  1072. ediff-control-frame
  1073. (list (cons 'title (ediff-make-base-title))
  1074. (cons 'icon-name (ediff-make-narrow-control-buffer-id))
  1075. ))
  1076. ;; set frame/icon titles for XEmacs
  1077. (setq frame-title-format (ediff-make-base-title)
  1078. frame-icon-title-format (ediff-make-narrow-control-buffer-id))
  1079. ;; force an update of the frame title
  1080. (modify-frame-parameters ediff-control-frame '(()))))
  1081. (defun ediff-make-narrow-control-buffer-id (&optional skip-name)
  1082. (concat
  1083. (if skip-name
  1084. " "
  1085. (ediff-make-base-title))
  1086. (cond ((< ediff-current-difference 0)
  1087. (format " _/%d" ediff-number-of-differences))
  1088. ((>= ediff-current-difference ediff-number-of-differences)
  1089. (format " $/%d" ediff-number-of-differences))
  1090. (t
  1091. (format " %d/%d"
  1092. (1+ ediff-current-difference)
  1093. ediff-number-of-differences)))))
  1094. (defun ediff-make-base-title ()
  1095. (concat
  1096. (cdr (assoc 'name ediff-control-frame-parameters))
  1097. ediff-control-buffer-suffix))
  1098. (defun ediff-make-wide-control-buffer-id ()
  1099. (cond ((< ediff-current-difference 0)
  1100. (list (format "%%b At start of %d diffs"
  1101. ediff-number-of-differences)))
  1102. ((>= ediff-current-difference ediff-number-of-differences)
  1103. (list (format "%%b At end of %d diffs"
  1104. ediff-number-of-differences)))
  1105. (t
  1106. (list (format "%%b diff %d of %d"
  1107. (1+ ediff-current-difference)
  1108. ediff-number-of-differences)))))
  1109. ;; If buff is not live, return nil
  1110. (defun ediff-get-visible-buffer-window (buff)
  1111. (if (ediff-buffer-live-p buff)
  1112. (if (featurep 'xemacs)
  1113. (get-buffer-window buff t)
  1114. (get-buffer-window buff 'visible))))
  1115. ;;; Functions to decide when to redraw windows
  1116. (defun ediff-keep-window-config (control-buf)
  1117. (and (eq control-buf (current-buffer))
  1118. (/= (buffer-size) 0)
  1119. (ediff-with-current-buffer control-buf
  1120. (let ((ctl-wind ediff-control-window)
  1121. (A-wind ediff-window-A)
  1122. (B-wind ediff-window-B)
  1123. (C-wind ediff-window-C))
  1124. (and
  1125. (ediff-window-visible-p A-wind)
  1126. (ediff-window-visible-p B-wind)
  1127. ;; if buffer C is defined then take it into account
  1128. (or (not ediff-3way-job)
  1129. (ediff-window-visible-p C-wind))
  1130. (eq (window-buffer A-wind) ediff-buffer-A)
  1131. (eq (window-buffer B-wind) ediff-buffer-B)
  1132. (or (not ediff-3way-job)
  1133. (eq (window-buffer C-wind) ediff-buffer-C))
  1134. (string= ediff-window-config-saved
  1135. (format "%S%S%S%S%S%S%S"
  1136. ctl-wind A-wind B-wind C-wind
  1137. ediff-split-window-function
  1138. (ediff-multiframe-setup-p)
  1139. ediff-wide-display-p)))))))
  1140. (provide 'ediff-wind)
  1141. ;; Local Variables:
  1142. ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
  1143. ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
  1144. ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
  1145. ;; End:
  1146. ;;; ediff-wind.el ends here