]> code.delx.au - gnu-emacs/blobdiff - lisp/diff-mode.el
(customize-changed-options): Doc addition. Load the
[gnu-emacs] / lisp / diff-mode.el
index c46d152d97e3d6b0e92e08b2e4e6748381ef5afa..7899da63eed9a93091b86b40e21ee907ec57916f 100644 (file)
@@ -1,9 +1,9 @@
-;;; diff-mode.el --- A mode for viewing/editing context diffs
+;;; diff-mode.el --- a mode for viewing/editing context diffs
 
-;; Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002  Free Software Foundation, Inc.
 
 ;; Author: Stefan Monnier <monnier@cs.yale.edu>
-;; Keywords: patch diff
+;; Keywords: convenience patch diff
 
 ;; This file is part of GNU Emacs.
 
 ;; commands, editing and various conversions as well as jumping
 ;; to the corresponding source file.
 
-;; inspired by Pavel Machek's patch-mode.el (<pavel@atrey.karlin.mff.cuni.cz>)
-;; some efforts were spent to have it somewhat compatible with XEmacs'
+;; Inspired by Pavel Machek's patch-mode.el (<pavel@atrey.karlin.mff.cuni.cz>)
+;; Some efforts were spent to have it somewhat compatible with XEmacs'
 ;; diff-mode as well as with compilation-minor-mode
 
-;; to use it, simply add to your .emacs the following lines:
-;; 
-;; (autoload 'diff-mode "diff-mode" "Diff major mode" t)
-;; (add-to-list 'auto-mode-alist '("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode))
-
 ;; Bugs:
 
 ;; - Reverse doesn't work with normal diffs.
@@ -173,27 +168,27 @@ when editing big diffs)."
 
 (defface diff-header-face
   '((((type tty pc) (class color) (background light))
-     (:foreground "blue1" :bold t))
+     (:foreground "blue1" :weight bold))
     (((type tty pc) (class color) (background dark))
-     (:foreground "green" :bold t))
+     (:foreground "green" :weight bold))
     (((class color) (background light))
      (:background "grey85"))
     (((class color) (background dark))
      (:background "grey45"))
-    (t (:bold t)))
+    (t (:weight bold)))
   "`diff-mode' face inherited by hunk and index header faces.")
 (defvar diff-header-face 'diff-header-face)
 
 (defface diff-file-header-face
   '((((type tty pc) (class color) (background light))
-     (:foreground "yellow" :bold t))
+     (:foreground "yellow" :weight bold))
     (((type tty pc) (class color) (background dark))
-     (:foreground "cyan" :bold t))
+     (:foreground "cyan" :weight bold))
     (((class color) (background light))
-     (:background "grey70" :bold t))
+     (:background "grey70" :weight bold))
     (((class color) (background dark))
-     (:background "grey60" :bold t))
-    (t (:bold t)))                     ; :height 1.3
+     (:background "grey60" :weight bold))
+    (t (:weight bold)))                        ; :height 1.3
   "`diff-mode' face used to highlight file header lines.")
 (defvar diff-file-header-face 'diff-file-header-face)
 
@@ -219,9 +214,9 @@ when editing big diffs)."
 
 (defface diff-changed-face
   '((((type tty pc) (class color) (background light))
-     (:foreground "magenta" :bold t :italic t))
+     (:foreground "magenta" :weight bold :slant italic))
     (((type tty pc) (class color) (background dark))
-     (:foreground "yellow" :bold t :italic t))
+     (:foreground "yellow" :weight bold :slant italic))
     (t ()))
   "`diff-mode' face used to highlight changed lines.")
 (defvar diff-changed-face 'diff-changed-face)
@@ -747,10 +742,7 @@ else cover the whole bufer."
                           (delete-char 1) (insert "-") t)
                       ((?\\ ?#) t)
                       (t (when (and first last (< first last))
-                           (let ((str
-                                  (save-excursion
-                                    (delete-and-extract-region first last))))
-                             (insert str)))
+                           (insert (delete-and-extract-region first last)))
                          (setq first nil last nil)
                          (equal ?\  c)))
                (forward-line 1))))))))))
