aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-05-26 17:25:44 +0000
committerStefan Monnier2008-05-26 17:25:44 +0000
commitbf6970a5f63943e08dfcc94b136f95a23a65dca0 (patch)
tree1344222c3fdffebf20dd691d1d731cb7a4be9d72
parentdc49f3766bc0f2a565df20cb725c24a73c3cbea1 (diff)
downloademacs-bf6970a5f63943e08dfcc94b136f95a23a65dca0.tar.gz
emacs-bf6970a5f63943e08dfcc94b136f95a23a65dca0.zip
(diff-context-mid-hunk-header-re): New const.
(diff-font-lock-keywords, diff-context->unified) (diff-reverse-direction, diff-fixup-modifs, diff-sanity-check-hunk) (diff-hunk-text, diff-find-source-location): Use it. (diff-post-command-hook): Let the user edit the hunk headers.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/diff-mode.el60
2 files changed, 45 insertions, 27 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fe4d01360b7..7f7c3f043c1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12008-05-26 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * diff-mode.el (diff-context-mid-hunk-header-re): New const.
4 (diff-font-lock-keywords, diff-context->unified)
5 (diff-reverse-direction, diff-fixup-modifs, diff-sanity-check-hunk)
6 (diff-hunk-text, diff-find-source-location): Use it.
7 (diff-post-command-hook): Let the user edit the hunk headers.
8
12008-05-26 Andreas Schwab <schwab@suse.de> 92008-05-26 Andreas Schwab <schwab@suse.de>
2 10
3 * vc.el (vc-default-prettify-state-info): Fix formatting of an 11 * vc.el (vc-default-prettify-state-info): Fix formatting of an
@@ -15,8 +23,8 @@
15 23
162008-05-25 John Paul Wallington <jpw@pobox.com> 242008-05-25 John Paul Wallington <jpw@pobox.com>
17 25
18 * proced.el (proced-next-line, proced-previous-line): Avoid 26 * proced.el (proced-next-line, proced-previous-line):
19 calling `next-line' and `previous-line' from Lisp code. 27 Avoid calling `next-line' and `previous-line' from Lisp code.
20 28
212008-05-25 Ed Reingold <reingold@emr.cs.iit.edu> 292008-05-25 Ed Reingold <reingold@emr.cs.iit.edu>
22 30
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index 4913ef72e35..447a8446250 100644
--- a/lisp/diff-mode.el
+++ b/lisp/diff-mode.el
@@ -369,6 +369,8 @@ when editing big diffs)."
369 369
370(defconst diff-hunk-header-re-unified 370(defconst diff-hunk-header-re-unified
371 "^@@ -\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? \\+\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? @@") 371 "^@@ -\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? \\+\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? @@")
372(defconst diff-context-mid-hunk-header-re
373 "--- \\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$")
372 374
373(defvar diff-font-lock-keywords 375(defvar diff-font-lock-keywords
374 `((,(concat "\\(" diff-hunk-header-re-unified "\\)\\(.*\\)$") 376 `((,(concat "\\(" diff-hunk-header-re-unified "\\)\\(.*\\)$")
@@ -376,7 +378,7 @@ when editing big diffs)."
376 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context 378 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context
377 (1 diff-hunk-header-face) (2 diff-function-face)) 379 (1 diff-hunk-header-face) (2 diff-function-face))
378 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context 380 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context
379 ("^--- .+ ----$" . diff-hunk-header-face) ;context 381 (,diff-context-mid-hunk-header-re . diff-hunk-header-face) ;context
380 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal 382 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal
381 ("^---$" . diff-hunk-header-face) ;normal 383 ("^---$" . diff-hunk-header-face) ;normal
382 ;; For file headers, accept files with spaces, but be careful to rule 384 ;; For file headers, accept files with spaces, but be careful to rule
@@ -977,7 +979,7 @@ With a prefix argument, convert unified format to context format."
977 (reversible t)) 979 (reversible t))
978 (replace-match "") 980 (replace-match "")
979 (unless (re-search-forward 981 (unless (re-search-forward
980 "^--- \\([0-9]+\\),\\(-?[0-9]+\\) ----$" nil t) 982 diff-context-mid-hunk-header-re nil t)
981 (error "Can't find matching `--- n1,n2 ----' line")) 983 (error "Can't find matching `--- n1,n2 ----' line"))
982 (let ((line2s (match-string 1)) 984 (let ((line2s (match-string 1))
983 (line2e (match-string 2)) 985 (line2e (match-string 2))
@@ -1068,11 +1070,14 @@ else cover the whole buffer."
1068 (when (= (char-after) ?-) (delete-char 1) (insert "+")) 1070 (when (= (char-after) ?-) (delete-char 1) (insert "+"))
1069 (forward-line 1)) 1071 (forward-line 1))
1070 (let ((half1 (delete-and-extract-region half1s (point)))) 1072 (let ((half1 (delete-and-extract-region half1s (point))))
1071 (unless (looking-at "^--- \\([0-9]+,-?[0-9]+\\) ----$") 1073 (unless (looking-at diff-context-mid-hunk-header-re)
1072 (insert half1) 1074 (insert half1)
1073 (error "Can't find matching `--- n1,n2 ----' line")) 1075 (error "Can't find matching `--- n1,n2 ----' line"))
1074 (let ((str1 (match-string 1))) 1076 (let* ((str1end (or (match-end 2) (match-end 1)))
1075 (replace-match lines1 nil nil nil 1) 1077 (str1 (buffer-substring (match-beginning 1) str1end)))
1078 (goto-char str1end)
1079 (insert lines1)
1080 (delete-region (match-beginning 1) str1end)
1076 (forward-line 1) 1081 (forward-line 1)
1077 (let ((half2s (point))) 1082 (let ((half2s (point)))
1078 (while (looking-at "[!+ \\][ \t]\\|#") 1083 (while (looking-at "[!+ \\][ \t]\\|#")
@@ -1137,7 +1142,7 @@ else cover the whole buffer."
1137 (if old1 1142 (if old1
1138 (unless (string= new1 old1) (replace-match new1 t t nil 2)) 1143 (unless (string= new1 old1) (replace-match new1 t t nil 2))
1139 (goto-char (match-end 2)) (insert "," new1)))) 1144 (goto-char (match-end 2)) (insert "," new1))))
1140 ((looking-at "--- \\([0-9]+\\),\\([0-9]*\\) ----$") 1145 ((looking-at diff-context-mid-hunk-header-re)
1141 (when (> (+ space bang plus) 0) 1146 (when (> (+ space bang plus) 0)
1142 (let* ((old1 (match-string 1)) 1147 (let* ((old1 (match-string 1))
1143 (old2 (match-string 2)) 1148 (old2 (match-string 2))
@@ -1189,25 +1194,29 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
1189 (goto-char (car diff-unhandled-changes)) 1194 (goto-char (car diff-unhandled-changes))
1190 ;; Maybe we've cut the end of the hunk before point. 1195 ;; Maybe we've cut the end of the hunk before point.
1191 (if (and (bolp) (not (bobp))) (backward-char 1)) 1196 (if (and (bolp) (not (bobp))) (backward-char 1))
1192 ;; We used to fixup modifs on all the changes, but it turns out 1197 ;; We used to fixup modifs on all the changes, but it turns out that
1193 ;; that it's safer not to do it on big changes, for example 1198 ;; it's safer not to do it on big changes, e.g. when yanking a big
1194 ;; when yanking a big diff, since we might then screw up perfectly 1199 ;; diff, or when the user edits the header, since we might then
1195 ;; correct values. -stef 1200 ;; screw up perfectly correct values. --Stef
1196 ;; (unless (ignore-errors
1197 ;; (diff-beginning-of-hunk)
1198 ;; (save-excursion
1199 ;; (diff-end-of-hunk)
1200 ;; (> (point) (car diff-unhandled-changes))))
1201 ;; (goto-char (car diff-unhandled-changes))
1202 ;; (re-search-forward diff-hunk-header-re (cdr diff-unhandled-changes))
1203 ;; (diff-beginning-of-hunk))
1204 ;; (diff-fixup-modifs (point) (cdr diff-unhandled-changes))
1205 (diff-beginning-of-hunk) 1201 (diff-beginning-of-hunk)
1206 (when (save-excursion 1202 (let* ((style (if (looking-at "\\*\\*\\*") 'context))
1203 (start (line-beginning-position (if (eq style 'context) 3 2)))
1204 (mid (if (eq style 'context)
1205 (save-excursion
1206 (re-search-forward diff-context-mid-hunk-header-re
1207 nil t)))))
1208 (when (and ;; Don't try to fixup changes in the hunk header.
1209 (> (car diff-unhandled-changes) start)
1210 ;; Don't try to fixup changes in the mid-hunk header either.
1211 (or (not mid)
1212 (< (cdr diff-unhandled-changes) (match-beginning 0))
1213 (> (car diff-unhandled-changes) (match-end 0)))
1214 (save-excursion
1207 (diff-end-of-hunk nil 'donttrustheader) 1215 (diff-end-of-hunk nil 'donttrustheader)
1208 (>= (point) (cdr diff-unhandled-changes))) 1216 ;; Don't try to fixup changes past the end of the hunk.
1217 (>= (point) (cdr diff-unhandled-changes))))
1209 (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))) 1218 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
1210 (setq diff-unhandled-changes nil))) 1219 (setq diff-unhandled-changes nil))))
1211 1220
1212(defun diff-next-error (arg reset) 1221(defun diff-next-error (arg reset)
1213 ;; Select a window that displays the current buffer so that point 1222 ;; Select a window that displays the current buffer so that point
@@ -1367,7 +1376,7 @@ Only works for unified diffs."
1367 (1+ (- (string-to-number (match-string 2)) 1376 (1+ (- (string-to-number (match-string 2))
1368 (string-to-number (match-string 1)))) 1377 (string-to-number (match-string 1))))
1369 1)) 1378 1))
1370 (if (not (looking-at "--- \\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$")) 1379 (if (not (looking-at diff-context-mid-hunk-header-re))
1371 (error "Unrecognized context diff second hunk header format") 1380 (error "Unrecognized context diff second hunk header format")
1372 (forward-line) 1381 (forward-line)
1373 (diff-sanity-check-context-hunk-half 1382 (diff-sanity-check-context-hunk-half
@@ -1447,7 +1456,7 @@ char-offset in TEXT."
1447 ;; context diff 1456 ;; context diff
1448 (forward-line 2) 1457 (forward-line 2)
1449 (setq src-pos (point)) 1458 (setq src-pos (point))
1450 (re-search-forward "^--- " nil t) 1459 (re-search-forward diff-context-mid-hunk-header-re nil t)
1451 (forward-line 0) 1460 (forward-line 0)
1452 (setq divider-pos (point)) 1461 (setq divider-pos (point))
1453 (forward-line 1) 1462 (forward-line 1)
@@ -1563,7 +1572,8 @@ SWITCHED is non-nil if the patch is already applied."
1563 (error "Can't find the hunk header") 1572 (error "Can't find the hunk header")
1564 (if other (match-string 1) 1573 (if other (match-string 1)
1565 (if (match-end 3) (match-string 3) 1574 (if (match-end 3) (match-string 3)
1566 (unless (re-search-forward "^--- \\([0-9,]+\\)" nil t) 1575 (unless (re-search-forward
1576 diff-context-mid-hunk-header-re nil t)
1567 (error "Can't find the hunk separator")) 1577 (error "Can't find the hunk separator"))
1568 (match-string 1))))) 1578 (match-string 1)))))
1569 (file (or (diff-find-file-name other) (error "Can't find the file"))) 1579 (file (or (diff-find-file-name other) (error "Can't find the file")))