Mercurial > emacs
comparison lisp/smerge-mode.el @ 91010:aaccdab0ee26
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 852-856)
- Update from CVS
- Merge from emacs--rel--22
* emacs--rel--22 (patch 93-96)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 245)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-249
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 21 Aug 2007 04:54:03 +0000 |
parents | f55f9811f5d7 5b92bb6e6570 |
children | 14c4a6aac623 |
comparison
equal
deleted
inserted
replaced
91009:e7395a700642 | 91010:aaccdab0ee26 |
---|---|
322 (mapc (lambda (m) (if m (move-marker m nil))) ends))))) | 322 (mapc (lambda (m) (if m (move-marker m nil))) ends))))) |
323 | 323 |
324 (defvar smerge-resolve-function | 324 (defvar smerge-resolve-function |
325 (lambda () (error "Don't know how to resolve")) | 325 (lambda () (error "Don't know how to resolve")) |
326 "Mode-specific merge function. | 326 "Mode-specific merge function. |
327 The function is called with no argument and with the match data set | 327 The function is called with zero or one argument (non-nil if the resolution |
328 function should only apply safe heuristics) and with the match data set | |
328 according to `smerge-match-conflict'.") | 329 according to `smerge-match-conflict'.") |
329 (add-to-list 'debug-ignored-errors "Don't know how to resolve") | 330 (add-to-list 'debug-ignored-errors "Don't know how to resolve") |
330 | 331 |
331 (defvar smerge-text-properties | 332 (defvar smerge-text-properties |
332 `(help-echo "merge conflict: mouse-3 shows a menu" | 333 `(help-echo "merge conflict: mouse-3 shows a menu" |
376 (let ((beg (re-search-backward smerge-end-re nil t)) | 377 (let ((beg (re-search-backward smerge-end-re nil t)) |
377 (end (re-search-forward smerge-begin-re nil t))) | 378 (end (re-search-forward smerge-begin-re nil t))) |
378 (smerge-remove-props (or beg (point-min)) (or end (point-max))) | 379 (smerge-remove-props (or beg (point-min)) (or end (point-max))) |
379 (push event unread-command-events))))) | 380 (push event unread-command-events))))) |
380 | 381 |
381 (defun smerge-resolve () | 382 (defun smerge-resolve (&optional safe) |
382 "Resolve the conflict at point intelligently. | 383 "Resolve the conflict at point intelligently. |
383 This relies on mode-specific knowledge and thus only works in | 384 This relies on mode-specific knowledge and thus only works in |
384 some major modes. Uses `smerge-resolve-function' to do the actual work." | 385 some major modes. Uses `smerge-resolve-function' to do the actual work." |
385 (interactive) | 386 (interactive) |
386 (smerge-match-conflict) | 387 (smerge-match-conflict) |
391 (eq (match-beginning 1) (match-beginning 3))) | 392 (eq (match-beginning 1) (match-beginning 3))) |
392 (smerge-keep-n 3)) | 393 (smerge-keep-n 3)) |
393 ;; Mode-specific conflict resolution. | 394 ;; Mode-specific conflict resolution. |
394 ((condition-case nil | 395 ((condition-case nil |
395 (atomic-change-group | 396 (atomic-change-group |
396 (funcall smerge-resolve-function) | 397 (if safe |
397 t) | 398 (funcall smerge-resolve-function safe) |
399 (funcall smerge-resolve-function)) | |
400 t) | |
398 (error nil)) | 401 (error nil)) |
399 ;; Nothing to do: the resolution function has done it already. | 402 ;; Nothing to do: the resolution function has done it already. |
400 nil) | 403 nil) |
401 ;; FIXME: Add "if [ diff -b MINE OTHER ]; then select OTHER; fi" | 404 ;; FIXME: Add "if [ diff -b MINE OTHER ]; then select OTHER; fi" |
402 ((and (match-end 2) | 405 ((and (match-end 2) |
409 nil) | 412 nil) |
410 ) | 413 ) |
411 (t | 414 (t |
412 (error "Don't know how to resolve"))) | 415 (error "Don't know how to resolve"))) |
413 (smerge-auto-leave)) | 416 (smerge-auto-leave)) |
417 | |
418 (defun smerge-resolve-all () | |
419 "Perform automatic resolution on all conflicts." | |
420 (interactive) | |
421 (save-excursion | |
422 (goto-char (point-min)) | |
423 (while (re-search-forward smerge-begin-re nil t) | |
424 (condition-case nil | |
425 (progn | |
426 (smerge-match-conflict) | |
427 (smerge-resolve 'safe)) | |
428 (error nil))))) | |
429 | |
430 (defun smerge-batch-resolve () | |
431 ;; command-line-args-left is what is left of the command line. | |
432 (if (not noninteractive) | |
433 (error "`smerge-batch-resolve' is to be used only with -batch")) | |
434 (while command-line-args-left | |
435 (let ((file (pop command-line-args-left))) | |
436 (message "Resolving conflicts in %s..." file) | |
437 (when (file-readable-p file) | |
438 (with-current-buffer (find-file-noselect file) | |
439 (smerge-resolve-all) | |
440 (save-buffer) | |
441 (kill-buffer (current-buffer))))))) | |
414 | 442 |
415 (defun smerge-keep-base () | 443 (defun smerge-keep-base () |
416 "Revert to the base version." | 444 "Revert to the base version." |
417 (interactive) | 445 (interactive) |
418 (smerge-match-conflict) | 446 (smerge-match-conflict) |
675 | 703 |
676 ;; Call diff on those files. | 704 ;; Call diff on those files. |
677 (unwind-protect | 705 (unwind-protect |
678 (with-temp-buffer | 706 (with-temp-buffer |
679 (let ((coding-system-for-read 'emacs-mule)) | 707 (let ((coding-system-for-read 'emacs-mule)) |
680 (call-process diff-command nil t nil file1 file2)) | 708 ;; Don't forget -a to make sure diff treats it as a text file |
709 ;; even if it contains \0 and such. | |
710 (call-process diff-command nil t nil "-a" file1 file2)) | |
681 ;; Process diff's output. | 711 ;; Process diff's output. |
682 (goto-char (point-min)) | 712 (goto-char (point-min)) |
683 (while (not (eobp)) | 713 (while (not (eobp)) |
684 (if (not (looking-at "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?\\([acd]\\)\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?$")) | 714 (if (not (looking-at "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?\\([acd]\\)\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?$")) |
685 (error "Unexpected patch hunk header: %s" | 715 (error "Unexpected patch hunk header: %s" |
829 (set-window-configuration windows) | 859 (set-window-configuration windows) |
830 (message "Conflict resolution finished; you may save the buffer"))))) | 860 (message "Conflict resolution finished; you may save the buffer"))))) |
831 (message "Please resolve conflicts now; exit ediff when done"))) | 861 (message "Please resolve conflicts now; exit ediff when done"))) |
832 | 862 |
833 | 863 |
864 (defconst smerge-parsep-re | |
865 (concat smerge-begin-re "\\|" smerge-end-re "\\|" | |
866 smerge-base-re "\\|" smerge-other-re "\\|")) | |
867 | |
834 ;;;###autoload | 868 ;;;###autoload |
835 (define-minor-mode smerge-mode | 869 (define-minor-mode smerge-mode |
836 "Minor mode to simplify editing output from the diff3 program. | 870 "Minor mode to simplify editing output from the diff3 program. |
837 \\{smerge-mode-map}" | 871 \\{smerge-mode-map}" |
838 :group 'smerge :lighter " SMerge" | 872 :group 'smerge :lighter " SMerge" |
843 (font-lock-remove-keywords nil smerge-font-lock-keywords)) | 877 (font-lock-remove-keywords nil smerge-font-lock-keywords)) |
844 (goto-char (point-min)) | 878 (goto-char (point-min)) |
845 (while (smerge-find-conflict) | 879 (while (smerge-find-conflict) |
846 (save-excursion | 880 (save-excursion |
847 (font-lock-fontify-region (match-beginning 0) (match-end 0) nil))))) | 881 (font-lock-fontify-region (match-beginning 0) (match-end 0) nil))))) |
882 (if (string-match (regexp-quote smerge-parsep-re) paragraph-separate) | |
883 (unless smerge-mode | |
884 (set (make-local-variable 'paragraph-separate) | |
885 (replace-match "" t t paragraph-separate))) | |
886 (when smerge-mode | |
887 (set (make-local-variable 'paragraph-separate) | |
888 (concat smerge-parsep-re paragraph-separate)))) | |
848 (unless smerge-mode | 889 (unless smerge-mode |
849 (smerge-remove-props (point-min) (point-max)))) | 890 (smerge-remove-props (point-min) (point-max)))) |
850 | 891 |
851 | 892 |
852 (provide 'smerge-mode) | 893 (provide 'smerge-mode) |