;;; 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: convenience patch diff
(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))))))))))
(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 ()
(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
(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)))
"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)
;; (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))
(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)
(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)))