ediff-init.el 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  1. ;;; ediff-init.el --- Macros, variables, and defsubsts used by Ediff
  2. ;; Copyright (C) 1994-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. ;; Start compiler pacifier
  19. (defvar ediff-metajob-name)
  20. (defvar ediff-meta-buffer)
  21. (defvar ediff-grab-mouse)
  22. (defvar ediff-mouse-pixel-position)
  23. (defvar ediff-mouse-pixel-threshold)
  24. (defvar ediff-whitespace)
  25. (defvar ediff-multiframe)
  26. (defvar ediff-use-toolbar-p)
  27. (defvar mswindowsx-bitmap-file-path)
  28. ;; end pacifier
  29. (defvar ediff-force-faces nil
  30. "If t, Ediff will think that it is running on a display that supports faces.
  31. This is provided as a temporary relief for users of face-capable displays
  32. that Ediff doesn't know about.")
  33. ;; Are we running as a window application or on a TTY?
  34. (defsubst ediff-device-type ()
  35. (if (featurep 'xemacs)
  36. (device-type (selected-device))
  37. window-system))
  38. ;; in XEmacs: device-type is tty on tty and stream in batch.
  39. (defun ediff-window-display-p ()
  40. (and (ediff-device-type) (not (memq (ediff-device-type) '(tty pc stream)))))
  41. ;; test if supports faces
  42. (defun ediff-has-face-support-p ()
  43. (cond ((ediff-window-display-p))
  44. (ediff-force-faces)
  45. ((ediff-color-display-p))
  46. ((featurep 'emacs) (memq (ediff-device-type) '(pc)))
  47. ((featurep 'xemacs) (memq (ediff-device-type) '(tty pc)))
  48. ))
  49. ;; toolbar support for emacs hasn't been implemented in ediff
  50. (defun ediff-has-toolbar-support-p ()
  51. (if (featurep 'xemacs)
  52. (if (featurep 'toolbar) (console-on-window-system-p))))
  53. (defun ediff-has-gutter-support-p ()
  54. (if (featurep 'xemacs)
  55. (if (featurep 'gutter) (console-on-window-system-p))))
  56. (defun ediff-use-toolbar-p ()
  57. (and (ediff-has-toolbar-support-p) ;Can it do it ?
  58. (boundp 'ediff-use-toolbar-p)
  59. ediff-use-toolbar-p)) ;Does the user want it ?
  60. ;; Defines VAR as an advertised local variable.
  61. ;; Performs a defvar, then executes `make-variable-buffer-local' on
  62. ;; the variable. Also sets the `permanent-local' property,
  63. ;; so that `kill-all-local-variables' (called by major-mode setting
  64. ;; commands) won't destroy Ediff control variables.
  65. ;;
  66. ;; Plagiarized from `emerge-defvar-local' for XEmacs.
  67. (defmacro ediff-defvar-local (var value doc)
  68. "Defines VAR as a local variable."
  69. (declare (indent defun))
  70. `(progn
  71. (defvar ,var ,value ,doc)
  72. (make-variable-buffer-local ',var)
  73. (put ',var 'permanent-local t)))
  74. ;; Variables that control each Ediff session---local to the control buffer.
  75. ;; Mode variables
  76. ;; The buffer in which the A variant is stored.
  77. (ediff-defvar-local ediff-buffer-A nil "")
  78. ;; The buffer in which the B variant is stored.
  79. (ediff-defvar-local ediff-buffer-B nil "")
  80. ;; The buffer in which the C variant is stored or where the merge buffer lives.
  81. (ediff-defvar-local ediff-buffer-C nil "")
  82. ;; Ancestor buffer
  83. (ediff-defvar-local ediff-ancestor-buffer nil "")
  84. ;; The Ediff control buffer
  85. (ediff-defvar-local ediff-control-buffer nil "")
  86. (ediff-defvar-local ediff-temp-indirect-buffer nil
  87. "If t, the buffer is a temporary indirect buffer.
  88. It needs to be killed when we quit the session.")
  89. ;; Association between buff-type and ediff-buffer-*
  90. (defconst ediff-buffer-alist
  91. '((?A . ediff-buffer-A)
  92. (?B . ediff-buffer-B)
  93. (?C . ediff-buffer-C)))
  94. ;;; Macros
  95. (defmacro ediff-odd-p (arg)
  96. `(eq (logand ,arg 1) 1))
  97. (defmacro ediff-buffer-live-p (buf)
  98. `(and ,buf (get-buffer ,buf) (buffer-name (get-buffer ,buf))))
  99. (defmacro ediff-get-buffer (arg)
  100. `(cond ((eq ,arg 'A) ediff-buffer-A)
  101. ((eq ,arg 'B) ediff-buffer-B)
  102. ((eq ,arg 'C) ediff-buffer-C)
  103. ((eq ,arg 'Ancestor) ediff-ancestor-buffer)
  104. ))
  105. (defmacro ediff-get-value-according-to-buffer-type (buf-type list)
  106. `(cond ((eq ,buf-type 'A) (nth 0 ,list))
  107. ((eq ,buf-type 'B) (nth 1 ,list))
  108. ((eq ,buf-type 'C) (nth 2 ,list))
  109. ))
  110. (defmacro ediff-char-to-buftype (arg)
  111. `(cond ((memq ,arg '(?a ?A)) 'A)
  112. ((memq ,arg '(?b ?B)) 'B)
  113. ((memq ,arg '(?c ?C)) 'C)
  114. ))
  115. ;; A-list is supposed to be of the form (A . symb) (B . symb)...)
  116. ;; where the first part of any association is a buffer type and the second is
  117. ;; an appropriate symbol. Given buffer-type, this function returns the
  118. ;; symbol. This is used to avoid using `intern'
  119. (defsubst ediff-get-symbol-from-alist (buf-type alist)
  120. (cdr (assoc buf-type alist)))
  121. (defconst ediff-difference-vector-alist
  122. '((A . ediff-difference-vector-A)
  123. (B . ediff-difference-vector-B)
  124. (C . ediff-difference-vector-C)
  125. (Ancestor . ediff-difference-vector-Ancestor)))
  126. (defmacro ediff-get-difference (n buf-type)
  127. `(aref
  128. (symbol-value
  129. (ediff-get-symbol-from-alist
  130. ,buf-type ediff-difference-vector-alist))
  131. ,n))
  132. ;; Tell if it has been previously determined that the region has
  133. ;; no diffs other than the white space and newlines
  134. ;; The argument, N, is the diff region number used by Ediff to index the
  135. ;; diff vector. It is 1 less than the number seen by the user.
  136. ;; Returns:
  137. ;; t if the diffs are whitespace in all buffers
  138. ;; 'A (in 3-buf comparison only) if there are only whitespace
  139. ;; diffs in bufs B and C
  140. ;; 'B (in 3-buf comparison only) if there are only whitespace
  141. ;; diffs in bufs A and C
  142. ;; 'C (in 3-buf comparison only) if there are only whitespace
  143. ;; diffs in bufs A and B
  144. ;;
  145. ;; A Difference Vector has the form:
  146. ;; [diff diff diff ...]
  147. ;; where each diff has the form:
  148. ;; [overlay fine-diff-vector no-fine-diffs-flag state-of-difference]
  149. ;; fine-diff-vector is a vector [fine-diff fine-diff fine-diff ...]
  150. ;; no-fine-diffs-flag says if there are fine differences.
  151. ;; state-of-difference is A, B, C, or nil, indicating which buffer is
  152. ;; different from the other two (used only in 3-way jobs).
  153. (defmacro ediff-no-fine-diffs-p (n)
  154. `(aref (ediff-get-difference ,n 'A) 2))
  155. (defmacro ediff-get-diff-overlay-from-diff-record (diff-rec)
  156. `(aref ,diff-rec 0))
  157. (defmacro ediff-get-diff-overlay (n buf-type)
  158. `(ediff-get-diff-overlay-from-diff-record
  159. (ediff-get-difference ,n ,buf-type)))
  160. (defmacro ediff-get-fine-diff-vector-from-diff-record (diff-rec)
  161. `(aref ,diff-rec 1))
  162. (defmacro ediff-set-fine-diff-vector (n buf-type fine-vec)
  163. `(aset (ediff-get-difference ,n ,buf-type) 1 ,fine-vec))
  164. (defmacro ediff-get-state-of-diff (n buf-type)
  165. `(if (ediff-buffer-live-p ediff-buffer-C)
  166. (aref (ediff-get-difference ,n ,buf-type) 3)))
  167. (defmacro ediff-set-state-of-diff (n buf-type val)
  168. `(aset (ediff-get-difference ,n ,buf-type) 3 ,val))
  169. (defmacro ediff-get-state-of-merge (n)
  170. `(if ediff-state-of-merge
  171. (aref (aref ediff-state-of-merge ,n) 0)))
  172. (defmacro ediff-set-state-of-merge (n val)
  173. `(if ediff-state-of-merge
  174. (aset (aref ediff-state-of-merge ,n) 0 ,val)))
  175. (defmacro ediff-get-state-of-ancestor (n)
  176. `(if ediff-state-of-merge
  177. (aref (aref ediff-state-of-merge ,n) 1)))
  178. ;; if flag is t, puts a mark on diff region saying that
  179. ;; the differences are in white space only. If flag is nil,
  180. ;; the region is marked as essential (i.e., differences are
  181. ;; not just in the white space and newlines.)
  182. (defmacro ediff-mark-diff-as-space-only (n flag)
  183. `(aset (ediff-get-difference ,n 'A) 2 ,flag))
  184. (defmacro ediff-get-fine-diff-vector (n buf-type)
  185. `(ediff-get-fine-diff-vector-from-diff-record
  186. (ediff-get-difference ,n ,buf-type)))
  187. ;; Macro to switch to BUFFER, evaluate BODY, returns to original buffer.
  188. ;; Doesn't save the point and mark.
  189. ;; This is `with-current-buffer' with the added test for live buffers."
  190. (defmacro ediff-with-current-buffer (buffer &rest body)
  191. "Evaluates BODY in BUFFER."
  192. (declare (indent 1) (debug (form body)))
  193. `(if (ediff-buffer-live-p ,buffer)
  194. (save-current-buffer
  195. (set-buffer ,buffer)
  196. ,@body)
  197. (or (eq this-command 'ediff-quit)
  198. (error ediff-KILLED-VITAL-BUFFER))
  199. ))
  200. (defsubst ediff-multiframe-setup-p ()
  201. (and (ediff-window-display-p) ediff-multiframe))
  202. (defmacro ediff-narrow-control-frame-p ()
  203. `(and (ediff-multiframe-setup-p)
  204. (equal ediff-help-message ediff-brief-message-string)))
  205. (defmacro ediff-3way-comparison-job ()
  206. `(memq
  207. ediff-job-name
  208. '(ediff-files3 ediff-buffers3)))
  209. (ediff-defvar-local ediff-3way-comparison-job nil "")
  210. (defmacro ediff-merge-job ()
  211. `(memq
  212. ediff-job-name
  213. '(ediff-merge-files
  214. ediff-merge-buffers
  215. ediff-merge-files-with-ancestor
  216. ediff-merge-buffers-with-ancestor
  217. ediff-merge-revisions
  218. ediff-merge-revisions-with-ancestor)))
  219. (ediff-defvar-local ediff-merge-job nil "")
  220. (defmacro ediff-patch-job ()
  221. `(eq ediff-job-name 'epatch))
  222. (defmacro ediff-merge-with-ancestor-job ()
  223. `(memq
  224. ediff-job-name
  225. '(ediff-merge-files-with-ancestor
  226. ediff-merge-buffers-with-ancestor
  227. ediff-merge-revisions-with-ancestor)))
  228. (ediff-defvar-local ediff-merge-with-ancestor-job nil "")
  229. (defmacro ediff-3way-job ()
  230. `(or ediff-3way-comparison-job ediff-merge-job))
  231. (ediff-defvar-local ediff-3way-job nil "")
  232. ;; A diff3 job is like a 3way job, but ediff-merge doesn't require the use
  233. ;; of diff3.
  234. (defmacro ediff-diff3-job ()
  235. `(or ediff-3way-comparison-job
  236. ediff-merge-with-ancestor-job))
  237. (ediff-defvar-local ediff-diff3-job nil "")
  238. (defmacro ediff-windows-job ()
  239. `(memq ediff-job-name '(ediff-windows-wordwise ediff-windows-linewise)))
  240. (ediff-defvar-local ediff-windows-job nil "")
  241. (defmacro ediff-word-mode-job ()
  242. `(memq ediff-job-name '(ediff-windows-wordwise ediff-regions-wordwise)))
  243. (ediff-defvar-local ediff-word-mode-job nil "")
  244. (defmacro ediff-narrow-job ()
  245. `(memq ediff-job-name '(ediff-windows-wordwise
  246. ediff-regions-wordwise
  247. ediff-windows-linewise
  248. ediff-regions-linewise)))
  249. (ediff-defvar-local ediff-narrow-job nil "")
  250. ;; Note: ediff-merge-directory-revisions-with-ancestor is not treated as an
  251. ;; ancestor metajob, since it behaves differently.
  252. (defsubst ediff-ancestor-metajob (&optional metajob)
  253. (memq (or metajob ediff-metajob-name)
  254. '(ediff-merge-directories-with-ancestor
  255. ediff-merge-filegroups-with-ancestor)))
  256. (defsubst ediff-revision-metajob (&optional metajob)
  257. (memq (or metajob ediff-metajob-name)
  258. '(ediff-directory-revisions
  259. ediff-merge-directory-revisions
  260. ediff-merge-directory-revisions-with-ancestor)))
  261. (defsubst ediff-patch-metajob (&optional metajob)
  262. (memq (or metajob ediff-metajob-name)
  263. '(ediff-multifile-patch)))
  264. ;; metajob involving only one group of files, such as multipatch or directory
  265. ;; revision
  266. (defsubst ediff-one-filegroup-metajob (&optional metajob)
  267. (or (ediff-revision-metajob metajob)
  268. (ediff-patch-metajob metajob)
  269. ;; add more here
  270. ))
  271. ;; jobs suitable for the operation of collecting diffs into a multifile patch
  272. (defsubst ediff-collect-diffs-metajob (&optional metajob)
  273. (memq (or metajob ediff-metajob-name)
  274. '(ediff-directories
  275. ediff-merge-directories
  276. ediff-merge-directories-with-ancestor
  277. ediff-directory-revisions
  278. ediff-merge-directory-revisions
  279. ediff-merge-directory-revisions-with-ancestor
  280. ;; add more here
  281. )))
  282. (defsubst ediff-merge-metajob (&optional metajob)
  283. (memq (or metajob ediff-metajob-name)
  284. '(ediff-merge-directories
  285. ediff-merge-directories-with-ancestor
  286. ediff-merge-directory-revisions
  287. ediff-merge-directory-revisions-with-ancestor
  288. ediff-merge-filegroups-with-ancestor
  289. ;; add more here
  290. )))
  291. (defsubst ediff-metajob3 (&optional metajob)
  292. (memq (or metajob ediff-metajob-name)
  293. '(ediff-merge-directories-with-ancestor
  294. ediff-merge-filegroups-with-ancestor
  295. ediff-directories3
  296. ediff-filegroups3)))
  297. (defsubst ediff-comparison-metajob3 (&optional metajob)
  298. (memq (or metajob ediff-metajob-name)
  299. '(ediff-directories3 ediff-filegroups3)))
  300. ;; with no argument, checks if we are in ediff-control-buffer
  301. ;; with argument, checks if we are in ediff-meta-buffer
  302. (defun ediff-in-control-buffer-p (&optional meta-buf-p)
  303. (and (boundp 'ediff-control-buffer)
  304. (eq (if meta-buf-p ediff-meta-buffer ediff-control-buffer)
  305. (current-buffer))))
  306. (defsubst ediff-barf-if-not-control-buffer (&optional meta-buf-p)
  307. (or (ediff-in-control-buffer-p meta-buf-p)
  308. (error "%S: This command runs in Ediff Control Buffer only!"
  309. this-command)))
  310. (defgroup ediff-highlighting nil
  311. "Highlighting of difference regions in Ediff."
  312. :prefix "ediff-"
  313. :group 'ediff)
  314. (defgroup ediff-merge nil
  315. "Merging utilities."
  316. :prefix "ediff-"
  317. :group 'ediff)
  318. (defgroup ediff-hook nil
  319. "Hooks run by Ediff."
  320. :prefix "ediff-"
  321. :group 'ediff)
  322. ;; Hook variables
  323. (defcustom ediff-before-setup-hook nil
  324. "Hooks to run before Ediff begins to set up windows and buffers.
  325. This hook can be used to save the previous window config, which can be restored
  326. on ediff-quit or ediff-suspend."
  327. :type 'hook
  328. :group 'ediff-hook)
  329. (defcustom ediff-before-setup-windows-hook nil
  330. "Hooks to run before Ediff sets its window configuration.
  331. This hook is run every time when Ediff arranges its windows.
  332. This happens each time Ediff detects that the windows were messed up by the
  333. user."
  334. :type 'hook
  335. :group 'ediff-hook)
  336. (defcustom ediff-after-setup-windows-hook nil
  337. "Hooks to run after Ediff sets its window configuration.
  338. This can be used to set up control window or icon in a desired place."
  339. :type 'hook
  340. :group 'ediff-hook)
  341. (defcustom ediff-before-setup-control-frame-hook nil
  342. "Hooks run before setting up the frame to display Ediff Control Panel.
  343. Can be used to change control frame parameters to position it where it
  344. is desirable."
  345. :type 'hook
  346. :group 'ediff-hook)
  347. (defcustom ediff-after-setup-control-frame-hook nil
  348. "Hooks run after setting up the frame to display Ediff Control Panel.
  349. Can be used to move the frame where it is desired."
  350. :type 'hook
  351. :group 'ediff-hook)
  352. (defcustom ediff-startup-hook nil
  353. "Hooks to run in the control buffer after Ediff has been set up and is ready for the job."
  354. :type 'hook
  355. :group 'ediff-hook)
  356. (defcustom ediff-select-hook nil
  357. "Hooks to run after a difference has been selected."
  358. :type 'hook
  359. :group 'ediff-hook)
  360. (defcustom ediff-unselect-hook nil
  361. "Hooks to run after a difference has been unselected."
  362. :type 'hook
  363. :group 'ediff-hook)
  364. (defcustom ediff-prepare-buffer-hook nil
  365. "Hooks run after buffers A, B, and C are set up.
  366. For each buffer, the hooks are run with that buffer made current."
  367. :type 'hook
  368. :group 'ediff-hook)
  369. (defcustom ediff-load-hook nil
  370. "Hook run after Ediff is loaded. Can be used to change defaults."
  371. :type 'hook
  372. :group 'ediff-hook)
  373. (defcustom ediff-mode-hook nil
  374. "Hook run just after ediff-mode is set up in the control buffer.
  375. This is done before any windows or frames are created. One can use it to
  376. set local variables that determine how the display looks like."
  377. :type 'hook
  378. :group 'ediff-hook)
  379. (defcustom ediff-keymap-setup-hook nil
  380. "Hook run just after the default bindings in Ediff keymap are set up."
  381. :type 'hook
  382. :group 'ediff-hook)
  383. (defcustom ediff-display-help-hook nil
  384. "Hooks run after preparing the help message."
  385. :type 'hook
  386. :group 'ediff-hook)
  387. (defcustom ediff-suspend-hook nil
  388. "Hooks to run in the Ediff control buffer when Ediff is suspended."
  389. :type 'hook
  390. :group 'ediff-hook)
  391. (defcustom ediff-quit-hook nil
  392. "Hooks to run in the Ediff control buffer after finishing Ediff."
  393. :type 'hook
  394. :group 'ediff-hook)
  395. (defcustom ediff-cleanup-hook nil
  396. "Hooks to run on exiting Ediff but before killing the control and variant buffers."
  397. :type 'hook
  398. :group 'ediff-hook)
  399. ;; Error messages
  400. (defconst ediff-KILLED-VITAL-BUFFER
  401. "You have killed a vital Ediff buffer---you must leave Ediff now!")
  402. (defconst ediff-NO-DIFFERENCES
  403. "Sorry, comparison of identical variants is not what I am made for...")
  404. (defconst ediff-BAD-DIFF-NUMBER
  405. ;; %S stands for this-command, %d - diff number, %d - max diff
  406. "%S: Bad diff region number, %d. Valid numbers are 1 to %d")
  407. (defconst ediff-BAD-INFO (format "
  408. *** The Info file for Ediff, a part of the standard distribution
  409. *** of %sEmacs, does not seem to be properly installed.
  410. ***
  411. *** Please contact your system administrator. "
  412. (if (featurep 'xemacs) "X" "")))
  413. ;; Selective browsing
  414. (ediff-defvar-local ediff-skip-diff-region-function 'ediff-show-all-diffs
  415. "Function that determines the next/previous diff region to show.
  416. Should return t for regions to be ignored and nil otherwise.
  417. This function gets a region number as an argument. The region number
  418. is the one used internally by Ediff. It is 1 less than the number seen
  419. by the user.")
  420. (ediff-defvar-local ediff-hide-regexp-matches-function
  421. 'ediff-hide-regexp-matches
  422. "Function to use in determining which regions to hide.
  423. See the documentation string of `ediff-hide-regexp-matches' for details.")
  424. (ediff-defvar-local ediff-focus-on-regexp-matches-function
  425. 'ediff-focus-on-regexp-matches
  426. "Function to use in determining which regions to focus on.
  427. See the documentation string of `ediff-focus-on-regexp-matches' for details.")
  428. ;; Regexp that determines buf A regions to focus on when skipping to diff
  429. (ediff-defvar-local ediff-regexp-focus-A "" "")
  430. ;; Regexp that determines buf B regions to focus on when skipping to diff
  431. (ediff-defvar-local ediff-regexp-focus-B "" "")
  432. ;; Regexp that determines buf C regions to focus on when skipping to diff
  433. (ediff-defvar-local ediff-regexp-focus-C "" "")
  434. ;; connective that determines whether to focus regions that match both or
  435. ;; one of the regexps
  436. (ediff-defvar-local ediff-focus-regexp-connective 'and "")
  437. ;; Regexp that determines buf A regions to ignore when skipping to diff
  438. (ediff-defvar-local ediff-regexp-hide-A "" "")
  439. ;; Regexp that determines buf B regions to ignore when skipping to diff
  440. (ediff-defvar-local ediff-regexp-hide-B "" "")
  441. ;; Regexp that determines buf C regions to ignore when skipping to diff
  442. (ediff-defvar-local ediff-regexp-hide-C "" "")
  443. ;; connective that determines whether to hide regions that match both or
  444. ;; one of the regexps
  445. (ediff-defvar-local ediff-hide-regexp-connective 'and "")
  446. ;;; Copying difference regions between buffers.
  447. ;; A list of killed diffs.
  448. ;; A diff is saved here if it is replaced by a diff
  449. ;; from another buffer. This alist has the form:
  450. ;; \((num (buff-object . diff) (buff-object . diff) (buff-object . diff)) ...),
  451. ;; where some buffer-objects may be missing.
  452. (ediff-defvar-local ediff-killed-diffs-alist nil "")
  453. ;; Syntax table to use in ediff-forward-word-function
  454. ;; This is chosen by a heuristic. The important thing is for all buffers to
  455. ;; have the same syntax table. Which is not too important.
  456. (ediff-defvar-local ediff-syntax-table nil "")
  457. ;; Highlighting
  458. (defcustom ediff-before-flag-bol (if (featurep 'xemacs) (make-glyph "->>") "->>")
  459. "Flag placed before a highlighted block of differences, if block starts at beginning of a line."
  460. :type 'string
  461. :tag "Region before-flag at beginning of line"
  462. :group 'ediff)
  463. (defcustom ediff-after-flag-eol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
  464. "Flag placed after a highlighted block of differences, if block ends at end of a line."
  465. :type 'string
  466. :tag "Region after-flag at end of line"
  467. :group 'ediff)
  468. (defcustom ediff-before-flag-mol (if (featurep 'xemacs) (make-glyph "->>") "->>")
  469. "Flag placed before a highlighted block of differences, if block starts in mid-line."
  470. :type 'string
  471. :tag "Region before-flag in the middle of line"
  472. :group 'ediff)
  473. (defcustom ediff-after-flag-mol (if (featurep 'xemacs) (make-glyph "<<-") "<<-")
  474. "Flag placed after a highlighted block of differences, if block ends in mid-line."
  475. :type 'string
  476. :tag "Region after-flag in the middle of line"
  477. :group 'ediff)
  478. (defcustom ediff-use-faces t
  479. "If t, differences are highlighted using faces, if device supports faces.
  480. If nil, differences are highlighted using ASCII flags, ediff-before-flag
  481. and ediff-after-flag. On a non-window system, differences are always
  482. highlighted using ASCII flags."
  483. :type 'boolean
  484. :group 'ediff-highlighting)
  485. (ediff-defvar-local ediff-use-faces t "")
  486. ;; this indicates that diff regions are word-size, so fine diffs are
  487. ;; permanently nixed; used in ediff-windows-wordwise and ediff-regions-wordwise
  488. (ediff-defvar-local ediff-word-mode nil "")
  489. ;; Name of the job (ediff-files, ediff-windows, etc.)
  490. (ediff-defvar-local ediff-job-name nil "")
  491. ;; Narrowing and ediff-region/windows support
  492. ;; This is a list (overlay-A overlay-B overlay-C)
  493. ;; If set, Ediff compares only those parts of buffers A/B/C that lie within
  494. ;; the bounds of these overlays.
  495. (ediff-defvar-local ediff-narrow-bounds nil "")
  496. ;; List (overlay-A overlay-B overlay-C), where each overlay spans the
  497. ;; entire corresponding buffer.
  498. (ediff-defvar-local ediff-wide-bounds nil "")
  499. ;; Current visibility boundaries in buffers A, B, and C.
  500. ;; This is also a list of overlays. When the user toggles narrow/widen,
  501. ;; this list changes from ediff-wide-bounds to ediff-narrow-bounds.
  502. ;; and back.
  503. (ediff-defvar-local ediff-visible-bounds nil "")
  504. (ediff-defvar-local ediff-start-narrowed t
  505. "Non-nil means start narrowed, if doing ediff-windows-* or ediff-regions-*")
  506. (ediff-defvar-local ediff-quit-widened t
  507. "*Non-nil means: when finished, Ediff widens buffers A/B.
  508. Actually, Ediff restores the scope of visibility that existed at startup.")
  509. (defcustom ediff-keep-variants t
  510. "nil means prompt to remove unmodified buffers A/B/C at session end.
  511. Supplying a prefix argument to the quit command `q' temporarily reverses the
  512. meaning of this variable."
  513. :type 'boolean
  514. :group 'ediff)
  515. (defcustom ediff-highlight-all-diffs t
  516. "If nil, only the selected differences are highlighted.
  517. Otherwise, all difference regions are highlighted, but the selected region is
  518. shown in brighter colors."
  519. :type 'boolean
  520. :group 'ediff-highlighting)
  521. (ediff-defvar-local ediff-highlight-all-diffs t "")
  522. ;; The suffix of the control buffer name.
  523. (ediff-defvar-local ediff-control-buffer-suffix nil "")
  524. ;; Same as ediff-control-buffer-suffix, but without <,>.
  525. ;; It's a number rather than string.
  526. (ediff-defvar-local ediff-control-buffer-number nil "")
  527. ;; The original values of ediff-protected-variables for buffer A
  528. (ediff-defvar-local ediff-buffer-values-orig-A nil "")
  529. ;; The original values of ediff-protected-variables for buffer B
  530. (ediff-defvar-local ediff-buffer-values-orig-B nil "")
  531. ;; The original values of ediff-protected-variables for buffer C
  532. (ediff-defvar-local ediff-buffer-values-orig-C nil "")
  533. ;; The original values of ediff-protected-variables for buffer Ancestor
  534. (ediff-defvar-local ediff-buffer-values-orig-Ancestor nil "")
  535. ;; association between buff-type and ediff-buffer-values-orig-*
  536. (defconst ediff-buffer-values-orig-alist
  537. '((A . ediff-buffer-values-orig-A)
  538. (B . ediff-buffer-values-orig-B)
  539. (C . ediff-buffer-values-orig-C)
  540. (Ancestor . ediff-buffer-values-orig-Ancestor)))
  541. ;; Buffer-local variables to be saved then restored during Ediff sessions
  542. (defconst ediff-protected-variables '(
  543. ;;buffer-read-only
  544. mode-line-format))
  545. ;; Vector of differences between the variants. Each difference is
  546. ;; represented by a vector of two overlays plus a vector of fine diffs,
  547. ;; plus a no-fine-diffs flag. The first overlay spans the
  548. ;; difference region in the A buffer and the second overlays the diff in
  549. ;; the B buffer. If a difference section is empty, the corresponding
  550. ;; overlay's endpoints coincide.
  551. ;;
  552. ;; The precise form of a Difference Vector for one buffer is:
  553. ;; [diff diff diff ...]
  554. ;; where each diff has the form:
  555. ;; [diff-overlay fine-diff-vector no-fine-diffs-flag state-of-diff]
  556. ;; fine-diff-vector is a vector [fine-diff-overlay fine-diff-overlay ...]
  557. ;; no-fine-diffs-flag says if there are fine differences.
  558. ;; state-of-difference is A, B, C, or nil, indicating which buffer is
  559. ;; different from the other two (used only in 3-way jobs.
  560. (ediff-defvar-local ediff-difference-vector-A nil "")
  561. (ediff-defvar-local ediff-difference-vector-B nil "")
  562. (ediff-defvar-local ediff-difference-vector-C nil "")
  563. (ediff-defvar-local ediff-difference-vector-Ancestor nil "")
  564. ;; A-list of diff vector types associated with buffer types
  565. (defconst ediff-difference-vector-alist
  566. '((A . ediff-difference-vector-A)
  567. (B . ediff-difference-vector-B)
  568. (C . ediff-difference-vector-C)
  569. (Ancestor . ediff-difference-vector-Ancestor)))
  570. ;; [ status status status ...]
  571. ;; Each status: [state-of-merge state-of-ancestor]
  572. ;; state-of-merge is default-A, default-B, prefer-A, or prefer-B. It
  573. ;; indicates the way a diff region was created in buffer C.
  574. ;; state-of-ancestor says if the corresponding region in ancestor buffer is
  575. ;; empty.
  576. (ediff-defvar-local ediff-state-of-merge nil "")
  577. ;; The difference that is currently selected.
  578. (ediff-defvar-local ediff-current-difference -1 "")
  579. ;; Number of differences found.
  580. (ediff-defvar-local ediff-number-of-differences nil "")
  581. ;; Buffer containing the output of diff, which is used by Ediff to step
  582. ;; through files.
  583. (ediff-defvar-local ediff-diff-buffer nil "")
  584. ;; Like ediff-diff-buffer, but contains context diff. It is not used by
  585. ;; Ediff, but it is saved in a file, if user requests so.
  586. (ediff-defvar-local ediff-custom-diff-buffer nil "")
  587. ;; Buffer used for diff-style fine differences between regions.
  588. (ediff-defvar-local ediff-fine-diff-buffer nil "")
  589. ;; Temporary buffer used for computing fine differences.
  590. (defconst ediff-tmp-buffer " *ediff-tmp*" "")
  591. ;; Buffer used for messages
  592. (defconst ediff-msg-buffer " *ediff-message*" "")
  593. ;; Buffer containing the output of diff when diff returns errors.
  594. (ediff-defvar-local ediff-error-buffer nil "")
  595. ;; Buffer to display debug info
  596. (ediff-defvar-local ediff-debug-buffer "*ediff-debug*" "")
  597. ;; List of ediff control panels associated with each buffer A/B/C/Ancestor.
  598. ;; Not used any more, but may be needed in the future.
  599. (ediff-defvar-local ediff-this-buffer-ediff-sessions nil "")
  600. ;; to be deleted in due time
  601. ;; List of difference overlays disturbed by working with the current diff.
  602. (defvar ediff-disturbed-overlays nil "")
  603. ;; Priority of non-selected overlays.
  604. (defvar ediff-shadow-overlay-priority 100 "")
  605. (defcustom ediff-version-control-package 'vc
  606. "Version control package used.
  607. Currently, Ediff supports vc.el, rcs.el, pcl-cvs.el, and generic-sc.el. The
  608. standard Emacs interface to RCS, CVS, SCCS, etc., is vc.el. However, some
  609. people find the other two packages more convenient. Set this variable to the
  610. appropriate symbol: `rcs', `pcl-cvs', or `generic-sc' if you so desire."
  611. :type 'symbol
  612. :group 'ediff)
  613. (defcustom ediff-coding-system-for-read 'raw-text
  614. "The coding system for read to use when running the diff program as a subprocess.
  615. In most cases, the default will do. However, under certain circumstances in
  616. MS-Windows you might need to use something like 'raw-text-dos here.
  617. So, if the output that your diff program sends to Emacs contains extra ^M's,
  618. you might need to experiment here, if the default or 'raw-text-dos doesn't
  619. work."
  620. :type 'symbol
  621. :group 'ediff)
  622. (defcustom ediff-coding-system-for-write (if (featurep 'xemacs)
  623. 'escape-quoted
  624. 'emacs-internal)
  625. "The coding system for write to use when writing out difference regions
  626. to temp files in buffer jobs and when Ediff needs to find fine differences."
  627. :type 'symbol
  628. :group 'ediff)
  629. (defalias 'ediff-read-event
  630. (if (featurep 'xemacs) 'next-command-event 'read-event))
  631. (defalias 'ediff-overlayp
  632. (if (featurep 'xemacs) 'extentp 'overlayp))
  633. (defalias 'ediff-make-overlay
  634. (if (featurep 'xemacs) 'make-extent 'make-overlay))
  635. (defalias 'ediff-delete-overlay
  636. (if (featurep 'xemacs) 'delete-extent 'delete-overlay))
  637. ;; Assumes that emacs-major-version and emacs-minor-version are defined.
  638. (defun ediff-check-version (op major minor &optional type-of-emacs)
  639. "Check the current version against MAJOR and MINOR version numbers.
  640. The comparison uses operator OP, which may be any of: =, >, >=, <, <=.
  641. TYPE-OF-EMACS is either 'xemacs or 'emacs."
  642. (and (cond ((eq type-of-emacs 'xemacs) (featurep 'xemacs))
  643. ((eq type-of-emacs 'emacs) (featurep 'emacs))
  644. (t))
  645. (cond ((eq op '=) (and (= emacs-minor-version minor)
  646. (= emacs-major-version major)))
  647. ((memq op '(> >= < <=))
  648. (and (or (funcall op emacs-major-version major)
  649. (= emacs-major-version major))
  650. (if (= emacs-major-version major)
  651. (funcall op emacs-minor-version minor)
  652. t)))
  653. (t
  654. (error "%S: Invalid op in ediff-check-version" op)))))
  655. ;; ediff-check-version seems to be totally unused anyway.
  656. (make-obsolete 'ediff-check-version 'version< "23.1")
  657. (defun ediff-color-display-p ()
  658. (condition-case nil
  659. (if (featurep 'xemacs)
  660. (eq (device-class (selected-device)) 'color) ; xemacs form
  661. (display-color-p)) ; emacs form
  662. (error nil)))
  663. ;; A var local to each control panel buffer. Indicates highlighting style
  664. ;; in effect for this buffer: `face', `ascii',
  665. ;; `off' -- turned off \(on a dumb terminal only\).
  666. (ediff-defvar-local ediff-highlighting-style
  667. (if (and (ediff-has-face-support-p) ediff-use-faces) 'face 'ascii)
  668. "")
  669. (if (ediff-window-display-p)
  670. (if (featurep 'xemacs)
  671. (progn
  672. (defalias 'ediff-display-pixel-width 'device-pixel-width)
  673. (defalias 'ediff-display-pixel-height 'device-pixel-height))
  674. (defalias 'ediff-display-pixel-width
  675. (if (fboundp 'display-pixel-width)
  676. 'display-pixel-width
  677. 'x-display-pixel-width))
  678. (defalias 'ediff-display-pixel-height
  679. (if (fboundp 'display-pixel-height)
  680. 'display-pixel-height
  681. 'x-display-pixel-height))))
  682. ;; A-list of current-diff-overlay symbols associated with buf types
  683. (defconst ediff-current-diff-overlay-alist
  684. '((A . ediff-current-diff-overlay-A)
  685. (B . ediff-current-diff-overlay-B)
  686. (C . ediff-current-diff-overlay-C)
  687. (Ancestor . ediff-current-diff-overlay-Ancestor)))
  688. ;; A-list of current-diff-face-* symbols associated with buf types
  689. (defconst ediff-current-diff-face-alist
  690. '((A . ediff-current-diff-A)
  691. (B . ediff-current-diff-B)
  692. (C . ediff-current-diff-C)
  693. (Ancestor . ediff-current-diff-Ancestor)))
  694. (defun ediff-set-overlay-face (extent face)
  695. (ediff-overlay-put extent 'face face)
  696. (ediff-overlay-put extent 'help-echo 'ediff-region-help-echo))
  697. (defun ediff-region-help-echo (extent-or-window &optional overlay point)
  698. (unless overlay
  699. (setq overlay extent-or-window))
  700. (let ((is-current (ediff-overlay-get overlay 'ediff))
  701. (face (ediff-overlay-get overlay 'face))
  702. (diff-num (ediff-overlay-get overlay 'ediff-diff-num))
  703. face-help)
  704. ;; This happens only for refinement overlays
  705. (if (stringp face)
  706. (setq face (intern face)))
  707. (setq face-help (and face (get face 'ediff-help-echo)))
  708. (cond ((and is-current diff-num) ; current diff region
  709. (format "Difference region %S -- current" (1+ diff-num)))
  710. (face-help) ; refinement of current diff region
  711. (diff-num ; non-current
  712. (format "Difference region %S -- non-current" (1+ diff-num)))
  713. (t "")) ; none
  714. ))
  715. (defun ediff-set-face-pixmap (face pixmap)
  716. "Set face pixmap on a monochrome display."
  717. (if (and (ediff-window-display-p) (not (ediff-color-display-p)))
  718. (condition-case nil
  719. (set-face-background-pixmap face pixmap)
  720. (error
  721. (message "Pixmap not found for %S: %s" (face-name face) pixmap)
  722. (sit-for 1)))))
  723. (defun ediff-hide-face (face)
  724. (if (and (ediff-has-face-support-p)
  725. (boundp 'add-to-list)
  726. (boundp 'facemenu-unlisted-faces))
  727. (add-to-list 'facemenu-unlisted-faces face)))
  728. (defface ediff-current-diff-A
  729. (if (featurep 'emacs)
  730. '((((class color) (min-colors 16))
  731. (:foreground "firebrick" :background "pale green"))
  732. (((class color))
  733. (:foreground "blue3" :background "yellow3"))
  734. (t (:inverse-video t)))
  735. '((((type tty)) (:foreground "blue3" :background "yellow3"))
  736. (((class color)) (:foreground "firebrick" :background "pale green"))
  737. (t (:inverse-video t))))
  738. "Face for highlighting the selected difference in buffer A."
  739. :group 'ediff-highlighting)
  740. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  741. ;; this variable is set to nil, then again to the appropriate face.
  742. (defvar ediff-current-diff-face-A 'ediff-current-diff-A
  743. "Face for highlighting the selected difference in buffer A.
  744. DO NOT CHANGE this variable. Instead, use the customization
  745. widget to customize the actual face object `ediff-current-diff-A'
  746. this variable represents.")
  747. (ediff-hide-face ediff-current-diff-face-A)
  748. ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
  749. ;; This means that some user customization may be trashed.
  750. (and (featurep 'xemacs)
  751. (ediff-has-face-support-p)
  752. (not (ediff-color-display-p))
  753. (copy-face 'modeline ediff-current-diff-face-A))
  754. (defface ediff-current-diff-B
  755. (if (featurep 'emacs)
  756. '((((class color) (min-colors 16))
  757. (:foreground "DarkOrchid" :background "Yellow"))
  758. (((class color))
  759. (:foreground "magenta3" :background "yellow3"
  760. :weight bold))
  761. (t (:inverse-video t)))
  762. '((((type tty)) (:foreground "magenta3" :background "yellow3"
  763. :weight bold))
  764. (((class color)) (:foreground "DarkOrchid" :background "Yellow"))
  765. (t (:inverse-video t))))
  766. "Face for highlighting the selected difference in buffer B."
  767. :group 'ediff-highlighting)
  768. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  769. ;; this variable is set to nil, then again to the appropriate face.
  770. (defvar ediff-current-diff-face-B 'ediff-current-diff-B
  771. "Face for highlighting the selected difference in buffer B.
  772. this variable. Instead, use the customization
  773. widget to customize the actual face `ediff-current-diff-B'
  774. this variable represents.")
  775. (ediff-hide-face ediff-current-diff-face-B)
  776. ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
  777. ;; This means that some user customization may be trashed.
  778. (and (featurep 'xemacs)
  779. (ediff-has-face-support-p)
  780. (not (ediff-color-display-p))
  781. (copy-face 'modeline ediff-current-diff-face-B))
  782. (defface ediff-current-diff-C
  783. (if (featurep 'emacs)
  784. '((((class color) (min-colors 16))
  785. (:foreground "Navy" :background "Pink"))
  786. (((class color))
  787. (:foreground "cyan3" :background "yellow3" :weight bold))
  788. (t (:inverse-video t)))
  789. '((((type tty)) (:foreground "cyan3" :background "yellow3" :weight bold))
  790. (((class color)) (:foreground "Navy" :background "Pink"))
  791. (t (:inverse-video t))))
  792. "Face for highlighting the selected difference in buffer C."
  793. :group 'ediff-highlighting)
  794. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  795. ;; this variable is set to nil, then again to the appropriate face.
  796. (defvar ediff-current-diff-face-C 'ediff-current-diff-C
  797. "Face for highlighting the selected difference in buffer C.
  798. DO NOT CHANGE this variable. Instead, use the customization
  799. widget to customize the actual face object `ediff-current-diff-C'
  800. this variable represents.")
  801. (ediff-hide-face ediff-current-diff-face-C)
  802. ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
  803. ;; This means that some user customization may be trashed.
  804. (and (featurep 'xemacs)
  805. (ediff-has-face-support-p)
  806. (not (ediff-color-display-p))
  807. (copy-face 'modeline ediff-current-diff-face-C))
  808. (defface ediff-current-diff-Ancestor
  809. (if (featurep 'emacs)
  810. '((((class color) (min-colors 16))
  811. (:foreground "Black" :background "VioletRed"))
  812. (((class color))
  813. (:foreground "black" :background "magenta3"))
  814. (t (:inverse-video t)))
  815. '((((type tty)) (:foreground "black" :background "magenta3"))
  816. (((class color)) (:foreground "Black" :background "VioletRed"))
  817. (t (:inverse-video t))))
  818. "Face for highlighting the selected difference in buffer Ancestor."
  819. :group 'ediff-highlighting)
  820. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  821. ;; this variable is set to nil, then again to the appropriate face.
  822. (defvar ediff-current-diff-face-Ancestor 'ediff-current-diff-Ancestor
  823. "Face for highlighting the selected difference in buffer Ancestor.
  824. DO NOT CHANGE this variable. Instead, use the customization
  825. widget to customize the actual face object `ediff-current-diff-Ancestor'
  826. this variable represents.")
  827. (ediff-hide-face ediff-current-diff-face-Ancestor)
  828. ;; Until custom.el for XEmacs starts supporting :inverse-video we do this.
  829. ;; This means that some user customization may be trashed.
  830. (and (featurep 'xemacs)
  831. (ediff-has-face-support-p)
  832. (not (ediff-color-display-p))
  833. (copy-face 'modeline ediff-current-diff-face-Ancestor))
  834. (defface ediff-fine-diff-A
  835. (if (featurep 'emacs)
  836. '((((class color) (min-colors 16))
  837. (:foreground "Navy" :background "sky blue"))
  838. (((class color))
  839. (:foreground "white" :background "sky blue" :weight bold))
  840. (t (:underline t :stipple "gray3")))
  841. '((((type tty)) (:foreground "white" :background "sky blue" :weight bold))
  842. (((class color)) (:foreground "Navy" :background "sky blue"))
  843. (t (:underline t :stipple "gray3"))))
  844. "Face for highlighting the refinement of the selected diff in buffer A."
  845. :group 'ediff-highlighting)
  846. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  847. ;; this variable is set to nil, then again to the appropriate face.
  848. (defvar ediff-fine-diff-face-A 'ediff-fine-diff-A
  849. "Face for highlighting the fine differences in buffer A.
  850. DO NOT CHANGE this variable. Instead, use the customization
  851. widget to customize the actual face object `ediff-fine-diff-A'
  852. this variable represents.")
  853. (ediff-hide-face ediff-fine-diff-face-A)
  854. (defface ediff-fine-diff-B
  855. (if (featurep 'emacs)
  856. '((((class color) (min-colors 16))
  857. (:foreground "Black" :background "cyan"))
  858. (((class color))
  859. (:foreground "magenta3" :background "cyan3"))
  860. (t (:underline t :stipple "gray3")))
  861. '((((type tty)) (:foreground "magenta3" :background "cyan3"))
  862. (((class color)) (:foreground "Black" :background "cyan"))
  863. (t (:underline t :stipple "gray3"))))
  864. "Face for highlighting the refinement of the selected diff in buffer B."
  865. :group 'ediff-highlighting)
  866. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  867. ;; this variable is set to nil, then again to the appropriate face.
  868. (defvar ediff-fine-diff-face-B 'ediff-fine-diff-B
  869. "Face for highlighting the fine differences in buffer B.
  870. DO NOT CHANGE this variable. Instead, use the customization
  871. widget to customize the actual face object `ediff-fine-diff-B'
  872. this variable represents.")
  873. (ediff-hide-face ediff-fine-diff-face-B)
  874. (defface ediff-fine-diff-C
  875. (if (featurep 'emacs)
  876. '((((type pc))
  877. (:foreground "white" :background "Turquoise"))
  878. (((class color) (min-colors 16))
  879. (:foreground "Black" :background "Turquoise"))
  880. (((class color))
  881. (:foreground "yellow3" :background "Turquoise"
  882. :weight bold))
  883. (t (:underline t :stipple "gray3")))
  884. '((((type tty)) (:foreground "yellow3" :background "Turquoise"
  885. :weight bold))
  886. (((type pc)) (:foreground "white" :background "Turquoise"))
  887. (((class color)) (:foreground "Black" :background "Turquoise"))
  888. (t (:underline t :stipple "gray3"))))
  889. "Face for highlighting the refinement of the selected diff in buffer C."
  890. :group 'ediff-highlighting)
  891. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  892. ;; this variable is set to nil, then again to the appropriate face.
  893. (defvar ediff-fine-diff-face-C 'ediff-fine-diff-C
  894. "Face for highlighting the fine differences in buffer C.
  895. DO NOT CHANGE this variable. Instead, use the customization
  896. widget to customize the actual face object `ediff-fine-diff-C'
  897. this variable represents.")
  898. (ediff-hide-face ediff-fine-diff-face-C)
  899. (defface ediff-fine-diff-Ancestor
  900. (if (featurep 'emacs)
  901. '((((class color) (min-colors 16))
  902. (:foreground "Black" :background "Green"))
  903. (((class color))
  904. (:foreground "red3" :background "green"))
  905. (t (:underline t :stipple "gray3")))
  906. '((((type tty)) (:foreground "red3" :background "green"))
  907. (((class color)) (:foreground "Black" :background "Green"))
  908. (t (:underline t :stipple "gray3"))))
  909. "Face for highlighting the refinement of the selected diff in the ancestor buffer.
  910. At present, this face is not used and no fine differences are computed for the
  911. ancestor buffer."
  912. :group 'ediff-highlighting)
  913. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  914. ;; this variable is set to nil, then again to the appropriate face.
  915. (defvar ediff-fine-diff-face-Ancestor 'ediff-fine-diff-Ancestor
  916. "Face for highlighting the fine differences in buffer Ancestor.
  917. DO NOT CHANGE this variable. Instead, use the customization
  918. widget to customize the actual face object `ediff-fine-diff-Ancestor'
  919. this variable represents.")
  920. (ediff-hide-face ediff-fine-diff-face-Ancestor)
  921. ;; Some installs don't have stipple or Stipple. So, try them in turn.
  922. (defvar stipple-pixmap
  923. (cond ((not (ediff-has-face-support-p)) nil)
  924. ((and (boundp 'x-bitmap-file-path)
  925. (locate-library "stipple" t x-bitmap-file-path)) "stipple")
  926. ((and (boundp 'mswindowsx-bitmap-file-path)
  927. (locate-library "stipple" t mswindowsx-bitmap-file-path)) "stipple")
  928. (t "Stipple")))
  929. (defface ediff-even-diff-A
  930. (if (featurep 'emacs)
  931. `((((type pc))
  932. (:foreground "green3" :background "light grey"))
  933. (((class color) (min-colors 16))
  934. (:foreground "Black" :background "light grey"))
  935. (((class color))
  936. (:foreground "red3" :background "light grey"
  937. :weight bold))
  938. (t (:italic t :stipple ,stipple-pixmap)))
  939. `((((type tty)) (:foreground "red3" :background "light grey"
  940. :weight bold))
  941. (((type pc)) (:foreground "green3" :background "light grey"))
  942. (((class color)) (:foreground "Black" :background "light grey"))
  943. (t (:italic t :stipple ,stipple-pixmap))))
  944. "Face for highlighting even-numbered non-current differences in buffer A."
  945. :group 'ediff-highlighting)
  946. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  947. ;; this variable is set to nil, then again to the appropriate face.
  948. (defvar ediff-even-diff-face-A 'ediff-even-diff-A
  949. "Face for highlighting even-numbered non-current differences in buffer A.
  950. DO NOT CHANGE this variable. Instead, use the customization
  951. widget to customize the actual face object `ediff-even-diff-A'
  952. this variable represents.")
  953. (ediff-hide-face ediff-even-diff-face-A)
  954. (defface ediff-even-diff-B
  955. (if (featurep 'emacs)
  956. `((((class color) (min-colors 16))
  957. (:foreground "White" :background "Grey"))
  958. (((class color))
  959. (:foreground "blue3" :background "Grey" :weight bold))
  960. (t (:italic t :stipple ,stipple-pixmap)))
  961. `((((type tty)) (:foreground "blue3" :background "Grey" :weight bold))
  962. (((class color)) (:foreground "White" :background "Grey"))
  963. (t (:italic t :stipple ,stipple-pixmap))))
  964. "Face for highlighting even-numbered non-current differences in buffer B."
  965. :group 'ediff-highlighting)
  966. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  967. ;; this variable is set to nil, then again to the appropriate face.
  968. (defvar ediff-even-diff-face-B 'ediff-even-diff-B
  969. "Face for highlighting even-numbered non-current differences in buffer B.
  970. DO NOT CHANGE this variable. Instead, use the customization
  971. widget to customize the actual face object `ediff-even-diff-B'
  972. this variable represents.")
  973. (ediff-hide-face ediff-even-diff-face-B)
  974. (defface ediff-even-diff-C
  975. (if (featurep 'emacs)
  976. `((((type pc))
  977. (:foreground "yellow3" :background "light grey"))
  978. (((class color) (min-colors 16))
  979. (:foreground "Black" :background "light grey"))
  980. (((class color))
  981. (:foreground "yellow3" :background "light grey"
  982. :weight bold))
  983. (t (:italic t :stipple ,stipple-pixmap)))
  984. `((((type tty)) (:foreground "yellow3" :background "light grey"
  985. :weight bold))
  986. (((type pc)) (:foreground "yellow3" :background "light grey"))
  987. (((class color)) (:foreground "Black" :background "light grey"))
  988. (t (:italic t :stipple ,stipple-pixmap))))
  989. "Face for highlighting even-numbered non-current differences in buffer C."
  990. :group 'ediff-highlighting)
  991. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  992. ;; this variable is set to nil, then again to the appropriate face.
  993. (defvar ediff-even-diff-face-C 'ediff-even-diff-C
  994. "Face for highlighting even-numbered non-current differences in buffer C.
  995. DO NOT CHANGE this variable. Instead, use the customization
  996. widget to customize the actual face object `ediff-even-diff-C'
  997. this variable represents.")
  998. (ediff-hide-face ediff-even-diff-face-C)
  999. (defface ediff-even-diff-Ancestor
  1000. (if (featurep 'emacs)
  1001. `((((type pc))
  1002. (:foreground "cyan3" :background "light grey"))
  1003. (((class color) (min-colors 16))
  1004. (:foreground "White" :background "Grey"))
  1005. (((class color))
  1006. (:foreground "cyan3" :background "light grey"
  1007. :weight bold))
  1008. (t (:italic t :stipple ,stipple-pixmap)))
  1009. `((((type tty)) (:foreground "cyan3" :background "light grey"
  1010. :weight bold))
  1011. (((type pc)) (:foreground "cyan3" :background "light grey"))
  1012. (((class color)) (:foreground "White" :background "Grey"))
  1013. (t (:italic t :stipple ,stipple-pixmap))))
  1014. "Face for highlighting even-numbered non-current differences in the ancestor buffer."
  1015. :group 'ediff-highlighting)
  1016. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  1017. ;; this variable is set to nil, then again to the appropriate face.
  1018. (defvar ediff-even-diff-face-Ancestor 'ediff-even-diff-Ancestor
  1019. "Face for highlighting even-numbered non-current differences in buffer Ancestor.
  1020. DO NOT CHANGE this variable. Instead, use the customization
  1021. widget to customize the actual face object `ediff-even-diff-Ancestor'
  1022. this variable represents.")
  1023. (ediff-hide-face ediff-even-diff-face-Ancestor)
  1024. ;; Association between buffer types and even-diff-face symbols
  1025. (defconst ediff-even-diff-face-alist
  1026. '((A . ediff-even-diff-A)
  1027. (B . ediff-even-diff-B)
  1028. (C . ediff-even-diff-C)
  1029. (Ancestor . ediff-even-diff-Ancestor)))
  1030. (defface ediff-odd-diff-A
  1031. (if (featurep 'emacs)
  1032. '((((type pc))
  1033. (:foreground "green3" :background "gray40"))
  1034. (((class color) (min-colors 16))
  1035. (:foreground "White" :background "Grey"))
  1036. (((class color))
  1037. (:foreground "red3" :background "black" :weight bold))
  1038. (t (:italic t :stipple "gray1")))
  1039. '((((type tty)) (:foreground "red3" :background "black" :weight bold))
  1040. (((type pc)) (:foreground "green3" :background "gray40"))
  1041. (((class color)) (:foreground "White" :background "Grey"))
  1042. (t (:italic t :stipple "gray1"))))
  1043. "Face for highlighting odd-numbered non-current differences in buffer A."
  1044. :group 'ediff-highlighting)
  1045. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  1046. ;; this variable is set to nil, then again to the appropriate face.
  1047. (defvar ediff-odd-diff-face-A 'ediff-odd-diff-A
  1048. "Face for highlighting odd-numbered non-current differences in buffer A.
  1049. DO NOT CHANGE this variable. Instead, use the customization
  1050. widget to customize the actual face object `ediff-odd-diff-A'
  1051. this variable represents.")
  1052. (ediff-hide-face ediff-odd-diff-face-A)
  1053. (defface ediff-odd-diff-B
  1054. (if (featurep 'emacs)
  1055. '((((type pc))
  1056. (:foreground "White" :background "gray40"))
  1057. (((class color) (min-colors 16))
  1058. (:foreground "Black" :background "light grey"))
  1059. (((class color))
  1060. (:foreground "cyan3" :background "black" :weight bold))
  1061. (t (:italic t :stipple "gray1")))
  1062. '((((type tty)) (:foreground "cyan3" :background "black" :weight bold))
  1063. (((type pc)) (:foreground "White" :background "gray40"))
  1064. (((class color)) (:foreground "Black" :background "light grey"))
  1065. (t (:italic t :stipple "gray1"))))
  1066. "Face for highlighting odd-numbered non-current differences in buffer B."
  1067. :group 'ediff-highlighting)
  1068. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  1069. ;; this variable is set to nil, then again to the appropriate face.
  1070. (defvar ediff-odd-diff-face-B 'ediff-odd-diff-B
  1071. "Face for highlighting odd-numbered non-current differences in buffer B.
  1072. DO NOT CHANGE this variable. Instead, use the customization
  1073. widget to customize the actual face object `ediff-odd-diff-B'
  1074. this variable represents.")
  1075. (ediff-hide-face ediff-odd-diff-face-B)
  1076. (defface ediff-odd-diff-C
  1077. (if (featurep 'emacs)
  1078. '((((type pc))
  1079. (:foreground "yellow3" :background "gray40"))
  1080. (((class color) (min-colors 16))
  1081. (:foreground "White" :background "Grey"))
  1082. (((class color))
  1083. (:foreground "yellow3" :background "black" :weight bold))
  1084. (t (:italic t :stipple "gray1")))
  1085. '((((type tty)) (:foreground "yellow3" :background "black" :weight bold))
  1086. (((type pc)) (:foreground "yellow3" :background "gray40"))
  1087. (((class color)) (:foreground "White" :background "Grey"))
  1088. (t (:italic t :stipple "gray1"))))
  1089. "Face for highlighting odd-numbered non-current differences in buffer C."
  1090. :group 'ediff-highlighting)
  1091. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  1092. ;; this variable is set to nil, then again to the appropriate face.
  1093. (defvar ediff-odd-diff-face-C 'ediff-odd-diff-C
  1094. "Face for highlighting odd-numbered non-current differences in buffer C.
  1095. DO NOT CHANGE this variable. Instead, use the customization
  1096. widget to customize the actual face object `ediff-odd-diff-C'
  1097. this variable represents.")
  1098. (ediff-hide-face ediff-odd-diff-face-C)
  1099. (defface ediff-odd-diff-Ancestor
  1100. (if (featurep 'emacs)
  1101. '((((class color) (min-colors 16))
  1102. (:foreground "cyan3" :background "gray40"))
  1103. (((class color))
  1104. (:foreground "green3" :background "black" :weight bold))
  1105. (t (:italic t :stipple "gray1")))
  1106. '((((type tty)) (:foreground "green3" :background "black" :weight bold))
  1107. (((class color)) (:foreground "cyan3" :background "gray40"))
  1108. (t (:italic t :stipple "gray1"))))
  1109. "Face for highlighting odd-numbered non-current differences in the ancestor buffer."
  1110. :group 'ediff-highlighting)
  1111. ;; An internal variable. Ediff takes the face from here. When unhighlighting,
  1112. ;; this variable is set to nil, then again to the appropriate face.
  1113. (defvar ediff-odd-diff-face-Ancestor 'ediff-odd-diff-Ancestor
  1114. "Face for highlighting odd-numbered non-current differences in buffer Ancestor.
  1115. DO NOT CHANGE this variable. Instead, use the customization
  1116. widget to customize the actual face object `ediff-odd-diff-Ancestor'
  1117. this variable represents.")
  1118. (ediff-hide-face ediff-odd-diff-face-Ancestor)
  1119. ;; Association between buffer types and odd-diff-face symbols
  1120. (defconst ediff-odd-diff-face-alist
  1121. '((A . ediff-odd-diff-A)
  1122. (B . ediff-odd-diff-B)
  1123. (C . ediff-odd-diff-C)
  1124. (Ancestor . ediff-odd-diff-Ancestor)))
  1125. ;; A-list of fine-diff face symbols associated with buffer types
  1126. (defconst ediff-fine-diff-face-alist
  1127. '((A . ediff-fine-diff-A)
  1128. (B . ediff-fine-diff-B)
  1129. (C . ediff-fine-diff-C)
  1130. (Ancestor . ediff-fine-diff-Ancestor)))
  1131. ;; Help echo
  1132. (put ediff-fine-diff-face-A 'ediff-help-echo
  1133. "A `refinement' of the current difference region")
  1134. (put ediff-fine-diff-face-B 'ediff-help-echo
  1135. "A `refinement' of the current difference region")
  1136. (put ediff-fine-diff-face-C 'ediff-help-echo
  1137. "A `refinement' of the current difference region")
  1138. (put ediff-fine-diff-face-Ancestor 'ediff-help-echo
  1139. "A `refinement' of the current difference region")
  1140. (add-hook 'ediff-quit-hook 'ediff-cleanup-mess)
  1141. (add-hook 'ediff-suspend-hook 'ediff-default-suspend-function)
  1142. ;;; Overlays
  1143. (ediff-defvar-local ediff-current-diff-overlay-A nil
  1144. "Overlay for the current difference region in buffer A.")
  1145. (ediff-defvar-local ediff-current-diff-overlay-B nil
  1146. "Overlay for the current difference region in buffer B.")
  1147. (ediff-defvar-local ediff-current-diff-overlay-C nil
  1148. "Overlay for the current difference region in buffer C.")
  1149. (ediff-defvar-local ediff-current-diff-overlay-Ancestor nil
  1150. "Overlay for the current difference region in the ancestor buffer.")
  1151. ;; Compute priority of a current ediff overlay.
  1152. (defun ediff-highest-priority (start end buffer)
  1153. (let ((pos (max 1 (1- start)))
  1154. ovr-list)
  1155. (if (featurep 'xemacs)
  1156. (1+ ediff-shadow-overlay-priority)
  1157. (ediff-with-current-buffer buffer
  1158. (while (< pos (min (point-max) (1+ end)))
  1159. (setq ovr-list (append (overlays-at pos) ovr-list))
  1160. (setq pos (next-overlay-change pos)))
  1161. (+ 1 ediff-shadow-overlay-priority
  1162. (apply 'max
  1163. (cons
  1164. 1
  1165. (mapcar
  1166. (lambda (ovr)
  1167. (if (and ovr
  1168. ;; exclude ediff overlays from priority
  1169. ;; calculation, or else priority will keep
  1170. ;; increasing
  1171. (null (ediff-overlay-get ovr 'ediff))
  1172. (null (ediff-overlay-get ovr 'ediff-diff-num)))
  1173. ;; use the overlay priority or 0
  1174. (or (ediff-overlay-get ovr 'priority) 0)
  1175. 0))
  1176. ovr-list))))))))
  1177. (defvar ediff-toggle-read-only-function 'toggle-read-only
  1178. "Function to be used to toggle read-only status of the buffer.
  1179. If nil, Ediff tries using the command bound to C-x C-q.")
  1180. (defcustom ediff-make-buffers-readonly-at-startup nil
  1181. "Make all variant buffers read-only when Ediff starts up.
  1182. This property can be toggled interactively."
  1183. :type 'boolean
  1184. :group 'ediff)
  1185. ;;; Misc
  1186. ;; if nil, this silences some messages
  1187. (defvar ediff-verbose-p t)
  1188. (defcustom ediff-autostore-merges 'group-jobs-only
  1189. "Save the results of merge jobs automatically.
  1190. With value nil, don't save automatically. With value t, always
  1191. save. Anything else means save automatically only if the merge
  1192. job is part of a group of jobs, such as `ediff-merge-directory'
  1193. or `ediff-merge-directory-revisions'."
  1194. :type '(choice (const nil) (const t) (const group-jobs-only))
  1195. :group 'ediff-merge)
  1196. (make-variable-buffer-local 'ediff-autostore-merges)
  1197. ;; file where the result of the merge is to be saved. used internally
  1198. (ediff-defvar-local ediff-merge-store-file nil "")
  1199. (defcustom ediff-merge-filename-prefix "merge_"
  1200. "Prefix to be attached to saved merge buffers."
  1201. :type 'string
  1202. :group 'ediff-merge)
  1203. (defcustom ediff-no-emacs-help-in-control-buffer nil
  1204. "Non-nil means C-h should not invoke Emacs help in control buffer.
  1205. Instead, C-h would jump to previous difference."
  1206. :type 'boolean
  1207. :group 'ediff)
  1208. ;; This is the same as temporary-file-directory from Emacs 20.3.
  1209. ;; Copied over here because XEmacs doesn't have this variable.
  1210. (defcustom ediff-temp-file-prefix
  1211. (file-name-as-directory
  1212. (cond ((boundp 'temporary-file-directory) temporary-file-directory)
  1213. ((fboundp 'temp-directory) (temp-directory))
  1214. (t "/tmp/")))
  1215. ;;; (file-name-as-directory
  1216. ;;; (cond ((memq system-type '(ms-dos windows-nt))
  1217. ;;; (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp"))
  1218. ;;; (t
  1219. ;;; (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp"))))
  1220. "Prefix to put on Ediff temporary file names.
  1221. Do not start with `~/' or `~USERNAME/'."
  1222. :type 'string
  1223. :group 'ediff)
  1224. (defcustom ediff-temp-file-mode 384 ; u=rw only
  1225. "Mode for Ediff temporary files."
  1226. :type 'integer
  1227. :group 'ediff)
  1228. ;; Metacharacters that have to be protected from the shell when executing
  1229. ;; a diff/diff3 command.
  1230. (defcustom ediff-metachars "[ \t\n!\"#$&'()*;<=>?[\\^`{|~]"
  1231. "Regexp that matches characters that must be quoted with `\\' in shell command line.
  1232. This default should work without changes."
  1233. :type 'string
  1234. :group 'ediff)
  1235. ;; needed to simulate frame-char-width in XEmacs.
  1236. (defvar ediff-H-glyph (if (featurep 'xemacs) (make-glyph "H")))
  1237. ;; Temporary file used for refining difference regions in buffer A.
  1238. (ediff-defvar-local ediff-temp-file-A nil "")
  1239. ;; Temporary file used for refining difference regions in buffer B.
  1240. (ediff-defvar-local ediff-temp-file-B nil "")
  1241. ;; Temporary file used for refining difference regions in buffer C.
  1242. (ediff-defvar-local ediff-temp-file-C nil "")
  1243. (defun ediff-file-remote-p (file-name)
  1244. (file-remote-p file-name))
  1245. ;; File for which we can get attributes, such as size or date
  1246. (defun ediff-listable-file (file-name)
  1247. (let ((handler (find-file-name-handler file-name 'file-local-copy)))
  1248. (or (null handler) (eq handler 'dired-handler-fn))))
  1249. (defsubst ediff-frame-unsplittable-p (frame)
  1250. (cdr (assq 'unsplittable (frame-parameters frame))))
  1251. (defsubst ediff-get-next-window (wind prev-wind)
  1252. (cond ((window-live-p wind) wind)
  1253. (prev-wind (next-window wind))
  1254. (t (selected-window))
  1255. ))
  1256. (defsubst ediff-kill-buffer-carefully (buf)
  1257. "Kill buffer BUF if it exists."
  1258. (if (ediff-buffer-live-p buf)
  1259. (kill-buffer (get-buffer buf))))
  1260. (defsubst ediff-background-face (buf-type dif-num)
  1261. ;; The value of dif-num is always 1- the one that user sees.
  1262. ;; This is why even face is used when dif-num is odd.
  1263. (ediff-get-symbol-from-alist
  1264. buf-type (if (ediff-odd-p dif-num)
  1265. ediff-even-diff-face-alist
  1266. ediff-odd-diff-face-alist)
  1267. ))
  1268. ;; activate faces on diff regions in buffer
  1269. (defun ediff-paint-background-regions-in-one-buffer (buf-type unhighlight)
  1270. (let ((diff-vector
  1271. (eval (ediff-get-symbol-from-alist
  1272. buf-type ediff-difference-vector-alist)))
  1273. overl diff-num)
  1274. (mapcar (lambda (rec)
  1275. (setq overl (ediff-get-diff-overlay-from-diff-record rec)
  1276. diff-num (ediff-overlay-get overl 'ediff-diff-num))
  1277. (if (ediff-overlay-buffer overl)
  1278. ;; only if overlay is alive
  1279. (ediff-set-overlay-face
  1280. overl
  1281. (if (not unhighlight)
  1282. (ediff-background-face buf-type diff-num))))
  1283. )
  1284. diff-vector)))
  1285. ;; activate faces on diff regions in all buffers
  1286. (defun ediff-paint-background-regions (&optional unhighlight)
  1287. (ediff-paint-background-regions-in-one-buffer
  1288. 'A unhighlight)
  1289. (ediff-paint-background-regions-in-one-buffer
  1290. 'B unhighlight)
  1291. (ediff-paint-background-regions-in-one-buffer
  1292. 'C unhighlight)
  1293. (ediff-paint-background-regions-in-one-buffer
  1294. 'Ancestor unhighlight))
  1295. ;; arg is a record for a given diff in a difference vector
  1296. ;; this record is itself a vector
  1297. (defsubst ediff-clear-fine-diff-vector (diff-record)
  1298. (if diff-record
  1299. (mapc 'ediff-delete-overlay
  1300. (ediff-get-fine-diff-vector-from-diff-record diff-record))))
  1301. (defsubst ediff-clear-fine-differences-in-one-buffer (n buf-type)
  1302. (ediff-clear-fine-diff-vector (ediff-get-difference n buf-type))
  1303. (ediff-set-fine-diff-vector n buf-type nil))
  1304. (defsubst ediff-clear-fine-differences (n)
  1305. (ediff-clear-fine-differences-in-one-buffer n 'A)
  1306. (ediff-clear-fine-differences-in-one-buffer n 'B)
  1307. (if ediff-3way-job
  1308. (ediff-clear-fine-differences-in-one-buffer n 'C)))
  1309. (defsubst ediff-mouse-event-p (event)
  1310. (if (featurep 'xemacs)
  1311. (button-event-p event)
  1312. (string-match "mouse" (format "%S" (event-basic-type event)))))
  1313. (defsubst ediff-key-press-event-p (event)
  1314. (if (featurep 'xemacs)
  1315. (key-press-event-p event)
  1316. (or (char-or-string-p event) (symbolp event))))
  1317. (defun ediff-event-point (event)
  1318. (cond ((ediff-mouse-event-p event)
  1319. (if (featurep 'xemacs)
  1320. (event-point event)
  1321. (posn-point (event-start event))))
  1322. ((ediff-key-press-event-p event)
  1323. (point))
  1324. (t (error "Error"))))
  1325. (defun ediff-event-buffer (event)
  1326. (cond ((ediff-mouse-event-p event)
  1327. (if (featurep 'xemacs)
  1328. (event-buffer event)
  1329. (window-buffer (posn-window (event-start event)))))
  1330. ((ediff-key-press-event-p event)
  1331. (current-buffer))
  1332. (t (error "Error"))))
  1333. (defun ediff-event-key (event-or-key)
  1334. (if (featurep 'xemacs)
  1335. ;;(if (eventp event-or-key) (event-key event-or-key) event-or-key)
  1336. (if (eventp event-or-key) (event-to-character event-or-key t t) event-or-key)
  1337. event-or-key))
  1338. (defun ediff-last-command-char ()
  1339. (ediff-event-key last-command-event))
  1340. (defsubst ediff-frame-iconified-p (frame)
  1341. (and (ediff-window-display-p) (frame-live-p frame)
  1342. (if (featurep 'xemacs)
  1343. (frame-iconified-p frame)
  1344. (eq (frame-visible-p frame) 'icon))))
  1345. (defsubst ediff-window-visible-p (wind)
  1346. ;; under TTY, window-live-p also means window is visible
  1347. (and (window-live-p wind)
  1348. (or (not (ediff-window-display-p))
  1349. (frame-visible-p (window-frame wind)))))
  1350. (defsubst ediff-frame-char-width (frame)
  1351. (if (featurep 'xemacs)
  1352. (/ (frame-pixel-width frame) (frame-width frame))
  1353. (frame-char-width frame)))
  1354. (defun ediff-reset-mouse (&optional frame do-not-grab-mouse)
  1355. (or frame (setq frame (selected-frame)))
  1356. (if (ediff-window-display-p)
  1357. (let ((frame-or-wind frame))
  1358. (if (featurep 'xemacs)
  1359. (setq frame-or-wind (frame-selected-window frame)))
  1360. (or do-not-grab-mouse
  1361. ;; don't set mouse if the user said to never do this
  1362. (not ediff-grab-mouse)
  1363. ;; Don't grab on quit, if the user doesn't want to.
  1364. ;; If ediff-grab-mouse = t, then mouse won't be grabbed for
  1365. ;; sessions that are not part of a group (this is done in
  1366. ;; ediff-recenter). The condition below affects only terminating
  1367. ;; sessions in session groups (in which case mouse is warped into
  1368. ;; a meta buffer).
  1369. (and (eq ediff-grab-mouse 'maybe)
  1370. (memq this-command '(ediff-quit ediff-update-diffs)))
  1371. (set-mouse-position frame-or-wind 1 0))
  1372. )))
  1373. (defsubst ediff-spy-after-mouse ()
  1374. (setq ediff-mouse-pixel-position (mouse-pixel-position)))
  1375. ;; It is not easy to find out when the user grabs the mouse, since emacs and
  1376. ;; xemacs behave differently when mouse is not in any frame. Also, this is
  1377. ;; sensitive to when the user grabbed mouse. Not used for now.
  1378. (defun ediff-user-grabbed-mouse ()
  1379. (if ediff-mouse-pixel-position
  1380. (cond ((not (eq (car ediff-mouse-pixel-position)
  1381. (car (mouse-pixel-position)))))
  1382. ((and (car (cdr ediff-mouse-pixel-position))
  1383. (car (cdr (mouse-pixel-position)))
  1384. (cdr (cdr ediff-mouse-pixel-position))
  1385. (cdr (cdr (mouse-pixel-position))))
  1386. (not (and (< (abs (- (car (cdr ediff-mouse-pixel-position))
  1387. (car (cdr (mouse-pixel-position)))))
  1388. ediff-mouse-pixel-threshold)
  1389. (< (abs (- (cdr (cdr ediff-mouse-pixel-position))
  1390. (cdr (cdr (mouse-pixel-position)))))
  1391. ediff-mouse-pixel-threshold))))
  1392. (t nil))))
  1393. (defsubst ediff-frame-char-height (frame)
  1394. (if (featurep 'xemacs)
  1395. (glyph-height ediff-H-glyph (frame-selected-window frame))
  1396. (frame-char-height frame)))
  1397. ;; Some overlay functions
  1398. (defsubst ediff-overlay-start (overl)
  1399. (if (ediff-overlayp overl)
  1400. (if (featurep 'xemacs)
  1401. (extent-start-position overl)
  1402. (overlay-start overl))))
  1403. (defsubst ediff-overlay-end (overl)
  1404. (if (ediff-overlayp overl)
  1405. (if (featurep 'xemacs)
  1406. (extent-end-position overl)
  1407. (overlay-end overl))))
  1408. (defsubst ediff-empty-overlay-p (overl)
  1409. (= (ediff-overlay-start overl) (ediff-overlay-end overl)))
  1410. ;; like overlay-buffer in Emacs. In XEmacs, returns nil if the extent is
  1411. ;; dead. Otherwise, works like extent-buffer
  1412. (defun ediff-overlay-buffer (overl)
  1413. (if (featurep 'xemacs)
  1414. (and (extent-live-p overl) (extent-object overl))
  1415. (overlay-buffer overl)))
  1416. ;; like overlay-get in Emacs. In XEmacs, returns nil if the extent is
  1417. ;; dead. Otherwise, like extent-property
  1418. (defun ediff-overlay-get (overl property)
  1419. (if (featurep 'xemacs)
  1420. (and (extent-live-p overl) (extent-property overl property))
  1421. (overlay-get overl property)))
  1422. ;; These two functions are here because XEmacs refuses to
  1423. ;; handle overlays whose buffers were deleted.
  1424. (defun ediff-move-overlay (overlay beg end &optional buffer)
  1425. "Calls `move-overlay' in Emacs and `set-extent-endpoints' in Lemacs.
  1426. Checks if overlay's buffer exists before actually doing the move."
  1427. (let ((buf (and overlay (ediff-overlay-buffer overlay))))
  1428. (if (ediff-buffer-live-p buf)
  1429. (if (featurep 'xemacs)
  1430. (set-extent-endpoints overlay beg end)
  1431. (move-overlay overlay beg end buffer))
  1432. ;; buffer's dead
  1433. (if overlay
  1434. (ediff-delete-overlay overlay)))))
  1435. (defun ediff-overlay-put (overlay prop value)
  1436. "Calls `overlay-put' or `set-extent-property' depending on Emacs version.
  1437. Checks if overlay's buffer exists."
  1438. (if (ediff-buffer-live-p (ediff-overlay-buffer overlay))
  1439. (if (featurep 'xemacs)
  1440. (set-extent-property overlay prop value)
  1441. (overlay-put overlay prop value))
  1442. (ediff-delete-overlay overlay)))
  1443. ;; temporarily uses DIR to abbreviate file name
  1444. ;; if DIR is nil, use default-directory
  1445. (defun ediff-abbreviate-file-name (file &optional dir)
  1446. (cond ((stringp dir)
  1447. (let ((directory-abbrev-alist (list (cons dir ""))))
  1448. (abbreviate-file-name file)))
  1449. (t
  1450. (if (featurep 'xemacs)
  1451. ;; XEmacs requires addl argument
  1452. (abbreviate-file-name file t)
  1453. (abbreviate-file-name file)))))
  1454. ;; Takes a directory and returns the parent directory.
  1455. ;; does nothing to `/'. If the ARG is a regular file,
  1456. ;; strip the file AND the last dir.
  1457. (defun ediff-strip-last-dir (dir)
  1458. (if (not (stringp dir)) (setq dir default-directory))
  1459. (setq dir (expand-file-name dir))
  1460. (or (file-directory-p dir) (setq dir (file-name-directory dir)))
  1461. (let* ((pos (1- (length dir)))
  1462. (last-char (aref dir pos)))
  1463. (if (and (> pos 0) (= last-char ?/))
  1464. (setq dir (substring dir 0 pos)))
  1465. (ediff-abbreviate-file-name (file-name-directory dir))))
  1466. (defun ediff-truncate-string-left (str newlen)
  1467. ;; leave space for ... on the left
  1468. (let ((len (length str))
  1469. substr)
  1470. (if (<= len newlen)
  1471. str
  1472. (setq newlen (max 0 (- newlen 3)))
  1473. (setq substr (substring str (max 0 (- len 1 newlen))))
  1474. (concat "..." substr))))
  1475. (defsubst ediff-nonempty-string-p (string)
  1476. (and (stringp string) (not (string= string ""))))
  1477. (unless (fboundp 'subst-char-in-string)
  1478. (defun subst-char-in-string (fromchar tochar string &optional inplace)
  1479. "Replace FROMCHAR with TOCHAR in STRING each time it occurs.
  1480. Unless optional argument INPLACE is non-nil, return a new string."
  1481. (let ((i (length string))
  1482. (newstr (if inplace string (copy-sequence string))))
  1483. (while (> i 0)
  1484. (setq i (1- i))
  1485. (if (eq (aref newstr i) fromchar)
  1486. (aset newstr i tochar)))
  1487. newstr)))
  1488. (defun ediff-abbrev-jobname (jobname)
  1489. (cond ((eq jobname 'ediff-directories)
  1490. "Compare two directories")
  1491. ((eq jobname 'ediff-files)
  1492. "Compare two files")
  1493. ((eq jobname 'ediff-buffers)
  1494. "Compare two buffers")
  1495. ((eq jobname 'ediff-directories3)
  1496. "Compare three directories")
  1497. ((eq jobname 'ediff-files3)
  1498. "Compare three files")
  1499. ((eq jobname 'ediff-buffers3)
  1500. "Compare three buffers")
  1501. ((eq jobname 'ediff-revision)
  1502. "Compare file with a version")
  1503. ((eq jobname 'ediff-directory-revisions)
  1504. "Compare dir files with versions")
  1505. ((eq jobname 'ediff-merge-directory-revisions)
  1506. "Merge dir files with versions")
  1507. ((eq jobname 'ediff-merge-directory-revisions-with-ancestor)
  1508. "Merge dir versions via ancestors")
  1509. (t
  1510. (capitalize
  1511. (subst-char-in-string ?- ?\s (substring (symbol-name jobname) 6))))
  1512. ))
  1513. ;; If ediff modified mode line, strip the modification
  1514. (defsubst ediff-strip-mode-line-format ()
  1515. (and (consp mode-line-format)
  1516. (member (car mode-line-format)
  1517. '(" A: " " B: " " C: " " Ancestor: "))
  1518. (setq mode-line-format (nth 2 mode-line-format))))
  1519. ;; Verify that we have a difference selected.
  1520. (defsubst ediff-valid-difference-p (&optional n)
  1521. (or n (setq n ediff-current-difference))
  1522. (and (>= n 0) (< n ediff-number-of-differences)))
  1523. (defsubst ediff-show-all-diffs (n)
  1524. "Don't skip difference regions."
  1525. nil)
  1526. (defsubst ediff-message-if-verbose (string &rest args)
  1527. (if ediff-verbose-p
  1528. (apply 'message string args)))
  1529. (defun ediff-file-attributes (filename attr-number)
  1530. (if (ediff-listable-file filename)
  1531. (nth attr-number (file-attributes filename))
  1532. -1)
  1533. )
  1534. (defsubst ediff-file-size (filename)
  1535. (ediff-file-attributes filename 7))
  1536. (defsubst ediff-file-modtime (filename)
  1537. (ediff-file-attributes filename 5))
  1538. (defun ediff-convert-standard-filename (fname)
  1539. (if (fboundp 'convert-standard-filename)
  1540. (convert-standard-filename fname)
  1541. fname))
  1542. (if (featurep 'emacs)
  1543. (defalias 'ediff-with-syntax-table 'with-syntax-table)
  1544. (if (fboundp 'with-syntax-table)
  1545. (defalias 'ediff-with-syntax-table 'with-syntax-table)
  1546. ;; stolen from subr.el in emacs 21
  1547. (defmacro ediff-with-syntax-table (table &rest body)
  1548. (let ((old-table (make-symbol "table"))
  1549. (old-buffer (make-symbol "buffer")))
  1550. `(let ((,old-table (syntax-table))
  1551. (,old-buffer (current-buffer)))
  1552. (unwind-protect
  1553. (progn
  1554. (set-syntax-table (copy-syntax-table ,table))
  1555. ,@body)
  1556. (save-current-buffer
  1557. (set-buffer ,old-buffer)
  1558. (set-syntax-table ,old-table))))))))
  1559. (provide 'ediff-init)
  1560. ;; Local Variables:
  1561. ;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
  1562. ;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
  1563. ;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
  1564. ;; End:
  1565. ;;; ediff-init.el ends here