Mercurial > emacs
comparison lisp/ediff-ptch.el @ 19047:f90d40b0bff5
new version
author | Michael Kifer <kifer@cs.stonybrook.edu> |
---|---|
date | Thu, 31 Jul 1997 04:04:23 +0000 |
parents | 1405083241e8 |
children | 1ecc4a79d048 |
comparison
equal
deleted
inserted
replaced
19046:689f3dc973f9 | 19047:f90d40b0bff5 |
---|---|
153 | 153 |
154 | 154 |
155 ;; no longer used | 155 ;; no longer used |
156 ;; return the number of matches of regexp in buf starting from the beginning | 156 ;; return the number of matches of regexp in buf starting from the beginning |
157 (defun ediff-count-matches (regexp buf) | 157 (defun ediff-count-matches (regexp buf) |
158 (ediff-eval-in-buffer buf | 158 (ediff-with-current-buffer buf |
159 (let ((count 0) opoint) | 159 (let ((count 0) opoint) |
160 (save-excursion | 160 (save-excursion |
161 (goto-char (point-min)) | 161 (goto-char (point-min)) |
162 (while (and (not (eobp)) | 162 (while (and (not (eobp)) |
163 (progn (setq opoint (point)) | 163 (progn (setq opoint (point)) |
172 ;; where filenames are files to which patch would have applied the patch; | 172 ;; where filenames are files to which patch would have applied the patch; |
173 ;; marker1 delimits the beginning of the corresponding patch and marker2 does | 173 ;; marker1 delimits the beginning of the corresponding patch and marker2 does |
174 ;; it for the end. This list is then assigned to ediff-patch-map. | 174 ;; it for the end. This list is then assigned to ediff-patch-map. |
175 ;; Returns the number of elements in the list ediff-patch-map | 175 ;; Returns the number of elements in the list ediff-patch-map |
176 (defun ediff-map-patch-buffer (buf) | 176 (defun ediff-map-patch-buffer (buf) |
177 (ediff-eval-in-buffer buf | 177 (ediff-with-current-buffer buf |
178 (let ((count 0) | 178 (let ((count 0) |
179 (mark1 (move-marker (make-marker) (point-min))) | 179 (mark1 (move-marker (make-marker) (point-min))) |
180 (mark1-end (point-min)) | 180 (mark1-end (point-min)) |
181 (possible-file-names '("/dev/null" . "/dev/null")) | 181 (possible-file-names '("/dev/null" . "/dev/null")) |
182 mark2-end mark2 filenames | 182 mark2-end mark2 filenames |
401 (setq patch-buf | 401 (setq patch-buf |
402 (find-file-noselect | 402 (find-file-noselect |
403 (read-file-name "Which file contains the patch? " | 403 (read-file-name "Which file contains the patch? " |
404 dir nil 'must-match)))) | 404 dir nil 'must-match)))) |
405 | 405 |
406 (ediff-eval-in-buffer patch-buf | 406 (ediff-with-current-buffer patch-buf |
407 (goto-char (point-min)) | 407 (goto-char (point-min)) |
408 (or (ediff-get-visible-buffer-window patch-buf) | 408 (or (ediff-get-visible-buffer-window patch-buf) |
409 (progn | 409 (progn |
410 (pop-to-buffer patch-buf 'other-window) | 410 (pop-to-buffer patch-buf 'other-window) |
411 (select-window (previous-window))))) | 411 (select-window (previous-window))))) |
416 ;; depending on how many patches are in the patch file. | 416 ;; depending on how many patches are in the patch file. |
417 ;; At present, there is no support for meta-level patches. | 417 ;; At present, there is no support for meta-level patches. |
418 ;; Should return either the ctl buffer or the meta-buffer | 418 ;; Should return either the ctl buffer or the meta-buffer |
419 (defun ediff-dispatch-file-patching-job (patch-buf filename | 419 (defun ediff-dispatch-file-patching-job (patch-buf filename |
420 &optional startup-hooks) | 420 &optional startup-hooks) |
421 (ediff-eval-in-buffer patch-buf | 421 (ediff-with-current-buffer patch-buf |
422 ;; relativize names in the patch with respect to source-file | 422 ;; relativize names in the patch with respect to source-file |
423 (ediff-fixup-patch-map filename) | 423 (ediff-fixup-patch-map filename) |
424 (if (< (length ediff-patch-map) 2) | 424 (if (< (length ediff-patch-map) 2) |
425 (ediff-patch-file-internal | 425 (ediff-patch-file-internal |
426 patch-buf | 426 patch-buf |
436 (defun ediff-patch-buffer-internal (patch-buf buf-to-patch-name | 436 (defun ediff-patch-buffer-internal (patch-buf buf-to-patch-name |
437 &optional startup-hooks) | 437 &optional startup-hooks) |
438 (let* ((buf-to-patch (get-buffer buf-to-patch-name)) | 438 (let* ((buf-to-patch (get-buffer buf-to-patch-name)) |
439 (file-name-ok (if buf-to-patch (buffer-file-name buf-to-patch))) | 439 (file-name-ok (if buf-to-patch (buffer-file-name buf-to-patch))) |
440 (buf-mod-status (buffer-modified-p buf-to-patch)) | 440 (buf-mod-status (buffer-modified-p buf-to-patch)) |
441 (multifile-patch-p (> (length (ediff-eval-in-buffer patch-buf | 441 (multifile-patch-p (> (length (ediff-with-current-buffer patch-buf |
442 ediff-patch-map)) 1)) | 442 ediff-patch-map)) 1)) |
443 default-dir file-name ctl-buf) | 443 default-dir file-name ctl-buf) |
444 (if file-name-ok | 444 (if file-name-ok |
445 (setq file-name file-name-ok) | 445 (setq file-name file-name-ok) |
446 (if multifile-patch-p | 446 (if multifile-patch-p |
447 (error | 447 (error |
448 "Can't apply multi-file patches to buffers that visit no files")) | 448 "Can't apply multi-file patches to buffers that visit no files")) |
449 (ediff-eval-in-buffer buf-to-patch | 449 (ediff-with-current-buffer buf-to-patch |
450 (setq default-dir default-directory) | 450 (setq default-dir default-directory) |
451 (setq file-name (ediff-make-temp-file buf-to-patch)) | 451 (setq file-name (ediff-make-temp-file buf-to-patch)) |
452 (set-visited-file-name file-name) | 452 (set-visited-file-name file-name) |
453 (setq buffer-auto-save-file-name nil) ; don't create auto-save file | 453 (setq buffer-auto-save-file-name nil) ; don't create auto-save file |
454 ;;don't confuse the user with a new bufname | 454 ;;don't confuse the user with a new bufname |
464 | 464 |
465 (if file-name-ok | 465 (if file-name-ok |
466 () | 466 () |
467 ;; buffer wasn't visiting any file, | 467 ;; buffer wasn't visiting any file, |
468 ;; so we will not run meta-level ediff here | 468 ;; so we will not run meta-level ediff here |
469 (ediff-eval-in-buffer ctl-buf | 469 (ediff-with-current-buffer ctl-buf |
470 (delete-file (buffer-file-name ediff-buffer-A)) | 470 (delete-file (buffer-file-name ediff-buffer-A)) |
471 (delete-file (buffer-file-name ediff-buffer-B)) | 471 (delete-file (buffer-file-name ediff-buffer-B)) |
472 (ediff-eval-in-buffer ediff-buffer-A | 472 (ediff-with-current-buffer ediff-buffer-A |
473 (if default-dir (setq default-directory default-dir)) | 473 (if default-dir (setq default-directory default-dir)) |
474 (set-visited-file-name nil) | 474 (set-visited-file-name nil) |
475 (rename-buffer buf-to-patch-name) | 475 (rename-buffer buf-to-patch-name) |
476 (set-buffer-modified-p buf-mod-status)) | 476 (set-buffer-modified-p buf-mod-status)) |
477 (ediff-eval-in-buffer ediff-buffer-B | 477 (ediff-with-current-buffer ediff-buffer-B |
478 (setq buffer-auto-save-file-name nil) ; don't create auto-save file | 478 (setq buffer-auto-save-file-name nil) ; don't create auto-save file |
479 (if default-dir (setq default-directory default-dir)) | 479 (if default-dir (setq default-directory default-dir)) |
480 (set-visited-file-name nil) | 480 (set-visited-file-name nil) |
481 (rename-buffer (ediff-unique-buffer-name | 481 (rename-buffer (ediff-unique-buffer-name |
482 (concat buf-to-patch-name "_patched") "")) | 482 (concat buf-to-patch-name "_patched") "")) |
494 ;; that initially is source-filename but may be changed to a temp | 494 ;; that initially is source-filename but may be changed to a temp |
495 ;; file for the purpose of patching. | 495 ;; file for the purpose of patching. |
496 (true-source-filename source-filename) | 496 (true-source-filename source-filename) |
497 (target-filename source-filename) | 497 (target-filename source-filename) |
498 target-buf buf-to-patch file-name-magic-p | 498 target-buf buf-to-patch file-name-magic-p |
499 patch-return-code ctl-buf backup-style) | 499 patch-return-code ctl-buf backup-style aux-wind) |
500 | 500 |
501 (if (string-match "-V" ediff-patch-options) | 501 (if (string-match "-V" ediff-patch-options) |
502 (error | 502 (error |
503 "Ediff doesn't take the -V option in `ediff-patch-options'--sorry")) | 503 "Ediff doesn't take the -V option in `ediff-patch-options'--sorry")) |
504 | 504 |
518 | 518 |
519 ;; Checkout orig file, if necessary, so that the patched file | 519 ;; Checkout orig file, if necessary, so that the patched file |
520 ;; could be checked back in. | 520 ;; could be checked back in. |
521 (ediff-maybe-checkout buf-to-patch) | 521 (ediff-maybe-checkout buf-to-patch) |
522 | 522 |
523 (ediff-eval-in-buffer patch-diagnostics | 523 (ediff-with-current-buffer patch-diagnostics |
524 (insert-buffer patch-buf) | 524 (insert-buffer patch-buf) |
525 (message "Applying patch ... ") | 525 (message "Applying patch ... ") |
526 ;; fix environment for gnu patch, so it won't make numbered extensions | 526 ;; fix environment for gnu patch, so it won't make numbered extensions |
527 (setq backup-style (getenv "VERSION_CONTROL")) | 527 (setq backup-style (getenv "VERSION_CONTROL")) |
528 (setenv "VERSION_CONTROL" nil) | 528 (setenv "VERSION_CONTROL" nil) |
591 ;; changed, and the temp copy of the original is later deleted. | 591 ;; changed, and the temp copy of the original is later deleted. |
592 ;; Without magic, the original file is renamed (usually into | 592 ;; Without magic, the original file is renamed (usually into |
593 ;; old-name_orig) and the result of patching will have the same name as | 593 ;; old-name_orig) and the result of patching will have the same name as |
594 ;; the original. | 594 ;; the original. |
595 (if (not file-name-magic-p) | 595 (if (not file-name-magic-p) |
596 (ediff-eval-in-buffer buf-to-patch | 596 (ediff-with-current-buffer buf-to-patch |
597 (set-visited-file-name | 597 (set-visited-file-name |
598 (concat source-filename ediff-backup-extension)) | 598 (concat source-filename ediff-backup-extension)) |
599 (set-buffer-modified-p nil)) | 599 (set-buffer-modified-p nil)) |
600 | 600 |
601 ;; Black magic in effect. | 601 ;; Black magic in effect. |
624 | 624 |
625 (setq ctl-buf | 625 (setq ctl-buf |
626 (ediff-buffers-internal | 626 (ediff-buffers-internal |
627 buf-to-patch target-buf nil | 627 buf-to-patch target-buf nil |
628 startup-hooks 'epatch)) | 628 startup-hooks 'epatch)) |
629 (ediff-eval-in-buffer ctl-buf | 629 (ediff-with-current-buffer ctl-buf |
630 (setq ediff-patchbufer patch-buf | 630 (setq ediff-patchbufer patch-buf |
631 ediff-patch-diagnostics patch-diagnostics)) | 631 ediff-patch-diagnostics patch-diagnostics)) |
632 | 632 |
633 (bury-buffer patch-diagnostics) | 633 (bury-buffer patch-diagnostics) |
634 (message "Type `P', if you need to see patch diagnostics") | 634 (message "Type `P', if you need to see patch diagnostics") |
646 ediff-meta-patchbufer patch-buf) | 646 ediff-meta-patchbufer patch-buf) |
647 )) | 647 )) |
648 startup-hooks)) | 648 startup-hooks)) |
649 (setq meta-buf (ediff-prepare-meta-buffer | 649 (setq meta-buf (ediff-prepare-meta-buffer |
650 'ediff-filegroup-action | 650 'ediff-filegroup-action |
651 (ediff-eval-in-buffer patch-buf | 651 (ediff-with-current-buffer patch-buf |
652 ;; nil replaces a regular expression | 652 ;; nil replaces a regular expression |
653 (cons (list nil (format "%S" patch-buf)) | 653 (cons (list nil (format "%S" patch-buf)) |
654 ediff-patch-map)) | 654 ediff-patch-map)) |
655 "*Ediff Session Group Panel" | 655 "*Ediff Session Group Panel" |
656 'ediff-redraw-directory-group-buffer | 656 'ediff-redraw-directory-group-buffer |
662 | 662 |
663 | 663 |
664 | 664 |
665 ;;; Local Variables: | 665 ;;; Local Variables: |
666 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) | 666 ;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun) |
667 ;;; eval: (put 'ediff-eval-in-buffer 'lisp-indent-hook 1) | 667 ;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1) |
668 ;;; eval: (put 'ediff-eval-in-buffer 'edebug-form-spec '(form body)) | 668 ;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body)) |
669 ;;; End: | 669 ;;; End: |
670 | 670 |
671 ;;; ediff-ptch.el ends here | 671 ;;; ediff-ptch.el ends here |