ediff-init.el 68 KB

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