1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-29 11:02:01 +00:00
emacs/lisp/ediff-ptch.el

845 lines
30 KiB
EmacsLisp
Raw Normal View History

1996-06-22 01:44:38 +00:00
;;; ediff-ptch.el --- Ediff's patch support
2005-08-06 22:13:43 +00:00
;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2009-01-05 03:18:22 +00:00
;; 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
1996-06-22 01:44:38 +00:00
2002-01-07 Michael Kifer <kifer@cs.stonybrook.edu> * viper-init.el (viper-cond-compile-for-xemacs-or-emacs): new macro that replaces viper-emacs-p and viper-xemacs-p in many cases. Used to reduce the number of warnings. * viper-cmd.el: use viper-cond-compile-for-xemacs-or-emacs. (viper-standard-value): moved here from viper.el. (viper-set-unread-command-events): moved to viper-util.el (viper-check-minibuffer-overlay): make sure viper-minibuffer-overlay is moved to cover the entire input field. * viper-util.el: use viper-cond-compile-for-xemacs-or-emacs. (viper-read-key-sequence, viper-set-unread-command-events, viper-char-symbol-sequence-p, viper-char-array-p): moved here. * viper-ex.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-keym.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-mous.el: use viper-cond-compile-for-xemacs-or-emacs. * viper-macs.el (viper-char-array-p, viper-char-symbol-sequence-p, viper-event-vector-p): moved to viper-util.el * viper.el (viper-standard-value): moved to viper-cmd.el. Use viper-cond-compile-for-xemacs-or-emacs. * ediff-help.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-hook.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-init.el (ediff-cond-compile-for-xemacs-or-emacs): new macro designed to be used in many places where ediff-emacs-p or ediff-xemacs-p was previously used. Reduces the number of warnings. Use ediff-cond-compile-for-xemacs-or-emacs in many places in lieue of ediff-xemacs-p. (ediff-make-current-diff-overlay, ediff-highlight-diff-in-one-buffer, ediff-convert-fine-diffs-to-overlays, ediff-empty-diff-region-p, ediff-whitespace-diff-region-p, ediff-get-region-contents): moved to ediff-util.el. (ediff-event-key): moved here. * ediff-merge.el: got rid of unreferenced variables. * ediff-mult.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff-util.el: use ediff-cond-compile-for-xemacs-or-emacs. (ediff-cleanup-mess): improved the way windows are set up after quitting ediff. (ediff-janitor): use ediff-dispose-of-variant-according-to-user. (ediff-dispose-of-variant-according-to-user): new function designed to be smarter and also understands indirect buffers. (ediff-highlight-diff-in-one-buffer, ediff-unhighlight-diff-in-one-buffer, ediff-unhighlight-diffs-totally-in-one-buffer, ediff-highlight-diff, ediff-highlight-diff, ediff-unhighlight-diff, ediff-unhighlight-diffs-totally, ediff-empty-diff-region-p, ediff-whitespace-diff-region-p, ediff-get-region-contents, ediff-make-current-diff-overlay): moved here. (ediff-format-bindings-of): new function by Hannu Koivisto <azure@iki.fi>. (ediff-setup): make sure the merge buffer is always widened and modifiable. (ediff-write-merge-buffer-and-maybe-kill): refuse to write the result of a merge into a file visited by another buffer. (ediff-arrange-autosave-in-merge-jobs): check if the merge file is visited by another buffer and ask to save/delete that buffer. (ediff-verify-file-merge-buffer): new function to do the above. * ediff-vers.el: load ediff-init.el at compile time. * ediff-wind.el: use ediff-cond-compile-for-xemacs-or-emacs. * ediff.el (ediff-windows, ediff-regions-wordwise, ediff-regions-linewise): use indirect buffers to improve robustness and make it possible to compare regions of the same buffer (even overlapping regions). (ediff-clone-buffer-for-region-comparison, ediff-clone-buffer-for-window-comparison): new functions. (ediff-files-internal): refuse to compare identical files. (ediff-regions-internal): get rid of the warning about comparing regions of the same buffer. * ediff-diff.el (ediff-convert-fine-diffs-to-overlays): moved here. Plus the following fixes courtesy of Dave Love: Doc fixes. (ediff-word-1): Use word class and move - to the front per regexp documentation. (ediff-wordify): Bind forward-word-function outside loop. (ediff-copy-to-buffer): Use insert-buffer-substring rather than consing buffer contents. (ediff-goto-word): Move syntax table setting outside loop.
2002-01-08 04:36:01 +00:00
;; Author: Michael Kifer <kifer@cs.stonybrook.edu>
1996-06-22 01:44:38 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
1996-06-22 01:44:38 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
1996-06-22 01:44:38 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1996-06-22 01:44:38 +00:00
;;; Commentary:
1996-06-22 01:44:38 +00:00
;;; Code:
2003-02-04 11:26:42 +00:00
1997-05-31 01:10:39 +00:00
(provide 'ediff-ptch)
1997-05-31 01:10:39 +00:00
(defgroup ediff-ptch nil
"Ediff patch support."
1997-05-31 01:10:39 +00:00
:tag "Patch"
:prefix "ediff-"
:group 'ediff)
;; compiler pacifier
(eval-when-compile
2008-05-03 20:53:53 +00:00
(require 'ediff))
1997-05-31 01:10:39 +00:00
;; end pacifier
1996-06-22 01:44:38 +00:00
1996-08-30 16:57:35 +00:00
(require 'ediff-init)
1997-07-17 19:37:07 +00:00
(defcustom ediff-patch-program "patch"
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Name of the program that applies patches.
1997-07-17 19:37:07 +00:00
It is recommended to use GNU-compatible versions."
:type 'string
:group 'ediff-ptch)
(defcustom ediff-patch-options "-f"
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Options to pass to ediff-patch-program.
1997-07-17 19:37:07 +00:00
Note: the `-b' option should be specified in `ediff-backup-specs'.
It is recommended to pass the `-f' option to the patch program, so it won't ask
1999-11-01 07:16:15 +00:00
questions. However, some implementations don't accept this option, in which
1997-07-17 19:37:07 +00:00
case the default value for this variable should be changed."
:type 'string
:group 'ediff-ptch)
1996-06-22 01:44:38 +00:00
(defvar ediff-last-dir-patch nil
"Last directory used by an Ediff command for file to patch.")
1997-07-17 19:37:07 +00:00
;; the default backup extension
(defconst ediff-default-backup-extension
* bitmaps/README: * xfns.c: * termcap.c: * term.c: * syswait.h: * systty.h: * systime.h: * syssignal.h: * sysdep.c: * process.h: * process.c: * print.c: * ndir.h: * lread.c: * keyboard.c: * getpagesize.h: * floatfns.c: * fileio.c: * emacs.c: * doc.c: * dispnew.c: * dired.c: * data.c: * callproc.c: * buffer.c: * README: * Makefile.in: * s/template.h: * s/msdos.h: * m/vax.h: Remove VMS support. * s/vms.h: * vlimit.h: * uaf.h: * temacs.opt: * param.h: * ioctl.h: Remove file. * descrip.mms: * compile.com: Remove file. * Create.c: Remove VMS support. * message.el (Module): * gnus-start.el (Module): * gnus-registry.el (Module): * textmodes/texinfmt.el: * nxml/nxml-enc.el: * mail/feedmail.el: * international/mule.el: * international/latexenc.el: * emulation/viper-util.el: * emulation/viper-init.el: * emulation/viper-ex.el: * emacs-lisp/bytecomp.el: * version.el: * subr.el: * startup.el: * sort.el: * shadowfile.el: * recentf.el: * printing.el: * paths.el: * minibuffer.el: * ls-lisp.el: * loadup.el: * hippie-exp.el: * finder.el: * files.el: * ediff-util.el: * ediff-ptch.el: * ediff-init.el: * ediff-diff.el: * dired.el: * dired-aux.el: * cus-edit.el: * bindings.el: * arc-mode.el: * add-log.el: Remove VMS support. * obsolete/vmsproc.el: * obsolete/vms-pmail.el: * obsolete/vms-patch.el: Remove file. * etags.c: * emacsclient.c: Remove VMS support. * termcap.src: Remove file. * README: * PROBLEMS: * MACHINES: Remove VMS info. * ediff.texi: Remove VMS support. * os.texi: * intro.texi: * files.texi: Remove VMS support. * emacs.texi: Remove VMS support. * make-dist: * README: Remove VMS support. * vms: Remove directory.
2008-07-31 05:33:56 +00:00
(if (memq system-type '(emx ms-dos))
1997-07-17 19:37:07 +00:00
"_orig" ".orig"))
2003-02-04 11:26:42 +00:00
1997-07-17 19:37:07 +00:00
(defcustom ediff-backup-extension ediff-default-backup-extension
1996-09-20 01:10:05 +00:00
"Backup extension used by the patch program.
1997-07-17 19:37:07 +00:00
See also `ediff-backup-specs'."
:type 'string
:group 'ediff-ptch)
1996-09-20 01:10:05 +00:00
1997-09-06 04:16:05 +00:00
(defun ediff-test-patch-utility ()
(condition-case nil
(cond ((eq 0 (call-process ediff-patch-program nil nil nil "-z." "-b"))
;; GNU `patch' v. >= 2.2
'gnu)
((eq 0 (call-process ediff-patch-program nil nil nil "-b"))
'posix)
(t 'traditional))
(file-error nil)))
1997-09-06 04:16:05 +00:00
2003-02-04 11:26:42 +00:00
(defcustom ediff-backup-specs
1997-09-06 04:16:05 +00:00
(let ((type (ediff-test-patch-utility)))
(cond ((eq type 'gnu)
;; GNU `patch' v. >= 2.2
(format "-z%s -b" ediff-backup-extension))
((eq type 'posix)
;; POSIX `patch' -- ediff-backup-extension must be ".orig"
(setq ediff-backup-extension ediff-default-backup-extension)
"-b")
(t
;; traditional `patch'
(format "-b %s" ediff-backup-extension))))
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Backup directives to pass to the patch program.
1996-09-20 01:10:05 +00:00
Ediff requires that the old version of the file \(before applying the patch\)
1999-11-01 07:16:15 +00:00
be saved in a file named `the-patch-file.extension'. Usually `extension' is
1996-09-20 01:10:05 +00:00
`.orig', but this can be changed by the user and may depend on the system.
Therefore, Ediff needs to know the backup extension used by the patch program.
Some versions of the patch program let you specify `-b backup-extension'.
1997-07-17 19:37:07 +00:00
Other versions only permit `-b', which assumes the extension `.orig'
1999-11-01 07:16:15 +00:00
\(in which case ediff-backup-extension MUST be also `.orig'\). The latest
1997-07-17 19:37:07 +00:00
versions of GNU patch require `-b -z backup-extension'.
1996-09-20 01:10:05 +00:00
Note that both `ediff-backup-extension' and `ediff-backup-specs'
1999-11-01 07:16:15 +00:00
must be set properly. If your patch program takes the option `-b',
1996-09-20 01:10:05 +00:00
but not `-b extension', the variable `ediff-backup-extension' must
1997-09-06 04:16:05 +00:00
still be set so Ediff will know which extension to use.
1999-11-01 07:16:15 +00:00
Ediff tries to guess the appropriate value for this variables. It is believed
1997-09-06 04:16:05 +00:00
to be working for `traditional' patch, all versions of GNU patch, and for POSIX
1999-11-01 07:16:15 +00:00
patch. So, don't change these variables, unless the default doesn't work."
1997-05-31 01:10:39 +00:00
:type 'string
:group 'ediff-ptch)
1996-09-20 01:10:05 +00:00
1996-06-22 01:44:38 +00:00
1997-05-31 01:10:39 +00:00
(defcustom ediff-patch-default-directory nil
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Default directory to look for patches."
1997-05-31 01:10:39 +00:00
:type '(choice (const nil) string)
:group 'ediff-ptch)
1996-06-22 01:44:38 +00:00
;; This context diff does not recognize spaces inside files, but removing ' '
;; from [^ \t] breaks normal patches for some reason
1997-05-31 01:10:39 +00:00
(defcustom ediff-context-diff-label-regexp
1996-06-22 01:44:38 +00:00
(concat "\\(" ; context diff 2-liner
"^\\*\\*\\* +\\([^ \t]+\\)[^*]+[\t ]*\n--- +\\([^ \t]+\\)"
1996-06-22 01:44:38 +00:00
"\\|" ; GNU unified format diff 2-liner
"^--- +\\([^ \t]+\\)[\t ]+.*\n\\+\\+\\+ +\\([^ \t]+\\)"
"\\)")
* align.el: * allout.el: * apropos.el: * arc-mode.el: * autoinsert.el: * avoid.el: * battery.el: * bookmark.el: * buff-menu.el: * calculator.el: * chistory.el: * cmuscheme.el: * comint.el: * compare-w.el: * dabbrev.el: * delim-col.el: * desktop.el: * diff-mode.el: * diff.el: * dired-aux.el: * dired-x.el: * dired.el: * dos-vars.el: * ediff-diff.el: * ediff-help.el: * ediff-init.el: * ediff-merg.el: * ediff-mult.el: * ediff-ptch.el: * ediff-vers.el: * ediff-wind.el: * ediff.el: * emerge.el: * facemenu.el: * faces.el: * ffap.el: * filecache.el: * find-dired.el: * font-core.el: * font-lock.el: * forms.el: * fringe.el: * help-at-pt.el: * hippie-exp.el: * ido.el: * image-file.el: * imenu.el: * indent.el: * info.el: * isearchb.el: * iswitchb.el: * jit-lock.el: * jka-compr.el: * log-edit.el: * lpr.el: * ls-lisp.el: * man.el: * menu-bar.el: * midnight.el: * mouse-sel.el: * mouse.el: * msb.el: * outline.el: * paren.el: * pcmpl-cvs.el: * pcmpl-gnu.el: * pcomplete.el: * pcvs-info.el: * pcvs-parse.el: * printing.el: * ps-mule.el: * ps-print.el: * replace.el: * ruler-mode.el: * saveplace.el: * sb-image.el: * scroll-bar.el: * sha1.el: * shadowfile.el: * shell.el: * sort.el: * speedbar.el: * strokes.el: * tempo.el: * term.el: * terminal.el: * time-stamp.el: * time.el: * tree-widget.el: * type-break.el: * vc-cvs.el: * vc-hg.el: * vc-mcvs.el: * vc-rcs.el: * vc-sccs.el: * vc.el: * view.el: * w32-vars.el: * whitespace.el: * wid-edit.el: Remove leading * from docstrings of defcustoms, deffaces, defconsts and defuns.
2008-12-03 05:48:14 +00:00
"Regexp matching filename 2-liners at the start of each context diff.
1997-07-17 19:37:07 +00:00
You probably don't want to change that, unless you are using an obscure patch
program."
1997-05-31 01:10:39 +00:00
:type 'regexp
:group 'ediff-ptch)
1996-06-22 01:44:38 +00:00
1999-11-01 07:16:15 +00:00
;; The buffer of the patch file. Local to control buffer.
1996-06-22 01:44:38 +00:00
(ediff-defvar-local ediff-patchbufer nil "")
;; The buffer where patch displays its diagnostics.
(ediff-defvar-local ediff-patch-diagnostics nil "")
1999-11-01 07:16:15 +00:00
;; Map of patch buffer. Has the form:
1996-06-22 01:44:38 +00:00
;; ((filename1 marker1 marker2) (filename2 marker1 marker2) ...)
;; where filenames are files to which patch would have applied the patch;
;; marker1 delimits the beginning of the corresponding patch and marker2 does
;; it for the end.
(ediff-defvar-local ediff-patch-map nil "")
;; strip prefix from filename
;; returns /dev/null, if can't strip prefix
(defsubst ediff-file-name-sans-prefix (filename prefix)
(if prefix
(save-match-data
(if (string-match (concat "^" (if (stringp prefix)
(regexp-quote prefix)
""))
filename)
(substring filename (match-end 0))
(concat "/null/" filename)))
filename)
)
1996-06-22 01:44:38 +00:00
;; no longer used
;; return the number of matches of regexp in buf starting from the beginning
(defun ediff-count-matches (regexp buf)
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer buf
1996-06-22 01:44:38 +00:00
(let ((count 0) opoint)
(save-excursion
(goto-char (point-min))
(while (and (not (eobp))
(progn (setq opoint (point))
(re-search-forward regexp nil t)))
(if (= opoint (point))
(forward-char 1)
(setq count (1+ count)))))
count)))
2003-02-04 11:26:42 +00:00
;; Scan BUF (which is supposed to contain a patch) and make a list of the form
;; ((nil nil filename-spec1 marker1 marker2)
;; (nil nil filename-spec2 marker1 marker2) ...)
2003-02-04 11:26:42 +00:00
;; where filename-spec[12] are files to which the `patch' program would
;; have applied the patch.
;; nin, nil are placeholders. See ediff-make-new-meta-list-element in
;; ediff-meta.el for the explanations.
;; In the beginning we don't know exactly which files need to be patched.
;; We usually come up with two candidates and ediff-file-name-sans-prefix
;; resolves this later.
;;
;; The marker `marker1' delimits the beginning of the corresponding patch and
;; `marker2' does it for the end.
;; The result of ediff-map-patch-buffer is a list, which is then assigned
;; to ediff-patch-map.
;; The function returns the number of elements in the list ediff-patch-map
1996-06-22 01:44:38 +00:00
(defun ediff-map-patch-buffer (buf)
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer buf
1996-06-22 01:44:38 +00:00
(let ((count 0)
(mark1 (move-marker (make-marker) (point-min)))
(mark1-end (point-min))
(possible-file-names '("/dev/null" . "/dev/null"))
mark2-end mark2 filenames
beg1 beg2 end1 end2
patch-map opoint)
(save-excursion
(goto-char (point-min))
(setq opoint (point))
(while (and (not (eobp))
(re-search-forward ediff-context-diff-label-regexp nil t))
(if (= opoint (point))
(forward-char 1) ; ensure progress towards the end
(setq mark2 (move-marker (make-marker) (match-beginning 0))
mark2-end (match-end 0)
beg1 (or (match-beginning 2) (match-beginning 4))
1996-09-20 01:10:05 +00:00
end1 (or (match-end 2) (match-end 4))
beg2 (or (match-beginning 3) (match-beginning 5))
end2 (or (match-end 3) (match-end 5)))
1996-06-22 01:44:38 +00:00
;; possible-file-names is holding the new file names until we
;; insert the old file name in the patch map
;; It is a pair
;; (filename-from-1st-header-line . filename-from-2nd-line)
1996-06-22 01:44:38 +00:00
(setq possible-file-names
(cons (if (and beg1 end1)
(buffer-substring beg1 end1)
"/dev/null")
(if (and beg2 end2)
(buffer-substring beg2 end2)
"/dev/null")))
;; check for any `Index:' or `Prereq:' lines, but don't use them
(if (re-search-backward "^Index:" mark1-end 'noerror)
(move-marker mark2 (match-beginning 0)))
(if (re-search-backward "^Prereq:" mark1-end 'noerror)
(move-marker mark2 (match-beginning 0)))
(goto-char mark2-end)
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
(if filenames
(setq patch-map
(cons (ediff-make-new-meta-list-element
filenames mark1 mark2)
patch-map)))
1996-06-22 01:44:38 +00:00
(setq mark1 mark2
mark1-end mark2-end
filenames possible-file-names))
(setq opoint (point)
count (1+ count))))
(setq mark2 (point-max-marker)
patch-map (cons (ediff-make-new-meta-list-element
possible-file-names mark1 mark2)
patch-map))
1996-06-22 01:44:38 +00:00
(setq ediff-patch-map (nreverse patch-map))
count)))
;; Fix up the file names in the list using the argument FILENAME
;; Algorithm: find the files' directories in the patch and, if a directory is
;; absolute, cut it out from the corresponding file name in the patch.
;; Relative directories are not cut out.
;; Prepend the directory of FILENAME to each resulting file (which came
;; originally from the patch).
;; In addition, the first file in the patch document is replaced by FILENAME.
;; Each file is actually a pair of files found in the context diff header
;; In the end, for each pair, we ask the user which file to patch.
1996-06-22 01:44:38 +00:00
;; Note: Ediff doesn't recognize multi-file patches that are separated
1999-11-01 07:16:15 +00:00
;; with the `Index:' line. It treats them as a single-file patch.
1996-06-22 01:44:38 +00:00
;;
;; Executes inside the patch buffer
(defun ediff-fixup-patch-map (filename)
(setq filename (expand-file-name filename))
(let ((actual-dir (if (file-directory-p filename)
;; directory part of filename
(file-name-as-directory filename)
(file-name-directory filename)))
;; In case 2 files are possible patch targets, the user will be offered
;; to choose file1 or file2. In a multifile patch, if the user chooses
;; 1 or 2, this choice is preserved to decide future alternatives.
chosen-alternative
1996-06-22 01:44:38 +00:00
)
;; chop off base-dirs
(mapc (lambda (session-info)
(let* ((proposed-file-names
;; Filename-spec is objA; it is represented as
;; (file1 . file2). Get it using ediff-get-session-objA.
(ediff-get-session-objA-name session-info))
;; base-dir1 is the dir part of the 1st file in the patch
(base-dir1
(or (file-name-directory (car proposed-file-names))
""))
;; directory part of the 2nd file in the patch
(base-dir2
(or (file-name-directory (cdr proposed-file-names))
""))
)
;; If both base-dir1 and base-dir2 are relative and exist,
;; assume that
;; these dirs lead to the actual files starting at the present
;; directory. So, we don't strip these relative dirs from the
;; file names. This is a heuristic intended to improve guessing
(let ((default-directory (file-name-directory filename)))
(unless (or (file-name-absolute-p base-dir1)
(file-name-absolute-p base-dir2)
(not (file-exists-p base-dir1))
(not (file-exists-p base-dir2)))
(setq base-dir1 ""
base-dir2 "")))
(or (string= (car proposed-file-names) "/dev/null")
(setcar proposed-file-names
(ediff-file-name-sans-prefix
(car proposed-file-names) base-dir1)))
(or (string=
(cdr proposed-file-names) "/dev/null")
(setcdr proposed-file-names
(ediff-file-name-sans-prefix
(cdr proposed-file-names) base-dir2)))
))
ediff-patch-map)
1996-06-22 01:44:38 +00:00
;; take the given file name into account
(or (file-directory-p filename)
(string= "/dev/null" filename)
(setcar (ediff-get-session-objA (car ediff-patch-map))
(cons (file-name-nondirectory filename)
(file-name-nondirectory filename))))
1996-06-22 01:44:38 +00:00
;; prepend actual-dir
(mapc (lambda (session-info)
(let ((proposed-file-names
(ediff-get-session-objA-name session-info)))
(if (and (string-match "^/null/" (car proposed-file-names))
(string-match "^/null/" (cdr proposed-file-names)))
;; couldn't intuit the file name to patch, so
;; something is amiss
(progn
(with-output-to-temp-buffer ediff-msg-buffer
(ediff-with-current-buffer standard-output
(fundamental-mode))
(princ
(format "
1996-06-22 01:44:38 +00:00
The patch file contains a context diff for
%s
%s
However, Ediff cannot infer the name of the actual file
1999-11-01 07:16:15 +00:00
to be patched on your system. If you know the correct file name,
1996-06-22 01:44:38 +00:00
please enter it now.
If you don't know and still would like to apply patches to
other files, enter /dev/null
"
(substring (car proposed-file-names) 6)
(substring (cdr proposed-file-names) 6))))
(let ((directory t)
user-file)
(while directory
(setq user-file
(read-file-name
"Please enter file name: "
actual-dir actual-dir t))
(if (not (file-directory-p user-file))
(setq directory nil)
(setq directory t)
(beep)
(message "%s is a directory" user-file)
(sit-for 2)))
(setcar (ediff-get-session-objA session-info)
(cons user-file user-file))))
(setcar proposed-file-names
(expand-file-name
(concat actual-dir (car proposed-file-names))))
(setcdr proposed-file-names
(expand-file-name
(concat actual-dir (cdr proposed-file-names)))))
))
ediff-patch-map)
;; Check for the existing files in each pair and discard the nonexisting
;; ones. If both exist, ask the user.
(mapcar (lambda (session-info)
(let* ((file1 (car (ediff-get-session-objA-name session-info)))
(file2 (cdr (ediff-get-session-objA-name session-info)))
(session-file-object
(ediff-get-session-objA session-info))
1999-11-01 07:16:15 +00:00
(f1-exists (file-exists-p file1))
(f2-exists (file-exists-p file2)))
(cond
((and
;; The patch program prefers the shortest file as the patch
;; target. However, this is a questionable heuristic. In an
;; interactive program, like ediff, we can offer the user a
;; choice.
;; (< (length file2) (length file1))
(not f1-exists)
f2-exists)
;; replace file-pair with the winning file2
(setcar session-file-object file2))
((and
;; (< (length file1) (length file2))
(not f2-exists)
f1-exists)
;; replace file-pair with the winning file1
(setcar session-file-object file1))
1999-11-01 07:16:15 +00:00
((and f1-exists f2-exists
(string= file1 file2))
(setcar session-file-object file1))
((and f1-exists f2-exists (eq chosen-alternative 1))
(setcar session-file-object file1))
((and f1-exists f2-exists (eq chosen-alternative 2))
(setcar session-file-object file2))
1999-11-01 07:16:15 +00:00
((and f1-exists f2-exists)
(with-output-to-temp-buffer ediff-msg-buffer
(ediff-with-current-buffer standard-output
(fundamental-mode))
1999-11-01 07:16:15 +00:00
(princ (format "
1996-06-22 01:44:38 +00:00
Ediff has inferred that
%s
%s
1997-09-06 04:16:05 +00:00
are two possible targets for applying the patch.
1996-06-22 01:44:38 +00:00
Both files seem to be plausible alternatives.
Please advice:
Type `y' to use %s as the target;
Type `n' to use %s as the target.
"
file1 file2 file1 file2)))
(setcar session-file-object
(if (y-or-n-p (format "Use %s ? " file1))
(progn
(setq chosen-alternative 1)
file1)
(setq chosen-alternative 2)
file2))
)
(f2-exists (setcar session-file-object file2))
(f1-exists (setcar session-file-object file1))
1999-11-01 07:16:15 +00:00
(t
(with-output-to-temp-buffer ediff-msg-buffer
(ediff-with-current-buffer standard-output
(fundamental-mode))
1999-11-01 07:16:15 +00:00
(princ "\nEdiff has inferred that")
(if (string= file1 file2)
(princ (format "
1996-06-22 01:44:38 +00:00
%s
is assumed to be the target for this patch. However, this file does not exist."
1999-11-01 07:16:15 +00:00
file1))
(princ (format "
1996-06-22 01:44:38 +00:00
%s
1997-09-06 04:16:05 +00:00
%s
1999-11-01 07:16:15 +00:00
are two possible targets for this patch. However, these files do not exist."
file1 file2)))
(princ "
1997-09-06 04:16:05 +00:00
\nPlease enter an alternative patch target ...\n"))
1999-11-01 07:16:15 +00:00
(let ((directory t)
target)
(while directory
2003-02-04 11:26:42 +00:00
(setq target (read-file-name
1999-11-01 07:16:15 +00:00
"Please enter a patch target: "
actual-dir actual-dir t))
(if (not (file-directory-p target))
(setq directory nil)
(beep)
(message "%s is a directory" target)
(sit-for 2)))
(setcar session-file-object target))))))
1996-06-22 01:44:38 +00:00
ediff-patch-map)
))
(defun ediff-show-patch-diagnostics ()
(interactive)
(cond ((window-live-p ediff-window-A)
(set-window-buffer ediff-window-A ediff-patch-diagnostics))
((window-live-p ediff-window-B)
(set-window-buffer ediff-window-B ediff-patch-diagnostics))
(t (display-buffer ediff-patch-diagnostics 'not-this-window))))
1999-11-01 07:16:15 +00:00
;; prompt for file, get the buffer
(defun ediff-prompt-for-patch-file ()
(let ((dir (cond (ediff-use-last-dir ediff-last-dir-patch)
(ediff-patch-default-directory) ; try patch default dir
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy of Scott Bronson. (ex-cmd-assoc,ex-compile,ex-cmd-one-letr): New functions. (viper-check-sub,viper-get-ex-command,viper-execute-ex-command): Deleted functions. (viper-get-ex-com-subr,viper-ex,ex-mark): Changed to use the new ex-token-list. (viper-get-ex-address-subr): convert registers to char data type. * viper-util.el (viper-int-to-char,viper-char-equal): new functions. (viper-memq-char): use viper-int-to-char. (viper-file-checked-in-p): use vc-locking-user, if vc doesn't have vc-locking-state. (viper-read-key): use viper-read-key-sequence. * viper.el (viper-major-mode-modifier-list): added inferior-emacs-lisp-mode. (this-major-mode-requires-vi-state): new function that uses simple heuristics to decide if vi state is appropriate. (set-viper-state-in-major-mode): use this-major-mode-requires-vi-state. (viper-non-hook-settings): don't advise read-key-sequence. (viper-read-key-sequence): new function that replaces the previously used advice to read-key-sequence. * viper-cmd.el (viper-test-com-defun,viper-exec-change, viper-exec-Change,viper-execute-com,viper-insert,viper-append, viper-Append,viper-Insert,viper-open-line,viper-Open-line, viper-open-line-at-point,viper-substitute,viper-overwrite, viper-replace-char-subr,viper-forward-word,viper-forward-Word): got rid of the negative character hack. (viper-escape-to-state,viper-replace-state-exit-cmd): use viper-read-key-sequence. (viper-envelop-ESC-key): no need for ad-get-orig-definition. (viper-minibuffer-standard-hook,viper-read-string-with-history): don't override existing minibuffer-setup-hook. (viper-mark-point,viper-goto-mark-subr,viper-brac-function): convert registers to char data type. (viper-autoindent): use viper-indent-line. * viper-keym.el: use viper-exec-key-in-emacs. * viper.texi: Added credits, new commands, like :make. * ediff-util.el: Copyright years. (ediff-choose-syntax-table): New function. (ediff-setup): Use ediff-choose-syntax-table. (ediff-file-checked-out-p,ediff-file-checked-in-p): check if vc-state is available. (ediff-make-temp-file): use ediff-coding-system-for-write. * ediff-init.el (ediff-with-syntax-table): New macro, uses with-syntax-table. (ediff-coding-system-for-read): from ediff-diff.el (ediff-coding-system-for-write): new variable. (ediff-highest-priority): fixed the bug having to do with disappearing overlays. (ediff-file-remote-p): use file-remote-p, if available. (ediff-listable-file): new function. (ediff-file-attributes): use ediff-listable-file. * ediff-mult.el (ediff-meta-insert-file-info1): use ediff-listable-file. * ediff-ptch.el (ediff-prompt-for-patch-file): use ediff-coding-system-for-read. (ediff-patch-file-internal): use ediff-coding-system-for-write. * ediff-diff.el (ediff-coding-system-for-read): moved to ediff-init.el. (ediff-match-diff3-line,ediff-get-diff3-group): improved pattern. * ediff.el: Date of last update, copyright years. * ediff-wind (ediff-setup-control-frame): Nill->nil. * ediff.texi: added clarifications, acknowledgements.
2001-07-21 05:28:24 +00:00
(t default-directory)))
(coding-system-for-read ediff-coding-system-for-read)
patch-file-name)
(setq patch-file-name
(read-file-name
2005-09-24 Emilio C. Lopes <eclig@gmx.net> * woman.el (woman-file-name): * wid-edit.el (widget-file-prompt-value) (widget-coding-system-prompt-value): * w32-fns.el (set-w32-system-coding-system): * vc.el (vc-version-diff, vc-annotate): * textmodes/reftex-auc.el (reftex-arg-cite) (reftex-arg-index-tag): * textmodes/refer.el (refer-get-bib-files): * textmodes/artist.el (artist-figlet-choose-font): * terminal.el (terminal-emulator): * replace.el (occur-read-primary-args): * rect.el (string-rectangle, string-insert-rectangle): * ps-print.el (ps-print-preprint): * progmodes/pascal.el (pascal-goto-defun): * progmodes/etags.el (visit-tags-table, visit-tags-table-buffer): * progmodes/compile.el (compilation-find-file): * printing.el (pr-interactive-n-up): * play/animate.el (animate-birthday-present): * net/rcompile.el (remote-compile): * man.el (man, Man-goto-section, Man-follow-manual-reference): * mail/rmailsum.el (rmail-summary-search-backward) (rmail-summary-search): * mail/rmailout.el (rmail-output-read-rmail-file-name) (rmail-output-read-file-name): * mail/rmail.el (rmail-search, rmail-search-backwards): * mail/mailabbrev.el (merge-mail-abbrevs, rebuild-mail-abbrevs): * locate.el (locate): * international/quail.el (quail-show-keyboard-layout): * international/mule.el (set-buffer-file-coding-system) (revert-buffer-with-coding-system, set-file-name-coding-system) (set-terminal-coding-system, set-keyboard-coding-system) (set-next-selection-coding-system): * international/mule-diag.el (describe-coding-system) (describe-font, describe-fontset): * international/mule-cmds.el (universal-coding-system-argument) (search-unencodable-char, describe-input-method) (set-language-environment, describe-language-environment): * international/codepage.el (codepage-setup): * international/code-pages.el (codepage-setup): * info.el (Info-search, Info-follow-reference) (Info-search-backward): * emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-clear-cache, ad-activate) (ad-deactivate, ad-update, ad-unadvise, ad-read-advice-name) (ad-enable-advice, ad-disable-advice, ad-remove-advice) (ad-read-regexp): * ediff-util.el (ediff-toggle-regexp-match): * ediff-ptch.el (ediff-prompt-for-patch-file): * dired-aux.el (dired-diff): * diff.el (diff): * cus-edit.el (custom-variable-prompt): * calendar/timeclock.el (timeclock-ask-for-project): * calc/calcalg3.el (calc-get-fit-variables): * calc/calc-store.el (calc-edit-variable) (calc-permanent-variable): * vc-mcvs.el (vc-mcvs-register): * shadowfile.el (shadow-define-literal-group): * woman.el (woman-file-name): * vc.el (vc-version-diff, vc-merge): * textmodes/reftex-index.el (reftex-index-complete-tag): * format.el (format-decode-buffer, format-decode-region): * emulation/viper-cmd.el (viper-read-string-with-history): * emacs-lisp/debug.el (cancel-debug-on-entry): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): * ediff.el (ediff-merge-revisions) (ediff-merge-revisions-with-ancestor, ediff-revision): * completion.el (interactive-completion-string-reader): * calc/calc-prog.el (calc-user-define-formula): Follow convention for reading with the minibuffer.
2005-09-24 13:44:02 +00:00
(format "Patch is in file%s: "
(cond ((and buffer-file-name
(equal (expand-file-name dir)
(file-name-directory buffer-file-name)))
(concat
" (default "
(file-name-nondirectory buffer-file-name)
")"))
(t "")))
dir buffer-file-name 'must-match))
(if (file-directory-p patch-file-name)
(error "Patch file cannot be a directory: %s" patch-file-name)
(find-file-noselect patch-file-name))
1999-11-01 07:16:15 +00:00
))
;; Try current buffer, then the other window's buffer. Else, give up.
(defun ediff-prompt-for-patch-buffer ()
(get-buffer
(read-buffer
"Buffer that holds the patch: "
1999-11-01 07:16:15 +00:00
(cond ((save-excursion
(goto-char (point-min))
(re-search-forward ediff-context-diff-label-regexp nil t))
(current-buffer))
((save-window-excursion
(other-window 1)
(save-excursion
(goto-char (point-min))
(and (re-search-forward ediff-context-diff-label-regexp nil t)
(current-buffer)))))
((save-window-excursion
(other-window -1)
(save-excursion
(goto-char (point-min))
(and (re-search-forward ediff-context-diff-label-regexp nil t)
(current-buffer)))))
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy of Scott Bronson. (ex-cmd-assoc,ex-compile,ex-cmd-one-letr): New functions. (viper-check-sub,viper-get-ex-command,viper-execute-ex-command): Deleted functions. (viper-get-ex-com-subr,viper-ex,ex-mark): Changed to use the new ex-token-list. (viper-get-ex-address-subr): convert registers to char data type. * viper-util.el (viper-int-to-char,viper-char-equal): new functions. (viper-memq-char): use viper-int-to-char. (viper-file-checked-in-p): use vc-locking-user, if vc doesn't have vc-locking-state. (viper-read-key): use viper-read-key-sequence. * viper.el (viper-major-mode-modifier-list): added inferior-emacs-lisp-mode. (this-major-mode-requires-vi-state): new function that uses simple heuristics to decide if vi state is appropriate. (set-viper-state-in-major-mode): use this-major-mode-requires-vi-state. (viper-non-hook-settings): don't advise read-key-sequence. (viper-read-key-sequence): new function that replaces the previously used advice to read-key-sequence. * viper-cmd.el (viper-test-com-defun,viper-exec-change, viper-exec-Change,viper-execute-com,viper-insert,viper-append, viper-Append,viper-Insert,viper-open-line,viper-Open-line, viper-open-line-at-point,viper-substitute,viper-overwrite, viper-replace-char-subr,viper-forward-word,viper-forward-Word): got rid of the negative character hack. (viper-escape-to-state,viper-replace-state-exit-cmd): use viper-read-key-sequence. (viper-envelop-ESC-key): no need for ad-get-orig-definition. (viper-minibuffer-standard-hook,viper-read-string-with-history): don't override existing minibuffer-setup-hook. (viper-mark-point,viper-goto-mark-subr,viper-brac-function): convert registers to char data type. (viper-autoindent): use viper-indent-line. * viper-keym.el: use viper-exec-key-in-emacs. * viper.texi: Added credits, new commands, like :make. * ediff-util.el: Copyright years. (ediff-choose-syntax-table): New function. (ediff-setup): Use ediff-choose-syntax-table. (ediff-file-checked-out-p,ediff-file-checked-in-p): check if vc-state is available. (ediff-make-temp-file): use ediff-coding-system-for-write. * ediff-init.el (ediff-with-syntax-table): New macro, uses with-syntax-table. (ediff-coding-system-for-read): from ediff-diff.el (ediff-coding-system-for-write): new variable. (ediff-highest-priority): fixed the bug having to do with disappearing overlays. (ediff-file-remote-p): use file-remote-p, if available. (ediff-listable-file): new function. (ediff-file-attributes): use ediff-listable-file. * ediff-mult.el (ediff-meta-insert-file-info1): use ediff-listable-file. * ediff-ptch.el (ediff-prompt-for-patch-file): use ediff-coding-system-for-read. (ediff-patch-file-internal): use ediff-coding-system-for-write. * ediff-diff.el (ediff-coding-system-for-read): moved to ediff-init.el. (ediff-match-diff3-line,ediff-get-diff3-group): improved pattern. * ediff.el: Date of last update, copyright years. * ediff-wind (ediff-setup-control-frame): Nill->nil. * ediff.texi: added clarifications, acknowledgements.
2001-07-21 05:28:24 +00:00
(t (ediff-other-buffer (current-buffer))))
1999-11-01 07:16:15 +00:00
'must-match)))
(defun ediff-get-patch-buffer (&optional arg patch-buf)
"Obtain patch buffer. If patch is already in a buffer---use it.
Else, read patch file into a new buffer. If patch buffer is passed as an
optional argument, then use it."
(let ((last-nonmenu-event t) ; Emacs: don't use dialog box
last-command-event) ; XEmacs: don't use dialog box
(cond ((ediff-buffer-live-p patch-buf))
;; even prefix arg: patch in buffer
((and (integerp arg) (eq 0 (mod arg 2)))
(setq patch-buf (ediff-prompt-for-patch-buffer)))
;; odd prefix arg: get patch from a file
((and (integerp arg) (eq 1 (mod arg 2)))
(setq patch-buf (ediff-prompt-for-patch-file)))
(t (setq patch-buf
(if (y-or-n-p "Is the patch already in a buffer? ")
(ediff-prompt-for-patch-buffer)
(ediff-prompt-for-patch-file)))))
2003-02-04 11:26:42 +00:00
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer patch-buf
1996-06-22 01:44:38 +00:00
(goto-char (point-min))
(or (ediff-get-visible-buffer-window patch-buf)
(progn
(pop-to-buffer patch-buf 'other-window)
(select-window (previous-window)))))
(ediff-map-patch-buffer patch-buf)
patch-buf))
;; Dispatch the right patch file function: regular or meta-level,
;; depending on how many patches are in the patch file.
;; At present, there is no support for meta-level patches.
;; Should return either the ctl buffer or the meta-buffer
(defun ediff-dispatch-file-patching-job (patch-buf filename
&optional startup-hooks)
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer patch-buf
1996-06-22 01:44:38 +00:00
;; relativize names in the patch with respect to source-file
(ediff-fixup-patch-map filename)
(if (< (length ediff-patch-map) 2)
(ediff-patch-file-internal
patch-buf
(if (and ediff-patch-map
(not (string-match
"^/dev/null"
;; this is the file to patch
(ediff-get-session-objA-name (car ediff-patch-map))))
2003-02-04 11:26:42 +00:00
(> (length
(ediff-get-session-objA-name (car ediff-patch-map)))
1))
(ediff-get-session-objA-name (car ediff-patch-map))
1996-06-22 01:44:38 +00:00
filename)
startup-hooks)
(ediff-multi-patch-internal patch-buf startup-hooks))
))
1999-11-01 07:16:15 +00:00
;; When patching a buffer, never change the orig file. Instead, create a new
1997-09-06 04:16:05 +00:00
;; buffer, ***_patched, even if the buff visits a file.
;; Users who want to actually patch the buffer should use
;; ediff-patch-file, not ediff-patch-buffer.
(defun ediff-patch-buffer-internal (patch-buf
buf-to-patch-name
&optional startup-hooks)
1996-06-22 01:44:38 +00:00
(let* ((buf-to-patch (get-buffer buf-to-patch-name))
1997-09-06 04:16:05 +00:00
(visited-file (if buf-to-patch (buffer-file-name buf-to-patch)))
1996-06-22 01:44:38 +00:00
(buf-mod-status (buffer-modified-p buf-to-patch))
1997-07-31 04:04:23 +00:00
(multifile-patch-p (> (length (ediff-with-current-buffer patch-buf
1996-06-22 01:44:38 +00:00
ediff-patch-map)) 1))
default-dir file-name ctl-buf)
1997-09-06 04:16:05 +00:00
(if multifile-patch-p
(error
1999-11-01 07:16:15 +00:00
"To apply multi-file patches, please use `ediff-patch-file'"))
1997-09-06 04:16:05 +00:00
;; create a temp file to patch
(ediff-with-current-buffer buf-to-patch
(setq default-dir default-directory)
(setq file-name (ediff-make-temp-file buf-to-patch))
;; temporarily switch visited file name, if any
(set-visited-file-name file-name)
;; don't create auto-save file, if buff was visiting a file
(or visited-file
(setq buffer-auto-save-file-name nil))
;; don't confuse the user with a new bufname
(rename-buffer buf-to-patch-name)
(set-buffer-modified-p nil)
(set-visited-file-modtime) ; sync buffer and temp file
(setq default-directory default-dir)
)
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; dispatch a patch function
(setq ctl-buf (ediff-dispatch-file-patching-job
patch-buf file-name startup-hooks))
2003-02-04 11:26:42 +00:00
1997-09-06 04:16:05 +00:00
(ediff-with-current-buffer ctl-buf
(delete-file (buffer-file-name ediff-buffer-A))
(delete-file (buffer-file-name ediff-buffer-B))
(ediff-with-current-buffer ediff-buffer-A
(if default-dir (setq default-directory default-dir))
(set-visited-file-name visited-file) ; visited-file might be nil
(rename-buffer buf-to-patch-name)
(set-buffer-modified-p buf-mod-status))
(ediff-with-current-buffer ediff-buffer-B
(setq buffer-auto-save-file-name nil) ; don't create auto-save file
(if default-dir (setq default-directory default-dir))
(set-visited-file-name nil)
2003-02-04 11:26:42 +00:00
(rename-buffer (ediff-unique-buffer-name
1997-09-06 04:16:05 +00:00
(concat buf-to-patch-name "_patched") ""))
(set-buffer-modified-p t)))
1996-06-22 01:44:38 +00:00
))
1997-09-06 04:16:05 +00:00
;; Traditional patch has weird return codes.
;; GNU and Posix return 1 if some hanks failed and 2 in case of trouble.
;; 0 is a good code in all cases.
;; We'll do the concervative thing.
(defun ediff-patch-return-code-ok (code)
(eq code 0))
;;; (if (eq (ediff-test-patch-utility) 'traditional)
;;; (eq code 0)
;;; (not (eq code 2))))
1996-06-22 01:44:38 +00:00
(defun ediff-patch-file-internal (patch-buf source-filename
&optional startup-hooks)
(setq source-filename (expand-file-name source-filename))
2003-02-04 11:26:42 +00:00
1996-09-20 01:10:05 +00:00
(let* ((shell-file-name ediff-shell)
1996-06-22 01:44:38 +00:00
(patch-diagnostics (get-buffer-create "*ediff patch diagnostics*"))
;; ediff-find-file may use a temp file to do the patch
;; so, we save source-filename and true-source-filename as a var
;; that initially is source-filename but may be changed to a temp
;; file for the purpose of patching.
(true-source-filename source-filename)
(target-filename source-filename)
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy of Scott Bronson. (ex-cmd-assoc,ex-compile,ex-cmd-one-letr): New functions. (viper-check-sub,viper-get-ex-command,viper-execute-ex-command): Deleted functions. (viper-get-ex-com-subr,viper-ex,ex-mark): Changed to use the new ex-token-list. (viper-get-ex-address-subr): convert registers to char data type. * viper-util.el (viper-int-to-char,viper-char-equal): new functions. (viper-memq-char): use viper-int-to-char. (viper-file-checked-in-p): use vc-locking-user, if vc doesn't have vc-locking-state. (viper-read-key): use viper-read-key-sequence. * viper.el (viper-major-mode-modifier-list): added inferior-emacs-lisp-mode. (this-major-mode-requires-vi-state): new function that uses simple heuristics to decide if vi state is appropriate. (set-viper-state-in-major-mode): use this-major-mode-requires-vi-state. (viper-non-hook-settings): don't advise read-key-sequence. (viper-read-key-sequence): new function that replaces the previously used advice to read-key-sequence. * viper-cmd.el (viper-test-com-defun,viper-exec-change, viper-exec-Change,viper-execute-com,viper-insert,viper-append, viper-Append,viper-Insert,viper-open-line,viper-Open-line, viper-open-line-at-point,viper-substitute,viper-overwrite, viper-replace-char-subr,viper-forward-word,viper-forward-Word): got rid of the negative character hack. (viper-escape-to-state,viper-replace-state-exit-cmd): use viper-read-key-sequence. (viper-envelop-ESC-key): no need for ad-get-orig-definition. (viper-minibuffer-standard-hook,viper-read-string-with-history): don't override existing minibuffer-setup-hook. (viper-mark-point,viper-goto-mark-subr,viper-brac-function): convert registers to char data type. (viper-autoindent): use viper-indent-line. * viper-keym.el: use viper-exec-key-in-emacs. * viper.texi: Added credits, new commands, like :make. * ediff-util.el: Copyright years. (ediff-choose-syntax-table): New function. (ediff-setup): Use ediff-choose-syntax-table. (ediff-file-checked-out-p,ediff-file-checked-in-p): check if vc-state is available. (ediff-make-temp-file): use ediff-coding-system-for-write. * ediff-init.el (ediff-with-syntax-table): New macro, uses with-syntax-table. (ediff-coding-system-for-read): from ediff-diff.el (ediff-coding-system-for-write): new variable. (ediff-highest-priority): fixed the bug having to do with disappearing overlays. (ediff-file-remote-p): use file-remote-p, if available. (ediff-listable-file): new function. (ediff-file-attributes): use ediff-listable-file. * ediff-mult.el (ediff-meta-insert-file-info1): use ediff-listable-file. * ediff-ptch.el (ediff-prompt-for-patch-file): use ediff-coding-system-for-read. (ediff-patch-file-internal): use ediff-coding-system-for-write. * ediff-diff.el (ediff-coding-system-for-read): moved to ediff-init.el. (ediff-match-diff3-line,ediff-get-diff3-group): improved pattern. * ediff.el: Date of last update, copyright years. * ediff-wind (ediff-setup-control-frame): Nill->nil. * ediff.texi: added clarifications, acknowledgements.
2001-07-21 05:28:24 +00:00
;; this ensures that the patch process gets patch buffer in the
;; encoding that Emacs thinks is right for that type of text
2003-02-04 11:26:42 +00:00
(coding-system-for-write
* viper-ex.el (ex-token-list,ex-cmd-execute): Revamped, courtesy of Scott Bronson. (ex-cmd-assoc,ex-compile,ex-cmd-one-letr): New functions. (viper-check-sub,viper-get-ex-command,viper-execute-ex-command): Deleted functions. (viper-get-ex-com-subr,viper-ex,ex-mark): Changed to use the new ex-token-list. (viper-get-ex-address-subr): convert registers to char data type. * viper-util.el (viper-int-to-char,viper-char-equal): new functions. (viper-memq-char): use viper-int-to-char. (viper-file-checked-in-p): use vc-locking-user, if vc doesn't have vc-locking-state. (viper-read-key): use viper-read-key-sequence. * viper.el (viper-major-mode-modifier-list): added inferior-emacs-lisp-mode. (this-major-mode-requires-vi-state): new function that uses simple heuristics to decide if vi state is appropriate. (set-viper-state-in-major-mode): use this-major-mode-requires-vi-state. (viper-non-hook-settings): don't advise read-key-sequence. (viper-read-key-sequence): new function that replaces the previously used advice to read-key-sequence. * viper-cmd.el (viper-test-com-defun,viper-exec-change, viper-exec-Change,viper-execute-com,viper-insert,viper-append, viper-Append,viper-Insert,viper-open-line,viper-Open-line, viper-open-line-at-point,viper-substitute,viper-overwrite, viper-replace-char-subr,viper-forward-word,viper-forward-Word): got rid of the negative character hack. (viper-escape-to-state,viper-replace-state-exit-cmd): use viper-read-key-sequence. (viper-envelop-ESC-key): no need for ad-get-orig-definition. (viper-minibuffer-standard-hook,viper-read-string-with-history): don't override existing minibuffer-setup-hook. (viper-mark-point,viper-goto-mark-subr,viper-brac-function): convert registers to char data type. (viper-autoindent): use viper-indent-line. * viper-keym.el: use viper-exec-key-in-emacs. * viper.texi: Added credits, new commands, like :make. * ediff-util.el: Copyright years. (ediff-choose-syntax-table): New function. (ediff-setup): Use ediff-choose-syntax-table. (ediff-file-checked-out-p,ediff-file-checked-in-p): check if vc-state is available. (ediff-make-temp-file): use ediff-coding-system-for-write. * ediff-init.el (ediff-with-syntax-table): New macro, uses with-syntax-table. (ediff-coding-system-for-read): from ediff-diff.el (ediff-coding-system-for-write): new variable. (ediff-highest-priority): fixed the bug having to do with disappearing overlays. (ediff-file-remote-p): use file-remote-p, if available. (ediff-listable-file): new function. (ediff-file-attributes): use ediff-listable-file. * ediff-mult.el (ediff-meta-insert-file-info1): use ediff-listable-file. * ediff-ptch.el (ediff-prompt-for-patch-file): use ediff-coding-system-for-read. (ediff-patch-file-internal): use ediff-coding-system-for-write. * ediff-diff.el (ediff-coding-system-for-read): moved to ediff-init.el. (ediff-match-diff3-line,ediff-get-diff3-group): improved pattern. * ediff.el: Date of last update, copyright years. * ediff-wind (ediff-setup-control-frame): Nill->nil. * ediff.texi: added clarifications, acknowledgements.
2001-07-21 05:28:24 +00:00
(if (boundp 'buffer-file-coding-system) buffer-file-coding-system))
2003-02-04 11:26:42 +00:00
target-buf buf-to-patch file-name-magic-p
1997-07-31 04:04:23 +00:00
patch-return-code ctl-buf backup-style aux-wind)
2003-02-04 11:26:42 +00:00
1997-09-06 04:16:05 +00:00
(if (string-match "V" ediff-patch-options)
1996-06-22 01:44:38 +00:00
(error
"Ediff doesn't take the -V option in `ediff-patch-options'--sorry"))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; Make a temp file, if source-filename has a magic file handler (or if
;; it is handled via auto-mode-alist and similar magic).
;; Check if there is a buffer visiting source-filename and if they are in
;; sync; arrange for the deletion of temp file.
(ediff-find-file 'true-source-filename 'buf-to-patch
'ediff-last-dir-patch 'startup-hooks)
;; Check if source file name has triggered black magic, such as file name
;; handlers or auto mode alist, and make a note of it.
;; true-source-filename should be either the original name or a
;; temporary file where we put the after-product of the file handler.
(setq file-name-magic-p (not (equal (file-truename true-source-filename)
(file-truename source-filename))))
2003-02-04 11:26:42 +00:00
;; Checkout orig file, if necessary, so that the patched file
1996-12-28 02:53:04 +00:00
;; could be checked back in.
(ediff-maybe-checkout buf-to-patch)
1996-06-22 01:44:38 +00:00
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer patch-diagnostics
(insert-buffer-substring patch-buf)
1996-06-22 01:44:38 +00:00
(message "Applying patch ... ")
;; fix environment for gnu patch, so it won't make numbered extensions
(setq backup-style (getenv "VERSION_CONTROL"))
(setenv "VERSION_CONTROL" nil)
1996-09-20 01:10:05 +00:00
(setq patch-return-code
(call-process-region
(point-min) (point-max)
shell-file-name
t ; delete region (which contains the patch
t ; insert output (patch diagnostics) in current buffer
nil ; don't redisplay
shell-command-switch ; usually -c
(format "%s %s %s %s"
ediff-patch-program
ediff-patch-options
ediff-backup-specs
(expand-file-name true-source-filename))
))
1996-06-22 01:44:38 +00:00
;; restore environment for gnu patch
(setenv "VERSION_CONTROL" backup-style))
(message "Applying patch ... done")
(message "")
(switch-to-buffer patch-diagnostics)
(sit-for 0) ; synchronize - let the user see diagnostics
2003-02-04 11:26:42 +00:00
1997-09-06 04:16:05 +00:00
(or (and (ediff-patch-return-code-ok patch-return-code)
1996-09-20 01:10:05 +00:00
(file-exists-p
(concat true-source-filename ediff-backup-extension)))
(progn
(with-output-to-temp-buffer ediff-msg-buffer
(ediff-with-current-buffer standard-output
(fundamental-mode))
2003-02-04 11:26:42 +00:00
(princ (format
1997-09-06 04:16:05 +00:00
"Patch program has failed due to a bad patch file,
it couldn't apply all hunks, OR
it couldn't create the backup for the file being patched.
1996-09-20 01:10:05 +00:00
1997-07-17 19:37:07 +00:00
The former could be caused by a corrupt patch file or because the %S
program doesn't understand the format of the patch file in use.
1996-09-20 01:10:05 +00:00
1997-07-17 19:37:07 +00:00
The second problem might be due to an incompatibility among these settings:
1997-09-06 04:16:05 +00:00
ediff-patch-program = %S ediff-patch-options = %S
ediff-backup-extension = %S ediff-backup-specs = %S
1996-09-20 01:10:05 +00:00
See Ediff on-line manual for more details on these variables.
2003-02-04 11:26:42 +00:00
In particular, check the documentation for `ediff-backup-specs'.
1997-09-06 04:16:05 +00:00
In any of the above cases, Ediff doesn't compare files automatically.
However, if the patch was applied partially and the backup file was created,
you can still examine the changes via M-x ediff-files"
ediff-patch-program
ediff-patch-program
ediff-patch-options
ediff-backup-extension
ediff-backup-specs
)))
1996-09-20 01:10:05 +00:00
(beep 1)
(if (setq aux-wind (get-buffer-window ediff-msg-buffer))
(progn
(select-window aux-wind)
(goto-char (point-max))))
1997-07-17 19:37:07 +00:00
(switch-to-buffer-other-window patch-diagnostics)
1996-09-20 01:10:05 +00:00
(error "Patch appears to have failed")))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; If black magic is involved, apply patch to a temp copy of the
1999-11-01 07:16:15 +00:00
;; file. Otherwise, apply patch to the orig copy. If patch is applied
1996-06-22 01:44:38 +00:00
;; to temp copy, we name the result old-name_patched for local files
1999-11-01 07:16:15 +00:00
;; and temp-copy_patched for remote files. The orig file name isn't
1996-06-22 01:44:38 +00:00
;; changed, and the temp copy of the original is later deleted.
;; Without magic, the original file is renamed (usually into
;; old-name_orig) and the result of patching will have the same name as
;; the original.
(if (not file-name-magic-p)
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer buf-to-patch
1996-09-20 01:10:05 +00:00
(set-visited-file-name
(concat source-filename ediff-backup-extension))
1996-06-22 01:44:38 +00:00
(set-buffer-modified-p nil))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; Black magic in effect.
;; If orig file was remote, put the patched file in the temp directory.
;; If orig file is local, put the patched file in the directory of
;; the orig file.
(setq target-filename
(concat
(if (ediff-file-remote-p (file-truename source-filename))
true-source-filename
source-filename)
"_patched"))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
(rename-file true-source-filename target-filename t)
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; arrange that the temp copy of orig will be deleted
1996-09-20 01:10:05 +00:00
(rename-file (concat true-source-filename ediff-backup-extension)
1996-06-22 01:44:38 +00:00
true-source-filename t))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; make orig buffer read-only
(setq startup-hooks
(cons 'ediff-set-read-only-in-buf-A startup-hooks))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;; set up a buf for the patched file
(setq target-buf (find-file-noselect target-filename))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
(setq ctl-buf
(ediff-buffers-internal
buf-to-patch target-buf nil
startup-hooks 'epatch))
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer ctl-buf
1996-06-22 01:44:38 +00:00
(setq ediff-patchbufer patch-buf
ediff-patch-diagnostics patch-diagnostics))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
(bury-buffer patch-diagnostics)
(message "Type `P', if you need to see patch diagnostics")
ctl-buf))
(defun ediff-multi-patch-internal (patch-buf &optional startup-hooks)
(let (meta-buf)
(setq startup-hooks
;; this sets various vars in the meta buffer inside
;; ediff-prepare-meta-buffer
1999-11-25 04:34:23 +00:00
(cons `(lambda ()
;; tell what to do if the user clicks on a session record
(setq ediff-session-action-function
'ediff-patch-file-form-meta
ediff-meta-patchbufer patch-buf) )
1996-06-22 01:44:38 +00:00
startup-hooks))
2003-02-04 11:26:42 +00:00
(setq meta-buf (ediff-prepare-meta-buffer
1996-06-22 01:44:38 +00:00
'ediff-filegroup-action
1997-07-31 04:04:23 +00:00
(ediff-with-current-buffer patch-buf
(cons (ediff-make-new-meta-list-header
nil ; regexp
(format "%S" patch-buf) ; obj A
nil nil ; objects B,C
nil ; merge-auto-store-dir
nil ; comparison-func
)
1996-06-22 01:44:38 +00:00
ediff-patch-map))
"*Ediff Session Group Panel"
'ediff-redraw-directory-group-buffer
'ediff-multifile-patch
startup-hooks))
(ediff-show-meta-buffer meta-buf)
))
2003-02-04 11:26:42 +00:00
1996-06-22 01:44:38 +00:00
;;; Local Variables:
;;; eval: (put 'ediff-defvar-local 'lisp-indent-hook 'defun)
1997-07-31 04:04:23 +00:00
;;; eval: (put 'ediff-with-current-buffer 'lisp-indent-hook 1)
;;; eval: (put 'ediff-with-current-buffer 'edebug-form-spec '(form body))
1996-06-22 01:44:38 +00:00
;;; End:
;; arch-tag: 2fe2161e-e116-469b-90fa-5cbb44c1bd1b
1996-06-22 01:44:38 +00:00
;;; ediff-ptch.el ends here