annotate lisp/diff-mode.el @ 31538:46aca282e6b0

(diff-apply-hunk): Function basically rewritten. Now understands non-unified diffs. Some functionality moved into `diff-hunk-text' and `diff-find-text'. Add OTHER-FILE, DRY-RUN, POPUP, and NOERROR arguments. If DRY-RUN is true, don't actually modify anything. Only reposition point in the patched file if the patch succeeds. Only pop up another window if POPUP is true. Emit a message describing what happened if successful, and at what line-offset. Automatically detect reversed hunks and do something appropriate. (diff-hunk-text, diff-find-text): New functions. (diff-filter-lines): Function removed. (diff-test-hunk): New function. (diff-goto-source): Rewritten in terms of diff-apply-hunk.
author Miles Bader <miles@gnu.org>
date Mon, 11 Sep 2000 13:49:38 +0000
parents d58461428926
children 74d7a9c42c2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1 ;;; diff-mode.el --- A mode for viewing/editing context diffs
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
2
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
4
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
5 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
6 ;; Keywords: patch diff
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
7 ;; Revision: $Id: diff-mode.el,v 1.11 2000/09/07 20:14:27 fx Exp $
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
8
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
10
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
13 ;; 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
14 ;; any later version.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
15
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
19 ;; GNU General Public License for more details.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
20
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
23 ;; 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
24 ;; 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
25
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
26 ;;; Commentary:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
27
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
28 ;; Provides support for font-lock patterns, outline-regexps, navigation
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
29 ;; commands, editing and various conversions as well as jumping
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
30 ;; to the corresponding source file.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
31
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
32 ;; inspired by Pavel Machek's patch-mode.el (<pavel@atrey.karlin.mff.cuni.cz>)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
33 ;; some efforts were spent to have it somewhat compatible with XEmacs'
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
34 ;; diff-mode as well as with compilation-minor-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
35
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
36 ;; to use it, simply add to your .emacs the following lines:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
37 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
38 ;; (autoload 'diff-mode "diff-mode" "Diff major mode" t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
39 ;; (add-to-list 'auto-mode-alist '("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
40
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
41 ;; Bugs:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
42
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
43 ;; - Reverse doesn't work with normal diffs.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
44 ;; - (nitpick) The mark is not always quite right in diff-goto-source.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
45
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
46 ;; Todo:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
47
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
48 ;; - Add change-log support.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
49 ;; - Spice up the minor-mode with font-lock support.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
50 ;; - Improve narrowed-view support.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
51 ;; - Improve the `compile' support (?).
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
52 ;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
53 ;; - Support for # comments in context->unified.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
54 ;; - Do a fuzzy search in diff-goto-source.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
55 ;; - Allow diff.el to use diff-mode.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
56 ;; This mostly means ability to jump from half-hunk to half-hunk
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
57 ;; in context (and normal) diffs and to jump to the corresponding
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
58 ;; (i.e. new or old) file.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
59 ;; - 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
60
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 ;;; Code:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
62
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
63 (eval-when-compile (require 'cl))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
64
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
65
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
66 (defgroup diff-mode ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 "Major-mode for viewing/editing diffs"
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
68 :version "21.1"
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 :group 'tools
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
70 :group 'diff)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
71
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
72 (defcustom diff-jump-to-old-file-flag nil
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
73 "*Non-nil means `diff-goto-source' jumps to the old file.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
74 Else, it jumps to the new file."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
75 :group 'diff-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 :type '(boolean))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78 (defcustom diff-update-on-the-fly-flag t
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 "*Non-nil means hunk headers are kept up-to-date on-the-fly.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
80 When editing a diff file, the line numbers in the hunk headers
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
81 need to be kept consistent with the actual diff. This can
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 either be done on the fly (but this sometimes interacts poorly with the
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 undo mechanism) or whenever the file is written (can be slow
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
84 when editing big diffs)."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 :group 'diff-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 :type '(boolean))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
87
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
88 (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
89 "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
90
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (defvar diff-outline-regexp
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 "\\([*+][*+][*+] [^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
93
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 ;;;; keymap, menu, ...
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
96 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
97
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
98 (easy-mmode-defmap diff-mode-shared-map
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
99 '(;; From Pavel Machek's patch-mode.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
100 ("n" . diff-hunk-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
101 ("N" . diff-file-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
102 ("p" . diff-hunk-prev)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
103 ("P" . diff-file-prev)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
104 ("k" . diff-hunk-kill)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
105 ("K" . diff-file-kill)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
106 ;; From compilation-minor-mode.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
107 ("}" . diff-file-next)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
108 ("{" . diff-file-prev)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 ("\C-m" . diff-goto-source)
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
110 ([mouse-2] . diff-mouse-goto-source)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
111 ;; 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
112 ("W" . widen)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
113 ;;("." . 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
114 ;;("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
115 ("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
116 ;;("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
117 ;;("N" . diff-narrow)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 ;;("h" . diff-show-header)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
119 ;;("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
120 ;;("q" . diff-quit)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 (" " . scroll-up)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 ("\177" . scroll-down)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
123 ;; 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
124 ("A" . diff-ediff-patch)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 ("r" . diff-restrict-view)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 ("R" . diff-reverse-direction)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 ("U" . diff-context->unified)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
128 ("C" . diff-unified->context))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
129 "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
130
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
131 (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
132 `(("\e" . ,diff-mode-shared-map)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
133 ;; From compilation-minor-mode.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
134 ("\C-c\C-c" . diff-goto-source)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
135 ;; Misc operations.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
136 ("\C-cda" . diff-apply-hunk))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 "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
138
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 (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
140 "Menu for `diff-mode'."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
141 '("Diff"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
142 ["Jump to Source" diff-goto-source t]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143 ["Apply with Ediff" diff-ediff-patch t]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
144 ["-----" nil nil]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
145 ["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
146 ["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
147 ["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
148 ;;["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
149 ))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
150
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
151 (defcustom diff-minor-mode-prefix "\C-cd"
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
152 "Prefix key for `diff-minor-mode' commands."
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
153 :group 'diff-mode
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
154 :type '(choice (string "\e") (string "C-cd") string))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
155
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
156 (easy-mmode-defmap diff-minor-mode-map
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
157 `((,diff-minor-mode-prefix . ,diff-mode-shared-map))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
158 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
159
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
161 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
162 ;;;; font-lock support
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
164
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 (defface diff-file-header-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 (:background "grey70" :bold t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
168 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 "diff-mode face used to highlight file header lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
170 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (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
172
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (defface diff-index-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 (:background "grey70" :bold t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
176 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 "diff-mode face used to highlight index header lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
178 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 (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
180
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 (defface diff-hunk-header-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 (:background "grey85"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
184 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 "diff-mode face used to highlight hunk header lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
186 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (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
188
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 (defface diff-removed-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
190 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 "diff-mode face used to highlight removed lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
192 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 (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
194
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 (defface diff-added-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
196 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 "diff-mode face used to highlight added lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
198 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 (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
200
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201 (defface diff-changed-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
202 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 "diff-mode face used to highlight changed lines."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
204 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 (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
206
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 (defvar diff-font-lock-keywords
31479
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
208 '(("^@@ \\(-[0-9,]+ \\+[0-9,]+\\) @@\\(.*\\)$" ;unified
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
209 (1 diff-hunk-header-face)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
210 (2 font-lock-comment-face))
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
211 ("^--- \\(.+\\) ----$" ;context
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
212 (1 diff-hunk-header-face))
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
213 ("\\(\\*\\{15\\}\\)\\(.*\\)\n" ;context
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
214 (1 diff-hunk-header-face)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
215 (2 font-lock-comment-face))
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
216 ("^\\*\\*\\* \\(.+\\) \\*\\*\\*" ;context
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
217 (1 diff-hunk-header-face))
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
218 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)" (2 diff-file-header-face))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219 ("^[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
220 ("^!.*\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
221 ("^[+>].*\n" . diff-added-face)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 ("^[-<].*\n" . diff-removed-face)
31479
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
223 ("^Index: \\(.+\\)$" (1 diff-index-face))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
224 ("^#.*" . font-lock-string-face)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
225 ("^[^-=+*!<>].*\n" . font-lock-comment-face)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
226
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
227 (defconst diff-font-lock-defaults
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
228 '(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
229
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
230 (defvar diff-imenu-generic-expression
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
231 ;; Prefer second name as first is most likely to be a backup or
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
232 ;; version-control name.
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
233 '((nil "\\+\\+\\+\\ \\([^\t\n]+\\)\t" 1) ; unidiffs
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
234 (nil "^--- \\([^\t\n]+\\)\t.*\n\\*" 1))) ; context diffs
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
235
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 ;;;; Compile support
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
238 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
239
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (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
241 '(("Index: \\(.+\\)" 1)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (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
244 '(("@@ -\\([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
245 ("--- \\([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
246 ("\\([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
247
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249 ;;;; Movement
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
251
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
252 (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
253 (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
254 (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
255
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
256 (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
257 (if (looking-at diff-hunk-header-re) (goto-char (match-end 0)))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
258 (let ((end (and (re-search-forward (case style
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
259 (unified "^[^-+# \\]")
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
260 (context "^[^-+#! \\]")
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
261 (normal "^[^<>#\\]")
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
262 (t "^[^-+#!<> \\]"))
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
263 nil t)
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
264 (match-beginning 0))))
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
265 ;; The return value is used by easy-mmode-define-navigation.
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
266 (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
267
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 (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
269 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
270 (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
271 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
272 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
273 (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
274 (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
275
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
276 (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
277 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
278 (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
279 (forward-line 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
280 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
281 (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
282 (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
283
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 (defun diff-end-of-file ()
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
285 (re-search-forward "^[-+#!<>0-9@* \\]" nil t)
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
286 (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
287 (beginning-of-line))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
289 ;; Define diff-{hunk,file}-{prev,next}
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
290 (easy-mmode-define-navigation
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
291 diff-hunk diff-hunk-header-re "hunk" diff-end-of-hunk)
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
292 (easy-mmode-define-navigation
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
293 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
294
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 (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
296 "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
297 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
298 (interactive "P")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (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
301 (narrow-to-region (point)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302 (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
303 (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 (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
305
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
307 (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
308 "Kill current hunk."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (diff-beginning-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 (let ((start (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
312 (firsthunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
313 (ignore-errors
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
314 (diff-beginning-of-file) (diff-hunk-next) (point))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 (nexthunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 (ignore-errors
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
317 (diff-hunk-next) (point))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (nextfile (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 (ignore-errors
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
320 (diff-file-next) (point)))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 (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
322 (or (null nexthunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323 (and nextfile (> nexthunk nextfile))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 ;; we're the only hunk for this file, so kill the file
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
325 (diff-file-kill)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
326 (diff-end-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
327 (kill-region start (point)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
329 (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
330 "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
331 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
332 (diff-beginning-of-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (let* ((start (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
334 (prevhunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335 (ignore-errors
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
336 (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
337 (index (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 (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
339 (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
340 (diff-end-of-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 (kill-region start (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
343 (defun diff-kill-junk ()
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
344 "Kill spurious empty diffs."
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
345 (interactive)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
346 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
347 (let ((inhibit-read-only t))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
348 (goto-char (point-min))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
349 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
350 "\\([^-+!* <>].*\n\\)*?"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
351 "\\(\\(Index:\\) \\|"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
352 diff-file-header-re "\\)")
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
353 nil t)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
354 (delete-region (if (match-end 4) (match-beginning 0) (match-end 1))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
355 (match-beginning 3))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
356 (beginning-of-line)))))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
357
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 ;;;; jump to other buffers
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
360 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
362 (defvar diff-remembered-files-alist nil)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
363
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 (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
365 (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
366
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
367 (defun diff-merge-strings (ancestor from to)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
368 "Merge the diff between ANCESTOR and FROM into TO.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
369 Returns the merged string if successful or nil otherwise.
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
370 The strings are assumed not to contain any \"\\n\" (i.e. end of line).
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
371 If ANCESTOR = FROM, returns TO.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
372 If ANCESTOR = TO, returns FROM.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
373 The heuristic is simplistic and only really works for cases
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
374 like \(diff-merge-strings \"b/foo\" \"b/bar\" \"/a/c/foo\")."
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
375 ;; Ideally, we want:
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
376 ;; AMB ANB CMD -> CND
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
377 ;; but that's ambiguous if `foo' or `bar' is empty:
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
378 ;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
379 (let ((str (concat ancestor "\n" from "\n" to)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
380 (when (and (string-match (concat
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
381 "\\`\\(.*?\\)\\(.*\\)\\(.*\\)\n"
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
382 "\\1\\(.*\\)\\3\n"
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
383 "\\(.*\\(\\2\\).*\\)\\'") str)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
384 (equal to (match-string 5 str)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
385 (concat (substring str (match-beginning 5) (match-beginning 6))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
386 (match-string 4 str)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
387 (substring str (match-end 6) (match-end 5))))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
388
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 (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
390 "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
391 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
392 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (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
394 (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
395 (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
396 (let* ((limit (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
397 (condition-case ()
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
398 (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
399 (error (point-min)))))
26009
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
400 (header-files
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
401 (if (looking-at "[-*][-*][-*] \\(\\S-+\\)\\s-.*\n[-+][-+][-+] \\(\\S-+\\)\\s-.*$")
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
402 (list (if old (match-string 1) (match-string 2))
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
403 (if old (match-string 2) (match-string 1)))
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
404 (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
405 (fs (append
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
406 (when (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
407 (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
408 (list (match-string 1)))
26009
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
409 header-files
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
410 (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
411 (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
412 (if old (match-string 4) (match-string 2))))))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
413 (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
414 (or
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
415 ;; use any previously used preference
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
416 (cdr (assoc fs diff-remembered-files-alist))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
417 ;; try to be clever and use previous choices as an inspiration
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
418 (dolist (rf diff-remembered-files-alist)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
419 (let ((newfile (diff-merge-strings (caar rf) (car fs) (cdr rf))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
420 (if (and newfile (file-exists-p newfile)) (return newfile))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
421 ;; look for each file in turn. If none found, try again but
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
422 ;; ignoring the first level of directory, ...
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
423 (do* ((files fs (delq nil (mapcar 'diff-filename-drop-dir files)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
424 (file nil nil))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
425 ((or (null files)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
426 (setq file (do* ((files files (cdr files))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
427 (file (car files) (car files)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
428 ((or (null file) (file-exists-p file))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
429 file))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
430 file))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
431 ;; <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
432 (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
433 (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
434 (when (file-exists-p file) file)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
435 ;; if all else fails, ask the user
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
436 (let ((file (read-file-name (format "Use file %s: " (or (first fs) ""))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
437 nil (first fs) t (first fs))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
438 (set (make-local-variable 'diff-remembered-files-alist)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
439 (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
440 file)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
441
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
442 (defun diff-find-source-location (&optional other-file)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
443 "Find out (FILE LINE SPAN)."
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
444 (save-excursion
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
445 (diff-beginning-of-hunk)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
446 (let* ((old (if (not other-file) diff-jump-to-old-file-flag
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
447 (not diff-jump-to-old-file-flag)))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
448 ;; Find the location specification.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
449 (loc (if (not (looking-at "\\(?:\\*\\{15\\}.*\n\\)?[-@* ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?"))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
450 (error "Can't find the hunk header")
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
451 (if old (match-string 1)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
452 (if (match-end 3) (match-string 3)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
453 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
454 (error "Can't find the hunk separator"))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
455 (match-string 1)))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
456 ;; Extract the actual line number.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
457 (lines (if (string-match "^\\([0-9]*\\),\\([0-9]*\\)" loc)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
458 (cons (string-to-number (match-string 1 loc))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
459 (string-to-number (match-string 2 loc)))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
460 (cons (string-to-number loc) nil)))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
461 (file (diff-find-file-name old))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
462 (line (car lines))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
463 (span (if (or (null (cdr lines)) (< (cdr lines) 0)) 0
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
464 ;; Bad hack.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
465 (if (< (cdr lines) line) (cdr lines)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
466 (- (cdr lines) line)))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
467 ;; Update the user preference if he so wished.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
468 (when (> (prefix-numeric-value other-file) 8)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
469 (setq diff-jump-to-old-file-flag old))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
470 (if (null file) (error "Can't find the file")
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
471 (list file line span)))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
472
31479
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
473 (defun diff-mouse-goto-source (event)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
474 "Run `diff-goto-source' for the diff at a mouse click."
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
475 (interactive "e")
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
476 (save-excursion
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
477 (mouse-set-point event)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
478 (diff-goto-source)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 (defun diff-ediff-patch ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 "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
482 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 (condition-case err
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
484 (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
485 (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
486
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 ;;;; Conversion functions
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 ;;(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
492 ;; "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
493
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 (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
495 "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
496 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
497 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
498 (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
499 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 (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
501 (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
502 (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
503 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (goto-char start)
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
506 (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
507 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509 (if (match-beginning 2)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
510 ;; 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
511 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
512 ;; 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
513 (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
514 (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
515 ;; 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
516 (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
517 (lines1 (match-string 5))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 (line2 (match-string 6))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 (lines2 (match-string 7)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520 (replace-match
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 (concat "***************\n*** " line1 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
522 (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
523 (string-to-number lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 -1)) " ****"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
525 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
526 (save-restriction
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
527 (narrow-to-region (point)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
528 (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
529 (let ((hunk (buffer-string)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 (goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
531 (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
532 (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
533 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 (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
535 (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
536 (= (forward-line -1) 0))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
537 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538 (? (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
539 (?+ (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
540 (?- (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
541 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
543 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
544 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
545 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
546 (?\\ (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
547 (= (char-after) ?+))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 (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
549 (t (setq modif nil))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 (insert "--- " line2 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
553 (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
554 (string-to-number lines2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 -1)) " ----\n" hunk))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 ;;(goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
558 (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
559 (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
560 (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
561 (while (not (eobp))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
562 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
563 (? (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
564 (?- (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
565 (?+ (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
566 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
569 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
570 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571 (?\\ (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
572 (not (eobp)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 (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
574 (t (setq modif nil)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 (let ((last-pt (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
577 (when delete
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578 (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
579 (setq delete nil)))))))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581 (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
582 "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
583 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
584 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
585 (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
586 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
587 (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
588 (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
589 (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
590 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
591 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
592 (goto-char start)
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
593 (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
594 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
595 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
596 (if (match-beginning 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
597 ;; 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
598 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599 ;; 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
600 (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
601 (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
602 ;; 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
603 (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
604 (line1e (match-string 5))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 (pt1 (match-beginning 0)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 (replace-match "")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
607 (unless (re-search-forward
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608 "^--- \\([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
609 (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
610 (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
611 (line2e (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
612 (pt2 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
613 (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
614 (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
615 (point-marker))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
616 (goto-char pt1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
618 (while (< (point) pt2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
619 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
620 ((?! ?-) (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
621 (?\ ;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
622 (let* ((endline2
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
623 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
624 (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
625 (c (char-after pt2)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 (case c
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
627 ((?! ?+)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
628 (insert "+"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
629 (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
630 (delete-region pt2 endline2))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
631 (?\ ;FIXME: check consistency
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
632 (delete-region pt2 endline2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
633 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
634 (forward-line 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
635 (?\\ (forward-line 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
636 (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
637 (t (forward-line 1))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
638 (while (looking-at "[+! ] ")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
639 (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
640 (delete-char 1) (insert "+"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
641 (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
642 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
643 (goto-char pt1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
644 (insert "@@ -" line1s ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
645 (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
646 (string-to-number line1s)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647 -1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
648 " +" line2s ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 (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
650 (string-to-number line2s)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
651 -1)) " @@"))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
652
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
653 (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
654 "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
655 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
656 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
657 (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
658 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 (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
660 (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
661 (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
662 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
663 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
664 (goto-char start)
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
665 (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
666 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
667 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668 (cond
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
669 ;; a file header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
670 ((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
671 ;; 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
672 ((match-beginning 6)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 (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
674 (lines1 (match-string 6)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 (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
676 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 (let ((half1s (point)))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
678 (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
679 (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
680 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
681 (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
682 (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
683 (insert half1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
684 (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
685 (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
686 (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
687 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
688 (let ((half2s (point)))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
689 (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
690 (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
691 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
692 (let ((half2 (delete-and-extract-region half2s (point))))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
693 (insert (or half1 ""))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
694 (goto-char half1s)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
695 (insert (or half2 ""))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 (goto-char pt-lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697 (insert str1))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 ;; 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
699 ((match-beginning 7)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 (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
701 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
702 (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
703 (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
704 (?- (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
705 (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
706 (?+ (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
707 (delete-char 1) (insert "-") t)
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
708 ((?\\ ?#) t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (t (when (and first last (< first last))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
710 (let ((str
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
711 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
712 (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
713 (insert str)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (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
715 (equal ?\ c)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
716 (forward-line 1))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
717
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 (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
719 "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
720 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
721 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
722 (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
723 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (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
725 (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
726 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 (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
728 (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
729 (while (and (= (forward-line -1) 0) (<= start (point)))
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
730 (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
731 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (?\ (incf space))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
733 (?+ (incf plus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
734 (?- (incf minus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
735 (?! (incf bang))
28858
85d4cc0b8741 (diff-font-lock-keywords): Recognize comments.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28240
diff changeset
736 ((?\\ ?#) nil)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
737 (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
738 (cond
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
739 ((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
740 (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
741 (old2 (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
742 (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
743 (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
744 (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
745 (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
746 ((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
747 (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
748 (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
749 (old2 (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
750 (new (number-to-string
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
751 (+ 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
752 (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
753 ((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
754 (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
755 (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
756 (new (format
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (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
758 (+ 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
759 (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
760 (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
761
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 ;;;; Hooks
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (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
767 "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
768 (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
769 nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
770
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
771 ;; 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
772 ;; *-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
773 ;; 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
774 (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
775 (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
776 "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
777 See `after-change-functions' for the meaning of BEG, END and LEN."
29423
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
778 ;; Ignoring changes when inhibit-read-only is set is strictly speaking
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
779 ;; incorrect, but it turns out that inhibit-read-only is normally not set
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
780 ;; inside editing commands, while it tends to be set when the buffer gets
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
781 ;; updated by an async process or by a conversion function, both of which
12e89e9b65f6 (diff-font-lock-keywords, diff-hunk-header-re)
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 28858
diff changeset
782 ;; 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
783 (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
784 (if diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
785 (setq diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
786 (cons (min beg (car diff-unhandled-changes))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787 (max beg (cdr diff-unhandled-changes))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
788 (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
789
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
790 (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
791 "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
792 (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
793 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 (save-excursion
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
795 (goto-char (car diff-unhandled-changes))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
796 (unless (ignore-errors
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
797 (diff-beginning-of-hunk)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
798 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
799 (diff-end-of-hunk)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
800 (> (point) (car diff-unhandled-changes))))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
801 (goto-char (car diff-unhandled-changes))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
802 (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
803 (diff-beginning-of-hunk))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
804 (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
805 (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
806
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
807 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 ;;;; The main function
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
809 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 ;;;###autoload
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
812 (define-derived-mode diff-mode fundamental-mode "Diff"
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
813 "Major mode for viewing/editing context diffs.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
814 Supports unified and context diffs as well as (to a lesser extent) normal diffs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 When the buffer is read-only, the ESC prefix is not necessary.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
816 This mode runs `diff-mode-hook'.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
817 \\{diff-mode-map}"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
818 (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
819 (set (make-local-variable 'outline-regexp) diff-outline-regexp)
31269
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
820 (set (make-local-variable 'imenu-generic-expression)
64bb4634d6d8 (diff-mode) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents: 30873
diff changeset
821 diff-imenu-generic-expression)
31479
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
822 ;; These are not perfect. They would be better done separately for
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
823 ;; context diffs and unidiffs.
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
824 ;; (set (make-local-variable 'paragraph-start)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
825 ;; (concat "@@ " ; unidiff hunk
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
826 ;; "\\|\\*\\*\\* " ; context diff hunk or file start
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
827 ;; "\\|--- [^\t]+\t")) ; context or unidiff file
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
828 ;; ; start (first or second line)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
829 ;; (set (make-local-variable 'paragraph-separate) paragraph-start)
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
830 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
d58461428926 (diff-mouse-goto-source): New function.
Dave Love <fx@gnu.org>
parents: 31269
diff changeset
831 ;; compile support
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
832 (set (make-local-variable 'compilation-file-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 diff-file-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 (set (make-local-variable 'compilation-error-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835 diff-error-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 (when (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
837 (set (make-local-variable 'compilation-current-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
838 (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
839 (compilation-shell-minor-mode 1)
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
840 ;; setup change hooks
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
841 (toggle-read-only t)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
842 (if (not diff-update-on-the-fly-flag)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843 (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
844 (make-local-variable 'diff-unhandled-changes)
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
845 (add-hook (make-local-hook 'after-change-functions)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
846 'diff-after-change-function nil t)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
847 (add-hook (make-local-hook 'post-command-hook)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
848 '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
849 ;; Neat trick from Dave Love to add more bindings in read-only mode:
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
850 (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
28240
a0b15838fd22 (diff-mode-*-map): use `easy-mmode-defmap'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 27637
diff changeset
851 (cons 'buffer-read-only diff-mode-shared-map)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
852
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853 ;;;###autoload
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
854 (define-minor-mode diff-minor-mode
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
855 "Minor mode for viewing/editing context diffs.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
856 \\{diff-minor-mode-map}"
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
857 nil " Diff" nil
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
858 ;; FIXME: setup font-lock
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
859 ;; setup change hooks
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
860 (if (not diff-update-on-the-fly-flag)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
861 (add-hook 'write-contents-hooks 'diff-write-contents-hooks)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
862 (make-local-variable 'diff-unhandled-changes)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
863 (add-hook (make-local-hook 'after-change-functions)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
864 'diff-after-change-function nil t)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
865 (add-hook (make-local-hook 'post-command-hook)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
866 'diff-post-command-hook nil t)))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
867
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
868
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
869 ;;;
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
870 ;;; Misc operations that have proved useful at some point.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
871 ;;;
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
872
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
873 (defun diff-next-complex-hunk ()
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
874 "Jump to the next \"complex\" hunk.
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
875 \"Complex\" is approximated by \"the hunk changes the number of lines\".
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
876 Only works for unified diffs."
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
877 (interactive)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
878 (while
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
879 (and (re-search-forward "^@@ [-0-9]+,\\([0-9]+\\) [+0-9]+,\\([0-9]+\\) @@"
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
880 nil t)
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
881 (equal (match-string 1) (match-string 2)))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
882
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
883 (defun diff-hunk-text (hunk dest)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
884 "Returns the literal source text from HUNK, if DEST is nil, otherwise
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
885 the destination text."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
886 (with-current-buffer "foo"
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
887 (erase-buffer)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
888 (insert hunk)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
889 (goto-char (point-min))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
890 (let ((src nil)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
891 (dst nil)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
892 (divider nil)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
893 (num-pfx-chars 2))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
894 (cond ((looking-at "^@@")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
895 ;; unified diff
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
896 (setq num-pfx-chars 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
897 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
898 (setq src (point) dst (point)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
899 ((looking-at "^\\*\\*")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
900 ;; context diff
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
901 (forward-line 2)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
902 (setq src (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
903 (re-search-forward "^--- " nil t)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
904 (forward-line 0)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
905 (setq divider (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
906 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
907 (setq dst (point)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
908 ((looking-at "^[0-9]+a[0-9,]+$")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
909 ;; normal diff, insert
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
910 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
911 (setq dst (point)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
912 ((looking-at "^[0-9,]+d[0-9]+$")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
913 ;; normal diff, delete
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
914 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
915 (setq src (point)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
916 ((looking-at "^[0-9,]+c[0-9,]+$")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
917 ;; normal diff, change
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
918 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
919 (setq src (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
920 (re-search-forward "^---$" nil t)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
921 (forward-line 0)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
922 (setq divider (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
923 (forward-line 1)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
924 (setq dst (point)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
925 (t
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
926 (error "Unknown diff hunk type")))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
927
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
928 (if (if dest (null dst) (null src))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
929 ;; Implied empty text
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
930 ""
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
931
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
932 ;; Explicit text
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
933
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
934 ;; Delete unused text region
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
935 (let ((keep (if dest dst src))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
936 (kill (or divider (if dest src dst))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
937 (when (and kill (> kill keep))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
938 (delete-region kill (point-max)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
939 (delete-region (point-min) keep))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
940
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
941 ;; Remove line-prefix characters, and unneeded lines (for
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
942 ;; unified diffs).
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
943 (let ((kill-char (if dest ?- ?+)))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
944 (goto-char (point-min))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
945 (while (not (eobp))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
946 (if (eq (char-after) kill-char)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
947 (delete-region (point) (progn (forward-line 1) (point)))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
948 (delete-char num-pfx-chars)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
949 (forward-line 1))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
950
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
951 (buffer-substring-no-properties (point-min) (point-max))))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
952
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
953 (defun diff-find-text (text line)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
954 "Return the buffer position of the nearest occurance of TEXT to line LINE.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
955 If TEXT isn't found, nil is returned."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
956 (goto-line line)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
957 (let* ((orig (point))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
958 (forw (and (search-forward text nil t)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
959 (match-beginning 0)))
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
960 (back (and (goto-char (+ orig (length text)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
961 (search-backward text nil t)
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
962 (match-beginning 0))))
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
963 ;; Choose the closest match.
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
964 (if (and forw back)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
965 (if (> (- forw orig) (- orig back)) back forw)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
966 (or back forw))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
967
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
968 (defun diff-apply-hunk (&optional reverse other-file dry-run popup noerror)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
969 "Apply the current hunk to the source file.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
970 By default, the new source file is patched, but if the variable
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
971 `diff-jump-to-old-file-flag' is non-nil, then the old source file is
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
972 patched instead (some commands, such as `diff-goto-source' can change
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
973 the value of this variable when given an appropriate prefix argument).
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
974
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
975 With a prefix argument, REVERSE the hunk.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
976 If OTHER-FILE is non-nil, patch the old file by default, and reverse the
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
977 sense of `diff-jump-to-old-file-flag'.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
978 If DRY-RUN is non-nil, don't actually modify anything, just see whether
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
979 it's possible to do so.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
980 If POPUP is non-nil, pop up the patched file in another window; if POPUP
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
981 is `select' then select the new window too.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
982 If NOERROR is non-nil, then no error is signaled in the case where the hunk
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
983 cannot be found in the source file (other errors may still be signaled).
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
984
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
985 Return values are `t' if the hunk was sucessfully applied (or could be
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
986 applied, in the case where DRY-RUN was non-nil), `reversed' if the hunk
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
987 was applied backwards, or nil if the hunk couldn't be found and NOERROR
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
988 was non-nil."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
989 (interactive (list current-prefix-arg nil nil t))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
990
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
991 (when other-file
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
992 ;; OTHER-FILE inverts the sense of the hunk
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
993 (setq reverse (not reverse)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
994 (when diff-jump-to-old-file-flag
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
995 ;; The global variable `diff-jump-to-old-file-flag' inverts the
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
996 ;; sense of OTHER-FILE (in `diff-find-source-location')
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
997 (setq reverse (not reverse)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
998
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
999 (let* ((loc (diff-find-source-location other-file))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1000 (buf (find-file-noselect (car loc)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1001 (patch-line (cadr loc))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1002 (hunk
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1003 (save-excursion
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1004 (diff-beginning-of-hunk)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1005 (unless (looking-at diff-hunk-header-re)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1006 (error "Malformed hunk"))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1007 (buffer-substring (point) (progn (diff-end-of-hunk) (point)))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1008 (src (diff-hunk-text hunk reverse))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1009 (dst (diff-hunk-text hunk (not reverse)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1010 (pos
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1011 (with-current-buffer buf (diff-find-text src patch-line)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1012 (reversed-pos
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1013 (and (null pos)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1014 (with-current-buffer buf (diff-find-text dst patch-line)))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1015
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1016 (when (and reversed-pos popup)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1017 ;; A reversed patch was detected, perhaps apply it in reverse
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1018 ;; (this is only done in `interactive' mode, when POPUP is non-nil).
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1019 (if (or dry-run
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1020 (save-window-excursion
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1021 (pop-to-buffer buf)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1022 (goto-char reversed-pos)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1023 (if reverse
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1024 (y-or-n-p
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1025 "Hunk hasn't been applied yet, so can't reverse it; apply it now? ")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1026 (y-or-n-p "Hunk has already been applied; undo it? "))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1027
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1028 ;; Set up things to reverse the diff
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1029 (let ((swap dst))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1030 (setq pos reversed-pos)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1031 (setq src dst)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1032 (setq dst swap))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1033
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1034 ;; The user has chosen not to apply the reversed hunk, but we
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1035 ;; don't want to given an error message, so set things up so
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1036 ;; nothing else gets done down below
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1037 (message "(Nothing done)")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1038 (setq noerror t)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1039
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1040 (if (null pos)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1041 ;; POS is nil, so we couldn't find the source text.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1042 (unless noerror
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1043 (error "Can't find the text to patch"))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1044
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1045 (let ((reversed (if reversed-pos (not reverse) reverse)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1046 (unless dry-run
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1047 ;; Apply the hunk
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1048 (with-current-buffer buf
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1049 (goto-char pos)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1050 (delete-char (length src))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1051 (insert dst)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1052
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1053 (when popup
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1054 ;; Show a message describing what was done
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1055 (let ((real-line
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1056 (1+ (with-current-buffer buf (count-lines (point-min) pos))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1057 (msg
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1058 (if dry-run
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1059 (if reversed "already applied" "not yet applied")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1060 (if reversed "undone" "applied"))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1061 (cond ((= real-line patch-line)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1062 (message "Hunk %s" msg))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1063 ((= real-line (1+ patch-line))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1064 (message "Hunk %s at offset 1 line" msg))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1065 (t
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1066 (message "Hunk %s at offset %d lines"
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1067 msg
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1068 (- real-line patch-line)))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1069
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1070 ;; Display BUF in a window, and maybe select it
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1071 (cond ((eq popup 'select)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1072 (pop-to-buffer buf)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1073 (goto-char pos))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1074 (t
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1075 (set-window-point (display-buffer buf) pos))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1076
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1077 ;; Return an appropriate indicator of success
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1078 (if reversed 'reversed t)))))
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1079
31538
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1080
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1081 (defun diff-test-hunk (&optional reverse)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1082 "See whether it's possible to apply the current hunk.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1083 With a prefix argument, REVERSE the hunk."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1084 (interactive "P")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1085 (diff-apply-hunk reverse nil t t))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1086
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1087 (defun diff-goto-source (&optional other-file)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1088 "Jump to the corresponding source line.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1089 `diff-jump-to-old-file-flag' (or its opposite if the OTHER-FILE prefix arg
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1090 is give) determines whether to jump to the old or the new file.
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1091 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1092 then `diff-jump-to-old-file-flag' is also set, for the next invocations."
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1093 (interactive "P")
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1094 (or (diff-apply-hunk nil other-file t 'select t)
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1095 ;; couldn't actually find the hunk, just obey the hunk line number
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1096 (let ((loc (diff-find-source-location other-file)))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1097 (find-file-other-window (car loc))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1098 (goto-line (cadr loc))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1099 (error "Hunk text not found"))))
46aca282e6b0 (diff-apply-hunk): Function basically rewritten. Now understands
Miles Bader <miles@gnu.org>
parents: 31479
diff changeset
1100
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1101
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1102 ;; provide the package
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1103 (provide 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1104
30873
7f824fa01e10 (diff-mode-map): Bind diff-apply-hunk.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 29423
diff changeset
1105 ;;; 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
1106 ;; 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
1107 ;; (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
1108 ;; (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
1109 ;; (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
1110 ;; 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
1111 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1112 ;; 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
1113 ;; 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
1114 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1115 ;; 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
1116 ;; - added basic `compile' support.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1117 ;; - 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
1118 ;; - 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
1119 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1120 ;; 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
1121 ;; - 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
1122 ;; - accept diffs using -T
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1123 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1124 ;; 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
1125 ;; interface to ediff-patch
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1126 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1127 ;; 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
1128 ;; (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
1129 ;; (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
1130 ;; (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
1131 ;; 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
1132 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1133 ;; 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
1134 ;; (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
1135 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1136 ;; 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
1137 ;; 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
1138 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1139
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
1140 ;;; diff-mode.el ends here