Mercurial > emacs
comparison lisp/diff-mode.el @ 82255:eea3be43d1de
(diff-font-lock-keywords): Fix up false positives.
(diff-beginning-of-file): Adjust to the fact that diff-file-header-re
may match up to 4 lines.
(diff-beginning-of-file-and-junk): Rewrite.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 03 Aug 2007 22:06:36 +0000 |
parents | b98604865ea0 |
children | e5a68f18fcb9 |
comparison
equal
deleted
inserted
replaced
82254:368110c6f6e6 | 82255:eea3be43d1de |
---|---|
347 (1 diff-hunk-header-face) (2 diff-function-face)) | 347 (1 diff-hunk-header-face) (2 diff-function-face)) |
348 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context | 348 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context |
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\\)" |
357 (1 diff-indicator-added-face) (2 diff-added-face)) | 360 (1 diff-indicator-added-face) (2 diff-added-face)) |
358 ("^\\(!\\)\\(.*\n\\)" | 361 ("^\\(!\\)\\(.*\n\\)" |
423 (looking-at "^@@")))) | 426 (looking-at "^@@")))) |
424 | 427 |
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) |
435 (re-search-forward (concat "^[^-+#!<>0-9@* \\]\\|" diff-file-header-re) | 448 (re-search-forward (concat "^[^-+#!<>0-9@* \\]\\|" diff-file-header-re) |
436 nil 'move) | 449 nil 'move) |
479 | 492 |
480 (defun diff-beginning-of-file-and-junk () | 493 (defun diff-beginning-of-file-and-junk () |
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." |
507 (interactive) | 528 (interactive) |
508 (diff-beginning-of-file-and-junk) | 529 (diff-beginning-of-file-and-junk) |