summaryrefslogtreecommitdiff
path: root/lisp/diff-mode.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2000-11-12 16:59:52 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2000-11-12 16:59:52 +0000
commit637406f5c58f4221841a1de9b8e08069a0720c70 (patch)
tree8336a2340ae9b20567b4913816010bb5d0d7e9f4 /lisp/diff-mode.el
parentfe1accb2a102c1a62ce0e080fb89d6b233333a6b (diff)
downloademacs-637406f5c58f4221841a1de9b8e08069a0720c70.tar.gz
(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.
Diffstat (limited to 'lisp/diff-mode.el')
-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 @@
;; Author: Stefan Monnier <monnier@cs.yale.edu>
;; Keywords: patch diff
-;; Revision: $Id: diff-mode.el,v 1.32 2000/10/18 08:50:39 eliz Exp $
+;; Revision: $Id: diff-mode.el,v 1.33 2000/10/19 15:42:21 monnier Exp $
;; This file is part of GNU Emacs.
@@ -44,10 +44,8 @@
;; Todo:
-;; - Spice up the minor-mode with font-lock support.
;; - Improve narrowed-view support.
;; - Improve the `compile' support (?).
-;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
;; - Support for # comments in context->unified.
;; - Do a fuzzy search in diff-goto-source.
;; - Allow diff.el to use diff-mode.
@@ -56,6 +54,10 @@
;; (i.e. new or old) file.
;; - Handle `diff -b' output in context->unified.
+;; Low priority:
+;; - Spice up the minor-mode with font-lock support.
+;; - Recognize pcl-cvs' special string for `cvs-execute-single'.
+
;;; Code:
(eval-when-compile (require 'cl))
@@ -95,9 +97,9 @@ when editing big diffs)."
(defvar diff-outline-regexp
"\\([*+][*+][*+] [^0-9]\\|@@ ...\\|\\*\\*\\* [0-9].\\|--- [0-9]..\\)")
-;;;;
+;;;;
;;;; keymap, menu, ...
-;;;;
+;;;;
(easy-mmode-defmap diff-mode-shared-map
'(;; From Pavel Machek's patch-mode.
@@ -137,6 +139,7 @@ when editing big diffs)."
;; From compilation-minor-mode.
("\C-c\C-c" . diff-goto-source)
;; Misc operations.
+ ("\C-c\C-s" . diff-split-hunk)
("\C-c\C-a" . diff-apply-hunk)
("\C-c\C-t" . diff-test-hunk))
"Keymap for `diff-mode'. See also `diff-mode-shared-map'.")
@@ -145,7 +148,8 @@ when editing big diffs)."
"Menu for `diff-mode'."
'("Diff"
["Jump to Source" diff-goto-source t]
- ["Apply with Ediff" diff-ediff-patch t]
+ ["Apply hunk" diff-apply-hunk t]
+ ["Apply diff with Ediff" diff-ediff-patch t]
["-----" nil nil]
["Reverse direction" diff-reverse-direction t]
["Context -> Unified" diff-context->unified t]
@@ -163,9 +167,9 @@ when editing big diffs)."
"Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
-;;;;
+;;;;
;;;; font-lock support
-;;;;
+;;;;
(defface diff-header-face
'((((type tty pc) (class color) (background light))
@@ -286,9 +290,9 @@ when editing big diffs)."
("--- \\([0-9]+\\),[0-9]+ ----" nil 1)
("\\([0-9]+\\)\\(,[0-9]+\\)?[adc]\\([0-9]+\\)" nil 3)))
-;;;;
+;;;;
;;;; Movement
-;;;;
+;;;;
(defconst diff-hunk-header-re "^\\(@@ -[0-9,]+ \\+[0-9,]+ @@.*\\|\\*\\{15\\}.*\n\\*\\*\\* .+ \\*\\*\\*\\*\\|[0-9]+\\(,[0-9]+\\)?[acd][0-9]+\\(,[0-9]+\\)?\\)$")
(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."
(match-beginning 3))
(beginning-of-line)))))
+(defun diff-count-matches (re start end)
+ (save-excursion
+ (let ((n 0))
+ (goto-char start)
+ (while (re-search-forward re end t) (incf n))
+ n)))
+
+(defun diff-split-hunk ()
+ "Split the current (unified diff) hunk at point into two hunks."
+ (interactive)
+ (beginning-of-line)
+ (let ((pos (point))
+ (start (progn (diff-beginning-of-hunk) (point))))
+ (unless (looking-at "@@ -\\([0-9]+\\),[0-9]+ \\+\\([0-9]+\\),[0-9]+ @@")
+ (error "diff-split-hunk only works on unified context diffs"))
+ (forward-line 1)
+ (let* ((start1 (string-to-number (match-string 1)))
+ (start2 (string-to-number (match-string 2)))
+ (newstart1 (+ start1 (diff-count-matches "^[- \t]" (point) pos)))
+ (newstart2 (+ start2 (diff-count-matches "^[+ \t]" (point) pos))))
+ (goto-char pos)
+ ;; Hopefully the after-change-function will not screw us over.
+ (insert "@@ -" (number-to-string newstart1) ",1 +"
+ (number-to-string newstart2) ",1 @@\n")
+ ;; Fix the original hunk-header.
+ (diff-fixup-modifs start pos))))
+
+
;;;;
;;;; jump to other buffers
;;;;