@@ -824,7 +816,7 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
     (if diff-unhandled-changes
        (setq diff-unhandled-changes
              (cons (min beg (car diff-unhandled-changes))
-                   (max beg (cdr diff-unhandled-changes))))
+                   (max end (cdr diff-unhandled-changes))))
       (setq diff-unhandled-changes (cons beg end)))))
 
 (defun diff-post-command-hook ()
@@ -833,6 +825,8 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
     (ignore-errors
       (save-excursion
        (goto-char (car diff-unhandled-changes))
+       ;; Maybe we've cut the end of the hunk before point.
+       (if (and (bolp) (not (bobp))) (backward-char 1))
        ;; We used to fixup modifs on all the changes, but it turns out
        ;; that it's safer not to do it on big changes, for example
        ;; when yanking a big diff, since we might then screw up perfectly
@@ -849,7 +843,7 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
        (diff-beginning-of-hunk)
        (when (save-excursion
                (diff-end-of-hunk)
-               (> (point) (cdr diff-unhandled-changes)))
+               (>= (point) (cdr diff-unhandled-changes)))
          (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
     (setq diff-unhandled-changes nil)))
 
@@ -862,7 +856,13 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
   "Major mode for viewing/editing context diffs.
 Supports unified and context diffs as well as (to a lesser extent)
 normal diffs.
-When the buffer is read-only, the ESC prefix is not necessary."
+When the buffer is read-only, the ESC prefix is not necessary.
+IF you edit the buffer manually, diff-mode will try to update the hunk
+headers for you on-the-fly.
+
+You can also switch between context diff and unified diff with \\[diff-context->unified],
+or vice versa with \\[diff-unified->context] and you can also revert the direction of
+a diff with \\[diff-reverse-direction]."
   (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
   (set (make-local-variable 'outline-regexp) diff-outline-regexp)
   (set (make-local-variable 'imenu-generic-expression)
@@ -878,16 +878,25 @@ When the buffer is read-only, the ESC prefix is not necessary."
   ;;   (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
   ;; compile support
 
-  ;;;; compile support is not good enough yet.  Also it can be annoying
-  ;; and should thus only be enabled conditionally.
-  ;; (set (make-local-variable 'compilation-file-regexp-alist)
-  ;;      diff-file-regexp-alist)
-  ;; (set (make-local-variable 'compilation-error-regexp-alist)
-  ;;      diff-error-regexp-alist)
-  ;; (when (string-match "\\.rej\\'" (or buffer-file-name ""))
-  ;;   (set (make-local-variable 'compilation-current-file)
-  ;;    (substring buffer-file-name 0 (match-beginning 0))))
-  ;; (compilation-shell-minor-mode 1)
+  ;;;; compile support is not good enough yet.  It should be merged
+  ;;;; with diff.el's support.
+  (set (make-local-variable 'compilation-file-regexp-alist)
+       diff-file-regexp-alist)
+  (set (make-local-variable 'compilation-error-regexp-alist)
+       diff-error-regexp-alist)
+  (when (string-match "\\.rej\\'" (or buffer-file-name ""))
+    (set (make-local-variable 'compilation-current-file)
+        (substring buffer-file-name 0 (match-beginning 0))))
+  ;; Be careful not to change compilation-last-buffer when we're just
+  ;; doing a C-x v = (for example).
+  (if (boundp 'compilation-last-buffer)
+      (let ((compilation-last-buffer compilation-last-buffer))
+       (compilation-minor-mode 1))
+    (compilation-minor-mode 1))
+  ;; M-RET and RET should be done by diff-mode because the `compile'
+  ;; support is significantly less good.
+  (add-to-list 'minor-mode-overriding-map-alist
+              (cons 'compilation-minor-mode (make-sparse-keymap)))
 
   (when (and (> (point-max) (point-min)) diff-default-read-only)
     (toggle-read-only t))
@@ -898,7 +907,7 @@ When the buffer is read-only, the ESC prefix is not necessary."
     (add-hook 'after-change-functions 'diff-after-change-function nil t)
     (add-hook 'post-command-hook 'diff-post-command-hook nil t))
   ;; Neat trick from Dave Love to add more bindings in read-only mode:
-  (add-to-list (make-local-variable 'minor-mode-overriding-map-alist)
+  (add-to-list 'minor-mode-overriding-map-alist
               (cons 'buffer-read-only diff-mode-shared-map))
   ;; add-log support
   (set (make-local-variable 'add-log-current-defun-function)
@@ -1188,8 +1197,8 @@ For use in `add-log-current-defun-function'."
            (let ((old (if switched dst src)))
              (with-temp-buffer
                (insert (car old))
-               (goto-char (cdr old))
                (funcall (with-current-buffer buf major-mode))
+               (goto-char (+ (point-min) (cdr old)))
                (add-log-current-defun))))
          (with-current-buffer buf
            (goto-char (+ (car pos) (cdr src)))