comparison lisp/smerge-mode.el @ 91813:ca1e1298a3d8

(smerge-auto-combine-max-separation): New var. (smerge-auto-combine): New fun.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 13 Feb 2008 15:10:57 +0000
parents 8f1628da223f
children a6d8268a0da6
comparison
equal deleted inserted replaced
91812:22cb32652c70 91813:ca1e1298a3d8
295 (delete-region (match-end n) (match-end 0)) 295 (delete-region (match-end n) (match-end 0))
296 (delete-region (match-beginning 0) (match-beginning n))) 296 (delete-region (match-beginning 0) (match-beginning n)))
297 297
298 (defun smerge-combine-with-next () 298 (defun smerge-combine-with-next ()
299 "Combine the current conflict with the next one." 299 "Combine the current conflict with the next one."
300 ;; `smerge-auto-combine' relies on the finish position (at the beginning
301 ;; of the closing marker).
300 (interactive) 302 (interactive)
301 (smerge-match-conflict) 303 (smerge-match-conflict)
302 (let ((ends nil)) 304 (let ((ends nil))
303 (dolist (i '(3 2 1 0)) 305 (dolist (i '(3 2 1 0))
304 (push (if (match-end i) (copy-marker (match-end i) t)) ends)) 306 (push (if (match-end i) (copy-marker (match-end i) t)) ends))
325 (match-beginning i) (match-end i)))) 327 (match-beginning i) (match-end i))))
326 (delete-region (car match-data) (cadr match-data)) 328 (delete-region (car match-data) (cadr match-data))
327 ;; Free the markers. 329 ;; Free the markers.
328 (dolist (m match-data) (if m (move-marker m nil))) 330 (dolist (m match-data) (if m (move-marker m nil)))
329 (mapc (lambda (m) (if m (move-marker m nil))) ends))))) 331 (mapc (lambda (m) (if m (move-marker m nil))) ends)))))
332
333 (defvar smerge-auto-combine-max-separation 2
334 "Max number of lines between conflicts that should be combined.")
335
336 (defun smerge-auto-combine ()
337 "Automatically combine conflicts that are near each other."
338 (interactive)
339 (save-excursion
340 (goto-char (point-min))
341 (while (smerge-find-conflict)
342 ;; 2 is 1 (default) + 1 (the begin markers).
343 (while (save-excursion
344 (smerge-find-conflict
345 (line-beginning-position
346 (+ 2 smerge-auto-combine-max-separation))))
347 (forward-line -1) ;Go back inside the conflict.
348 (smerge-combine-with-next)
349 (forward-line 1) ;Move past the end of the conflict.
350 ))))
330 351
331 (defvar smerge-resolve-function 352 (defvar smerge-resolve-function
332 (lambda () (error "Don't know how to resolve")) 353 (lambda () (error "Don't know how to resolve"))
333 "Mode-specific merge function. 354 "Mode-specific merge function.
334 The function is called with zero or one argument (non-nil if the resolution 355 The function is called with zero or one argument (non-nil if the resolution