aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-11-12 16:59:52 +0000
committerStefan Monnier2000-11-12 16:59:52 +0000
commitcd632e57a5215e9429f1459f1aef09b9eef358ba (patch)
tree839f368d8f3e5d1418580a38dfea100d7ced93b4
parent539211583477e45d265740af64b14f4c8410131c (diff)
downloademacs-cd632e57a5215e9429f1459f1aef09b9eef358ba.tar.gz
emacs-cd632e57a5215e9429f1459f1aef09b9eef358ba.zip
(diff-mode-menu): Add entry for applying hunk.
(diff-count-matches, diff-split-hunk): New functions. (diff-mode-map): Bind C-c C-s to diff-split-hunk.
-rw-r--r--lisp/diff-mode.el52
1 files changed, 42 insertions, 10 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index 2959b650ec6..1fb6aefef5e 100644
--- a/lisp/diff-mode.el
+++ b/lisp/diff-mode.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Stefan Monnier <monnier@cs.yale.edu> 5;; Author: Stefan Monnier <monnier@cs.yale.edu>
6;; Keywords: patch diff 6;; Keywords: patch diff
7;; Revision: $Id: diff-mode.el,v 1.32 2000/10/18 08:50:39 eliz Exp $ 7;; Revision: $Id: diff-mode.el,v 1.33 2000/10/19 15:42:21 monnier Exp $
8 8
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
10 10
@@ -44,10 +44,8 @@
44 44
45;; Todo: 45;; Todo:
46 46
47;; - Spice up the minor-mode with font-lock support.
48;; - Improve narrowed-view support. 47;; - Improve narrowed-view support.
49;; - Improve the `compile' support (?). 48;; - Improve the `compile' support (?).
50;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
51;; - Support for # comments in context->unified. 49;; - Support for # comments in context->unified.
52;; - Do a fuzzy search in diff-goto-source. 50;; - Do a fuzzy search in diff-goto-source.
53;; - Allow diff.el to use diff-mode. 51;; - Allow diff.el to use diff-mode.
@@ -56,6 +54,10 @@
56;; (i.e. new or old) file. 54;; (i.e. new or old) file.
57;; - Handle `diff -b' output in context->unified. 55;; - Handle `diff -b' output in context->unified.
58 56
57;; Low priority:
58;; - Spice up the minor-mode with font-lock support.
59;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
60
59;;; Code: 61;;; Code:
60 62
61(eval-when-compile (require 'cl)) 63(eval-when-compile (require 'cl))
@@ -95,9 +97,9 @@ when editing big diffs)."
95(defvar diff-outline-regexp 97(defvar diff-outline-regexp
96 "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)") 98 "\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")
97 99
98;;;; 100;;;;
99;;;; keymap, menu, ... 101;;;; keymap, menu, ...
100;;;; 102;;;;
101 103
102(easy-mmode-defmap diff-mode-shared-map 104(easy-mmode-defmap diff-mode-shared-map
103 '(;; From Pavel Machek's patch-mode. 105 '(;; From Pavel Machek's patch-mode.
@@ -137,6 +139,7 @@ when editing big diffs)."
137 ;; From compilation-minor-mode. 139 ;; From compilation-minor-mode.
138 ("\C-c\C-c" . diff-goto-source) 140 ("\C-c\C-c" . diff-goto-source)
139 ;; Misc operations. 141 ;; Misc operations.
142 ("\C-c\C-s" . diff-split-hunk)
140 ("\C-c\C-a" . diff-apply-hunk) 143 ("\C-c\C-a" . diff-apply-hunk)
141 ("\C-c\C-t" . diff-test-hunk)) 144 ("\C-c\C-t" . diff-test-hunk))
142 "Keymap for `diff-mode'. See also `diff-mode-shared-map'.") 145 "Keymap for `diff-mode'. See also `diff-mode-shared-map'.")
@@ -145,7 +148,8 @@ when editing big diffs)."
145 "Menu for `diff-mode'." 148 "Menu for `diff-mode'."
146 '("Diff" 149 '("Diff"
147 ["Jump to Source" diff-goto-source t] 150 ["Jump to Source" diff-goto-source t]
148 ["Apply with Ediff" diff-ediff-patch t] 151 ["Apply hunk" diff-apply-hunk t]
152 ["Apply diff with Ediff" diff-ediff-patch t]
149 ["-----" nil nil] 153 ["-----" nil nil]
150 ["Reverse direction" diff-reverse-direction t] 154 ["Reverse direction" diff-reverse-direction t]
151 ["Context -> Unified" diff-context->unified t] 155 ["Context -> Unified" diff-context->unified t]
@@ -163,9 +167,9 @@ when editing big diffs)."
163 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.") 167 "Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
164 168
165 169
166;;;; 170;;;;
167;;;; font-lock support 171;;;; font-lock support
168;;;; 172;;;;
169 173
170(defface diff-header-face 174(defface diff-header-face
171 '((((type tty pc) (class color) (background light)) 175 '((((type tty pc) (class color) (background light))
@@ -286,9 +290,9 @@ when editing big diffs)."
286 ("--- \\([0-9]+\\),[0-9]+ ----" nil 1) 290 ("--- \\([0-9]+\\),[0-9]+ ----" nil 1)
287 ("\\([0-9]+\\)\\(,[0-9]+\\)?[adc]\\([0-9]+\\)" nil 3))) 291 ("\\([0-9]+\\)\\(,[0-9]+\\)?[adc]\\([0-9]+\\)" nil 3)))
288 292
289;;;; 293;;;;
290;;;; Movement 294;;;; Movement
291;;;; 295;;;;
292 296
293(defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$") 297(defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")
294(defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1))) 298(defconst diff-file-header-re (concat "^\\(--- .+\n\\+\\+\\+\\|\\*\\*\\* .+\n---\\|[^-+!<>0-9@* ]\\).+\n" (substring diff-hunk-header-re 1)))
@@ -396,6 +400,34 @@ If the prefix ARG is given, restrict the view to the current file instead."
396 (match-beginning 3)) 400 (match-beginning 3))
397 (beginning-of-line))))) 401 (beginning-of-line)))))
398 402
403(defun diff-count-matches (re start end)
404 (save-excursion
405 (let ((n 0))
406 (goto-char start)
407 (while (re-search-forward re end t) (incf n))
408 n)))
409
410(defun diff-split-hunk ()
411 "Split the current (unified diff) hunk at point into two hunks."
412 (interactive)
413 (beginning-of-line)
414 (let ((pos (point))
415 (start (progn (diff-beginning-of-hunk) (point))))
416 (unless (looking-at "@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@")
417 (error "diff-split-hunk only works on unified context diffs"))
418 (forward-line 1)
419 (let* ((start1 (string-to-number (match-string 1)))
420 (start2 (string-to-number (match-string 2)))
421 (newstart1 (+ start1 (diff-count-matches "^[- \t]" (point) pos)))
422 (newstart2 (+ start2 (diff-count-matches "^[+ \t]" (point) pos))))
423 (goto-char pos)
424 ;; Hopefully the after-change-function will not screw us over.
425 (insert "@@ -" (number-to-string newstart1) ",1 +"
426 (number-to-string newstart2) ",1 @@\n")
427 ;; Fix the original hunk-header.
428 (diff-fixup-modifs start pos))))
429
430
399;;;; 431;;;;
400;;;; jump to other buffers 432;;;; jump to other buffers
401;;;; 433;;;;