diff options
| author | Stefan Monnier | 2007-07-22 21:26:34 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-07-22 21:26:34 +0000 |
| commit | fd69179929b3a9210ce9f4a49dfcacfe1b6d552e (patch) | |
| tree | 5c97bce0b1f66548b27b5d523716b890f9530e5b | |
| parent | 53cc90abac468db36ec45f7f67c4389f8b134165 (diff) | |
| download | emacs-fd69179929b3a9210ce9f4a49dfcacfe1b6d552e.tar.gz emacs-fd69179929b3a9210ce9f4a49dfcacfe1b6d552e.zip | |
(diff-beginning-of-file-and-junk): New function.
(diff-file-kill): Use it.
(diff-beginning-of-hunk): Add arg `try-harder' using it.
(diff-restrict-view, diff-find-source-location, diff-refine-hunk):
Use it so they find the hunk even when we're in the file header.
| -rw-r--r-- | lisp/ChangeLog | 10 | ||||
| -rw-r--r-- | lisp/diff-mode.el | 52 |
2 files changed, 49 insertions, 13 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ee6874c58a9..62efce60a3e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2007-07-22 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * diff-mode.el (diff-beginning-of-file-and-junk): New function. | ||
| 4 | (diff-file-kill): Use it. | ||
| 5 | (diff-beginning-of-hunk): Add arg `try-harder' using it. | ||
| 6 | (diff-restrict-view, diff-find-source-location, diff-refine-hunk): | ||
| 7 | Use it so they find the hunk even when we're in the file header. | ||
| 8 | |||
| 1 | 2007-07-22 Dan Nicolaescu <dann@ics.uci.edu> | 9 | 2007-07-22 Dan Nicolaescu <dann@ics.uci.edu> |
| 2 | 10 | ||
| 3 | * vc-git.el (vc-git-revision-granularity,vc-git-root), | 11 | * vc-git.el (vc-git-revision-granularity,vc-git-root), |
| @@ -28,7 +36,7 @@ | |||
| 28 | 36 | ||
| 29 | 2007-07-22 Stefan Monnier <monnier@iro.umontreal.ca> | 37 | 2007-07-22 Stefan Monnier <monnier@iro.umontreal.ca> |
| 30 | 38 | ||
| 31 | * textmodes/tex-mode.el (tex-font-script-display): Change default to 0.2. | 39 | * textmodes/tex-mode.el (tex-font-script-display): Change default. |
| 32 | 40 | ||
| 33 | 2007-07-22 Dan Nicolaescu <dann@ics.uci.edu> | 41 | 2007-07-22 Dan Nicolaescu <dann@ics.uci.edu> |
| 34 | 42 | ||
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index 64199147c21..358df76ba2f 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -390,13 +390,20 @@ when editing big diffs)." | |||
| 390 | ;; The return value is used by easy-mmode-define-navigation. | 390 | ;; The return value is used by easy-mmode-define-navigation. |
| 391 | (goto-char (or end (point-max))))) | 391 | (goto-char (or end (point-max))))) |
| 392 | 392 | ||
| 393 | (defun diff-beginning-of-hunk () | 393 | (defun diff-beginning-of-hunk (&optional try-harder) |
| 394 | "Move back to beginning of hunk. | ||
| 395 | If TRY-HARDER is non-nil, try to cater to the case where we're not in a hunk | ||
| 396 | but in the file header instead, in which case move forward to the first hunk." | ||
| 394 | (beginning-of-line) | 397 | (beginning-of-line) |
| 395 | (unless (looking-at diff-hunk-header-re) | 398 | (unless (looking-at diff-hunk-header-re) |
| 396 | (forward-line 1) | 399 | (forward-line 1) |
| 397 | (condition-case () | 400 | (condition-case () |
| 398 | (re-search-backward diff-hunk-header-re) | 401 | (re-search-backward diff-hunk-header-re) |
| 399 | (error (error "Can't find the beginning of the hunk"))))) | 402 | (error |
| 403 | (if (not try-harder) | ||
| 404 | (error "Can't find the beginning of the hunk") | ||
| 405 | (diff-beginning-of-file-and-junk) | ||
| 406 | (diff-hunk-next)))))) | ||
| 400 | 407 | ||
| 401 | (defun diff-beginning-of-file () | 408 | (defun diff-beginning-of-file () |
| 402 | (beginning-of-line) | 409 | (beginning-of-line) |
| @@ -425,7 +432,7 @@ when editing big diffs)." | |||
| 425 | If the prefix ARG is given, restrict the view to the current file instead." | 432 | If the prefix ARG is given, restrict the view to the current file instead." |
| 426 | (interactive "P") | 433 | (interactive "P") |
| 427 | (save-excursion | 434 | (save-excursion |
| 428 | (if arg (diff-beginning-of-file) (diff-beginning-of-hunk)) | 435 | (if arg (diff-beginning-of-file) (diff-beginning-of-hunk 'try-harder)) |
| 429 | (narrow-to-region (point) | 436 | (narrow-to-region (point) |
| 430 | (progn (if arg (diff-end-of-file) (diff-end-of-hunk)) | 437 | (progn (if arg (diff-end-of-file) (diff-end-of-hunk)) |
| 431 | (point))) | 438 | (point))) |
| @@ -453,18 +460,37 @@ If the prefix ARG is given, restrict the view to the current file instead." | |||
| 453 | (diff-end-of-hunk) | 460 | (diff-end-of-hunk) |
| 454 | (kill-region start (point))))) | 461 | (kill-region start (point))))) |
| 455 | 462 | ||
| 463 | (defun diff-beginning-of-file-and-junk () | ||
| 464 | "Go to the beginning of file-related diff-info. | ||
| 465 | This is like `diff-beginning-of-file' except it tries to skip back over leading | ||
| 466 | data such as \"Index: ...\" and such." | ||
| 467 | (let ((start (point)) | ||
| 468 | (file (condition-case err (progn (diff-beginning-of-file) (point)) | ||
| 469 | (error err))) | ||
| 470 | ;; prevhunk is one of the limits. | ||
| 471 | (prevhunk (save-excursion (ignore-errors (diff-hunk-prev) (point)))) | ||
| 472 | err) | ||
| 473 | (when (consp file) | ||
| 474 | ;; Presumably, we started before the file header, in the leading junk. | ||
| 475 | (setq err file) | ||
| 476 | (diff-file-next) | ||
| 477 | (setq file (point))) | ||
| 478 | (let ((index (save-excursion | ||
| 479 | (re-search-backward "^Index: " prevhunk t)))) | ||
| 480 | (when index (setq file index)) | ||
| 481 | (if (<= file start) | ||
| 482 | (goto-char file) | ||
| 483 | ;; File starts *after* the starting point: we really weren't in | ||
| 484 | ;; a file diff but elsewhere. | ||
| 485 | (goto-char start) | ||
| 486 | (signal (car err) (cdr err)))))) | ||
| 487 | |||
| 456 | (defun diff-file-kill () | 488 | (defun diff-file-kill () |
| 457 | "Kill current file's hunks." | 489 | "Kill current file's hunks." |
| 458 | (interactive) | 490 | (interactive) |
| 459 | (diff-beginning-of-file) | 491 | (diff-beginning-of-file-and-junk) |
| 460 | (let* ((start (point)) | 492 | (let* ((start (point)) |
| 461 | (prevhunk (save-excursion | ||
| 462 | (ignore-errors | ||
| 463 | (diff-hunk-prev) (point)))) | ||
| 464 | (index (save-excursion | ||
| 465 | (re-search-backward "^Index: " prevhunk t))) | ||
| 466 | (inhibit-read-only t)) | 493 | (inhibit-read-only t)) |
| 467 | (when index (setq start index)) | ||
| 468 | (diff-end-of-file) | 494 | (diff-end-of-file) |
| 469 | (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs. | 495 | (if (looking-at "^\n") (forward-char 1)) ;`tla' generates such diffs. |
| 470 | (kill-region start (point)))) | 496 | (kill-region start (point)))) |
| @@ -1289,7 +1315,8 @@ SRC and DST are the two variants of text as returned by `diff-hunk-text'. | |||
| 1289 | SWITCHED is non-nil if the patch is already applied." | 1315 | SWITCHED is non-nil if the patch is already applied." |
| 1290 | (save-excursion | 1316 | (save-excursion |
| 1291 | (let* ((other (diff-xor other-file diff-jump-to-old-file)) | 1317 | (let* ((other (diff-xor other-file diff-jump-to-old-file)) |
| 1292 | (char-offset (- (point) (progn (diff-beginning-of-hunk) (point)))) | 1318 | (char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) |
| 1319 | (point)))) | ||
| 1293 | ;; Check that the hunk is well-formed. Otherwise diff-mode and | 1320 | ;; Check that the hunk is well-formed. Otherwise diff-mode and |
| 1294 | ;; the user may disagree on what constitutes the hunk | 1321 | ;; the user may disagree on what constitutes the hunk |
| 1295 | ;; (e.g. because an empty line truncates the hunk mid-course), | 1322 | ;; (e.g. because an empty line truncates the hunk mid-course), |
| @@ -1464,7 +1491,8 @@ For use in `add-log-current-defun-function'." | |||
| 1464 | (defun diff-refine-hunk () | 1491 | (defun diff-refine-hunk () |
| 1465 | "Refine the current hunk by ignoring space differences." | 1492 | "Refine the current hunk by ignoring space differences." |
| 1466 | (interactive) | 1493 | (interactive) |
| 1467 | (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk) (point)))) | 1494 | (let* ((char-offset (- (point) (progn (diff-beginning-of-hunk 'try-harder) |
| 1495 | (point)))) | ||
| 1468 | (opts (case (char-after) (?@ "-bu") (?* "-bc") (t "-b"))) | 1496 | (opts (case (char-after) (?@ "-bu") (?* "-bc") (t "-b"))) |
| 1469 | (line-nb (and (or (looking-at "[^0-9]+\\([0-9]+\\)") | 1497 | (line-nb (and (or (looking-at "[^0-9]+\\([0-9]+\\)") |
| 1470 | (error "Can't find line number")) | 1498 | (error "Can't find line number")) |