comparison lisp/ediff/ediff-util.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents 1ce6082ce73f
children 318232e2a3f0
comparison
equal deleted inserted replaced
81:ebca3d831cea 82:6a378aca36af
1 ;;; ediff-util.el --- the core commands and utilities of ediff 1 ;;; ediff-util.el --- the core commands and utilities of ediff
2 2
3 ;; Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc. 3 ;; Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 4
5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu> 5 ;; Author: Michael Kifer <kifer@cs.sunysb.edu>
6 6
7 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
8 8
27 27
28 ;; Compiler pacifier 28 ;; Compiler pacifier
29 (defvar ediff-patch-diagnostics) 29 (defvar ediff-patch-diagnostics)
30 (defvar ediff-patchbufer) 30 (defvar ediff-patchbufer)
31 (defvar ediff-toolbar) 31 (defvar ediff-toolbar)
32 (defvar ediff-toolbar-3way)
33 (defvar bottom-toolbar)
34 (defvar bottom-toolbar-visible-p)
35 (defvar bottom-toolbar-height)
32 (defvar mark-active) 36 (defvar mark-active)
33 37
34 (eval-when-compile 38 (eval-when-compile
35 (let ((load-path (cons "." load-path))) 39 (let ((load-path (cons (expand-file-name ".") load-path)))
36 (or (featurep 'ediff-init) 40 (or (featurep 'ediff-init)
37 (load "ediff-init.el" nil nil 'nosuffix)) 41 (load "ediff-init.el" nil nil 'nosuffix))
38 (or (featurep 'ediff-help) 42 (or (featurep 'ediff-help)
39 (load "ediff-help.el" nil nil 'nosuffix)) 43 (load "ediff-help.el" nil nil 'nosuffix))
40 (or (featurep 'ediff-mult) 44 (or (featurep 'ediff-mult)
513 ediff-window-B 517 ediff-window-B
514 ediff-window-C 518 ediff-window-C
515 ediff-split-window-function 519 ediff-split-window-function
516 (ediff-multiframe-setup-p) 520 (ediff-multiframe-setup-p)
517 ediff-wide-display-p)) 521 ediff-wide-display-p))
522
523 ;; In multiframe, toolbar is set in ediff-setup-control-frame
518 (if (not (ediff-multiframe-setup-p)) 524 (if (not (ediff-multiframe-setup-p))
519 (ediff-make-bottom-toolbar)) ; checks if toolbar is requested 525 (ediff-make-bottom-toolbar)) ; this checks if toolbar is requested
520 (goto-char (point-min)) 526 (goto-char (point-min))
521 (skip-chars-forward ediff-whitespace))) 527 (skip-chars-forward ediff-whitespace)))
522 528
523 529
524 530
1179 (setq ediff-window-B nil) ; force update of window config 1185 (setq ediff-window-B nil) ; force update of window config
1180 (ediff-recenter 'no-rehighlight))))) 1186 (ediff-recenter 'no-rehighlight)))))
1181 1187
1182 ;;;###autoload 1188 ;;;###autoload
1183 (defun ediff-toggle-multiframe () 1189 (defun ediff-toggle-multiframe ()
1184 "Switch from the multiframe display to single-frame display and back. 1190 "Switch from multiframe display to single-frame display and back.
1185 For a permanent change, set the variable `ediff-window-setup-function', 1191 To change the default, set the variable `ediff-window-setup-function',
1186 which see." 1192 which see."
1187 (interactive) 1193 (interactive)
1188 (let (set-func window-setup-func) 1194 (let (window-setup-func)
1189 (or (ediff-window-display-p) 1195 (or (ediff-window-display-p)
1190 (error "%sEmacs is not running as a window application" 1196 (error "%sEmacs is not running as a window application"
1191 (if ediff-emacs-p "" "X"))) 1197 (if ediff-emacs-p "" "X")))
1192 1198
1193 ;;(setq set-func (if (ediff-in-control-buffer-p) 'setq 'setq-default))
1194
1195 (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe) 1199 (cond ((eq ediff-window-setup-function 'ediff-setup-windows-multiframe)
1196 ;; (eval 1200 (setq window-setup-func 'ediff-setup-windows-plain))
1197 ;; (list
1198 ;; set-func
1199 ;; 'ediff-window-setup-function ''ediff-setup-windows-plain))
1200 (setq window-setup-func 'ediff-setup-windows-plain)
1201 )
1202 ((eq ediff-window-setup-function 'ediff-setup-windows-plain) 1201 ((eq ediff-window-setup-function 'ediff-setup-windows-plain)
1203 (if (ediff-in-control-buffer-p) 1202 (if (ediff-in-control-buffer-p)
1204 (ediff-kill-bottom-toolbar)) 1203 (ediff-kill-bottom-toolbar))
1205 ;;(eval 1204 (setq window-setup-func 'ediff-setup-windows-multiframe)))
1206 ;; (list
1207 ;; set-func
1208 ;; 'ediff-window-setup-function 'ediff-setup-windows-multiframe))
1209 (setq window-setup-func 'ediff-setup-windows-multiframe)
1210 ))
1211 1205
1212 ;; change default 1206 ;; change default
1213 (setq-default ediff-window-setup-function window-setup-func) 1207 (setq-default ediff-window-setup-function window-setup-func)
1214 ;; change in all active ediff sessions 1208 ;; change in all active ediff sessions
1215 (mapcar (function (lambda(buf) 1209 (mapcar (function (lambda(buf)
1217 (setq ediff-window-setup-function window-setup-func 1211 (setq ediff-window-setup-function window-setup-func
1218 ediff-window-B nil)))) 1212 ediff-window-B nil))))
1219 ediff-session-registry) 1213 ediff-session-registry)
1220 (if (ediff-in-control-buffer-p) 1214 (if (ediff-in-control-buffer-p)
1221 (ediff-recenter 'no-rehighlight)))) 1215 (ediff-recenter 'no-rehighlight))))
1216
1217
1218 ;;;###autoload
1219 (defun ediff-toggle-use-toolbar ()
1220 "Enable or disable Ediff toolbar.
1221 Works only in versions of Emacs that support toolbars.
1222 To change the default, set the variable `ediff-use-toolbar-p', which see."
1223 (interactive)
1224 (if (featurep 'ediff-tbar)
1225 (progn
1226 (or (ediff-window-display-p)
1227 (error "%sEmacs is not running as a window application"
1228 (if ediff-emacs-p "" "X")))
1229 (if (ediff-use-toolbar-p)
1230 (ediff-kill-bottom-toolbar))
1231 ;; do this only after killing the toolbar
1232 (setq ediff-use-toolbar-p (not ediff-use-toolbar-p))
1233
1234 (mapcar (function (lambda(buf)
1235 (ediff-eval-in-buffer buf
1236 ;; force redisplay
1237 (setq ediff-window-config-saved "")
1238 )))
1239 ediff-session-registry)
1240 (if (ediff-in-control-buffer-p)
1241 (ediff-recenter 'no-rehighlight)))))
1242
1222 1243
1223 ;; if was using toolbar, kill it 1244 ;; if was using toolbar, kill it
1224 (defun ediff-kill-bottom-toolbar () 1245 (defun ediff-kill-bottom-toolbar ()
1225 ;; Using ctl-buffer or ediff-control-window for LOCALE does not 1246 ;; Using ctl-buffer or ediff-control-window for LOCALE does not
1226 ;; work properly in XEmacs 19.14: we have to use 1247 ;; work properly in XEmacs 19.14: we have to use
1231 (if (ediff-use-toolbar-p) 1252 (if (ediff-use-toolbar-p)
1232 (progn 1253 (progn
1233 (set-specifier bottom-toolbar (list (selected-frame) nil)) 1254 (set-specifier bottom-toolbar (list (selected-frame) nil))
1234 (set-specifier bottom-toolbar-visible-p (list (selected-frame) nil))))) 1255 (set-specifier bottom-toolbar-visible-p (list (selected-frame) nil)))))
1235 1256
1236 ;; if wants to use toolbar, make it 1257 ;; If wants to use toolbar, make it.
1237 (defun ediff-make-bottom-toolbar () 1258 ;; If not, zero the toolbar for XEmacs.
1238 (if (ediff-use-toolbar-p) 1259 ;; Do nothing for Emacs.
1260 (defun ediff-make-bottom-toolbar (&optional frame)
1261 (if (ediff-window-display-p)
1239 (progn 1262 (progn
1240 (set-specifier bottom-toolbar (list (selected-frame) ediff-toolbar)) 1263 (setq frame (or frame (selected-frame)))
1241 (set-specifier bottom-toolbar-visible-p (list (selected-frame) t)) 1264 (cond ((ediff-use-toolbar-p) ; this checks for XEmacs
1242 (set-specifier bottom-toolbar-height (list (selected-frame) 34))))) 1265 (set-specifier
1266 bottom-toolbar
1267 (list frame (if (ediff-3way-comparison-job)
1268 ediff-toolbar-3way ediff-toolbar)))
1269 (set-specifier bottom-toolbar-visible-p (list frame t))
1270 (set-specifier bottom-toolbar-height
1271 (list frame ediff-toolbar-height)))
1272 (ediff-xemacs-p
1273 (set-specifier bottom-toolbar-height (list frame 0)))
1274 ))
1275 ))
1243 1276
1244 ;; Merging 1277 ;; Merging
1245 1278
1246 (defun ediff-toggle-show-clashes-only () 1279 (defun ediff-toggle-show-clashes-only ()
1247 "Toggle the mode where only the regions where both buffers differ with the ancestor are shown." 1280 "Toggle the mode where only the regions where both buffers differ with the ancestor are shown."
2200 containing the variants should be removed \(if they haven't been modified\). 2233 containing the variants should be removed \(if they haven't been modified\).
2201 If it is t, they will be preserved unconditionally. A prefix argument, 2234 If it is t, they will be preserved unconditionally. A prefix argument,
2202 temporarily reverses the meaning of this variable." 2235 temporarily reverses the meaning of this variable."
2203 (interactive "P") 2236 (interactive "P")
2204 (ediff-barf-if-not-control-buffer) 2237 (ediff-barf-if-not-control-buffer)
2205 (if (y-or-n-p (format "Quit this Ediff session%s? " 2238 (let ((ctl-buf (current-buffer)))
2206 (if (ediff-buffer-live-p ediff-meta-buffer) 2239 (if (y-or-n-p (format "Quit this Ediff session%s? "
2207 " & show containing session group" ""))) 2240 (if (ediff-buffer-live-p ediff-meta-buffer)
2208 (progn 2241 " & show containing session group" "")))
2209 (message "") 2242 (progn
2210 (ediff-really-quit reverse-default-keep-variants)) 2243 (message "")
2211 (message ""))) 2244 (set-buffer ctl-buf)
2245 (ediff-really-quit reverse-default-keep-variants))
2246 (message ""))))
2212 2247
2213 2248
2214 ;; Perform the quit operations. 2249 ;; Perform the quit operations.
2215 (defun ediff-really-quit (reverse-default-keep-variants) 2250 (defun ediff-really-quit (reverse-default-keep-variants)
2216 (ediff-unhighlight-diffs-totally) 2251 (ediff-unhighlight-diffs-totally)
2420 (buffer-modified-p ediff-buffer-C) 2455 (buffer-modified-p ediff-buffer-C)
2421 (and ask (not (y-or-n-p (format "Kill buffer C [%s]? " 2456 (and ask (not (y-or-n-p (format "Kill buffer C [%s]? "
2422 (buffer-name ediff-buffer-C))))) 2457 (buffer-name ediff-buffer-C)))))
2423 (ediff-kill-buffer-carefully ediff-buffer-C)))) 2458 (ediff-kill-buffer-carefully ediff-buffer-C))))
2424 2459
2425 (defun ediff-maybe-save-and-delete-merge () 2460 (defun ediff-maybe-save-and-delete-merge (&optional save-and-continue)
2426 "Default hook to run on quitting a merge job. 2461 "Default hook to run on quitting a merge job.
2462 This can also be used to save merge buffer in the middle of an Ediff session.
2463
2464 If the optional SAVE-AND-CONTINUE argument is non-nil, save merge buffer and
2465 continue. Otherwise:
2427 If `ediff-autostore-merges' is nil, this does nothing. 2466 If `ediff-autostore-merges' is nil, this does nothing.
2428 If it is t, it saves the merge buffer in the file `ediff-merge-store-file' 2467 If it is t, it saves the merge buffer in the file `ediff-merge-store-file'
2429 or asks the user, if the latter is nil. It then then asks the user whether to 2468 or asks the user, if the latter is nil. It then asks the user whether to
2430 delete the merge buffer. 2469 delete the merge buffer.
2431 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved 2470 If `ediff-autostore-merges' is neither nil nor t, the merge buffer is saved
2432 only if this merge job is part of a group, i.e., was invoked from within 2471 only if this merge job is part of a group, i.e., was invoked from within
2433 `ediff-merge-directories', `ediff-merge-directory-revisions', and such." 2472 `ediff-merge-directories', `ediff-merge-directory-revisions', and such."
2434 (let ((merge-store-file ediff-merge-store-file)) 2473 (let ((merge-store-file ediff-merge-store-file)
2474 (ediff-autostore-merges ; fake ediff-autostore-merges, if necessary
2475 (if save-and-continue t ediff-autostore-merges)))
2435 (if ediff-autostore-merges 2476 (if ediff-autostore-merges
2436 (cond ((stringp ediff-merge-store-file) 2477 (cond ((stringp ediff-merge-store-file)
2437 ;; store, ask to delete 2478 ;; store, ask to delete
2438 (ediff-write-merge-buffer-then-kill 2479 (ediff-write-merge-buffer-and-maybe-kill
2439 ediff-buffer-C merge-store-file 'show-file)) 2480 ediff-buffer-C merge-store-file 'show-file save-and-continue))
2440 ((eq ediff-autostore-merges t) 2481 ((eq ediff-autostore-merges t)
2441 ;; ask for file name 2482 ;; ask for file name
2442 (setq merge-store-file 2483 (setq merge-store-file
2443 (read-file-name "Save the result of the merge in: ")) 2484 (read-file-name "Save the merge buffer in file: "))
2444 (ediff-write-merge-buffer-then-kill 2485 (ediff-write-merge-buffer-and-maybe-kill
2445 ediff-buffer-C merge-store-file)) 2486 ediff-buffer-C merge-store-file nil save-and-continue))
2446 ((and (ediff-buffer-live-p ediff-meta-buffer) 2487 ((and (ediff-buffer-live-p ediff-meta-buffer)
2447 (ediff-eval-in-buffer ediff-meta-buffer 2488 (ediff-eval-in-buffer ediff-meta-buffer
2448 (ediff-merge-metajob))) 2489 (ediff-merge-metajob)))
2449 ;; This case shouldn't occur, as the parent metajob must pass on 2490 ;; This case shouldn't occur, as the parent metajob must pass on
2450 ;; a file name, ediff-merge-store-file, where to save the result 2491 ;; a file name, ediff-merge-store-file, where to save the result
2451 ;; of the merge. 2492 ;; of the merge.
2452 ;; Ask where to save anyway--will decide what to do here later. 2493 ;; Ask where to save anyway--will decide what to do here later.
2453 (setq merge-store-file 2494 (setq merge-store-file
2454 (read-file-name "The result of the merge goes into: ")) 2495 (read-file-name "Save the merge buffer in file: "))
2455 (ediff-write-merge-buffer-then-kill 2496 (ediff-write-merge-buffer-and-maybe-kill
2456 ediff-buffer-C merge-store-file)))) 2497 ediff-buffer-C merge-store-file nil save-and-continue))))
2457 )) 2498 ))
2458 2499
2459 (defun ediff-write-merge-buffer-then-kill (buf file &optional show-file) 2500 ;; write merge buffer. If the optional argument save-and-continue is non-nil,
2501 ;; then don't kill the merge buffer
2502 (defun ediff-write-merge-buffer-and-maybe-kill (buf file
2503 &optional
2504 show-file save-and-continue)
2460 (ediff-eval-in-buffer buf 2505 (ediff-eval-in-buffer buf
2461 (if (or (not (file-exists-p file)) 2506 (if (or (not (file-exists-p file))
2462 (y-or-n-p (format "File %s exists, overwrite? " file))) 2507 (y-or-n-p (format "File %s exists, overwrite? " file)))
2463 (progn 2508 (progn
2464 (write-region (point-min) (point-max) file) 2509 (write-region (point-min) (point-max) file)
2465 (if show-file 2510 (if show-file
2466 (progn 2511 (progn
2467 (message "Merge buffer saved in: %s" file) 2512 (message "Merge buffer saved in: %s" file)
2468 (sit-for 2))) 2513 (sit-for 2)))
2469 (if (y-or-n-p "Merge buffer saved in file. Now kill the buffer? ") 2514 (if (and
2515 (not save-and-continue)
2516 (y-or-n-p "Merge buffer saved in file. Now kill the buffer? "))
2470 (ediff-kill-buffer-carefully buf)))))) 2517 (ediff-kill-buffer-carefully buf))))))
2471 2518
2472 ;; The default way of suspending Ediff. 2519 ;; The default way of suspending Ediff.
2473 ;; Buries Ediff buffers, kills all windows. 2520 ;; Buries Ediff buffers, kills all windows.
2474 (defun ediff-default-suspend-function () 2521 (defun ediff-default-suspend-function ()