aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-08-03 22:06:36 +0000
committerStefan Monnier2007-08-03 22:06:36 +0000
commit4c969f97e32159e63191ff848c3f9ea82426473c (patch)
tree3a53d6195cdd328acb8e31d9c71935cfacd0049b
parent866c361431989b399815c39db600d890c4ae064d (diff)
downloademacs-4c969f97e32159e63191ff848c3f9ea82426473c.tar.gz
emacs-4c969f97e32159e63191ff848c3f9ea82426473c.zip
(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.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/diff-mode.el73
2 files changed, 54 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c260af00a67..dde765a15e2 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12007-08-03 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * diff-mode.el (diff-font-lock-keywords): Fix up false positives.
4 (diff-beginning-of-file): Adjust to the fact that diff-file-header-re
5 may match up to 4 lines.
6 (diff-beginning-of-file-and-junk): Rewrite.
7
12007-08-03 Vinicius Jose Latorre <viniciusjl@ig.com.br> 82007-08-03 Vinicius Jose Latorre <viniciusjl@ig.com.br>
2 9
3 * printing.el: Evaluate require only during compilation. 10 * printing.el: Evaluate require only during compilation.
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index cfac6517209..3c8ad2c49ff 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.
482This is like `diff-beginning-of-file' except it tries to skip back over leading 495This is like `diff-beginning-of-file' except it tries to skip back over leading
483data such as \"Index: ...\" and such." 496data 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."