annotate lisp/diff-mode.el @ 80236:15905daa91d3

(uniquify-buffer-base-name): Undo last change.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 28 Feb 2008 19:46:59 +0000
parents f200e5de5464
children 3629f9a94638
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42472
5787452daded Comment fixes.
Pavel Janík <Pavel@Janik.cz>
parents: 42455
diff changeset
1 ;;; diff-mode.el --- a mode for viewing/editing context diffs
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64512
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
79721
73661ddc7ac7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78882
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5
70292
2b77fa42947f Update my email address.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 69608
diff changeset
6 ;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
42472
5787452daded Comment fixes.
Pavel Janík <Pavel@Janik.cz>
parents: 42455
diff changeset
7 ;; Keywords: convenience patch diff
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76982
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
14 ;; any later version.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; GNU General Public License for more details.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 64045
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 64045
diff changeset
24 ;; Boston, MA 02110-1301, USA.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
25
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26 ;;; Commentary:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27
35526
b40a6cecc4d5 (diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33488
diff changeset
28 ;; Provides support for font-lock, outline, navigation
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;; commands, editing and various conversions as well as jumping
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 ;; to the corresponding source file.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31
53833
32e20bdb34c9 (diff-file-regexp-alist, diff-error-regexp-alist)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53782
diff changeset
32 ;; Inspired by Pavel Machek's patch-mode.el (<pavel@@atrey.karlin.mff.cuni.cz>)
42472
5787452daded Comment fixes.
Pavel Janík <Pavel@Janik.cz>
parents: 42455
diff changeset
33 ;; Some efforts were spent to have it somewhat compatible with XEmacs'
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; diff-mode as well as with compilation-minor-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; Bugs:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
38 ;; - Reverse doesn't work with normal diffs.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40 ;; Todo:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
42 ;; - Add a `delete-after-apply' so C-c C-a automatically deletes hunks.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
43 ;; Also allow C-c C-a to delete already-applied hunks.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
44 ;;
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
45 ;; - Try `diff <file> <hunk>' to try and fuzzily discover the source location
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
46 ;; of a hunk. Show then the changes between <file> and <hunk> and make it
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
47 ;; possible to apply them to <file>, <hunk-src>, or <hunk-dst>.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
48 ;; Or maybe just make it into a ".rej to diff3-markers converter".
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
49 ;; Maybe just use `wiggle' (by Neil Brown) to do it for us.
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
50 ;;
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
51 ;; - Refine hunk on a word-by-word basis.
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
52 ;;
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
53 ;; - in diff-apply-hunk, strip context in replace-match to better
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
54 ;; preserve markers and spacing.
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
55 ;; - Handle `diff -b' output in context->unified.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
56
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57 ;;; Code:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (eval-when-compile (require 'cl))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59
65287
0cf1480347a9 (add-log-buffer-file-name-function): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64762
diff changeset
60 (defvar add-log-buffer-file-name-function)
0cf1480347a9 (add-log-buffer-file-name-function): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents: 64762
diff changeset
61
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 (defgroup diff-mode ()
64004
ea880752de3b (diff-mode): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents: 63415
diff changeset
64 "Major mode for viewing/editing diffs."
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
65 :version "21.1"
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 :group 'tools
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 :group 'diff)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
69 (defcustom diff-default-read-only nil
39386
50956864fe56 (diff-default-read-only): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39323
diff changeset
70 "If non-nil, `diff-mode' buffers default to being read-only."
50956864fe56 (diff-default-read-only): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39323
diff changeset
71 :type 'boolean
50956864fe56 (diff-default-read-only): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39323
diff changeset
72 :group 'diff-mode)
50956864fe56 (diff-default-read-only): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39323
diff changeset
73
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
74 (defcustom diff-jump-to-old-file nil
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 "*Non-nil means `diff-goto-source' jumps to the old file.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 Else, it jumps to the new file."
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
77 :type 'boolean
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
78 :group 'diff-mode)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
80 (defcustom diff-update-on-the-fly t
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 "*Non-nil means hunk headers are kept up-to-date on-the-fly.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 When editing a diff file, the line numbers in the hunk headers
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 need to be kept consistent with the actual diff. This can
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 either be done on the fly (but this sometimes interacts poorly with the
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 undo mechanism) or whenever the file is written (can be slow
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 when editing big diffs)."
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
87 :type 'boolean
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
88 :group 'diff-mode)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89
32061
cdfabbe10a24 (diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents: 32012
diff changeset
90 (defcustom diff-advance-after-apply-hunk t
cdfabbe10a24 (diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents: 32012
diff changeset
91 "*Non-nil means `diff-apply-hunk' will move to the next hunk after applying."
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
92 :type 'boolean
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
93 :group 'diff-mode)
32061
cdfabbe10a24 (diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents: 32012
diff changeset
94
cdfabbe10a24 (diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents: 32012
diff changeset
95
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
96 (defcustom diff-mode-hook nil
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
97 "Run after setting up the `diff-mode' major mode."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
98 :type 'hook
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
99 :options '(diff-delete-empty-files diff-make-unified)
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
100 :group 'diff-mode)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 (defvar diff-outline-regexp
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
105 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 ;;;; keymap, menu, ...
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
107 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
109 (easy-mmode-defmap diff-mode-shared-map
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
110 '(;; From Pavel Machek's patch-mode.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
111 ("n" . diff-hunk-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
112 ("N" . diff-file-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
113 ("p" . diff-hunk-prev)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
114 ("P" . diff-file-prev)
78882
ccd0441c69e1 * pcvs-defs.el (cvs-mode-map): Bind TAB and backtab.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78756
diff changeset
115 ("\t" . diff-hunk-next)
ccd0441c69e1 * pcvs-defs.el (cvs-mode-map): Bind TAB and backtab.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78756
diff changeset
116 ([backtab] . diff-hunk-prev)
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
117 ("k" . diff-hunk-kill)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
118 ("K" . diff-file-kill)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
119 ;; From compilation-minor-mode.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
120 ("}" . diff-file-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
121 ("{" . diff-file-prev)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 ("\C-m" . diff-goto-source)
54869
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
123 ([mouse-2] . diff-goto-source)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
124 ;; From XEmacs' diff-mode.
74269
fa6583f5269e (diff-mode-map): Add a binding for unified->context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72813
diff changeset
125 ;; Standard M-w is useful, so don't change M-W.
fa6583f5269e (diff-mode-map): Add a binding for unified->context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72813
diff changeset
126 ;;("W" . widen)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 ;;("." . diff-goto-source) ;display-buffer
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 ;;("f" . diff-goto-source) ;find-file
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
129 ("o" . diff-goto-source) ;other-window
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
130 ;;("w" . diff-goto-source) ;other-frame
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 ;;("N" . diff-narrow)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
132 ;;("h" . diff-show-header)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133 ;;("j" . diff-show-difference) ;jump to Nth diff
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 ;;("q" . diff-quit)
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
135 ;; Not useful if you have to metafy them.
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
136 ;;(" " . scroll-up)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
137 ;;("\177" . scroll-down)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
138 ;; Standard M-a is useful, so don't change M-A.
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
139 ;;("A" . diff-ediff-patch)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
140 ;; Standard M-r is useful, so don't change M-r or M-R.
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
141 ;;("r" . diff-restrict-view)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
142 ;;("R" . diff-reverse-direction)
53782
12d228ede0dd Bind q to `quit-window'.
Benjamin Rutt <brutt@bloomington.in.us>
parents: 53058
diff changeset
143 ("q" . quit-window))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
144 "Basic keymap for `diff-mode', bound to various prefix keys.")
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
146 (easy-mmode-defmap diff-mode-map
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
147 `(("\e" . ,diff-mode-shared-map)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
148 ;; From compilation-minor-mode.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
149 ("\C-c\C-c" . diff-goto-source)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
150 ;; Misc operations.
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
151 ("\C-c\C-a" . diff-apply-hunk)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
152 ("\C-c\C-e" . diff-ediff-patch)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
153 ("\C-c\C-n" . diff-restrict-view)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
154 ("\C-c\C-r" . diff-reverse-direction)
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
155 ("\C-c\C-s" . diff-split-hunk)
56919
34b22fc9d0ed (diff-mode-map): Bind toggle-next-error-follow-mode.
Eli Zaretskii <eliz@gnu.org>
parents: 56073
diff changeset
156 ("\C-c\C-t" . diff-test-hunk)
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
157 ("\C-c\C-u" . diff-context->unified)
74269
fa6583f5269e (diff-mode-map): Add a binding for unified->context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72813
diff changeset
158 ;; `d' because it duplicates the context :-( --Stef
fa6583f5269e (diff-mode-map): Add a binding for unified->context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 72813
diff changeset
159 ("\C-c\C-d" . diff-unified->context)
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
160 ("\C-c\C-w" . diff-refine-hunk)
57020
f1329d47fa1a (diff-mode-map): Rename `next-error-follow-mode' to `next-error-follow-minor-mode'.
Juri Linkov <juri@jurta.org>
parents: 56919
diff changeset
161 ("\C-c\C-f" . next-error-follow-minor-mode))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 "Keymap for `diff-mode'. See also `diff-mode-shared-map'.")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164 (easy-menu-define diff-mode-menu diff-mode-map
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 "Menu for `diff-mode'."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 '("Diff"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 ["Jump to Source" diff-goto-source t]
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
168 ["Apply hunk" diff-apply-hunk t]
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
169 ["Test applying hunk" diff-test-hunk t]
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
170 ["Apply diff with Ediff" diff-ediff-patch t]
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
171 "-----"
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 ["Reverse direction" diff-reverse-direction t]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 ["Context -> Unified" diff-context->unified t]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 ["Unified -> Context" diff-unified->context t]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)]
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
176 "-----"
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
177 ["Split hunk" diff-split-hunk t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
178 ["Refine hunk" diff-refine-hunk t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
179 ["Kill current hunk" diff-hunk-kill t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
180 ["Kill current file's hunks" diff-file-kill t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
181 "-----"
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
182 ["Previous Hunk" diff-hunk-prev t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
183 ["Next Hunk" diff-hunk-next t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
184 ["Previous File" diff-file-prev t]
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
185 ["Next File" diff-file-next t]
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 ))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187
31973
ad9838a9349c (diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31819
diff changeset
188 (defcustom diff-minor-mode-prefix "\C-c="
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
189 "Prefix key for `diff-minor-mode' commands."
62531
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
190 :type '(choice (string "\e") (string "C-c=") string)
c905fcf5e3d9 Specify missing group (and type, if simple) in defcustom.
Juanma Barranquero <lekktu@gmail.com>
parents: 61269
diff changeset
191 :group 'diff-mode)
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
192
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
193 (easy-mmode-defmap diff-minor-mode-map
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
194 `((,diff-minor-mode-prefix . ,diff-mode-shared-map))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
195 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
196
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
198 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 ;;;; font-lock support
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
200 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
202 (defface diff-header
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
203 '((((class color) (min-colors 88) (background light))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
204 :background "grey85")
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
205 (((class color) (min-colors 88) (background dark))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
206 :background "grey45")
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
207 (((class color) (background light))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
208 :foreground "blue1" :weight bold)
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
209 (((class color) (background dark))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
210 :foreground "green" :weight bold)
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
211 (t :weight bold))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
212 "`diff-mode' face inherited by hunk and index header faces."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
213 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
214 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
215 (put 'diff-header-face 'face-alias 'diff-header)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
216 (defvar diff-header-face 'diff-header)
31734
6b057ae8165d Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31705
diff changeset
217
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
218 (defface diff-file-header
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
219 '((((class color) (min-colors 88) (background light))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
220 :background "grey70" :weight bold)
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
221 (((class color) (min-colors 88) (background dark))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
222 :background "grey60" :weight bold)
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
223 (((class color) (background light))
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
224 :foreground "green" :weight bold)
55322
a02bfe4ba7ab (diff-header-face, diff-file-header-face): Use min-colors.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55088
diff changeset
225 (((class color) (background dark))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
226 :foreground "cyan" :weight bold)
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
227 (t :weight bold)) ; :height 1.3
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
228 "`diff-mode' face used to highlight file header lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
229 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
230 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
231 (put 'diff-file-header-face 'face-alias 'diff-file-header)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
232 (defvar diff-file-header-face 'diff-file-header)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
234 (defface diff-index
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
235 '((t :inherit diff-file-header))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
236 "`diff-mode' face used to highlight index header lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
237 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
238 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
239 (put 'diff-index-face 'face-alias 'diff-index)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
240 (defvar diff-index-face 'diff-index)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
241
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
242 (defface diff-hunk-header
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
243 '((t :inherit diff-header))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
244 "`diff-mode' face used to highlight hunk header lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
245 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
246 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
247 (put 'diff-hunk-header-face 'face-alias 'diff-hunk-header)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
248 (defvar diff-hunk-header-face 'diff-hunk-header)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
250 (defface diff-removed
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
251 '((t :inherit diff-changed))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
252 "`diff-mode' face used to highlight removed lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
253 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
254 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
255 (put 'diff-removed-face 'face-alias 'diff-removed)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
256 (defvar diff-removed-face 'diff-removed)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
257
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
258 (defface diff-added
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
259 '((t :inherit diff-changed))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
260 "`diff-mode' face used to highlight added lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
261 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
262 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
263 (put 'diff-added-face 'face-alias 'diff-added)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
264 (defvar diff-added-face 'diff-added)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
265
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
266 (defface diff-changed
32576
c6eb63e9c25c (diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents: 32482
diff changeset
267 '((((type tty pc) (class color) (background light))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
268 :foreground "magenta" :weight bold :slant italic)
32576
c6eb63e9c25c (diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents: 32482
diff changeset
269 (((type tty pc) (class color) (background dark))
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
270 :foreground "yellow" :weight bold :slant italic))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
271 "`diff-mode' face used to highlight changed lines."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
272 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
273 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
274 (put 'diff-changed-face 'face-alias 'diff-changed)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
275 (defvar diff-changed-face 'diff-changed)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
277 (defface diff-indicator-removed
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
278 '((t :inherit diff-removed))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
279 "`diff-mode' face used to highlight indicator of removed lines (-, <)."
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
280 :group 'diff-mode
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
281 :version "22.1")
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
282 (defvar diff-indicator-removed-face 'diff-indicator-removed)
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
283
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
284 (defface diff-indicator-added
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
285 '((t :inherit diff-added))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
286 "`diff-mode' face used to highlight indicator of added lines (+, >)."
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
287 :group 'diff-mode
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
288 :version "22.1")
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
289 (defvar diff-indicator-added-face 'diff-indicator-added)
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
290
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
291 (defface diff-indicator-changed
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
292 '((t :inherit diff-changed))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
293 "`diff-mode' face used to highlight indicator of changed lines."
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
294 :group 'diff-mode
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
295 :version "22.1")
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
296 (defvar diff-indicator-changed-face 'diff-indicator-changed)
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
297
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
298 (defface diff-function
69608
0c54773776e4 (diff-function): Make it inherit from diff-header instead of diff-context.
Nick Roberts <nickrob@snap.net.nz>
parents: 68651
diff changeset
299 '((t :inherit diff-header))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
300 "`diff-mode' face used to highlight function names produced by \"diff -p\"."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
301 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
302 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
303 (put 'diff-function-face 'face-alias 'diff-function)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
304 (defvar diff-function-face 'diff-function)
32603
87af45b9ad99 (diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents: 32588
diff changeset
305
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
306 (defface diff-context
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
307 '((((class color grayscale) (min-colors 88)) :inherit shadow))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
308 "`diff-mode' face used to highlight context and other side-information."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
309 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
310 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
311 (put 'diff-context-face 'face-alias 'diff-context)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
312 (defvar diff-context-face 'diff-context)
31734
6b057ae8165d Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31705
diff changeset
313
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
314 (defface diff-nonexistent
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
315 '((t :inherit diff-file-header))
62553
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
316 "`diff-mode' face used to highlight nonexistent files in recursive diffs."
e7408ff25265 (diff-header-face, diff-file-header-face)
Lute Kamstra <lute@gnu.org>
parents: 62531
diff changeset
317 :group 'diff-mode)
63197
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
318 ;; backward-compatibility alias
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
319 (put 'diff-nonexistent-face 'face-alias 'diff-nonexistent)
ce2a9eb0ff8a Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-368
Miles Bader <miles@gnu.org>
parents: 63051
diff changeset
320 (defvar diff-nonexistent-face 'diff-nonexistent)
37531
e71362bfa695 (diff-nonexistant-face): New face.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 35526
diff changeset
321
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
322 (defconst diff-yank-handler '(diff-yank-function))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
323 (defun diff-yank-function (text)
54540
2449619c7ccf (diff-font-lock-keywords): Disable yank-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54528
diff changeset
324 ;; FIXME: the yank-handler is now called separately on each piece of text
2449619c7ccf (diff-font-lock-keywords): Disable yank-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54528
diff changeset
325 ;; with a yank-handler property, so the next-single-property-change call
2449619c7ccf (diff-font-lock-keywords): Disable yank-handler.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54528
diff changeset
326 ;; below will always return nil :-( --stef
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
327 (let ((mixed (next-single-property-change 0 'yank-handler text))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
328 (start (point)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
329 ;; First insert the text.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
330 (insert text)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
331 ;; If the text does not include any diff markers and if we're not
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
332 ;; yanking back into a diff-mode buffer, get rid of the prefixes.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
333 (unless (or mixed (derived-mode-p 'diff-mode))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
334 (undo-boundary) ; Just in case the user wanted the prefixes.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
335 (let ((re (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
336 (if (re-search-backward "^[><!][ \t]" start t)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
337 (if (eq (char-after) ?!)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
338 "^[!+- ][ \t]" "^[<>][ \t]")
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
339 "^[ <>!+-]"))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
340 (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
341 (while (re-search-backward re start t)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
342 (replace-match "" t t)))))))
61269
5d2796fc9f80 (diff-minor-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 57418
diff changeset
343
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
344 (defconst diff-hunk-header-re-unified
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
345 "^@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@")
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
346
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347 (defvar diff-font-lock-keywords
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
348 `((,(concat "\\(" diff-hunk-header-re-unified "\\)\\(.*\\)$")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
349 (1 diff-hunk-header-face) (6 diff-function-face))
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
350 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
351 (1 diff-hunk-header-face) (2 diff-function-face))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
352 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
353 ("^--- .+ ----$" . diff-hunk-header-face) ;context
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
354 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
355 ("^---$" . diff-hunk-header-face) ;normal
32111
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
356 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)\\(.*[^*-]\\)?\n"
31734
6b057ae8165d Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31705
diff changeset
357 (0 diff-header-face) (2 diff-file-header-face prepend))
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
358 ("^\\([-<]\\)\\(.*\n\\)"
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
359 (1 diff-indicator-removed-face) (2 diff-removed-face))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
360 ("^\\([+>]\\)\\(.*\n\\)"
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
361 (1 diff-indicator-added-face) (2 diff-added-face))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
362 ("^\\(!\\)\\(.*\n\\)"
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
363 (1 diff-indicator-changed-face) (2 diff-changed-face))
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
364 ("^Index: \\(.+\\).*\n"
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
365 (0 diff-header-face) (1 diff-index-face prepend))
37567
50d77d1b2d58 (diff-nonexistent-face, diff-font-lock-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37531
diff changeset
366 ("^Only in .*\n" . diff-nonexistent-face)
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
367 ("^\\(#\\)\\(.*\\)"
64512
a4d1eb8d55e6 (diff-font-lock-keywords): Simplify comments fontifying rule.
Juri Linkov <juri@jurta.org>
parents: 64496
diff changeset
368 (1 font-lock-comment-delimiter-face)
a4d1eb8d55e6 (diff-font-lock-keywords): Simplify comments fontifying rule.
Juri Linkov <juri@jurta.org>
parents: 64496
diff changeset
369 (2 font-lock-comment-face))
64496
558b187cced1 (diff-file-header): Change foreground color from
Juri Linkov <juri@jurta.org>
parents: 64091
diff changeset
370 ("^[^-=+*!<>#].*\n" (0 diff-context-face))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
372 (defconst diff-font-lock-defaults
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
373 '(diff-font-lock-keywords t nil nil nil (font-lock-multiline . nil)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
374
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
375 (defvar diff-imenu-generic-expression
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
376 ;; Prefer second name as first is most likely to be a backup or
33488
352cb95d9f27 (diff-imenu-generic-expression): Modify unidiff
Dave Love <fx@gnu.org>
parents: 33432
diff changeset
377 ;; version-control name. The [\t\n] at the end of the unidiff pattern
352cb95d9f27 (diff-imenu-generic-expression): Modify unidiff
Dave Love <fx@gnu.org>
parents: 33432
diff changeset
378 ;; catches Debian source diff files (which lack the trailing date).
352cb95d9f27 (diff-imenu-generic-expression): Modify unidiff
Dave Love <fx@gnu.org>
parents: 33432
diff changeset
379 '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
380 (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
381
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
382 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
383 ;;;; Movement
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
384 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
385
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
386 (defvar diff-valid-unified-empty-line t
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
387 "If non-nil, empty lines are valid in unified diffs.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
388 Some versions of diff replace all-blank context lines in unified format with
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
389 empty lines. This makes the format less robust, but is tolerated.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
390 See http://lists.gnu.org/archive/html/emacs-devel/2007-11/msg01990.html")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
391
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
392 (defconst diff-hunk-header-re
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
393 (concat "^\\(?:" diff-hunk-header-re-unified ".*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$"))
57279
c8797551b3a0 (diff-file-header-re): Tighten up regexp a tiny bit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57020
diff changeset
394 (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+ \\|\\*\\*\\* .+\n--- \\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
395 (defvar diff-narrowed-to nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
396
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
397 (defun diff-end-of-hunk (&optional style donttrustheader)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
398 (let (end)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
399 (when (looking-at diff-hunk-header-re)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
400 (unless style
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
401 ;; Especially important for unified (because headers are ambiguous).
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
402 (setq style (cdr (assq (char-after) '((?@ . unified) (?* . context))))))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
403 (goto-char (match-end 0))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
404 (when (and (not donttrustheader) (match-end 2))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
405 (save-excursion
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
406 (re-search-forward (if diff-valid-unified-empty-line
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
407 "^[- \n]" "^[- ]")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
408 nil t
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
409 (string-to-number (match-string 2)))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
410 (setq end (line-beginning-position 2)))))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
411 ;; We may have a first evaluation of `end' thanks to the hunk header.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
412 (unless end
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
413 (setq end (and (re-search-forward
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
414 (case style
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
415 (unified (concat (if diff-valid-unified-empty-line
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
416 "^[^-+# \\\n]\\|" "^[^-+# \\]\\|")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
417 ;; A `unified' header is ambiguous.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
418 diff-file-header-re))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
419 (context "^[^-+#! \\]")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
420 (normal "^[^<>#\\]")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
421 (t "^[^-+#!<> \\]"))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
422 nil t)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
423 (match-beginning 0)))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
424 (when diff-valid-unified-empty-line
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
425 ;; While empty lines may be valid inside hunks, they are also likely
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
426 ;; to be unrelated to the hunk.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
427 (goto-char (or end (point-max)))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
428 (while (eq ?\n (char-before (1- (point))))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
429 (forward-char -1)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
430 (setq end (point)))))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
431 ;; The return value is used by easy-mmode-define-navigation.
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
432 (goto-char (or end (point-max)))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
433
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
434 (defun diff-beginning-of-hunk (&optional try-harder)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
435 "Move back to beginning of hunk.
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
436 If TRY-HARDER is non-nil, try to cater to the case where we're not in a hunk
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
437 but in the file header instead, in which case move forward to the first hunk."
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
438 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
439 (unless (looking-at diff-hunk-header-re)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
442 (re-search-backward diff-hunk-header-re)
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
443 (error
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
444 (if (not try-harder)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
445 (error "Can't find the beginning of the hunk")
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
446 (diff-beginning-of-file-and-junk)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
447 (diff-hunk-next))))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
448
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
449 (defun diff-beginning-of-file ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
450 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
451 (unless (looking-at diff-file-header-re)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
452 (forward-line 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
453 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
454 (re-search-backward diff-file-header-re)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
455 (error (error "Can't find the beginning of the file")))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
456
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
457 (defun diff-end-of-file ()
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
458 (re-search-forward "^[-+#!<>0-9@* \\]" nil t)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
459 (re-search-forward (concat "^[^-+#!<>0-9@* \\]\\|" diff-file-header-re)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
460 nil 'move)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
461 (if (match-beginning 1)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
462 (goto-char (match-beginning 1))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
463 (beginning-of-line)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
464
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
465 ;; Define diff-{hunk,file}-{prev,next}
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
466 (easy-mmode-define-navigation
53058
6ae6b1d05de0 (diff-hunk-prev, diff-hunk-next): Support
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 52401
diff changeset
467 diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk diff-restrict-view)
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
468 (easy-mmode-define-navigation
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
469 diff-file diff-file-header-re "file" diff-end-of-hunk)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
470
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471 (defun diff-restrict-view (&optional arg)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 "Restrict the view to the current hunk.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 If the prefix ARG is given, restrict the view to the current file instead."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 (interactive "P")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 (save-excursion
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
476 (if arg (diff-beginning-of-file) (diff-beginning-of-hunk 'try-harder))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 (narrow-to-region (point)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478 (progn (if arg (diff-end-of-file) (diff-end-of-hunk))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479 (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 (set (make-local-variable 'diff-narrowed-to) (if arg 'file 'hunk))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
483 (defun diff-hunk-kill ()
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 "Kill current hunk."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
486 (diff-beginning-of-hunk)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
487 (let* ((start (point))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
488 (nexthunk (when (re-search-forward diff-hunk-header-re nil t)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
489 (match-beginning 0)))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
490 (firsthunk (ignore-errors
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
491 (goto-char start)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
492 (diff-beginning-of-file) (diff-hunk-next) (point)))
71249
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
493 (nextfile (ignore-errors (diff-file-next) (point)))
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
494 (inhibit-read-only t))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
495 (goto-char start)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (if (and firsthunk (= firsthunk start)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 (or (null nexthunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 (and nextfile (> nexthunk nextfile))))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
499 ;; It's the only hunk for this file, so kill the file.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
500 (diff-file-kill)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 (diff-end-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 (kill-region start (point)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
504 (defconst diff-file-junk-re "diff \\|index ") ; "index " is output by git-diff.
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
505
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
506 (defun diff-beginning-of-file-and-junk ()
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
507 "Go to the beginning of file-related diff-info.
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
508 This is like `diff-beginning-of-file' except it tries to skip back over leading
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
509 data such as \"Index: ...\" and such."
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
510 (let ((orig (point))
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
511 ;; Skip forward over what might be "leading junk" so as to get
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
512 ;; closer to the actual diff.
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
513 (_ (progn (beginning-of-line)
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
514 (while (looking-at diff-file-junk-re)
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
515 (forward-line 1))))
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
516 (start (point))
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
517 (file (condition-case err (progn (diff-beginning-of-file) (point))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
518 (error err)))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
519 ;; prevhunk is one of the limits.
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
520 (prevhunk (save-excursion (ignore-errors (diff-hunk-prev) (point))))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
521 err)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
522 (when (consp file)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
523 ;; Presumably, we started before the file header, in the leading junk.
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
524 (setq err file)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
525 (diff-file-next)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
526 (setq file (point)))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
527 (let ((index (save-excursion
80099
f68e2df975f5 (diff-beginning-of-file-and-junk): If we're on the
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79843
diff changeset
528 (forward-line 1) ;In case we're looking at "Index:".
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
529 (re-search-backward "^Index: " prevhunk t))))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
530 (when index (setq file index))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
531 (if (<= file start)
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
532 (progn
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
533 (goto-char file)
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
534 ;; Now skip backward over the leading junk we may have before the
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
535 ;; diff itself.
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
536 (while (save-excursion
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
537 (and (zerop (forward-line -1))
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
538 (looking-at diff-file-junk-re)))
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
539 (forward-line -1)))
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
540 ;; File starts *after* the starting point: we really weren't in
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
541 ;; a file diff but elsewhere.
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
542 (goto-char orig)
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
543 (signal (car err) (cdr err))))))
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
544
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
545 (defun diff-file-kill ()
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 "Kill current file's hunks."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
547 (interactive)
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
548 (let ((orig (point))
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
549 (start (progn (diff-beginning-of-file-and-junk) (point)))
71249
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
550 (inhibit-read-only t))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 (diff-end-of-file)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
552 (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs.
80152
f200e5de5464 (diff-file-junk-re): New const.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80151
diff changeset
553 (if (> orig (point)) (error "Not inside a file diff"))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 (kill-region start (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
556 (defun diff-kill-junk ()
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
557 "Kill spurious empty diffs."
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
558 (interactive)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
559 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
560 (let ((inhibit-read-only t))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
561 (goto-char (point-min))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
562 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
563 "\\([^-+!* <>].*\n\\)*?"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
564 "\\(\\(Index:\\) \\|"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
565 diff-file-header-re "\\)")
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
566 nil t)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
567 (delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
568 (match-beginning 3))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
569 (beginning-of-line)))))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
570
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
571 (defun diff-count-matches (re start end)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
572 (save-excursion
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
573 (let ((n 0))
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
574 (goto-char start)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
575 (while (re-search-forward re end t) (incf n))
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
576 n)))
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
577
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
578 (defun diff-split-hunk ()
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
579 "Split the current (unified diff) hunk at point into two hunks."
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
580 (interactive)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
581 (beginning-of-line)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
582 (let ((pos (point))
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
583 (start (progn (diff-beginning-of-hunk) (point))))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
584 (unless (looking-at diff-hunk-header-re-unified)
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
585 (error "diff-split-hunk only works on unified context diffs"))
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
586 (forward-line 1)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
587 (let* ((start1 (string-to-number (match-string 1)))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
588 (start2 (string-to-number (match-string 3)))
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
589 (newstart1 (+ start1 (diff-count-matches "^[- \t]" (point) pos)))
71249
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
590 (newstart2 (+ start2 (diff-count-matches "^[+ \t]" (point) pos)))
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
591 (inhibit-read-only t))
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
592 (goto-char pos)
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
593 ;; Hopefully the after-change-function will not screw us over.
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
594 (insert "@@ -" (number-to-string newstart1) ",1 +"
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
595 (number-to-string newstart2) ",1 @@\n")
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
596 ;; Fix the original hunk-header.
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
597 (diff-fixup-modifs start pos))))
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47523
diff changeset
598
33432
7f6ffdaecedc (diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32666
diff changeset
599
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
601 ;;;; jump to other buffers
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
602 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
604 (defvar diff-remembered-files-alist nil)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
605
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 (defun diff-filename-drop-dir (file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
607 (when (string-match "/" file) (substring file (match-end 0))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
609 (defun diff-merge-strings (ancestor from to)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
610 "Merge the diff between ANCESTOR and FROM into TO.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
611 Returns the merged string if successful or nil otherwise.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
612 The strings are assumed not to contain any \"\\n\" (i.e. end of line).
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
613 If ANCESTOR = FROM, returns TO.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
614 If ANCESTOR = TO, returns FROM.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
615 The heuristic is simplistic and only really works for cases
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
616 like \(diff-merge-strings \"b/foo\" \"b/bar\" \"/a/c/foo\")."
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
617 ;; Ideally, we want:
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
618 ;; AMB ANB CMD -> CND
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
619 ;; but that's ambiguous if `foo' or `bar' is empty:
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
620 ;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
621 (let ((str (concat ancestor "\n" from "\n" to)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
622 (when (and (string-match (concat
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
623 "\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n"
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
624 "\\1\\(.*\\)\\3\n"
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
625 "\\(.*\\(\\2\\).*\\)\\'") str)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
626 (equal to (match-string 5 str)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
627 (concat (substring str (match-beginning 5) (match-beginning 6))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
628 (match-string 4 str)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
629 (substring str (match-end 6) (match-end 5))))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
630
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
631 (defun diff-tell-file-name (old name)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
632 "Tell Emacs where the find the source file of the current hunk.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
633 If the OLD prefix arg is passed, tell the file NAME of the old file."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
634 (interactive
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
635 (let* ((old current-prefix-arg)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
636 (fs (diff-hunk-file-names current-prefix-arg)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
637 (unless fs (error "No file name to look for"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
638 (list old (read-file-name (format "File for %s: " (car fs))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
639 nil (diff-find-file-name old) t))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
640 (let ((fs (diff-hunk-file-names old)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
641 (unless fs (error "No file name to look for"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
642 (push (cons fs name) diff-remembered-files-alist)))
61269
5d2796fc9f80 (diff-minor-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 57418
diff changeset
643
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
644 (defun diff-hunk-file-names (&optional old)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
645 "Give the list of file names textually mentioned for the current hunk."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
646 (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
647 (unless (looking-at diff-file-header-re)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
648 (or (ignore-errors (diff-beginning-of-file))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
649 (re-search-forward diff-file-header-re nil t)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
650 (let ((limit (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
651 (condition-case ()
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
652 (progn (diff-hunk-prev) (point))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
653 (error (point-min)))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
654 (header-files
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
655 (if (looking-at "[-*][-*][-*] \\(\\S-+\\)\\(\\s-.*\\)?\n[-+][-+][-+] \\(\\S-+\\)")
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
656 (list (if old (match-string 1) (match-string 3))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
657 (if old (match-string 3) (match-string 1)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
658 (forward-line 1) nil)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
659 (delq nil
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
660 (append
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
661 (when (and (not old)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
662 (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
663 (re-search-backward "^Index: \\(.+\\)" limit t)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
664 (list (match-string 1)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
665 header-files
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
666 (when (re-search-backward
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
667 "^diff \\(-\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?"
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
668 nil t)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
669 (list (if old (match-string 2) (match-string 4))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
670 (if old (match-string 4) (match-string 2)))))))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
671
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
672 (defun diff-find-file-name (&optional old prefix)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 "Return the file corresponding to the current patch.
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
674 Non-nil OLD means that we want the old file.
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
675 PREFIX is only used internally: don't use it."
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
676 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 (unless (looking-at diff-file-header-re)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
678 (or (ignore-errors (diff-beginning-of-file))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (re-search-forward diff-file-header-re nil t)))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
680 (let ((fs (diff-hunk-file-names old)))
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
681 (if prefix (setq fs (mapcar (lambda (f) (concat prefix f)) fs)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682 (or
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
683 ;; use any previously used preference
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
684 (cdr (assoc fs diff-remembered-files-alist))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
685 ;; try to be clever and use previous choices as an inspiration
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
686 (dolist (rf diff-remembered-files-alist)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
687 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
688 (if (and newfile (file-exists-p newfile)) (return newfile))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
689 ;; look for each file in turn. If none found, try again but
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
690 ;; ignoring the first level of directory, ...
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
691 (do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
692 (file nil nil))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
693 ((or (null files)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
694 (setq file (do* ((files files (cdr files))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
695 (file (car files) (car files)))
78676
b2023ab19990 (diff-find-file-name): Only accept regular files, to rule out
Glenn Morris <rgm@gnu.org>
parents: 78429
diff changeset
696 ;; Use file-regular-p to avoid
b2023ab19990 (diff-find-file-name): Only accept regular files, to rule out
Glenn Morris <rgm@gnu.org>
parents: 78429
diff changeset
697 ;; /dev/null, directories, etc.
b2023ab19990 (diff-find-file-name): Only accept regular files, to rule out
Glenn Morris <rgm@gnu.org>
parents: 78429
diff changeset
698 ((or (null file) (file-regular-p file))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
699 file))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
700 file))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
701 ;; <foo>.rej patches implicitly apply to <foo>
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 (and (string-match "\\.rej\\'" (or buffer-file-name ""))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703 (let ((file (substring buffer-file-name 0 (match-beginning 0))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
704 (when (file-exists-p file) file)))
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
705 ;; If we haven't found the file, maybe it's because we haven't paid
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
706 ;; attention to the PCL-CVS hint.
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
707 (and (not prefix)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
708 (boundp 'cvs-pcl-cvs-dirchange-re)
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
709 (save-excursion
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
710 (re-search-backward cvs-pcl-cvs-dirchange-re nil t))
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
711 (diff-find-file-name old (match-string 1)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
712 ;; if all else fails, ask the user
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
713 (let ((file (read-file-name (format "Use file %s: " (or (first fs) ""))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
714 nil (first fs) t (first fs))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
715 (set (make-local-variable 'diff-remembered-files-alist)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
716 (cons (cons fs file) diff-remembered-files-alist))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717 file)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718
32012
b1edfcd919a7 (diff-add-log-file-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31973
diff changeset
719
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 (defun diff-ediff-patch ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
721 "Call `ediff-patch-file' on the current buffer."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
722 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (condition-case err
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
724 (ediff-patch-file nil (current-buffer))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (wrong-number-of-arguments (ediff-patch-file))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47523
diff changeset
727 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 ;;;; Conversion functions
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47523
diff changeset
729 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
731 ;;(defvar diff-inhibit-after-change nil
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 ;; "Non-nil means inhibit `diff-mode's after-change functions.")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (defun diff-unified->context (start end)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
735 "Convert unified diffs to context diffs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
736 START and END are either taken from the region (if a prefix arg is given) or
78429
a3a4480349cb (diff-unified->context, diff-reverse-direction, diff-fixup-modifs):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78359
diff changeset
737 else cover the whole buffer."
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
738 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
739 (list (region-beginning) (region-end))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
740 (list (point-min) (point-max))))
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
741 (unless (markerp end) (setq end (copy-marker end t)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 (let (;;(diff-inhibit-after-change t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
743 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
745 (goto-char start)
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
746 (while (and (re-search-forward
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
747 (concat "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|"
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
748 diff-hunk-header-re-unified ".*\\)$")
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
749 nil t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
752 (if (match-beginning 2)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
753 ;; we matched a file header
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
755 ;; use reverse order to make sure the indices are kept valid
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
756 (replace-match "---" t t nil 3)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (replace-match "***" t t nil 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
758 ;; we matched a hunk header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
759 (let ((line1 (match-string 4))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 (lines1 (match-string 5))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761 (line2 (match-string 6))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 (lines2 (match-string 7)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (replace-match
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 (concat "***************\n*** " line1 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765 (number-to-string (+ (string-to-number line1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (string-to-number lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 -1)) " ****"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
768 (save-restriction
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
769 (narrow-to-region (line-beginning-position 2)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
770 ;; Call diff-end-of-hunk from just before
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
771 ;; the hunk header so it can use the hunk
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
772 ;; header info.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
773 (progn (diff-end-of-hunk 'unified) (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
774 (let ((hunk (buffer-string)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
775 (goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
776 (if (not (save-excursion (re-search-forward "^-" nil t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
777 (delete-region (point) (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
778 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
779 (let ((modif nil) last-pt)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 (while (progn (setq last-pt (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781 (= (forward-line -1) 0))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
782 (case (char-after)
64045
30fe6a97264a Fix brainos.
Juanma Barranquero <lekktu@gmail.com>
parents: 64004
diff changeset
783 (?\s (insert " ") (setq modif nil) (backward-char 1))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
784 (?+ (delete-region (point) last-pt) (setq modif t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785 (?- (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
789 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
790 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
791 (?\\ (when (save-excursion (forward-line -1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 (= (char-after) ?+))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793 (delete-region (point) last-pt) (setq modif t)))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
794 ;; diff-valid-unified-empty-line.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
795 (?\n (insert " ") (setq modif nil) (backward-char 2))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 (t (setq modif nil))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
797 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
798 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
799 (insert "--- " line2 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
800 (number-to-string (+ (string-to-number line2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801 (string-to-number lines2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
802 -1)) " ----\n" hunk))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
803 ;;(goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805 (if (not (save-excursion (re-search-forward "^+" nil t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
806 (delete-region (point) (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 (let ((modif nil) (delete nil))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 (while (not (eobp))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
809 (case (char-after)
64045
30fe6a97264a Fix brainos.
Juanma Barranquero <lekktu@gmail.com>
parents: 64004
diff changeset
810 (?\s (insert " ") (setq modif nil) (backward-char 1))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 (?- (setq delete t) (setq modif t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
812 (?+ (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
813 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
816 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818 (?\\ (when (save-excursion (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819 (not (eobp)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
820 (setq delete t) (setq modif t)))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
821 ;; diff-valid-unified-empty-line.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
822 (?\n (insert " ") (setq modif nil) (backward-char 2))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
823 (t (setq modif nil)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
824 (let ((last-pt (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
825 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
826 (when delete
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
827 (delete-region last-pt (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
828 (setq delete nil)))))))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
829
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
830 (defun diff-context->unified (start end &optional to-context)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
831 "Convert context diffs to unified diffs.
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
832 START and END are either taken from the region
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
833 \(when it is highlighted) or else cover the whole buffer.
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
834 With a prefix argument, convert unified format to context format."
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
835 (interactive (if (and transient-mark-mode mark-active)
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
836 (list (region-beginning) (region-end) current-prefix-arg)
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
837 (list (point-min) (point-max) current-prefix-arg)))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
838 (if to-context
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
839 (diff-unified->context start end)
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
840 (unless (markerp end) (setq end (copy-marker end t)))
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
841 (let ( ;;(diff-inhibit-after-change t)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
842 (inhibit-read-only t))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
843 (save-excursion
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
844 (goto-char start)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
845 (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\{15\\}.*\n\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]+\\) \\*\\*\\*\\*\\)$" nil t)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
846 (< (point) end))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
847 (combine-after-change-calls
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
848 (if (match-beginning 2)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
849 ;; we matched a file header
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
850 (progn
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
851 ;; use reverse order to make sure the indices are kept valid
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
852 (replace-match "+++" t t nil 3)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
853 (replace-match "---" t t nil 2))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
854 ;; we matched a hunk header
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
855 (let ((line1s (match-string 4))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
856 (line1e (match-string 5))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
857 (pt1 (match-beginning 0)))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
858 (replace-match "")
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
859 (unless (re-search-forward
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
860 "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
861 (error "Can't find matching `--- n1,n2 ----' line"))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
862 (let ((line2s (match-string 1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
863 (line2e (match-string 2))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
864 (pt2 (progn
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
865 (delete-region (progn (beginning-of-line) (point))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
866 (progn (forward-line 1) (point)))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
867 (point-marker))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
868 (goto-char pt1)
70333
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
869 (forward-line 1)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
870 (while (< (point) pt2)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
871 (case (char-after)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
872 ((?! ?-) (delete-char 2) (insert "-") (forward-line 1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
873 (?\s ;merge with the other half of the chunk
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
874 (let* ((endline2
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
875 (save-excursion
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
876 (goto-char pt2) (forward-line 1) (point)))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
877 (c (char-after pt2)))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
878 (case c
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
879 ((?! ?+)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
880 (insert "+"
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
881 (prog1 (buffer-substring (+ pt2 2) endline2)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
882 (delete-region pt2 endline2))))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
883 (?\s ;FIXME: check consistency
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
884 (delete-region pt2 endline2)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
885 (delete-char 1)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
886 (forward-line 1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
887 (?\\ (forward-line 1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
888 (t (delete-char 1) (forward-line 1)))))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
889 (t (forward-line 1))))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
890 (while (looking-at "[+! ] ")
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
891 (if (/= (char-after) ?!) (forward-char 1)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
892 (delete-char 1) (insert "+"))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
893 (delete-char 1) (forward-line 1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
894 (save-excursion
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
895 (goto-char pt1)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
896 (insert "@@ -" line1s ","
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
897 (number-to-string (- (string-to-number line1e)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
898 (string-to-number line1s)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
899 -1))
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
900 " +" line2s ","
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
901 (number-to-string (- (string-to-number line2e)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
902 (string-to-number line2s)
64d227e5dd44 (diff-mode-shared-map): Don't bind M-W, M-U, M-C,
Richard M. Stallman <rms@gnu.org>
parents: 70292
diff changeset
903 -1)) " @@")))))))))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
904
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 (defun diff-reverse-direction (start end)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
906 "Reverse the direction of the diffs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
907 START and END are either taken from the region (if a prefix arg is given) or
78429
a3a4480349cb (diff-unified->context, diff-reverse-direction, diff-fixup-modifs):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78359
diff changeset
908 else cover the whole buffer."
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
909 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
910 (list (region-beginning) (region-end))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 (list (point-min) (point-max))))
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
912 (unless (markerp end) (setq end (copy-marker end t)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
913 (let (;;(diff-inhibit-after-change t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
915 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 (goto-char start)
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
917 (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\{15\\}.*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\([0-9,]+\\) \\+\\([0-9,]+\\) @@.*\\)$" nil t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
918 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
920 (cond
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
921 ;; a file header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922 ((match-beginning 2) (replace-match "\\2\\5\n\\4\\3" nil))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923 ;; a context-diff hunk header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
924 ((match-beginning 6)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
925 (let ((pt-lines1 (match-beginning 6))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926 (lines1 (match-string 6)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
927 (replace-match "" nil nil nil 6)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
928 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
929 (let ((half1s (point)))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
930 (while (looking-at "[-! \\][ \t]\\|#")
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
931 (when (= (char-after) ?-) (delete-char 1) (insert "+"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
932 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
933 (let ((half1 (delete-and-extract-region half1s (point))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
934 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
935 (insert half1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
936 (error "Can't find matching `--- n1,n2 ----' line"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
937 (let ((str1 (match-string 1)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
938 (replace-match lines1 nil nil nil 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
939 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
940 (let ((half2s (point)))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
941 (while (looking-at "[!+ \\][ \t]\\|#")
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
942 (when (= (char-after) ?+) (delete-char 1) (insert "-"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
943 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
944 (let ((half2 (delete-and-extract-region half2s (point))))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
945 (insert (or half1 ""))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
946 (goto-char half1s)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
947 (insert (or half2 ""))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
948 (goto-char pt-lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
949 (insert str1))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
950 ;; a unified-diff hunk header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
951 ((match-beginning 7)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
952 (replace-match "@@ -\\8 +\\7 @@" nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
953 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
954 (let ((c (char-after)) first last)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
955 (while (case (setq c (char-after))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
956 (?- (setq first (or first (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
957 (delete-char 1) (insert "+") t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
958 (?+ (setq last (or last (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
959 (delete-char 1) (insert "-") t)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
960 ((?\\ ?#) t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
961 (t (when (and first last (< first last))
46407
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
962 (insert (delete-and-extract-region first last)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
963 (setq first nil last nil)
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
964 (memq c (if diff-valid-unified-empty-line
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
965 '(?\s ?\n) '(?\s)))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
966 (forward-line 1))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
967
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
968 (defun diff-fixup-modifs (start end)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
969 "Fixup the hunk headers (in case the buffer was modified).
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
970 START and END are either taken from the region (if a prefix arg is given) or
78429
a3a4480349cb (diff-unified->context, diff-reverse-direction, diff-fixup-modifs):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78359
diff changeset
971 else cover the whole buffer."
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
972 (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active))
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
973 (list (region-beginning) (region-end))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
974 (list (point-min) (point-max))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
975 (let ((inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
976 (save-excursion
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
977 (goto-char end) (diff-end-of-hunk nil 'donttrustheader)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
978 (let ((plus 0) (minus 0) (space 0) (bang 0))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
979 (while (and (= (forward-line -1) 0) (<= start (point)))
57279
c8797551b3a0 (diff-file-header-re): Tighten up regexp a tiny bit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57020
diff changeset
980 (if (not (looking-at
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
981 (concat diff-hunk-header-re-unified
57279
c8797551b3a0 (diff-file-header-re): Tighten up regexp a tiny bit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57020
diff changeset
982 "\\|[-*][-*][-*] [0-9,]+ [-*][-*][-*][-*]$"
c8797551b3a0 (diff-file-header-re): Tighten up regexp a tiny bit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57020
diff changeset
983 "\\|--- .+\n\\+\\+\\+ ")))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
984 (case (char-after)
57279
c8797551b3a0 (diff-file-header-re): Tighten up regexp a tiny bit.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57020
diff changeset
985 (?\s (incf space))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
986 (?+ (incf plus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
987 (?- (incf minus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
988 (?! (incf bang))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
989 ((?\\ ?#) nil)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
990 (t (setq space 0 plus 0 minus 0 bang 0)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
991 (cond
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
992 ((looking-at diff-hunk-header-re-unified)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
993 (let* ((old1 (match-string 2))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
994 (old2 (match-string 4))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
995 (new1 (number-to-string (+ space minus)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
996 (new2 (number-to-string (+ space plus))))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
997 (unless (string= new2 old2) (replace-match new2 t t nil 4))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
998 (unless (string= new1 old1) (replace-match new1 t t nil 2))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
999 ((looking-at "--- \\([0-9]+\\),\\([0-9]*\\) ----$")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1000 (when (> (+ space bang plus) 0)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1001 (let* ((old1 (match-string 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1002 (old2 (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1003 (new (number-to-string
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1004 (+ space bang plus -1 (string-to-number old1)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1005 (unless (string= new old2) (replace-match new t t nil 2)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1006 ((looking-at "\\*\\*\\* \\([0-9]+\\),\\(-?[0-9]*\\) \\*\\*\\*\\*$")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1007 (when (> (+ space bang minus) 0)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1008 (let* ((old (match-string 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1009 (new (format
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1010 (concat "%0" (number-to-string (length old)) "d")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1011 (+ space bang minus -1 (string-to-number old)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1012 (unless (string= new old) (replace-match new t t nil 2))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1013 (setq space 0 plus 0 minus 0 bang 0)))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1014
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47523
diff changeset
1015 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1016 ;;;; Hooks
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47523
diff changeset
1017 ;;;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1018
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1019 (defun diff-write-contents-hooks ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1020 "Fixup hunk headers if necessary."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1021 (if (buffer-modified-p) (diff-fixup-modifs (point-min) (point-max)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1022 nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1023
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1024 ;; It turns out that making changes in the buffer from within an
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1025 ;; *-change-function is asking for trouble, whereas making them
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1026 ;; from a post-command-hook doesn't pose much problems
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1027 (defvar diff-unhandled-changes nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1028 (defun diff-after-change-function (beg end len)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1029 "Remember to fixup the hunk header.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1030 See `after-change-functions' for the meaning of BEG, END and LEN."
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
1031 ;; Ignoring changes when inhibit-read-only is set is strictly speaking
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
1032 ;; incorrect, but it turns out that inhibit-read-only is normally not set
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
1033 ;; inside editing commands, while it tends to be set when the buffer gets
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
1034 ;; updated by an async process or by a conversion function, both of which
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
1035 ;; would rather not be uselessly slowed down by this hook.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1036 (when (and (not undo-in-progress) (not inhibit-read-only))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1037 (if diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1038 (setq diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1039 (cons (min beg (car diff-unhandled-changes))
46407
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
1040 (max end (cdr diff-unhandled-changes))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1041 (setq diff-unhandled-changes (cons beg end)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1042
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1043 (defun diff-post-command-hook ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1044 "Fixup hunk headers if necessary."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1045 (when (consp diff-unhandled-changes)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1046 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1047 (save-excursion
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
1048 (goto-char (car diff-unhandled-changes))
46407
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
1049 ;; Maybe we've cut the end of the hunk before point.
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
1050 (if (and (bolp) (not (bobp))) (backward-char 1))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1051 ;; We used to fixup modifs on all the changes, but it turns out
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1052 ;; that it's safer not to do it on big changes, for example
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1053 ;; when yanking a big diff, since we might then screw up perfectly
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1054 ;; correct values. -stef
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1055 ;; (unless (ignore-errors
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1056 ;; (diff-beginning-of-hunk)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1057 ;; (save-excursion
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1058 ;; (diff-end-of-hunk)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1059 ;; (> (point) (car diff-unhandled-changes))))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1060 ;; (goto-char (car diff-unhandled-changes))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1061 ;; (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1062 ;; (diff-beginning-of-hunk))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1063 ;; (diff-fixup-modifs (point) (cdr diff-unhandled-changes))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1064 (diff-beginning-of-hunk)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1065 (when (save-excursion
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1066 (diff-end-of-hunk nil 'donttrustheader)
46407
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
1067 (>= (point) (cdr diff-unhandled-changes)))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1068 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1069 (setq diff-unhandled-changes nil)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1070
55088
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1071 (defun diff-next-error (arg reset)
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1072 ;; Select a window that displays the current buffer so that point
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1073 ;; movements are reflected in that window. Otherwise, the user might
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1074 ;; never see the hunk corresponding to the source she's jumping to.
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1075 (pop-to-buffer (current-buffer))
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1076 (if reset (goto-char (point-min)))
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1077 (diff-hunk-next arg)
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1078 (diff-goto-source))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1079
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1080 ;;;###autoload
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
1081 (define-derived-mode diff-mode fundamental-mode "Diff"
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1082 "Major mode for viewing/editing context diffs.
39386
50956864fe56 (diff-default-read-only): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39323
diff changeset
1083 Supports unified and context diffs as well as (to a lesser extent)
76982
3a37aeee9537 (diff-mode): Revert 2007-03-04 change.
Chong Yidong <cyd@stupidchicken.com>
parents: 76453
diff changeset
1084 normal diffs.
76323
0aef0bcf12f7 (diff-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 75727
diff changeset
1085
47445
d54b5b9a2b77 (diff-mode): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46407
diff changeset
1086 When the buffer is read-only, the ESC prefix is not necessary.
63415
3ed17f92f3c9 (diff-mode): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 63197
diff changeset
1087 If you edit the buffer manually, diff-mode will try to update the hunk
47445
d54b5b9a2b77 (diff-mode): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46407
diff changeset
1088 headers for you on-the-fly.
d54b5b9a2b77 (diff-mode): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46407
diff changeset
1089
d54b5b9a2b77 (diff-mode): Docstring improvement.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46407
diff changeset
1090 You can also switch between context diff and unified diff with \\[diff-context->unified],
66130
a6131b478689 (diff-mode): Doc fix.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 65287
diff changeset
1091 or vice versa with \\[diff-unified->context] and you can also reverse the direction of
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1092 a diff with \\[diff-reverse-direction].
76323
0aef0bcf12f7 (diff-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 75727
diff changeset
1093
0aef0bcf12f7 (diff-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 75727
diff changeset
1094 \\{diff-mode-map}"
0aef0bcf12f7 (diff-mode): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 75727
diff changeset
1095
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1096 (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1097 (set (make-local-variable 'outline-regexp) diff-outline-regexp)
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
1098 (set (make-local-variable 'imenu-generic-expression)
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
1099 diff-imenu-generic-expression)
31479
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1100 ;; These are not perfect. They would be better done separately for
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1101 ;; context diffs and unidiffs.
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1102 ;; (set (make-local-variable 'paragraph-start)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1103 ;; (concat "@@ " ; unidiff hunk
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1104 ;; "\\|\\*\\*\\* " ; context diff hunk or file start
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1105 ;; "\\|--- [^\t]+\t")) ; context or unidiff file
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1106 ;; ; start (first or second line)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1107 ;; (set (make-local-variable 'paragraph-separate) paragraph-start)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1108 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
1109 ;; compile support
55088
386e33861abd (diff-next-error): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54928
diff changeset
1110 (set (make-local-variable 'next-error-function) 'diff-next-error)
35526
b40a6cecc4d5 (diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33488
diff changeset
1111
71248
3071d2ae4624 * diff-mode.el (diff-mode): Set buffer-read-only to t when
Chong Yidong <cyd@stupidchicken.com>
parents: 70542
diff changeset
1112 (setq buffer-read-only diff-default-read-only)
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
1113 ;; setup change hooks
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1114 (if (not diff-update-on-the-fly)
53833
32e20bdb34c9 (diff-file-regexp-alist, diff-error-regexp-alist)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53782
diff changeset
1115 (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1116 (make-local-variable 'diff-unhandled-changes)
31973
ad9838a9349c (diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31819
diff changeset
1117 (add-hook 'after-change-functions 'diff-after-change-function nil t)
ad9838a9349c (diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31819
diff changeset
1118 (add-hook 'post-command-hook 'diff-post-command-hook nil t))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1119 ;; Neat trick from Dave Love to add more bindings in read-only mode:
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1120 (lexical-let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1121 (add-to-list 'minor-mode-overriding-map-alist ro-bind)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1122 ;; Turn off this little trick in case the buffer is put in view-mode.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1123 (add-hook 'view-mode-hook
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1124 (lambda ()
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1125 (setq minor-mode-overriding-map-alist
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1126 (delq ro-bind minor-mode-overriding-map-alist)))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1127 nil t))
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1128 ;; add-log support
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1129 (set (make-local-variable 'add-log-current-defun-function)
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1130 'diff-current-defun)
32012
b1edfcd919a7 (diff-add-log-file-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31973
diff changeset
1131 (set (make-local-variable 'add-log-buffer-file-name-function)
b1edfcd919a7 (diff-add-log-file-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31973
diff changeset
1132 'diff-find-file-name))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1133
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1134 ;;;###autoload
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1135 (define-minor-mode diff-minor-mode
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1136 "Minor mode for viewing/editing context diffs.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1137 \\{diff-minor-mode-map}"
61269
5d2796fc9f80 (diff-minor-mode): Specify :group.
Lute Kamstra <lute@gnu.org>
parents: 57418
diff changeset
1138 :group 'diff-mode :lighter " Diff"
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1139 ;; FIXME: setup font-lock
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
1140 ;; setup change hooks
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1141 (if (not diff-update-on-the-fly)
53833
32e20bdb34c9 (diff-file-regexp-alist, diff-error-regexp-alist)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53782
diff changeset
1142 (add-hook 'write-contents-functions 'diff-write-contents-hooks nil t)
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
1143 (make-local-variable 'diff-unhandled-changes)
31973
ad9838a9349c (diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31819
diff changeset
1144 (add-hook 'after-change-functions 'diff-after-change-function nil t)
ad9838a9349c (diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31819
diff changeset
1145 (add-hook 'post-command-hook 'diff-post-command-hook nil t)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
1146
71556
31835ba46d29 (diff-find-file-name): Obey cvs-pcl-cvs-dirchange-re.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71249
diff changeset
1147 ;;; Handy hook functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1148
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1149 (defun diff-delete-if-empty ()
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1150 ;; An empty diff file means there's no more diffs to integrate, so we
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1151 ;; can just remove the file altogether. Very handy for .rej files if we
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1152 ;; remove hunks as we apply them.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1153 (when (and buffer-file-name
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1154 (eq 0 (nth 7 (file-attributes buffer-file-name))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1155 (delete-file buffer-file-name)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1156
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1157 (defun diff-delete-empty-files ()
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1158 "Arrange for empty diff files to be removed."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1159 (add-hook 'after-save-hook 'diff-delete-if-empty nil t))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1160
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1161 (defun diff-make-unified ()
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1162 "Turn context diffs into unified diffs if applicable."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1163 (if (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1164 (goto-char (point-min))
55392
480f9d542579 (diff-make-unified): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55322
diff changeset
1165 (and (looking-at diff-hunk-header-re) (eq (char-after) ?*)))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1166 (let ((mod (buffer-modified-p)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1167 (unwind-protect
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1168 (diff-context->unified (point-min) (point-max))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1169 (restore-buffer-modified-p mod)))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1170
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1171 ;;;
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1172 ;;; Misc operations that have proved useful at some point.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1173 ;;;
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1174
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1175 (defun diff-next-complex-hunk ()
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1176 "Jump to the next \"complex\" hunk.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1177 \"Complex\" is approximated by \"the hunk changes the number of lines\".
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1178 Only works for unified diffs."
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1179 (interactive)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1180 (while
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1181 (and (re-search-forward diff-hunk-header-re-unified nil t)
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1182 (equal (match-string 2) (match-string 4)))))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1183
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1184 (defun diff-sanity-check-context-hunk-half (lines)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1185 (let ((count lines))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1186 (while
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1187 (cond
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1188 ((and (memq (char-after) '(?\s ?! ?+ ?-))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1189 (memq (char-after (1+ (point))) '(?\s ?\t)))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1190 (decf count) t)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1191 ((or (zerop count) (= count lines)) nil)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1192 ((memq (char-after) '(?! ?+ ?-))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1193 (if (not (and (eq (char-after (1+ (point))) ?\n)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1194 (y-or-n-p "Try to auto-fix whitespace loss damage? ")))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1195 (error "End of hunk ambiguously marked")
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1196 (forward-char 1) (insert " ") (forward-line -1) t))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1197 ((< lines 0)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1198 (error "End of hunk ambiguously marked"))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1199 ((not (y-or-n-p "Try to auto-fix whitespace loss and word-wrap damage? "))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1200 (error "Abort!"))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1201 ((eolp) (insert " ") (forward-line -1) t)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1202 (t (insert " ") (delete-region (- (point) 2) (- (point) 1)) t))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1203 (forward-line))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1204
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1205 (defun diff-sanity-check-hunk ()
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1206 (let (;; Every modification is protected by a y-or-n-p, so it's probably
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1207 ;; OK to override a read-only setting.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1208 (inhibit-read-only t))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1209 (save-excursion
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1210 (cond
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1211 ((not (looking-at diff-hunk-header-re))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1212 (error "Not recognizable hunk header"))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1213
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1214 ;; A context diff.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1215 ((eq (char-after) ?*)
75727
612c9d0aab1d (diff-sanity-check-hunk): Fix last fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 75709
diff changeset
1216 (if (not (looking-at "\\*\\{15\\}\\(?: .*\\)?\n\\*\\*\\* \\([0-9]+\\),\\([0-9]+\\) \\*\\*\\*\\*"))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1217 (error "Unrecognized context diff first hunk header format")
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1218 (forward-line 2)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1219 (diff-sanity-check-context-hunk-half
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1220 (1+ (- (string-to-number (match-string 2))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1221 (string-to-number (match-string 1)))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1222 (if (not (looking-at "--- \\([0-9]+\\),\\([0-9]+\\) ----$"))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1223 (error "Unrecognized context diff second hunk header format")
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1224 (forward-line)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1225 (diff-sanity-check-context-hunk-half
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1226 (1+ (- (string-to-number (match-string 2))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1227 (string-to-number (match-string 1))))))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1228
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1229 ;; A unified diff.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1230 ((eq (char-after) ?@)
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1231 (if (not (looking-at diff-hunk-header-re-unified))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1232 (error "Unrecognized unified diff hunk header format")
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1233 (let ((before (string-to-number (match-string 2)))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1234 (after (string-to-number (match-string 4))))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1235 (forward-line)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1236 (while
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1237 (case (char-after)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1238 (?\s (decf before) (decf after) t)
78756
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1239 (?-
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1240 (if (and (looking-at diff-file-header-re)
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1241 (zerop before) (zerop after))
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1242 ;; No need to query: this is a case where two patches
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1243 ;; are concatenated and only counting the lines will
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1244 ;; give the right result. Let's just add an empty
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1245 ;; line so that our code which doesn't count lines
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1246 ;; will not get confused.
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1247 (progn (save-excursion (insert "\n")) nil)
c41c1aee3d31 (diff-sanity-check-hunk): Fix up the case when unified
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 78676
diff changeset
1248 (decf before) t))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1249 (?+ (decf after) t)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1250 (t
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1251 (cond
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1252 ((and diff-valid-unified-empty-line
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1253 ;; Not just (eolp) so we don't infloop at eob.
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1254 (eq (char-after) ?\n))
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1255 (decf before) (decf after) t)
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1256 ((and (zerop before) (zerop after)) nil)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1257 ((or (< before 0) (< after 0))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1258 (error (if (or (zerop before) (zerop after))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1259 "End of hunk ambiguously marked"
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1260 "Hunk seriously messed up")))
80151
533d83b5f687 Make it more robust in the presence of empty context lines in unified hunks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 80099
diff changeset
1261 ((not (y-or-n-p (concat "Try to auto-fix " (if (eolp) "whitespace loss" "word-wrap damage") "? ")))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1262 (error "Abort!"))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1263 ((eolp) (insert " ") (forward-line -1) t)
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1264 (t (insert " ")
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1265 (delete-region (- (point) 2) (- (point) 1)) t))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1266 (forward-line)))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1267
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1268 ;; A plain diff.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1269 (t
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1270 ;; TODO.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1271 )))))
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1272
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1273 (defun diff-hunk-text (hunk destp char-offset)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1274 "Return the literal source text from HUNK as (TEXT . OFFSET).
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
1275 If DESTP is nil, TEXT is the source, otherwise the destination text.
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1276 CHAR-OFFSET is a char-offset in HUNK, and OFFSET is the corresponding
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1277 char-offset in TEXT."
31556
74d7a9c42c2a (diff-hunk-text): Use `with-temp-buffer'.
Miles Bader <miles@gnu.org>
parents: 31538
diff changeset
1278 (with-temp-buffer
31819
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1279 (insert hunk)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1280 (goto-char (point-min))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1281 (let ((src-pos nil)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1282 (dst-pos nil)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1283 (divider-pos nil)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1284 (num-pfx-chars 2))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1285 ;; Set the following variables:
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1286 ;; SRC-POS buffer pos of the source part of the hunk or nil if none
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1287 ;; DST-POS buffer pos of the destination part of the hunk or nil
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1288 ;; DIVIDER-POS buffer pos of any divider line separating the src & dst
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1289 ;; NUM-PFX-CHARS number of line-prefix characters used by this format"
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1290 (cond ((looking-at "^@@")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1291 ;; unified diff
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1292 (setq num-pfx-chars 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1293 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1294 (setq src-pos (point) dst-pos (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1295 ((looking-at "^\\*\\*")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1296 ;; context diff
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1297 (forward-line 2)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1298 (setq src-pos (point))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1299 (re-search-forward "^--- " nil t)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1300 (forward-line 0)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1301 (setq divider-pos (point))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1302 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1303 (setq dst-pos (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1304 ((looking-at "^[0-9]+a[0-9,]+$")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1305 ;; normal diff, insert
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1306 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1307 (setq dst-pos (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1308 ((looking-at "^[0-9,]+d[0-9]+$")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1309 ;; normal diff, delete
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1310 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1311 (setq src-pos (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1312 ((looking-at "^[0-9,]+c[0-9,]+$")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1313 ;; normal diff, change
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1314 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1315 (setq src-pos (point))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1316 (re-search-forward "^---$" nil t)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1317 (forward-line 0)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1318 (setq divider-pos (point))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1319 (forward-line 1)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1320 (setq dst-pos (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1321 (t
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1322 (error "Unknown diff hunk type")))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1323
31819
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1324 (if (if destp (null dst-pos) (null src-pos))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1325 ;; Implied empty text
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1326 (if char-offset '("" . 0) "")
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1327
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1328 ;; For context diffs, either side can be empty, (if there's only
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1329 ;; added or only removed text). We should then use the other side.
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1330 (cond ((equal src-pos divider-pos) (setq src-pos dst-pos))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1331 ((equal dst-pos (point-max)) (setq dst-pos src-pos)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1332
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1333 (when char-offset (goto-char (+ (point-min) char-offset)))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1334
31819
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1335 ;; Get rid of anything except the desired text.
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1336 (save-excursion
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1337 ;; Delete unused text region
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1338 (let ((keep (if destp dst-pos src-pos)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1339 (when (and divider-pos (> divider-pos keep))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1340 (delete-region divider-pos (point-max)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1341 (delete-region (point-min) keep))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1342 ;; Remove line-prefix characters, and unneeded lines (unified diffs).
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1343 (let ((kill-char (if destp ?- ?+)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1344 (goto-char (point-min))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1345 (while (not (eobp))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1346 (if (eq (char-after) kill-char)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1347 (delete-region (point) (progn (forward-line 1) (point)))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1348 (delete-char num-pfx-chars)
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1349 (forward-line 1)))))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1350
31819
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1351 (let ((text (buffer-substring-no-properties (point-min) (point-max))))
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1352 (if char-offset (cons text (- (point) (point-min))) text))))))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1353
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1354
31734
6b057ae8165d Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31705
diff changeset
1355 (defun diff-find-text (text)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1356 "Return the buffer position (BEG . END) of the nearest occurrence of TEXT.
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1357 If TEXT isn't found, nil is returned."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1358 (let* ((orig (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1359 (forw (and (search-forward text nil t)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1360 (cons (match-beginning 0) (match-end 0))))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1361 (back (and (goto-char (+ orig (length text)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1362 (search-backward text nil t)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1363 (cons (match-beginning 0) (match-end 0)))))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1364 ;; Choose the closest match.
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1365 (if (and forw back)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1366 (if (> (- (car forw) orig) (- orig (car back))) back forw)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1367 (or back forw))))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1368
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1369 (defun diff-find-approx-text (text)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1370 "Return the buffer position (BEG . END) of the nearest occurrence of TEXT.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1371 Whitespace differences are ignored."
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1372 (let* ((orig (point))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1373 (re (concat "^[ \t\n ]*"
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1374 (mapconcat 'regexp-quote (split-string text) "[ \t\n ]+")
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1375 "[ \t\n ]*\n"))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1376 (forw (and (re-search-forward re nil t)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1377 (cons (match-beginning 0) (match-end 0))))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1378 (back (and (goto-char (+ orig (length text)))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1379 (re-search-backward re nil t)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1380 (cons (match-beginning 0) (match-end 0)))))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1381 ;; Choose the closest match.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1382 (if (and forw back)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1383 (if (> (- (car forw) orig) (- orig (car back))) back forw)
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1384 (or back forw))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1385
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1386 (defsubst diff-xor (a b) (if a (not b) b))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1387
31786
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1388 (defun diff-find-source-location (&optional other-file reverse)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1389 "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED).
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1390 BUF is the buffer corresponding to the source file.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1391 LINE-OFFSET is the offset between the expected and actual positions
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1392 of the text of the hunk or nil if the text was not found.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1393 POS is a pair (BEG . END) indicating the position of the text in the buffer.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1394 SRC and DST are the two variants of text as returned by `diff-hunk-text'.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1395 SRC is the variant that was found in the buffer.
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1396 SWITCHED is non-nil if the patch is already applied."
31735
9d50fe5df6ce Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31734
diff changeset
1397 (save-excursion
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1398 (let* ((other (diff-xor other-file diff-jump-to-old-file))
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
1399 (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
1400 (point))))
75191
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1401 ;; Check that the hunk is well-formed. Otherwise diff-mode and
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1402 ;; the user may disagree on what constitutes the hunk
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1403 ;; (e.g. because an empty line truncates the hunk mid-course),
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1404 ;; leading to potentially nasty surprises for the user.
98ad9ce30ba1 (diff-sanity-check-context-hunk-half, diff-sanity-check-hunk): New functions.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 74269
diff changeset
1405 (_ (diff-sanity-check-hunk))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1406 (hunk (buffer-substring (point)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1407 (save-excursion (diff-end-of-hunk) (point))))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1408 (old (diff-hunk-text hunk reverse char-offset))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1409 (new (diff-hunk-text hunk (not reverse) char-offset))
31735
9d50fe5df6ce Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31734
diff changeset
1410 ;; Find the location specification.
31786
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1411 (line (if (not (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?"))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1412 (error "Can't find the hunk header")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1413 (if other (match-string 1)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1414 (if (match-end 3) (match-string 3)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1415 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1416 (error "Can't find the hunk separator"))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1417 (match-string 1)))))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1418 (file (or (diff-find-file-name other) (error "Can't find the file")))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1419 (buf (find-file-noselect file)))
31735
9d50fe5df6ce Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31734
diff changeset
1420 ;; Update the user preference if he so wished.
9d50fe5df6ce Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31734
diff changeset
1421 (when (> (prefix-numeric-value other-file) 8)
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1422 (setq diff-jump-to-old-file other))
31786
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1423 (with-current-buffer buf
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1424 (goto-line (string-to-number line))
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1425 (let* ((orig-pos (point))
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1426 (switched nil)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1427 ;; FIXME: Check for case where both OLD and NEW are found.
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1428 (pos (or (diff-find-text (car old))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1429 (progn (setq switched t) (diff-find-text (car new)))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1430 (progn (setq switched nil)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1431 (condition-case nil
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1432 (diff-find-approx-text (car old))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1433 (invalid-regexp nil))) ;Regex too big.
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1434 (progn (setq switched t)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1435 (condition-case nil
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1436 (diff-find-approx-text (car new))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1437 (invalid-regexp nil))) ;Regex too big.
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1438 (progn (setq switched nil) nil))))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1439 (nconc
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1440 (list buf)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1441 (if pos
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1442 (list (count-lines orig-pos (car pos)) pos)
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1443 (list nil (cons orig-pos (+ orig-pos (length (car old))))))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1444 (if switched (list new old t) (list old new))))))))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1445
31735
9d50fe5df6ce Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31734
diff changeset
1446
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1447 (defun diff-hunk-status-msg (line-offset reversed dry-run)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1448 (let ((msg (if dry-run
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1449 (if reversed "already applied" "not yet applied")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1450 (if reversed "undone" "applied"))))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1451 (message (cond ((null line-offset) "Hunk text not found")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1452 ((= line-offset 0) "Hunk %s")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1453 ((= line-offset 1) "Hunk %s at offset %d line")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1454 (t "Hunk %s at offset %d lines"))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1455 msg line-offset)))
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1456
72813
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1457 (defvar diff-apply-hunk-to-backup-file nil)
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1458
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1459 (defun diff-apply-hunk (&optional reverse)
31819
e5a0c7120611 (diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31817
diff changeset
1460 "Apply the current hunk to the source file and go to the next.
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1461 By default, the new source file is patched, but if the variable
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1462 `diff-jump-to-old-file' is non-nil, then the old source file is
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1463 patched instead (some commands, such as `diff-goto-source' can change
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1464 the value of this variable when given an appropriate prefix argument).
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1465
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1466 With a prefix argument, REVERSE the hunk."
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1467 (interactive "P")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1468 (destructuring-bind (buf line-offset pos old new &optional switched)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1469 ;; If REVERSE go to the new file, otherwise go to the old.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1470 (diff-find-source-location (not reverse) reverse)
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1471 (cond
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1472 ((null line-offset)
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1473 (error "Can't find the text to patch"))
72813
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1474 ((with-current-buffer buf
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1475 (and buffer-file-name
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1476 (backup-file-name-p buffer-file-name)
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1477 (not diff-apply-hunk-to-backup-file)
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1478 (not (set (make-local-variable 'diff-apply-hunk-to-backup-file)
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1479 (yes-or-no-p (format "Really apply this hunk to %s? "
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1480 (file-name-nondirectory
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1481 buffer-file-name)))))))
76453
5e29de959ce6 (diff-apply-hunk): Use proper format string for
Andreas Schwab <schwab@suse.de>
parents: 76323
diff changeset
1482 (error "%s"
5e29de959ce6 (diff-apply-hunk): Use proper format string for
Andreas Schwab <schwab@suse.de>
parents: 76323
diff changeset
1483 (substitute-command-keys
72813
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1484 (format "Use %s\\[diff-apply-hunk] to apply it to the other file"
200db4ae9b54 (diff-apply-hunk-to-backup-file): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 71556
diff changeset
1485 (if (not reverse) "\\[universal-argument] ")))))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1486 ((and switched
35526
b40a6cecc4d5 (diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 33488
diff changeset
1487 ;; A reversed patch was detected, perhaps apply it in reverse.
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1488 (not (save-window-excursion
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1489 (pop-to-buffer buf)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1490 (goto-char (+ (car pos) (cdr old)))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1491 (y-or-n-p
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1492 (if reverse
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1493 "Hunk hasn't been applied yet; apply it now? "
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1494 "Hunk has already been applied; undo it? ")))))
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1495 (message "(Nothing done)"))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1496 (t
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1497 ;; Apply the hunk
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1498 (with-current-buffer buf
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1499 (goto-char (car pos))
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1500 (delete-region (car pos) (cdr pos))
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1501 (insert (car new)))
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1502 ;; Display BUF in a window
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1503 (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1504 (diff-hunk-status-msg line-offset (diff-xor switched reverse) nil)
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1505 (when diff-advance-after-apply-hunk
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1506 (diff-hunk-next))))))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1507
31684
e05ee0693dda (diff-hunk-text):
Miles Bader <miles@gnu.org>
parents: 31556
diff changeset
1508
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1509 (defun diff-test-hunk (&optional reverse)
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1510 "See whether it's possible to apply the current hunk.
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1511 With a prefix argument, try to REVERSE the hunk."
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1512 (interactive "P")
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1513 (destructuring-bind (buf line-offset pos src dst &optional switched)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1514 ;; If REVERSE go to the new file, otherwise go to the old.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1515 (diff-find-source-location (not reverse) reverse)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1516 (set-window-point (display-buffer buf) (+ (car pos) (cdr src)))
32063
3fb2a3b13c5e (diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents: 32061
diff changeset
1517 (diff-hunk-status-msg line-offset (diff-xor reverse switched) t)))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1518
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1519
54869
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
1520 (defalias 'diff-mouse-goto-source 'diff-goto-source)
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
1521
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
1522 (defun diff-goto-source (&optional other-file event)
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1523 "Jump to the corresponding source line.
37866
4e2d06e10072 (diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 37567
diff changeset
1524 `diff-jump-to-old-file' (or its opposite if the OTHER-FILE prefix arg
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1525 is given) determines whether to jump to the old or the new file.
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1526 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
70542
ef7506f44a3a (diff-context->unified): Use `region-beginning' and `region-end'
Juri Linkov <juri@jurta.org>
parents: 70333
diff changeset
1527 then `diff-jump-to-old-file' is also set, for the next invocations."
54869
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
1528 (interactive (list current-prefix-arg last-input-event))
32111
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1529 ;; When pointing at a removal line, we probably want to jump to
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1530 ;; the old location, and else to the new (i.e. as if reverting).
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1531 ;; This is a convenient detail when using smerge-diff.
54869
c491468e3c18 (diff-goto-source): Make it work for mouse bindings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54693
diff changeset
1532 (if event (posn-set-point (event-end event)))
32111
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1533 (let ((rev (not (save-excursion (beginning-of-line) (looking-at "[-<]")))))
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1534 (destructuring-bind (buf line-offset pos src dst &optional switched)
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1535 (diff-find-source-location other-file rev)
161c2ec9f5b2 (diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 32063
diff changeset
1536 (pop-to-buffer buf)
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1537 (goto-char (+ (car pos) (cdr src)))
32143
299f601ca8ba (diff-goto-source):
Miles Bader <miles@gnu.org>
parents: 32111
diff changeset
1538 (diff-hunk-status-msg line-offset (diff-xor rev switched) t))))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1539
31786
181947e98152 (diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31749
diff changeset
1540
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1541 (defun diff-current-defun ()
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1542 "Find the name of function at point.
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1543 For use in `add-log-current-defun-function'."
56073
dc1d86d80c20 Reindent `diff-current-defun'.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 56072
diff changeset
1544 (save-excursion
dc1d86d80c20 Reindent `diff-current-defun'.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 56072
diff changeset
1545 (when (looking-at diff-hunk-header-re)
dc1d86d80c20 Reindent `diff-current-defun'.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 56072
diff changeset
1546 (forward-line 1)
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
1547 (re-search-forward "^[^ ]" nil t))
56073
dc1d86d80c20 Reindent `diff-current-defun'.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 56072
diff changeset
1548 (destructuring-bind (buf line-offset pos src dst &optional switched)
dc1d86d80c20 Reindent `diff-current-defun'.
Kai Großjohann <kgrossjo@eu.uu.net>
parents: 56072
diff changeset
1549 (diff-find-source-location)
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1550 (beginning-of-line)
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1551 (or (when (memq (char-after) '(?< ?-))
31817
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1552 ;; Cursor is pointing at removed text. This could be a removed
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1553 ;; function, in which case, going to the source buffer will
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1554 ;; not help since the function is now removed. Instead,
e23774b771e1 (diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31795
diff changeset
1555 ;; try to figure out the function name just from the code-fragment.
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1556 (let ((old (if switched dst src)))
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1557 (with-temp-buffer
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1558 (insert (car old))
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1559 (funcall (with-current-buffer buf major-mode))
46407
4c4398249108 (diff-reverse-direction): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 42472
diff changeset
1560 (goto-char (+ (point-min) (cdr old)))
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1561 (add-log-current-defun))))
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1562 (with-current-buffer buf
41526
f0fb05d40941 (diff-end-of-hunk): Watch out for ambiguities.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 39386
diff changeset
1563 (goto-char (+ (car pos) (cdr src)))
31795
868648c4a36b * diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 31786
diff changeset
1564 (add-log-current-defun))))))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1565
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1566 (defun diff-refine-hunk ()
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1567 "Refine the current hunk by ignoring space differences."
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1568 (interactive)
78359
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
1569 (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder)
2dd5d799a16d * vc-git.el: (vc-directory-exclusion-list, vc-handled-backends):
Dan Nicolaescu <dann@ics.uci.edu>
parents: 78236
diff changeset
1570 (point))))
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1571 (opts (case (char-after) (?@ "-bu") (?* "-bc") (t "-b")))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1572 (line-nb (and (or (looking-at "[^0-9]+\\([0-9]+\\)")
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1573 (error "Can't find line number"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1574 (string-to-number (match-string 1))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1575 (hunk (delete-and-extract-region
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1576 (point) (save-excursion (diff-end-of-hunk) (point))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1577 (lead (make-string (1- line-nb) ?\n)) ;Line nums start at 1.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1578 (file1 (make-temp-file "diff1"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1579 (file2 (make-temp-file "diff2"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1580 (coding-system-for-read buffer-file-coding-system)
71249
3798a822991e * diff-mode.el (diff-hunk-kill, diff-file-kill, diff-split-hunk)
Chong Yidong <cyd@stupidchicken.com>
parents: 71248
diff changeset
1581 (inhibit-read-only t)
54528
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1582 old new)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1583 (unwind-protect
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1584 (save-excursion
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1585 (setq old (diff-hunk-text hunk nil char-offset))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1586 (setq new (diff-hunk-text hunk t char-offset))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1587 (write-region (concat lead (car old)) nil file1 nil 'nomessage)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1588 (write-region (concat lead (car new)) nil file2 nil 'nomessage)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1589 (with-temp-buffer
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1590 (let ((status
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1591 (call-process diff-command nil t nil
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1592 opts file1 file2)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1593 (case status
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1594 (0 nil) ;Nothing to reformat.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1595 (1 (goto-char (point-min))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1596 ;; Remove the file-header.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1597 (when (re-search-forward diff-hunk-header-re nil t)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1598 (delete-region (point-min) (match-beginning 0))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1599 (t (goto-char (point-max))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1600 (unless (bolp) (insert "\n"))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1601 (insert hunk)))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1602 (setq hunk (buffer-string))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1603 (unless (memq status '(0 1))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1604 (error "Diff returned: %s" status)))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1605 ;; Whatever happens, put back some equivalent text: either the new
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1606 ;; one or the original one in case some error happened.
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1607 (insert hunk)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1608 (delete-file file1)
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1609 (delete-file file2))))
67419634950d (diff-default-read-only): Change default.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53833
diff changeset
1610
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1611 ;; provide the package
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1612 (provide 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1613
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1614 ;;; Old Change Log from when diff-mode wasn't part of Emacs:
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1615 ;; Revision 1.11 1999/10/09 23:38:29 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1616 ;; (diff-mode-load-hook): dropped.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1617 ;; (auto-mode-alist): also catch *.diffs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1618 ;; (diff-find-file-name, diff-mode): add smarts to find the right file
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1619 ;; for *.rej files (that lack any file name indication).
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1620 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1621 ;; Revision 1.10 1999/09/30 15:32:11 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1622 ;; added support for "\ No newline at end of file".
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1623 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1624 ;; Revision 1.9 1999/09/15 00:01:13 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1625 ;; - added basic `compile' support.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1626 ;; - have diff-kill-hunk call diff-kill-file if it's the only hunk.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1627 ;; - diff-kill-file now tries to kill the leading garbage as well.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1628 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1629 ;; Revision 1.8 1999/09/13 21:10:09 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1630 ;; - don't use CL in the autoloaded code
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1631 ;; - accept diffs using -T
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1632 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1633 ;; Revision 1.7 1999/09/05 20:53:03 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1634 ;; interface to ediff-patch
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1635 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1636 ;; Revision 1.6 1999/09/01 20:55:13 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1637 ;; (ediff=patch-file): add bindings to call ediff-patch.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1638 ;; (diff-find-file-name): taken out of diff-goto-source.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1639 ;; (diff-unified->context, diff-context->unified, diff-reverse-direction,
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1640 ;; diff-fixup-modifs): only use the region if a prefix arg is given.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1641 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1642 ;; Revision 1.5 1999/08/31 19:18:52 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1643 ;; (diff-beginning-of-file, diff-prev-file): fixed wrong parenthesis.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1644 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1645 ;; Revision 1.4 1999/08/31 13:01:44 monnier
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1646 ;; use `combine-after-change-calls' to minimize the slowdown of font-lock.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1647 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1648
57418
3a8c458de33d (diff-current-defun): Fix 2004-06-13's change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 57279
diff changeset
1649 ;; arch-tag: 2571d7ff-bc28-4cf9-8585-42e21890be66
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1650 ;;; diff-mode.el ends here