diff options
Diffstat (limited to 'lisp/diff-mode.el')
| -rw-r--r-- | lisp/diff-mode.el | 79 |
1 files changed, 50 insertions, 29 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el index cfac6517209..be4c7e7b905 100644 --- a/lisp/diff-mode.el +++ b/lisp/diff-mode.el | |||
| @@ -349,8 +349,11 @@ when editing big diffs)." | |||
| 349 | ("^--- .+ ----$" . diff-hunk-header-face) ;context | 349 | ("^--- .+ ----$" . diff-hunk-header-face) ;context |
| 350 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal | 350 | ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ;normal |
| 351 | ("^---$" . diff-hunk-header-face) ;normal | 351 | ("^---$" . diff-hunk-header-face) ;normal |
| 352 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\([^\t\n]+\\)\\(.*[^*-]\\)?\n" | 352 | ;; For file headers, accept files with spaces, but be careful to rule |
| 353 | (0 diff-header-face) (2 diff-file-header-face prepend)) | 353 | ;; out false-positives when matching hunk headers. |
| 354 | ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\([^\t\n]+?\\)\\(?:\t.*\\| \\(\\*\\*\\*\\*\\|----\\)\\)?\n" | ||
| 355 | (0 diff-header-face) | ||
| 356 | (2 (if (not (match-end 3)) diff-file-header-face) prepend)) | ||
| 354 | ("^\\([-<]\\)\\(.*\n\\)" | 357 | ("^\\([-<]\\)\\(.*\n\\)" |
| 355 | (1 diff-indicator-removed-face) (2 diff-removed-face)) | 358 | (1 diff-indicator-removed-face) (2 diff-removed-face)) |
| 356 | ("^\\([+>]\\)\\(.*\n\\)" | 359 | ("^\\([+>]\\)\\(.*\n\\)" |
| @@ -425,10 +428,20 @@ but in the file header instead, in which case move forward to the first hunk." | |||
| 425 | (defun diff-beginning-of-file () | 428 | (defun diff-beginning-of-file () |
| 426 | (beginning-of-line) | 429 | (beginning-of-line) |
| 427 | (unless (looking-at diff-file-header-re) | 430 | (unless (looking-at diff-file-header-re) |
| 428 | (forward-line 2) | 431 | (let ((start (point)) |
| 429 | (condition-case () | 432 | res) |
| 430 | (re-search-backward diff-file-header-re) | 433 | ;; diff-file-header-re may need to match up to 4 lines, so in case |
| 431 | (error (error "Can't find the beginning of the file"))))) | 434 | ;; we're inside the header, we need to move up to 3 lines forward. |
| 435 | (forward-line 3) | ||
| 436 | (if (and (setq res (re-search-backward diff-file-header-re nil t)) | ||
| 437 | ;; Maybe the 3 lines forward were too much and we matched | ||
| 438 | ;; a file header after our starting point :-( | ||
| 439 | (or (<= (point) start) | ||
| 440 | (setq res (re-search-backward diff-file-header-re nil t)))) | ||
| 441 | res | ||
| 442 | (goto-char start) | ||
| 443 | (error "Can't find the beginning of the file"))))) | ||
| 444 | |||
| 432 | 445 | ||
| 433 | (defun diff-end-of-file () | 446 | (defun diff-end-of-file () |
| 434 | (re-search-forward "^[-+#!<>0-9@* \\]" nil t) | 447 | (re-search-forward "^[-+#!<>0-9@* \\]" nil t) |
| @@ -481,26 +494,34 @@ If the prefix ARG is given, restrict the view to the current file instead." | |||
| 481 | "Go to the beginning of file-related diff-info. | 494 | "Go to the beginning of file-related diff-info. |
| 482 | This is like `diff-beginning-of-file' except it tries to skip back over leading | 495 | This is like `diff-beginning-of-file' except it tries to skip back over leading |
| 483 | data such as \"Index: ...\" and such." | 496 | data such as \"Index: ...\" and such." |
| 484 | (let ((start (point)) | 497 | (let* ((start (point)) |
| 485 | (file (condition-case err (progn (diff-beginning-of-file) (point)) | 498 | (prevfile (condition-case err |
| 486 | (error err))) | 499 | (save-excursion (diff-beginning-of-file) (point)) |
| 487 | ;; prevhunk is one of the limits. | 500 | (error err))) |
| 488 | (prevhunk (save-excursion (ignore-errors (diff-hunk-prev) (point)))) | 501 | (err (if (consp prevfile) prevfile)) |
| 489 | err) | 502 | (nextfile (ignore-errors |
| 490 | (when (consp file) | 503 | (save-excursion |
| 491 | ;; Presumably, we started before the file header, in the leading junk. | 504 | (goto-char start) (diff-file-next) (point)))) |
| 492 | (setq err file) | 505 | ;; prevhunk is one of the limits. |
| 493 | (diff-file-next) | 506 | (prevhunk (save-excursion |
| 494 | (setq file (point))) | 507 | (ignore-errors |
| 495 | (let ((index (save-excursion | 508 | (if (numberp prevfile) (goto-char prevfile)) |
| 496 | (re-search-backward "^Index: " prevhunk t)))) | 509 | (diff-hunk-prev) (point)))) |
| 497 | (when index (setq file index)) | 510 | (previndex (save-excursion |
| 498 | (if (<= file start) | 511 | (re-search-backward "^Index: " prevhunk t)))) |
| 499 | (goto-char file) | 512 | ;; If we're in the junk, we should use nextfile instead of prevfile. |
| 500 | ;; File starts *after* the starting point: we really weren't in | 513 | (if (and (numberp nextfile) |
| 501 | ;; a file diff but elsewhere. | 514 | (or (not (numberp prevfile)) |
| 502 | (goto-char start) | 515 | (and previndex (> previndex prevfile)))) |
| 503 | (signal (car err) (cdr err)))))) | 516 | (setq prevfile nextfile)) |
| 517 | (if (and previndex (numberp prevfile) (< previndex prevfile)) | ||
| 518 | (setq prevfile previndex)) | ||
| 519 | (if (and (numberp prevfile) (<= prevfile start)) | ||
| 520 | (goto-char prevfile) | ||
| 521 | ;; File starts *after* the starting point: we really weren't in | ||
| 522 | ;; a file diff but elsewhere. | ||
| 523 | (goto-char start) | ||
| 524 | (signal (car err) (cdr err))))) | ||
| 504 | 525 | ||
| 505 | (defun diff-file-kill () | 526 | (defun diff-file-kill () |
| 506 | "Kill current file's hunks." | 527 | "Kill current file's hunks." |
| @@ -703,7 +724,7 @@ PREFIX is only used internally: don't use it." | |||
| 703 | (defun diff-unified->context (start end) | 724 | (defun diff-unified->context (start end) |
| 704 | "Convert unified diffs to context diffs. | 725 | "Convert unified diffs to context diffs. |
| 705 | START and END are either taken from the region (if a prefix arg is given) or | 726 | START and END are either taken from the region (if a prefix arg is given) or |
| 706 | else cover the whole bufer." | 727 | else cover the whole buffer." |
| 707 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) | 728 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) |
| 708 | (list (region-beginning) (region-end)) | 729 | (list (region-beginning) (region-end)) |
| 709 | (list (point-min) (point-max)))) | 730 | (list (point-min) (point-max)))) |
| @@ -886,7 +907,7 @@ With a prefix argument, convert unified format to context format." | |||
| 886 | (defun diff-reverse-direction (start end) | 907 | (defun diff-reverse-direction (start end) |
| 887 | "Reverse the direction of the diffs. | 908 | "Reverse the direction of the diffs. |
| 888 | START and END are either taken from the region (if a prefix arg is given) or | 909 | START and END are either taken from the region (if a prefix arg is given) or |
| 889 | else cover the whole bufer." | 910 | else cover the whole buffer." |
| 890 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) | 911 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) |
| 891 | (list (region-beginning) (region-end)) | 912 | (list (region-beginning) (region-end)) |
| 892 | (list (point-min) (point-max)))) | 913 | (list (point-min) (point-max)))) |
| @@ -948,7 +969,7 @@ else cover the whole bufer." | |||
| 948 | (defun diff-fixup-modifs (start end) | 969 | (defun diff-fixup-modifs (start end) |
| 949 | "Fixup the hunk headers (in case the buffer was modified). | 970 | "Fixup the hunk headers (in case the buffer was modified). |
| 950 | START and END are either taken from the region (if a prefix arg is given) or | 971 | START and END are either taken from the region (if a prefix arg is given) or |
| 951 | else cover the whole bufer." | 972 | else cover the whole buffer." |
| 952 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) | 973 | (interactive (if (or current-prefix-arg (and transient-mark-mode mark-active)) |
| 953 | (list (region-beginning) (region-end)) | 974 | (list (region-beginning) (region-end)) |
| 954 | (list (point-min) (point-max)))) | 975 | (list (point-min) (point-max)))) |