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