annotate lisp/diff-mode.el @ 27837:46fedf13d52e

(kill-paragraph, backward-kill-paragraph) (backward-kill-sentence, kill-sentence): Likewise.
author Dave Love <fx@gnu.org>
date Wed, 23 Feb 2000 23:09:46 +0000
parents 79014abee3cc
children a0b15838fd22
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
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
3 ;; Copyright (C) 1998-1999 Free Software Foundation, Inc.
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
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
7 ;; Revision: $Id: diff-mode.el,v 1.4 1999/12/07 07:04:03 monnier 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
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
43 ;; - reverse doesn't work with normal diffs.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
44 ;; - (nitpick) the mark is not always quite right in diff-goto-source.
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
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
48 ;; - spice up the minor-mode with editing and font-lock support.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
49 ;; - improve narrowed-view support.
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
50 ;; - improve the `compile' support (?).
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
51 ;; - recognize pcl-cvs' special string for `cvs-execute-single'.
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
52
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
53 ;;; Code:
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
54
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
55 (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
56
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
57
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
58 (defgroup diff-mode ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
59 "Major-mode for viewing/editing diffs"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
60 :group 'tools
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
61 :group 'diff)
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 (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
64 "*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
65 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
66 :group 'diff-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
67 :type '(boolean))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
68
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
69 (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
70 "*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
71 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
72 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
73 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
74 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
75 when editing big diffs)."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
76 :group 'diff-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
77 :type '(boolean))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
78
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
79 (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
80 "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
81
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
82 (defvar diff-outline-regexp
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
83 "\\([*+][*+][*+] [^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
84
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
85 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
86 ;;;; keymap, menu, ...
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
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
89 (defmacro diff-defmap (var bindings doc)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
90 `(defvar ,var
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
91 (let ((m (make-keymap)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
92 (dolist (b ,bindings)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
93 (define-key m (car b) (cdr b)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
94 m)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
95 ,doc))
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 (diff-defmap diff-mode-shared-map
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
98 '(;; from Pavel Machek's patch-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
99 ("n" . diff-next-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
100 ("N" . diff-next-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
101 ("p" . diff-prev-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
102 ("P" . diff-prev-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
103 ("k" . diff-kill-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
104 ("K" . diff-kill-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
105 ;; from compilation-minor-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
106 ("}" . diff-next-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
107 ("{" . diff-prev-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
108 ("\C-m" . diff-goto-source)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
109 ;; from XEmacs' diff-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
110 ("W" . widen)
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
111 ;;("\C-l" . diff-recenter)
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
112 ;;("." . 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
113 ;;("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
114 ("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
115 ;;("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
116 ;;("N" . diff-narrow)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
117 ;;("h" . diff-show-header)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
118 ;;("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
119 ;;("q" . diff-quit)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
120 (" " . scroll-up)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
121 ("\177" . scroll-down)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
122 ;; our very own bindings
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
123 ("A" . diff-ediff-patch)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
124 ("r" . diff-restrict-view)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
125 ("R" . diff-reverse-direction)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
126 ("U" . diff-context->unified)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
127 ("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
128 "Basic keymap for `diff-mode', bound to various prefix keys.")
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
129 (fset 'diff-mode-shared-map 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
130
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
131 (diff-defmap diff-mode-map
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)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
133 ;; from compilation-minor-mode
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
134 ("\C-c\C-c" . diff-goto-source))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
135 "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
136
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
137 (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
138 "Menu for `diff-mode'."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
139 '("Diff"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
140 ["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
141 ["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
142 ["-----" nil nil]
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
143 ["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
144 ["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
145 ["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
146 ;;["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
147 ))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
148
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
149 (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
150 "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
151 :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
152 :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
153
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
154 (diff-defmap 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
155 `((,diff-minor-mode-prefix . 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
156 "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
157
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
158
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
159 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
160 ;;;; font-lock support
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
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
163 (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
164 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
165 (:background "grey70" :bold t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
166 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
167 "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
168 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
169 (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
170
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
171 (defface diff-index-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
172 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
173 (:background "grey70" :bold t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
174 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
175 "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
176 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
177 (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
178
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
179 (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
180 '((((class color) (background light))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
181 (:background "grey85"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
182 (t (:bold t)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
183 "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
184 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
185 (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
186
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
187 (defface diff-removed-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
188 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
189 "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
190 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
191 (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
192
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
193 (defface diff-added-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
194 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
195 "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
196 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
197 (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
198
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
199 (defface diff-changed-face
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
200 '((t ()))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
201 "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
202 :group 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
203 (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
204
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
205 (defvar diff-font-lock-keywords
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
206 '(("^@@ .+ @@$" . diff-hunk-header-face) ;unified
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
207 ("^--- .+ ----$" . diff-hunk-header-face) ;context
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
208 ("^\\*\\*\\*.+\\*\\*\\*\n" . diff-hunk-header-face) ;context
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
209 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) .*\n" . diff-file-header-face)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
210 ("^[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
211 ("^!.*\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
212 ("^[+>].*\n" . diff-added-face)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
213 ("^[-<].*\n" . diff-removed-face)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
214 ("^Index: .*\n" . diff-index-face)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
215 ("^[^-=+*!<>].*\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
216
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
217 (defconst diff-font-lock-defaults
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
218 '(diff-font-lock-keywords t nil nil nil))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
219
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
220 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
221 ;;;; Compile support
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
222 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
223
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
224 (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
225 '(("Index: \\(.+\\)" 1)))
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 (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
228 '(("@@ -\\([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
229 ("--- \\([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
230 ("\\([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
231
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
232 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
233 ;;;; Movement
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
234 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
235
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
236 (defconst diff-hunk-header-re "^\\(@@ .+ @@\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
237 (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
238 (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
239
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
240 (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
241 (if (looking-at diff-hunk-header-re) (goto-char (match-end 0)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
242 (re-search-forward (case style
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
243 (unified "^[^-+ \\]")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
244 (context "^\\([^-+! \\][ \t]\\|--- .+ ----\\)")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
245 (normal "^\\([<>\\][ \t]\\|---\\)")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
246 (t "^[^-+!<> \\]"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
247 nil 'move)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
248 (beginning-of-line))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
249
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
250 (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
251 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
252 (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
253 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
254 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
255 (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
256 (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
257
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
258 (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
259 (beginning-of-line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
260 (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
261 (forward-line 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
262 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
263 (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
264 (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
265
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
266 (defun diff-end-of-file ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
267 (re-search-forward "^[-+!<>0-9@* \\]" nil t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
268 (re-search-forward "^[^-+!<>0-9@* \\]" nil 'move)
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
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
271 (defun diff-recenter ()
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
272 "Scroll if necessary to display the current hunk."
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
273 (interactive)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
274 (when (eq (current-buffer) (window-buffer (selected-window)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
275 (let ((endpt (save-excursion (diff-end-of-hunk) (point))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
276 (unless (<= endpt (window-end))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
277 (recenter)
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
278 ;;(unless (<= endpt (window-end 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
279 ;; (set-window-start (selected-window) (point)))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
280 ))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
281
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
282 (defun diff-next-hunk (&optional count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
283 "Move to next (COUNT'th) hunk."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
284 (interactive "p")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
285 (unless count (setq count 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
286 (if (< count 0) (diff-prev-hunk (- count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
287 (when (looking-at diff-hunk-header-re) (incf count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
288 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
289 (re-search-forward diff-hunk-header-re nil nil count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
290 (error (error "Can't find next hunk")))
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
291 (goto-char (match-beginning 0))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
292 (diff-recenter)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
293
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
294 (defun diff-prev-hunk (&optional count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
295 "Move to previous (COUNT'th) hunk."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
296 (interactive "p")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
297 (unless count (setq count 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
298 (if (< count 0) (diff-next-hunk (- count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
299 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
300 (re-search-backward diff-hunk-header-re nil nil count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
301 (error (error "Can't find previous hunk")))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
302
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
303 (defun diff-next-file (&optional count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
304 "Move to next (COUNT'th) file header."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
305 (interactive "p")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
306 (unless count (setq count 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
307 (if (< count 0) (diff-prev-file (- count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
308 (when (looking-at diff-file-header-re) (incf count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
309 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
310 (re-search-forward diff-file-header-re nil nil count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
311 (error (error "Can't find next 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
312 (goto-char (match-beginning 0))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
313 (diff-recenter)))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
314
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
315 (defun diff-prev-file (&optional count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
316 "Move to (COUNT'th) previous file header."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
317 (interactive "p")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
318 (unless count (setq count 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
319 (if (< count 0) (diff-next-file (- count))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
320 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
321 (re-search-backward diff-file-header-re nil nil count)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
322 (error (error "Can't find previous file")))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
323
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
324 (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
325 "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
326 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
327 (interactive "P")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
328 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
329 (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
330 (narrow-to-region (point)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
331 (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
332 (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
333 (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
334
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
335
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
336 (defun diff-kill-hunk ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
337 "Kill current hunk."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
338 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
339 (diff-beginning-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
340 (let ((start (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
341 (firsthunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
342 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
343 (diff-beginning-of-file) (diff-next-hunk) (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
344 (nexthunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
345 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
346 (diff-next-hunk) (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
347 (nextfile (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
348 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
349 (diff-next-file) (point)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
350 (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
351 (or (null nexthunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
352 (and nextfile (> nexthunk nextfile))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
353 ;; we're the only hunk for this file, so kill the file
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
354 (diff-kill-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
355 (diff-end-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
356 (kill-region start (point)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
357
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
358 (defun diff-kill-file ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
359 "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
360 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
361 (diff-beginning-of-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
362 (let* ((start (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
363 (prevhunk (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
364 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
365 (diff-prev-hunk) (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
366 (index (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
367 (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
368 (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
369 (diff-end-of-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
370 (kill-region start (point))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
371
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
372 (defun diff-kill-junk ()
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
373 "Kill spurious empty diffs."
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
374 (interactive)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
375 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
376 (let ((inhibit-read-only t))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
377 (goto-char (point-min))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
378 (while (re-search-forward (concat "^\\(Index: .*\n\\)"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
379 "\\([^-+!* <>].*\n\\)*?"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
380 "\\(\\(Index:\\) \\|"
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
381 diff-file-header-re "\\)")
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
382 nil t)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
383 (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
384 (match-beginning 3))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
385 (beginning-of-line)))))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
386
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
387 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
388 ;;;; jump to other buffers
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
389 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
390
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
391 (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
392
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
393 (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
394 (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
395
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
396 (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
397 "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
398 Returns the merged string if successful or nil otherwise.
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
399 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
400 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
401 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
402 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
403 ;; 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
404 ;; 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
405 ;; 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
406 ;; a/foo a/foo1 b/foo.c -> b/foo1.c but not 1b/foo.c or b/foo.c1
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
407 (let ((str (concat 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
408 (when (and (string-match (concat
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
409 "\\`\\(.*?\\)\\(.*\\)\\(.*\\) /|/ "
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
410 "\\1\\(.*\\)\\3 /|/ "
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
411 "\\(.*\\(\\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
412 (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
413 (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
414 (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
415 (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
416
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
417
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
418
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
419 (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
420 "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
421 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
422 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
423 (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
424 (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
425 (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
426 (let* ((limit (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
427 (condition-case ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
428 (progn (diff-prev-hunk) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
429 (error (point-min)))))
26009
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
430 (header-files
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
431 (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
432 (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
433 (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
434 (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
435 (fs (append
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
436 (when (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
437 (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
438 (list (match-string 1)))
26009
16ee8d330c59 (diff-find-file-name): use `Index:' preferentially.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 25979
diff changeset
439 header-files
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
440 (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
441 (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
442 (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
443 (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
444 (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
445 ;; 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
446 (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
447 ;; 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
448 (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
449 (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
450 (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
451 ;; 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
452 ;; 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
453 (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
454 (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
455 ((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
456 (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
457 (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
458 ((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
459 file))))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
460 file))
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
461 ;; <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
462 (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
463 (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
464 (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
465 ;; 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
466 (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
467 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
468 (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
469 (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
470 file)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
471
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
472 (defun diff-goto-source (&optional other-file)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
473 "Jump to the corresponding source line.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
474 `diff-jump-to-old-file-flag' (or its opposite if the OTHER-FILE prefix arg
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
475 is give) determines whether to jump to the old or the new file.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
476 If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[universal-argument])
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
477 then `diff-jump-to-old-file-flag' is also set, for the next invokations."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
478 (interactive "P")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
479 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
480 (let ((old (if (not other-file) diff-jump-to-old-file-flag
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
481 (not diff-jump-to-old-file-flag))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
482 (when (> (prefix-numeric-value other-file) 8)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
483 (setq diff-jump-to-old-file-flag old))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
484 (diff-beginning-of-hunk)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
485 (let* ((loc (if (not (looking-at "[-@*\n ]*\\([0-9,]+\\)\\([ acd+]+\\([0-9,]+\\)\\)?"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
486 (error "Can't find the hunk header")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
487 (if old (match-string 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
488 (if (match-end 3) (match-string 3)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
489 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
490 (error "Can't find the hunk separator"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
491 (match-string 1)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
492 (lines (if (string-match "^\\([0-9]*\\),\\([0-9]*\\)" loc)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
493 (cons (string-to-number (match-string 1 loc))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
494 (string-to-number (match-string 2 loc)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
495 (cons (string-to-number loc) nil)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
496 (file (diff-find-file-name old)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
497 (unless file (error "Can't find the file"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
498 (pop-to-buffer (find-file-noselect file))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
499 (let* ((line (car lines))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
500 (span (if (or (null (cdr lines)) (< (cdr lines) 0)) 0
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
501 (if (< (cdr lines) line) (cdr lines)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
502 (- (cdr lines) line)))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
503 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
504 (goto-line line)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
505 (forward-line span)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
506 (push-mark (point) t t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
507 (goto-line line)))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
508
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
509
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
510 (defun diff-ediff-patch ()
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
511 "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
512 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
513 (condition-case err
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
514 (ediff-patch-file (current-buffer))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
515 (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
516
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
517 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
518 ;;;; Conversion functions
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
519 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
520
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
521 ;;(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
522 ;; "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
523
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
524 (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
525 "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
526 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
527 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
528 (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
529 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
530 (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
531 (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
532 (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
533 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
534 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
535 (goto-char start)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
536 (while (and (re-search-forward "^\\(\\(---\\) .+\n\\(\\+\\+\\+\\) .+\\|@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([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
537 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
538 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
539 (if (match-beginning 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
540 ;;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
541 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
542 ;; 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
543 (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
544 (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
545 ;; 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
546 (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
547 (lines1 (match-string 5))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
548 (line2 (match-string 6))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
549 (lines2 (match-string 7)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
550 (replace-match
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
551 (concat "***************\n*** " line1 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
552 (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
553 (string-to-number lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
554 -1)) " ****"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
555 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
556 (save-restriction
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
557 (narrow-to-region (point)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
558 (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
559 (let ((hunk (buffer-string)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
560 (goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
561 (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
562 (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
563 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
564 (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
565 (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
566 (= (forward-line -1) 0))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
567 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
568 (? (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
569 (?+ (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
570 (?- (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
571 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
572 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
573 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
574 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
575 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
576 (?\\ (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
577 (= (char-after) ?+))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
578 (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
579 (t (setq modif nil))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
580 (goto-char (point-max))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
581 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
582 (insert "--- " line2 ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
583 (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
584 (string-to-number lines2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
585 -1)) " ----\n" hunk))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
586 ;;(goto-char (point-min))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
587 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
588 (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
589 (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
590 (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
591 (while (not (eobp))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
592 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
593 (? (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
594 (?- (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
595 (?+ (if (not modif)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
596 (progn (forward-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
597 (insert " "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
598 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
599 (insert "! "))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
600 (backward-char 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
601 (?\\ (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
602 (not (eobp)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
603 (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
604 (t (setq modif nil)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
605 (let ((last-pt (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
606 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
607 (when delete
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
608 (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
609 (setq delete nil)))))))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
610
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
611 (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
612 "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
613 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
614 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
615 (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
616 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
617 (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
618 (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
619 (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
620 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
621 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
622 (goto-char start)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
623 (while (and (re-search-forward "^\\(\\(\\*\\*\\*\\) .+\n\\(---\\) .+\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* \\([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
624 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
625 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
626 (if (match-beginning 2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
627 ;; 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
628 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
629 ;; 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
630 (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
631 (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
632 ;; 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
633 (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
634 (line1e (match-string 5))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
635 (pt1 (match-beginning 0)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
636 (replace-match "")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
637 (unless (re-search-forward
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
638 "^--- \\([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
639 (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
640 (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
641 (line2e (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
642 (pt2 (progn
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
643 (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
644 (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
645 (point-marker))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
646 (goto-char pt1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
647 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
648 (while (< (point) pt2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
649 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
650 ((?! ?-) (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
651 (?\ ;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
652 (let* ((endline2
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
653 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
654 (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
655 (c (char-after pt2)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
656 (case c
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
657 ((?! ?+)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
658 (insert "+"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
659 (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
660 (delete-region pt2 endline2))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
661 (?\ ;FIXME: check consistency
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
662 (delete-region pt2 endline2)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
663 (delete-char 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
664 (forward-line 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
665 (?\\ (forward-line 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
666 (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
667 (t (forward-line 1))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
668 (while (looking-at "[+! ] ")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
669 (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
670 (delete-char 1) (insert "+"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
671 (delete-char 1) (forward-line 1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
672 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
673 (goto-char pt1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
674 (insert "@@ -" line1s ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
675 (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
676 (string-to-number line1s)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
677 -1))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
678 " +" line2s ","
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
679 (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
680 (string-to-number line2s)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
681 -1)) " @@"))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
682
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
683 (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
684 "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
685 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
686 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
687 (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
688 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
689 (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
690 (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
691 (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
692 (inhibit-read-only t))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
693 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
694 (goto-char start)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
695 (while (and (re-search-forward "^\\(\\([-*][-*][-*] \\)\\(.+\\)\n\\([-+][-+][-+] \\)\\(.+\\)\\|\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\\*\n\\*\\*\\* \\(.+\\) \\*\\*\\*\\*\\|@@ -\\(.+\\) \\+\\(.+\\) @@\\)$" nil t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
696 (< (point) end))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
697 (combine-after-change-calls
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
698 (cond
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
699 ;; a file header
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
700 ((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
701 ;; 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
702 ((match-beginning 6)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
703 (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
704 (lines1 (match-string 6)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
705 (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
706 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
707 (let ((half1s (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
708 (while (looking-at "[-! \\][ \t]")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
709 (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
710 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
711 (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
712 (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
713 (insert half1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
714 (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
715 (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
716 (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
717 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
718 (let ((half2s (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
719 (while (looking-at "[!+ \\][ \t]")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
720 (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
721 (forward-line 1))
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
722 (let ((half2 (delete-and-extract-region half2s (point))))
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
723 (insert half1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
724 (goto-char half1s)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
725 (insert half2)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
726 (goto-char pt-lines1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
727 (insert str1))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
728 ;; 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
729 ((match-beginning 7)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
730 (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
731 (forward-line 1)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
732 (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
733 (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
734 (?- (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
735 (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
736 (?+ (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
737 (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
738 (?\\ t)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
739 (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
740 (let ((str
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
741 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
742 (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
743 (insert str)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
744 (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
745 (equal ?\ c)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
746 (forward-line 1))))))))))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
747
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
748 (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
749 "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
750 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
751 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
752 (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
753 (list (mark) (point))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
754 (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
755 (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
756 (save-excursion
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
757 (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
758 (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
759 (while (and (= (forward-line -1) 0) (<= start (point)))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
760 (if (not (looking-at "\\(@@ .+ @@\\|[-*][-*][-*] .+ [-*][-*][-*][-*]\\)$"))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
761 (case (char-after)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
762 (?\ (incf space))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
763 (?+ (incf plus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
764 (?- (incf minus))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
765 (?! (incf bang))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
766 (?\\ nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
767 (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
768 (cond
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
769 ((looking-at "@@ -[0-9]+,\\([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
770 (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
771 (old2 (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
772 (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
773 (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
774 (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
775 (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
776 ((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
777 (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
778 (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
779 (old2 (match-string 2))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
780 (new (number-to-string
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
781 (+ 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
782 (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
783 ((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
784 (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
785 (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
786 (new (format
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
787 (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
788 (+ 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
789 (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
790 (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
791
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
792 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
793 ;;;; Hooks
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
794 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
795
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
796 (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
797 "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
798 (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
799 nil)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
800
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
801 ;; 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
802 ;; *-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
803 ;; 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
804 (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
805 (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
806 "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
807 See `after-change-functions' for the meaning of BEG, END and LEN."
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
808 (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
809 (if diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
810 (setq diff-unhandled-changes
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
811 (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
812 (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
813 (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
814
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
815 (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
816 "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
817 (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
818 (ignore-errors
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
819 (save-excursion
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
820 (goto-char (car diff-unhandled-changes))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
821 (unless (ignore-errors
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
822 (diff-beginning-of-hunk)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
823 (save-excursion
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
824 (diff-end-of-hunk)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
825 (> (point) (car diff-unhandled-changes))))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
826 (goto-char (car diff-unhandled-changes))
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
827 (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
828 (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
829 (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
830 (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
831
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
832 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
833 ;;;; The main function
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
834 ;;;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
835
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
836 ;;;###autoload
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
837 (defun diff-mode ()
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
838 "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
839 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
840 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
841 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
842 \\{diff-mode-map}"
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
843 (interactive)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
844 (kill-all-local-variables)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
845 (setq major-mode 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
846 (setq mode-name "Diff")
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
847 (use-local-map diff-mode-map)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
848 (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
849 (set (make-local-variable 'outline-regexp) diff-outline-regexp)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
850 ;; compile support
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
851 (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
852 diff-file-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
853 (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
854 diff-error-regexp-alist)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
855 (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
856 (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
857 (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
858 (compilation-shell-minor-mode 1)
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 (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
861 (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
862 (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
863 (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
864 (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
865 '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
866 (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
867 '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
868 ;; 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
869 (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
870 (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
871 (run-hooks 'diff-mode-hook))
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
872
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
873 ;;;###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
874 (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
875 "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
876 \\{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
877 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
878 ;; FIXME: setup font-lock
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
879 ;; setup change hooks
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
880 (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
881 (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
882 (make-local-variable 'diff-unhandled-changes)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
883 (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
884 'diff-after-change-function nil t)
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
885 (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
886 '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
887
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
888
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
889 ;; provide the package
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
890 (provide 'diff-mode)
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
891
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
892 ;;; Change Log:
26748
8b8438e9ac12 * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26009
diff changeset
893 ;; $Log: diff-mode.el,v $
27637
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
894 ;; Revision 1.4 1999/12/07 07:04:03 monnier
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
895 ;; * diff-mode.el (diff-mode-shared-map): fset'd and doc change.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
896 ;; (diff-minor-mode, diff-minor-mode-prefix, diff-minor-mode-map):
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
897 ;; New code to support the minor mode version.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
898 ;; (diff-recenter): New function.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
899 ;; (diff-next-hunk, diff-next-file): Use it.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
900 ;; (diff-remembered-files-alist): New var.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
901 ;; (diff-merge-strings): New function.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
902 ;; (diff-find-file-name): Make it smarter and use the user's input more.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
903 ;; (diff-mode): Cosmetic changes.
79014abee3cc (diff-kill-junk): New interactive function.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 26748
diff changeset
904 ;;
25959
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
905 ;; 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
906 ;; (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
907 ;; (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
908 ;; (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
909 ;; 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
910 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
911 ;; 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
912 ;; 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
913 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
914 ;; 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
915 ;; - added basic `compile' support.
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
916 ;; - 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
917 ;; - 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
918 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
919 ;; 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
920 ;; - 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
921 ;; - accept diffs using -T
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
922 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
923 ;; 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
924 ;; interface to ediff-patch
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
925 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
926 ;; 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
927 ;; (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
928 ;; (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
929 ;; (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
930 ;; 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
931 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
932 ;; 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
933 ;; (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
934 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
935 ;; 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
936 ;; 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
937 ;;
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
938
1c62cbeca833 Initial revision, known outside of Emacs as version 1.8.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff changeset
939 ;;; diff-mode.el ends here