Mercurial > emacs
annotate lisp/diff-mode.el @ 38904:db6c2951e6a7
(struct face_cache): Add member
menu_face_changed_p.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 22 Aug 2001 09:43:40 +0000 |
parents | 50a5496b5f2c |
children | b5dd113d61d1 |
rev | line source |
---|---|
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; diff-mode.el --- A mode for viewing/editing context diffs |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
31269
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
3 ;; Copyright (C) 1998, 1999, 2000 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
|
4 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu> |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Keywords: patch diff |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; 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
|
9 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; 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
|
11 ;; it under the terms of the GNU General Public License as published by |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;; any later version. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; 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
|
16 ;; 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
|
17 ;; 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
|
18 ;; 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
|
19 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;; 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
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 ;;; Commentary: |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
35526
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
27 ;; 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
|
28 ;; 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
|
29 ;; 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
|
30 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 ;; inspired by Pavel Machek's patch-mode.el (<pavel@atrey.karlin.mff.cuni.cz>) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;; some efforts were spent to have it somewhat compatible with XEmacs' |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 ;; 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
|
34 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;; to use it, simply add to your .emacs the following lines: |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; (autoload 'diff-mode "diff-mode" "Diff major mode" t) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 ;; (add-to-list 'auto-mode-alist '("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode)) |
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 ;; Bugs: |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
42 ;; - 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
|
43 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;; Todo: |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
46 ;; - Improve narrowed-view support. |
35526
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
47 ;; - re-enable (conditionally) the `compile' support after improving it to use |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
48 ;; the same code as diff-goto-source. |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
49 ;; - Support for # comments in context->unified. |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
50 ;; - Do a fuzzy search in diff-goto-source. |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
51 ;; - Allow diff.el to use diff-mode. |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
52 ;; This mostly means ability to jump from half-hunk to half-hunk |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
53 ;; in context (and normal) diffs and to jump to the corresponding |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
54 ;; (i.e. new or old) file. |
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 |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
57 ;; Low priority: |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
58 ;; - Spice up the minor-mode with font-lock support. |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
59 ;; - Recognize pcl-cvs' special string for `cvs-execute-single'. |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
60 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 ;;; Code: |
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 (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
|
64 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (defgroup diff-mode () |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
67 "Major mode for viewing/editing diffs" |
31269
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
68 :version "21.1" |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 :group 'tools |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 :group 'diff) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 |
37866
4e2d06e10072
(diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37567
diff
changeset
|
72 (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
|
73 "*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
|
74 Else, it jumps to the new file." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 :group 'diff-mode |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 :type '(boolean)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 |
37866
4e2d06e10072
(diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37567
diff
changeset
|
78 (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
|
79 "*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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 when editing big diffs)." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 :group 'diff-mode |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 :type '(boolean)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 |
32061
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
88 (defcustom diff-advance-after-apply-hunk t |
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
89 "*Non-nil means `diff-apply-hunk' will move to the next hunk after applying." |
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
90 :group 'diff-mode |
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
91 :type 'boolean) |
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
92 |
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
93 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 (defvar diff-mode-hook nil |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 "Run after setting up the `diff-mode' major mode.") |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (defvar diff-outline-regexp |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 "\\([*+][*+][*+] [^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
|
99 |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
100 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 ;;;; keymap, menu, ... |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
102 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
104 (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
|
105 '(;; 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
|
106 ("n" . diff-hunk-next) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
107 ("N" . diff-file-next) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
108 ("p" . diff-hunk-prev) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
109 ("P" . diff-file-prev) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
110 ("k" . diff-hunk-kill) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
111 ("K" . diff-file-kill) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
112 ;; From compilation-minor-mode. |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
113 ("}" . diff-file-next) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
114 ("{" . diff-file-prev) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 ("\C-m" . diff-goto-source) |
31269
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
116 ([mouse-2] . diff-mouse-goto-source) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
117 ;; From XEmacs' diff-mode. |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 ("W" . widen) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 ;;("." . 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
|
120 ;;("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
|
121 ("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
|
122 ;;("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
|
123 ;;("N" . diff-narrow) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 ;;("h" . diff-show-header) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 ;;("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
|
126 ;;("q" . diff-quit) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 (" " . scroll-up) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 ("\177" . scroll-down) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
129 ;; Our very own bindings. |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 ("A" . diff-ediff-patch) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 ("r" . diff-restrict-view) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 ("R" . diff-reverse-direction) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 ("U" . diff-context->unified) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 ("C" . diff-unified->context)) |
26748
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
135 "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
|
136 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
137 (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
|
138 `(("\e" . ,diff-mode-shared-map) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
139 ;; From compilation-minor-mode. |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
140 ("\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
|
141 ;; Misc operations. |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
142 ("\C-c\C-s" . diff-split-hunk) |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
143 ("\C-c\C-a" . diff-apply-hunk) |
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
144 ("\C-c\C-t" . diff-test-hunk)) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 "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
|
146 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 (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
|
148 "Menu for `diff-mode'." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149 '("Diff" |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 ["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
|
151 ["Apply hunk" diff-apply-hunk t] |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
152 ["Apply diff with Ediff" diff-ediff-patch t] |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 ["-----" nil nil] |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 ["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
|
155 ["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
|
156 ["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
|
157 ;;["Fixup Headers" diff-fixup-modifs (not buffer-read-only)] |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 )) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
160 (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
|
161 "Prefix key for `diff-minor-mode' commands." |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
162 :group 'diff-mode |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
163 :type '(choice (string "\e") (string "C-c=") string)) |
26748
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
164 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
165 (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
|
166 `((,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
|
167 "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
|
168 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
170 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 ;;;; font-lock support |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
172 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
174 (defface diff-header-face |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
175 '((((type tty pc) (class color) (background light)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
176 (:foreground "blue1" :bold t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
177 (((type tty pc) (class color) (background dark)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
178 (:foreground "green" :bold t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
179 (((class color) (background light)) |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
180 (:background "grey85")) |
32588
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
181 (((class color) (background dark)) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
182 (:background "grey45")) |
31973
ad9838a9349c
(diff-mode-map, diff-minor-mode-prefix):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31819
diff
changeset
|
183 (t (:bold t))) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
184 "`diff-mode' face inherited by hunk and index header faces." |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
185 :group 'diff-mode) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
186 (defvar diff-header-face 'diff-header-face) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
187 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (defface diff-file-header-face |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
189 '((((type tty pc) (class color) (background light)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
190 (:foreground "yellow" :bold t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
191 (((type tty pc) (class color) (background dark)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
192 (:foreground "cyan" :bold t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
193 (((class color) (background light)) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
194 (:background "grey70" :bold t)) |
32588
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
195 (((class color) (background dark)) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
196 (:background "grey60" :bold t)) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
197 (t (:bold t))) ; :height 1.3 |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
198 "`diff-mode' face used to highlight file header lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 (defvar diff-file-header-face 'diff-file-header-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 (defface diff-index-face |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
203 '((t (:inherit diff-file-header-face))) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
204 "`diff-mode' face used to highlight index header lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 (defvar diff-index-face 'diff-index-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 (defface diff-hunk-header-face |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
209 '((t (:inherit diff-header-face))) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
210 "`diff-mode' face used to highlight hunk header lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 (defvar diff-hunk-header-face 'diff-hunk-header-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214 (defface diff-removed-face |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
215 '((t (:inherit diff-changed-face))) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
216 "`diff-mode' face used to highlight removed lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 (defvar diff-removed-face 'diff-removed-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220 (defface diff-added-face |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
221 '((t (:inherit diff-changed-face))) |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
222 "`diff-mode' face used to highlight added lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
223 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
224 (defvar diff-added-face 'diff-added-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 (defface diff-changed-face |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
227 '((((type tty pc) (class color) (background light)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
228 (:foreground "magenta" :bold t :italic t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
229 (((type tty pc) (class color) (background dark)) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
230 (:foreground "yellow" :bold t :italic t)) |
32576
c6eb63e9c25c
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32482
diff
changeset
|
231 (t ())) |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
232 "`diff-mode' face used to highlight changed lines." |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 :group 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 (defvar diff-changed-face 'diff-changed-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
236 (defface diff-function-face |
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
237 '((t (:inherit diff-context-face))) |
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
238 "`diff-mode' face used to highlight function names produced by \"diff -p\"." |
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
239 :group 'diff-mode) |
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
240 (defvar diff-function-face 'diff-function-face) |
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
241 |
32588
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
242 (defface diff-context-face |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
243 '((((class color) (background light)) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
244 (:foreground "grey50")) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
245 (((class color) (background dark)) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
246 (:foreground "grey70")) |
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
247 (t )) |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
248 "`diff-mode' face used to highlight context and other side-information." |
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
249 :group 'diff-mode) |
32588
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
250 (defvar diff-context-face 'diff-context-face) |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
251 |
37567
50d77d1b2d58
(diff-nonexistent-face, diff-font-lock-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37531
diff
changeset
|
252 (defface diff-nonexistent-face |
37531
e71362bfa695
(diff-nonexistant-face): New face.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35526
diff
changeset
|
253 '((t (:inherit diff-file-header-face))) |
37567
50d77d1b2d58
(diff-nonexistent-face, diff-font-lock-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37531
diff
changeset
|
254 "`diff-mode' face used to highlight nonexistent files in recursive diffs." |
37531
e71362bfa695
(diff-nonexistant-face): New face.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35526
diff
changeset
|
255 :group 'diff-mode) |
37567
50d77d1b2d58
(diff-nonexistent-face, diff-font-lock-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37531
diff
changeset
|
256 (defvar diff-nonexistent-face 'diff-nonexistent-face) |
37531
e71362bfa695
(diff-nonexistant-face): New face.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35526
diff
changeset
|
257 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
258 (defvar diff-font-lock-keywords |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
259 '(("^\\(@@ -[0-9,]+ \\+[0-9,]+ @@\\)\\(.*\\)$" ;unified |
31479
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
260 (1 diff-hunk-header-face) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
261 (2 diff-function-face)) |
37531
e71362bfa695
(diff-nonexistant-face): New face.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
35526
diff
changeset
|
262 ("^--- .+ ----$" . diff-hunk-header-face) ;context |
38029
50a5496b5f2c
(diff-font-lock-keywords): Fix unanchored regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37866
diff
changeset
|
263 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context |
31479
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
264 (1 diff-hunk-header-face) |
32603
87af45b9ad99
(diff-header-face, diff-file-header-face)
Eli Zaretskii <eliz@gnu.org>
parents:
32588
diff
changeset
|
265 (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
|
266 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context |
32111
161c2ec9f5b2
(diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32063
diff
changeset
|
267 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)\\(.*[^*-]\\)?\n" |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
268 (0 diff-header-face) (2 diff-file-header-face prepend)) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
269 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
270 ("^!.*\n" . diff-changed-face) ;context |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271 ("^[+>].*\n" . diff-added-face) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
272 ("^[-<].*\n" . diff-removed-face) |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
273 ("^Index: \\(.+\\).*\n" (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
|
274 ("^Only in .*\n" . diff-nonexistent-face) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
275 ("^#.*" . font-lock-string-face) |
32588
afbcd960831b
(diff-header-face, diff-file-header-face):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32576
diff
changeset
|
276 ("^[^-=+*!<>].*\n" . diff-context-face))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
277 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
278 (defconst diff-font-lock-defaults |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
279 '(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
|
280 |
31269
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
281 (defvar diff-imenu-generic-expression |
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
282 ;; 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
|
283 ;; 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
|
284 ;; 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
|
285 '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)[\t\n]" 1) ; unidiffs |
31269
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
286 (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs |
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
287 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
288 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
289 ;;;; Compile support |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
291 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 (defvar diff-file-regexp-alist |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293 '(("Index: \\(.+\\)" 1))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
295 (defvar diff-error-regexp-alist |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 '(("@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@" nil 2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
297 ("--- \\([0-9]+\\),[0-9]+ ----" nil 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 ("\\([0-9]+\\)\\(,[0-9]+\\)?[adc]\\([0-9]+\\)" nil 3))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
300 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301 ;;;; Movement |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
302 ;;;; |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
303 |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
304 (defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$") |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 (defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
306 (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
|
307 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 (defun diff-end-of-hunk (&optional style) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309 (if (looking-at diff-hunk-header-re) (goto-char (match-end 0))) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
310 (let ((end (and (re-search-forward (case style |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
311 (unified "^[^-+# \\]") |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
312 (context "^[^-+#! \\]") |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
313 (normal "^[^<>#\\]") |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
314 (t "^[^-+#!<> \\]")) |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
315 nil t) |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
316 (match-beginning 0)))) |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
317 ;; 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
|
318 (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
|
319 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
320 (defun diff-beginning-of-hunk () |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
321 (beginning-of-line) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
322 (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
|
323 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
324 (condition-case () |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
325 (re-search-backward diff-hunk-header-re) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 (error (error "Can't find the beginning of the hunk"))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 (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
|
329 (beginning-of-line) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 (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
|
331 (forward-line 2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
332 (condition-case () |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
333 (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
|
334 (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
|
335 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 (defun diff-end-of-file () |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
337 (re-search-forward "^[-+#!<>0-9@* \\]" nil t) |
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
338 (re-search-forward "^[^-+#!<>0-9@* \\]" nil 'move) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
339 (beginning-of-line)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
341 ;; Define diff-{hunk,file}-{prev,next} |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
342 (easy-mmode-define-navigation |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
343 diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk) |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
344 (easy-mmode-define-navigation |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
345 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
|
346 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
347 (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
|
348 "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
|
349 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
|
350 (interactive "P") |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
351 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
352 (if arg (diff-beginning-of-file) (diff-beginning-of-hunk)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
353 (narrow-to-region (point) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
354 (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
|
355 (point))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
356 (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
|
357 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
358 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
359 (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
|
360 "Kill current hunk." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
361 (interactive) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
362 (diff-beginning-of-hunk) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
363 (let ((start (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
364 (firsthunk (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
365 (ignore-errors |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
366 (diff-beginning-of-file) (diff-hunk-next) (point)))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
367 (nexthunk (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
368 (ignore-errors |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
369 (diff-hunk-next) (point)))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
370 (nextfile (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
371 (ignore-errors |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
372 (diff-file-next) (point))))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
373 (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
|
374 (or (null nexthunk) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 (and nextfile (> nexthunk nextfile)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
376 ;; we're 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
|
377 (diff-file-kill) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
378 (diff-end-of-hunk) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
379 (kill-region start (point))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
380 |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
381 (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
|
382 "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
|
383 (interactive) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
384 (diff-beginning-of-file) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
385 (let* ((start (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
386 (prevhunk (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
387 (ignore-errors |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
388 (diff-hunk-prev) (point)))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
389 (index (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
390 (re-search-backward "^Index: " prevhunk t)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
391 (when index (setq start index)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
392 (diff-end-of-file) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
393 (kill-region start (point)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
394 |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
395 (defun diff-kill-junk () |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
396 "Kill spurious empty diffs." |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
397 (interactive) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
398 (save-excursion |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
399 (let ((inhibit-read-only t)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
400 (goto-char (point-min)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
401 (while (re-search-forward (concat "^\\(Index: .*\n\\)" |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
402 "\\([^-+!* <>].*\n\\)*?" |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
403 "\\(\\(Index:\\) \\|" |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
404 diff-file-header-re "\\)") |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
405 nil t) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
406 (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
|
407 (match-beginning 3)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
408 (beginning-of-line))))) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
409 |
33432
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
410 (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
|
411 (save-excursion |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
412 (let ((n 0)) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
413 (goto-char start) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
414 (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
|
415 n))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
416 |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
417 (defun diff-split-hunk () |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
418 "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
|
419 (interactive) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
420 (beginning-of-line) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
421 (let ((pos (point)) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
422 (start (progn (diff-beginning-of-hunk) (point)))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
423 (unless (looking-at "@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@") |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
424 (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
|
425 (forward-line 1) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
426 (let* ((start1 (string-to-number (match-string 1))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
427 (start2 (string-to-number (match-string 2))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
428 (newstart1 (+ start1 (diff-count-matches "^[- \t]" (point) pos))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
429 (newstart2 (+ start2 (diff-count-matches "^[+ \t]" (point) pos)))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
430 (goto-char pos) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
431 ;; 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
|
432 (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
|
433 (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
|
434 ;; Fix the original hunk-header. |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
435 (diff-fixup-modifs start pos)))) |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
436 |
7f6ffdaecedc
(diff-mode-menu): Add entry for applying hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32666
diff
changeset
|
437 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
438 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
439 ;;;; jump to other buffers |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
440 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
441 |
26748
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
442 (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
|
443 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
444 (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
|
445 (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
|
446 |
26748
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
447 (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
|
448 "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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 ;; 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
|
456 ;; 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
|
457 ;; 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
|
458 ;; 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
|
459 (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
|
460 (when (and (string-match (concat |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
461 "\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n" |
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
462 "\\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
|
463 "\\(.*\\(\\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
|
464 (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
|
465 (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
|
466 (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
|
467 (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
|
468 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
469 (defun diff-find-file-name (&optional old) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
470 "Return the file corresponding to the current patch. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
471 Non-nil OLD means that we want the old file." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
472 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
473 (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
|
474 (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
|
475 (re-search-forward diff-file-header-re nil t))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
476 (let* ((limit (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
477 (condition-case () |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
478 (progn (diff-hunk-prev) (point)) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
479 (error (point-min))))) |
26009
16ee8d330c59
(diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25979
diff
changeset
|
480 (header-files |
32482
3e97369732ac
(diff-find-file-name): Fix regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32143
diff
changeset
|
481 (if (looking-at "[-*][-*][-*] \\(\\S-+\\)\\(\\s-.*\\)?\n[-+][-+][-+] \\(\\S-+\\)") |
32666
07a2c551b566
(diff-find-file-name): Fix regex subgroup number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32603
diff
changeset
|
482 (list (if old (match-string 1) (match-string 3)) |
07a2c551b566
(diff-find-file-name): Fix regex subgroup number.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32603
diff
changeset
|
483 (if old (match-string 3) (match-string 1))) |
26009
16ee8d330c59
(diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25979
diff
changeset
|
484 (forward-line 1) nil)) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
485 (fs (append |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
486 (when (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
487 (re-search-backward "^Index: \\(.+\\)" limit t)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
488 (list (match-string 1))) |
26009
16ee8d330c59
(diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
25979
diff
changeset
|
489 header-files |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
490 (when (re-search-backward "^diff \\(-\\S-+ +\\)*\\(\\S-+\\)\\( +\\(\\S-+\\)\\)?" nil t) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
491 (list (if old (match-string 2) (match-string 4)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
492 (if old (match-string 4) (match-string 2)))))) |
26748
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
493 (fs (delq nil fs))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
494 (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
|
495 ;; 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
|
496 (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
|
497 ;; 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
|
498 (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
|
499 (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
|
500 (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
|
501 ;; 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
|
502 ;; 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
|
503 (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
|
504 (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
|
505 ((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
|
506 (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
|
507 (file (car files) (car files))) |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
508 ((or (null file) (file-exists-p file)) |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
509 file)))) |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
510 file)) |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
511 ;; <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
|
512 (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
|
513 (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
|
514 (when (file-exists-p file) 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
|
515 ;; 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
|
516 (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
|
517 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
|
518 (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
|
519 (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
|
520 file))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
521 |
32012
b1edfcd919a7
(diff-add-log-file-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31973
diff
changeset
|
522 |
31479
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
523 (defun diff-mouse-goto-source (event) |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
524 "Run `diff-goto-source' for the diff at a mouse click." |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
525 (interactive "e") |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
526 (save-excursion |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
527 (mouse-set-point event) |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
528 (diff-goto-source))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
529 |
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
|
530 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
531 (defun diff-ediff-patch () |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
532 "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
|
533 (interactive) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
534 (condition-case err |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
535 (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
|
536 (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
|
537 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
538 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
539 ;;;; Conversion functions |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
540 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
541 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
542 ;;(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
|
543 ;; "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
|
544 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 (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
|
546 "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
|
547 START and END are either taken from the region (if a prefix arg is given) or |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
548 else cover the whole bufer." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
549 (interactive (if current-prefix-arg |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
550 (list (mark) (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
551 (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
|
552 (unless (markerp end) (setq end (copy-marker end))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
553 (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
|
554 (inhibit-read-only t)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
555 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
556 (goto-char start) |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
557 (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([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
|
558 (< (point) end)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
559 (combine-after-change-calls |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
560 (if (match-beginning 2) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
561 ;; 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
|
562 (progn |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
563 ;; 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
|
564 (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
|
565 (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
|
566 ;; 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
|
567 (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
|
568 (lines1 (match-string 5)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
569 (line2 (match-string 6)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
570 (lines2 (match-string 7))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
571 (replace-match |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
572 (concat "***************\n*** " line1 "," |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
573 (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
|
574 (string-to-number lines1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
575 -1)) " ****")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
576 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
577 (save-restriction |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
578 (narrow-to-region (point) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
579 (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
|
580 (let ((hunk (buffer-string))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
581 (goto-char (point-min)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
582 (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
|
583 (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
|
584 (goto-char (point-max)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
585 (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
|
586 (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
|
587 (= (forward-line -1) 0)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
588 (case (char-after) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
589 (? (insert " ") (setq modif nil) (backward-char 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
590 (?+ (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
|
591 (?- (if (not modif) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
592 (progn (forward-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
593 (insert " ")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
594 (delete-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
595 (insert "! ")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
596 (backward-char 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
597 (?\\ (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
|
598 (= (char-after) ?+)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
599 (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
|
600 (t (setq modif nil)))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
601 (goto-char (point-max)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
602 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
603 (insert "--- " line2 "," |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
604 (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
|
605 (string-to-number lines2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
606 -1)) " ----\n" hunk)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
607 ;;(goto-char (point-min)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
608 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
609 (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
|
610 (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
|
611 (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
|
612 (while (not (eobp)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
613 (case (char-after) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
614 (? (insert " ") (setq modif nil) (backward-char 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
615 (?- (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
|
616 (?+ (if (not modif) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
617 (progn (forward-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
618 (insert " ")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
619 (delete-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
620 (insert "! ")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
621 (backward-char 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
622 (?\\ (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
|
623 (not (eobp))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
624 (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
|
625 (t (setq modif nil))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
626 (let ((last-pt (point))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
627 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
628 (when delete |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
629 (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
|
630 (setq delete nil))))))))))))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
631 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
632 (defun diff-context->unified (start end) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
633 "Convert context diffs to unified diffs. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
634 START and END are either taken from the region (if a prefix arg is given) or |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
635 else cover the whole bufer." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
636 (interactive (if current-prefix-arg |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
637 (list (mark) (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
638 (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
|
639 (unless (markerp end) (setq end (copy-marker end))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
640 (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
|
641 (inhibit-read-only t)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
642 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
643 (goto-char start) |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
644 (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
|
645 (< (point) end)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
646 (combine-after-change-calls |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
647 (if (match-beginning 2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
648 ;; we matched a file header |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
649 (progn |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
650 ;; 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
|
651 (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
|
652 (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
|
653 ;; 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
|
654 (let ((line1s (match-string 4)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
655 (line1e (match-string 5)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
656 (pt1 (match-beginning 0))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
657 (replace-match "") |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
658 (unless (re-search-forward |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
659 "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
660 (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
|
661 (let ((line2s (match-string 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
662 (line2e (match-string 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
663 (pt2 (progn |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
664 (delete-region (progn (beginning-of-line) (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
665 (progn (forward-line 1) (point))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
666 (point-marker)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
667 (goto-char pt1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
668 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
669 (while (< (point) pt2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
670 (case (char-after) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
671 ((?! ?-) (delete-char 2) (insert "-") (forward-line 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
672 (?\ ;merge with the other half of the chunk |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
673 (let* ((endline2 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
674 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
675 (goto-char pt2) (forward-line 1) (point))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
676 (c (char-after pt2))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
677 (case c |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
678 ((?! ?+) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
679 (insert "+" |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
680 (prog1 (buffer-substring (+ pt2 2) endline2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
681 (delete-region pt2 endline2)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
682 (?\ ;FIXME: check consistency |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
683 (delete-region pt2 endline2) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
684 (delete-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
685 (forward-line 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
686 (?\\ (forward-line 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
687 (t (delete-char 1) (forward-line 1))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
688 (t (forward-line 1)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
689 (while (looking-at "[+! ] ") |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
690 (if (/= (char-after) ?!) (forward-char 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
691 (delete-char 1) (insert "+")) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
692 (delete-char 1) (forward-line 1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
693 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
694 (goto-char pt1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
695 (insert "@@ -" line1s "," |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
696 (number-to-string (- (string-to-number line1e) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
697 (string-to-number line1s) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 -1)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
699 " +" line2s "," |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
700 (number-to-string (- (string-to-number line2e) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
701 (string-to-number line2s) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 -1)) " @@")))))))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
703 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 (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
|
705 "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
|
706 START and END are either taken from the region (if a prefix arg is given) or |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
707 else cover the whole bufer." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
708 (interactive (if current-prefix-arg |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
709 (list (mark) (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 (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
|
711 (unless (markerp end) (setq end (copy-marker end))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 (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
|
713 (inhibit-read-only t)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
714 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
715 (goto-char start) |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
716 (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
|
717 (< (point) end)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
718 (combine-after-change-calls |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
719 (cond |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
720 ;; a file header |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
721 ((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
|
722 ;; 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
|
723 ((match-beginning 6) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
724 (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
|
725 (lines1 (match-string 6))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
726 (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
|
727 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
728 (let ((half1s (point))) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
729 (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
|
730 (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
|
731 (forward-line 1)) |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
732 (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
|
733 (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
|
734 (insert half1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
735 (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
|
736 (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
|
737 (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
|
738 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
739 (let ((half2s (point))) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
740 (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
|
741 (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
|
742 (forward-line 1)) |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
743 (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
|
744 (insert (or half1 "")) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
745 (goto-char half1s) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
746 (insert (or half2 "")))) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 (goto-char pt-lines1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
748 (insert str1)))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 ;; 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
|
750 ((match-beginning 7) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 (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
|
752 (forward-line 1) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
753 (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
|
754 (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
|
755 (?- (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
|
756 (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
|
757 (?+ (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
|
758 (delete-char 1) (insert "-") t) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
759 ((?\\ ?#) t) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
760 (t (when (and first last (< first last)) |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
761 (let ((str |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
762 (save-excursion |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
763 (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
|
764 (insert str))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
765 (setq first nil last nil) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
766 (equal ?\ c))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
767 (forward-line 1)))))))))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
768 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
769 (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
|
770 "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
|
771 START and END are either taken from the region (if a prefix arg is given) or |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
772 else cover the whole bufer." |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
773 (interactive (if current-prefix-arg |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
774 (list (mark) (point)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
775 (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
|
776 (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
|
777 (save-excursion |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
778 (goto-char end) (diff-end-of-hunk) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
779 (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
|
780 (while (and (= (forward-line -1) 0) (<= start (point))) |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
781 (if (not (looking-at "\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|[-*][-*][-*] .+ [-*][-*][-*][-*]\\)$")) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
782 (case (char-after) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
783 (?\ (incf space)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
784 (?+ (incf plus)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
785 (?- (incf minus)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
786 (?! (incf bang)) |
28858
85d4cc0b8741
(diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28240
diff
changeset
|
787 ((?\\ ?#) nil) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
788 (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
|
789 (cond |
29423
12e89e9b65f6
(diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
28858
diff
changeset
|
790 ((looking-at "@@ -[0-9]+,\\([0-9]*\\) \\+[0-9]+,\\([0-9]*\\) @@.*$") |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
791 (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
|
792 (old2 (match-string 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
793 (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
|
794 (new2 (number-to-string (+ space plus)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
795 (unless (string= new2 old2) (replace-match new2 t t nil 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
796 (unless (string= new1 old1) (replace-match new1 t t nil 1)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
797 ((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
|
798 (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
|
799 (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
|
800 (old2 (match-string 2)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
801 (new (number-to-string |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
802 (+ 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
|
803 (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
|
804 ((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
|
805 (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
|
806 (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
|
807 (new (format |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
808 (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
|
809 (+ 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
|
810 (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
|
811 (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
|
812 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
813 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
814 ;;;; Hooks |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
816 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
817 (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
|
818 "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
|
819 (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
|
820 nil) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
821 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
822 ;; 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
|
823 ;; *-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
|
824 ;; 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
|
825 (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
|
826 (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
|
827 "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
|
828 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
|
829 ;; 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
|
830 ;; 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
|
831 ;; 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
|
832 ;; 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
|
833 ;; 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
|
834 (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
|
835 (if diff-unhandled-changes |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
836 (setq diff-unhandled-changes |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
837 (cons (min beg (car diff-unhandled-changes)) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
838 (max beg (cdr diff-unhandled-changes)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
839 (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
|
840 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
841 (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
|
842 "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
|
843 (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
|
844 (ignore-errors |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
845 (save-excursion |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
846 (goto-char (car diff-unhandled-changes)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
847 (unless (ignore-errors |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
848 (diff-beginning-of-hunk) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
849 (save-excursion |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
850 (diff-end-of-hunk) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
851 (> (point) (car diff-unhandled-changes)))) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
852 (goto-char (car diff-unhandled-changes)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
853 (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes)) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
854 (diff-beginning-of-hunk)) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
855 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
856 (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
|
857 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
858 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
859 ;;;; The main function |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
860 ;;;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
862 ;;;###autoload |
28240
a0b15838fd22
(diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
27637
diff
changeset
|
863 (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
|
864 "Major 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
|
865 Supports unified and context diffs as well as (to a lesser extent) normal diffs. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
866 When the buffer is read-only, the ESC prefix is not necessary. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
867 This mode runs `diff-mode-hook'. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
868 \\{diff-mode-map}" |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
869 (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
|
870 (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
|
871 (set (make-local-variable 'imenu-generic-expression) |
64bb4634d6d8
(diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
30873
diff
changeset
|
872 diff-imenu-generic-expression) |
31479
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
873 ;; 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
|
874 ;; context diffs and unidiffs. |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
875 ;; (set (make-local-variable 'paragraph-start) |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
876 ;; (concat "@@ " ; unidiff hunk |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
877 ;; "\\|\\*\\*\\* " ; context diff hunk or file start |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
878 ;; "\\|--- [^\t]+\t")) ; context or unidiff file |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
879 ;; ; start (first or second line) |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
880 ;; (set (make-local-variable 'paragraph-separate) paragraph-start) |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
881 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t") |
d58461428926
(diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents:
31269
diff
changeset
|
882 ;; compile support |
35526
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
883 |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
884 ;;;; compile support is not good enough yet. Also it can be annoying |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
885 ;; and should thus only be enabled conditionally. |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
886 ;; (set (make-local-variable 'compilation-file-regexp-alist) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
887 ;; diff-file-regexp-alist) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
888 ;; (set (make-local-variable 'compilation-error-regexp-alist) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
889 ;; diff-error-regexp-alist) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
890 ;; (when (string-match "\\.rej\\'" (or buffer-file-name "")) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
891 ;; (set (make-local-variable 'compilation-current-file) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
892 ;; (substring buffer-file-name 0 (match-beginning 0)))) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
893 ;; (compilation-shell-minor-mode 1) |
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
894 |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
895 ;; setup change hooks |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
896 (toggle-read-only t) |
37866
4e2d06e10072
(diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37567
diff
changeset
|
897 (if (not diff-update-on-the-fly) |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
898 (add-hook 'write-contents-hooks 'diff-write-contents-hooks) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
899 (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
|
900 (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
|
901 (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
|
902 ;; Neat trick from Dave Love to add more bindings in read-only mode: |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
903 (add-to-list (make-local-variable 'minor-mode-overriding-map-alist) |
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
|
904 (cons 'buffer-read-only diff-mode-shared-map)) |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
905 ;; 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
|
906 (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
|
907 'diff-current-defun) |
32012
b1edfcd919a7
(diff-add-log-file-name): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31973
diff
changeset
|
908 (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
|
909 '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
|
910 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
911 ;;;###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
|
912 (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
|
913 "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
|
914 \\{diff-minor-mode-map}" |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
915 nil " Diff" nil |
8b8438e9ac12
* diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26009
diff
changeset
|
916 ;; FIXME: setup font-lock |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
917 ;; 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
|
918 (if (not diff-update-on-the-fly) |
27637
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
919 (add-hook 'write-contents-hooks 'diff-write-contents-hooks) |
79014abee3cc
(diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
26748
diff
changeset
|
920 (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
|
921 (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
|
922 (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
|
923 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
924 |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
925 ;;; |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
926 ;;; 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
|
927 ;;; |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
928 |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
929 (defun diff-next-complex-hunk () |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
930 "Jump to the next \"complex\" hunk. |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
931 \"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
|
932 Only works for unified diffs." |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
933 (interactive) |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
934 (while |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
935 (and (re-search-forward "^@@ [-0-9]+,\\([0-9]+\\) [+0-9]+,\\([0-9]+\\) @@" |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
936 nil t) |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
937 (equal (match-string 1) (match-string 2))))) |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
938 |
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
|
939 (defun diff-hunk-text (hunk destp &optional char-offset) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
940 "Return the literal source text from HUNK. |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
941 if DESTP is nil return the source, otherwise the destination text. |
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
|
942 If CHAR-OFFSET is non-nil, it should be a char-offset in |
31705 | 943 HUNK, and instead of a string, a cons cell is returned whose car is the |
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
|
944 appropriate text, and whose cdr is the corresponding char-offset in that text." |
31556
74d7a9c42c2a
(diff-hunk-text): Use `with-temp-buffer'.
Miles Bader <miles@gnu.org>
parents:
31538
diff
changeset
|
945 (with-temp-buffer |
31819
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
946 (insert hunk) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
947 (goto-char (point-min)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
948 (let ((src-pos nil) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
949 (dst-pos nil) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
950 (divider-pos nil) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
951 (num-pfx-chars 2)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
952 ;; Set the following variables: |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
953 ;; 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
|
954 ;; 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
|
955 ;; 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
|
956 ;; 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
|
957 (cond ((looking-at "^@@") |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
958 ;; unified diff |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
959 (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
|
960 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
961 (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
|
962 ((looking-at "^\\*\\*") |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
963 ;; context diff |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
964 (forward-line 2) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
965 (setq src-pos (point)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
966 (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
|
967 (forward-line 0) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
968 (setq divider-pos (point)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
969 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
970 (setq dst-pos (point))) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
971 ((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
|
972 ;; normal diff, insert |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
973 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
974 (setq dst-pos (point))) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
975 ((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
|
976 ;; normal diff, delete |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
977 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
978 (setq src-pos (point))) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
979 ((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
|
980 ;; normal diff, change |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
981 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
982 (setq src-pos (point)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
983 (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
|
984 (forward-line 0) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
985 (setq divider-pos (point)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
986 (forward-line 1) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
987 (setq dst-pos (point))) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
988 (t |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
989 (error "Unknown diff hunk type"))) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
990 |
31819
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
991 (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
|
992 ;; Implied empty text |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
993 (if char-offset '("" . 0) "") |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
994 |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
995 ;; 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
|
996 ;; 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
|
997 (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
|
998 ((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
|
999 |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1000 (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
|
1001 |
31819
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1002 ;; 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
|
1003 (save-excursion |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1004 ;; Delete unused text region |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1005 (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
|
1006 (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
|
1007 (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
|
1008 (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
|
1009 ;; 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
|
1010 (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
|
1011 (goto-char (point-min)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1012 (while (not (eobp)) |
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1013 (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
|
1014 (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
|
1015 (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
|
1016 (forward-line 1))))) |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1017 |
31819
e5a0c7120611
(diff-hunk-text): Properly handle one-sided context diffs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31817
diff
changeset
|
1018 (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
|
1019 (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
|
1020 |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1021 |
31734
6b057ae8165d
Docstring fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31705
diff
changeset
|
1022 (defun diff-find-text (text) |
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
|
1023 "Return the buffer position 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
|
1024 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
|
1025 (let* ((orig (point)) |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1026 (forw (and (search-forward text nil t) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
1027 (match-beginning 0))) |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1028 (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
|
1029 (search-backward text nil t) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
1030 (match-beginning 0)))) |
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
1031 ;; Choose the closest match. |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1032 (if (and forw back) |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1033 (if (> (- forw orig) (- orig back)) back forw) |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1034 (or back forw)))) |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1035 |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1036 (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
|
1037 |
31786
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1038 (defun diff-find-source-location (&optional other-file reverse) |
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
|
1039 "Find out (BUF LINE-OFFSET POS SRC DST SWITCHED)." |
31735
9d50fe5df6ce
Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31734
diff
changeset
|
1040 (save-excursion |
37866
4e2d06e10072
(diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37567
diff
changeset
|
1041 (let* ((other (diff-xor other-file diff-jump-to-old-file)) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1042 (char-offset (- (point) (progn (diff-beginning-of-hunk) (point)))) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1043 (hunk (buffer-substring (point) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1044 (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
|
1045 (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
|
1046 (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
|
1047 ;; Find the location specification. |
31786
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1048 (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
|
1049 (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
|
1050 (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
|
1051 (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
|
1052 (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
|
1053 (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
|
1054 (match-string 1))))) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1055 (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
|
1056 (buf (find-file-noselect file))) |
31735
9d50fe5df6ce
Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31734
diff
changeset
|
1057 ;; Update the user preference if he so wished. |
9d50fe5df6ce
Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31734
diff
changeset
|
1058 (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
|
1059 (setq diff-jump-to-old-file other)) |
31786
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1060 (with-current-buffer buf |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1061 (goto-line (string-to-number line)) |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1062 (let* ((orig-pos (point)) |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1063 (pos (diff-find-text (car old))) |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1064 (switched nil)) |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1065 (when (null pos) |
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1066 (setq pos (diff-find-text (car new)) switched t)) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1067 (nconc |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1068 (list buf) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1069 (if pos (list (count-lines orig-pos pos) pos) (list nil orig-pos)) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1070 (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
|
1071 |
31735
9d50fe5df6ce
Moved closer to its users.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31734
diff
changeset
|
1072 |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1073 (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
|
1074 (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
|
1075 (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
|
1076 (if reversed "undone" "applied")))) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1077 (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
|
1078 ((= 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
|
1079 ((= 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
|
1080 (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
|
1081 msg line-offset))) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1082 |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1083 |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1084 (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
|
1085 "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
|
1086 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
|
1087 `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
|
1088 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
|
1089 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
|
1090 |
32063
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1091 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
|
1092 (interactive "P") |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1093 (destructuring-bind (buf line-offset pos old new &optional switched) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1094 (diff-find-source-location nil reverse) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1095 (cond |
32063
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1096 ((null line-offset) |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1097 (error "Can't find the text to patch")) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1098 ((and switched |
35526
b40a6cecc4d5
(diff-mode): Disable preliminary support for `compile'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33488
diff
changeset
|
1099 ;; 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
|
1100 (not (save-window-excursion |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1101 (pop-to-buffer buf) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1102 (goto-char (+ pos (cdr old))) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1103 (y-or-n-p |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1104 (if reverse |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1105 "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
|
1106 "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
|
1107 (message "(Nothing done)")) |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1108 (t |
32063
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1109 ;; Apply the hunk |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1110 (with-current-buffer buf |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1111 (goto-char pos) |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1112 (delete-char (length (car old))) |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1113 (insert (car new))) |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1114 ;; Display BUF in a window |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1115 (set-window-point (display-buffer buf) (+ pos (cdr new))) |
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1116 (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
|
1117 (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
|
1118 (diff-hunk-next)))))) |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1119 |
31684 | 1120 |
31817
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1121 (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
|
1122 "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
|
1123 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
|
1124 (interactive "P") |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1125 (destructuring-bind (buf line-offset pos src dst &optional switched) |
e23774b771e1
(diff-file-header-face): Reset to its previous value.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31795
diff
changeset
|
1126 (diff-find-source-location nil reverse) |
32061
cdfabbe10a24
(diff-goto-source): Emit a status message.
Miles Bader <miles@gnu.org>
parents:
32012
diff
changeset
|
1127 (set-window-point (display-buffer buf) (+ pos (cdr src))) |
32063
3fb2a3b13c5e
(diff-test-hunk): Backout previous change. Fix doc string.
Miles Bader <miles@gnu.org>
parents:
32061
diff
changeset
|
1128 (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
|
1129 |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1130 |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1131 (defun diff-goto-source (&optional other-file) |
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1132 "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
|
1133 `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
|
1134 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
|
1135 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument]) |
37866
4e2d06e10072
(diff-jump-to-old-file, diff-update-on-the-fly):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
37567
diff
changeset
|
1136 then `diff-jump-to-old-file' is also set, for the next invocations." |
31538
46aca282e6b0
(diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents:
31479
diff
changeset
|
1137 (interactive "P") |
32111
161c2ec9f5b2
(diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32063
diff
changeset
|
1138 ;; 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
|
1139 ;; 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
|
1140 ;; This is a convenient detail when using smerge-diff. |
161c2ec9f5b2
(diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32063
diff
changeset
|
1141 (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
|
1142 (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
|
1143 (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
|
1144 (pop-to-buffer buf) |
161c2ec9f5b2
(diff-font-lock-keywords): Minor regex fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32063
diff
changeset
|
1145 (goto-char (+ pos (cdr src))) |
32143 | 1146 (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
|
1147 |
31786
181947e98152
(diff-find-source-location):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31749
diff
changeset
|
1148 |
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
|
1149 (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
|
1150 "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
|
1151 For use in `add-log-current-defun-function'." |
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
|
1152 (destructuring-bind (buf line-offset pos src dst &optional switched) |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
1153 (diff-find-source-location) |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
1154 (save-excursion |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
1155 (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
|
1156 (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
|
1157 ;; 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
|
1158 ;; 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
|
1159 ;; 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
|
1160 ;; 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
|
1161 (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
|
1162 (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
|
1163 (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
|
1164 (goto-char (cdr 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
|
1165 (funcall (with-current-buffer buf major-mode)) |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
1166 (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
|
1167 (with-current-buffer buf |
868648c4a36b
* diff-mode.el (diff-add-log-file-name, diff-current-defun): New funs.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
31786
diff
changeset
|
1168 (goto-char (+ pos (cdr 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
|
1169 (add-log-current-defun)))))) |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
1170 |
25959
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1171 ;; provide the package |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1172 (provide 'diff-mode) |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1173 |
30873
7f824fa01e10
(diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
29423
diff
changeset
|
1174 ;;; 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
|
1175 ;; 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
|
1176 ;; (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
|
1177 ;; (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
|
1178 ;; (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
|
1179 ;; 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
|
1180 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1181 ;; 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
|
1182 ;; 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
|
1183 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1184 ;; 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
|
1185 ;; - added basic `compile' support. |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1186 ;; - 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
|
1187 ;; - 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
|
1188 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1189 ;; 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
|
1190 ;; - 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
|
1191 ;; - accept diffs using -T |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1192 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1193 ;; 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
|
1194 ;; interface to ediff-patch |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1195 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1196 ;; 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
|
1197 ;; (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
|
1198 ;; (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
|
1199 ;; (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
|
1200 ;; 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
|
1201 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1202 ;; 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
|
1203 ;; (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
|
1204 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1205 ;; 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
|
1206 ;; 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
|
1207 ;; |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1208 |
1c62cbeca833
Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1209 ;;; diff-mode.el ends here |