ediff-wind.el 46 KB

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