;;; diff-mode.el --- a mode for viewing/editing context diffs -*- lexical-binding: t -*-
-;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
;; Keywords: convenience patch diff vc
;; but not all since they may hide useful M-<foo> global
;; bindings when editing.
(set-keymap-parent map diff-mode-shared-map)
- (dolist (key '("A" "r" "R" "g" "q" "W"))
+ (dolist (key '("A" "r" "R" "g" "q" "W" "z"))
(define-key map key nil))
map))
;; From compilation-minor-mode.
"Keymap for `diff-minor-mode'. See also `diff-mode-shared-map'.")
(define-minor-mode diff-auto-refine-mode
- "Automatically highlight changes in detail as the user visits hunks.
-When transitioning from disabled to enabled,
-try to refine the current hunk, as well."
+ "Toggle automatic diff hunk highlighting (Diff Auto Refine mode).
+With a prefix argument ARG, enable Diff Auto Refine mode if ARG
+is positive, and disable it otherwise. If called from Lisp,
+enable the mode if ARG is omitted or nil.
+
+Diff Auto Refine mode is a buffer-local minor mode used with
+`diff-mode'. When enabled, Emacs automatically highlights
+changes in detail as the user visits hunks. When transitioning
+from disabled to enabled, it tries to refine the current hunk, as
+well."
:group 'diff-mode :init-value t :lighter nil ;; " Auto-Refine"
(when diff-auto-refine-mode
(condition-case-no-debug nil (diff-refine-hunk) (error nil))))
(defvar diff-added-face 'diff-added)
(defface diff-changed
- '((((type tty pc) (class color) (background light))
+ ;; We normally apply a `shadow'-based face on the `diff-context'
+ ;; face, and keep `diff-changed' the default.
+ '((((class color grayscale) (min-colors 88)))
+ ;; If the terminal lacks sufficient colors for shadowing,
+ ;; highlight changed lines explicitly.
+ (((class color) (background light))
:foreground "magenta" :weight bold :slant italic)
- (((type tty pc) (class color) (background dark))
+ (((class color) (background dark))
:foreground "yellow" :weight bold :slant italic))
"`diff-mode' face used to highlight changed lines."
:group 'diff-mode)
(diff-find-file-name old noprompt (match-string 1)))
;; if all else fails, ask the user
(unless noprompt
- (let ((file (read-file-name (format "Use file %s: "
- (or (first fs) ""))
- nil (first fs) t (first fs))))
+ (let ((file (expand-file-name (or (first fs) ""))))
+ (setq file
+ (read-file-name (format "Use file %s: " file)
+ (file-name-directory file) file t
+ (file-name-nondirectory file)))
(set (make-local-variable 'diff-remembered-files-alist)
(cons (cons fs file) diff-remembered-files-alist))
file))))))
(old2 (match-string 4))
(new1 (number-to-string (+ space minus)))
(new2 (number-to-string (+ space plus))))
- (if old2
- (unless (string= new2 old2) (replace-match new2 t t nil 4))
- (goto-char (match-end 4)) (insert "," new2))
- (if old1
- (unless (string= new1 old1) (replace-match new1 t t nil 2))
- (goto-char (match-end 2)) (insert "," new1))))
+ (if old2
+ (unless (string= new2 old2) (replace-match new2 t t nil 4))
+ (goto-char (match-end 3))
+ (insert "," new2))
+ (if old1
+ (unless (string= new1 old1) (replace-match new1 t t nil 2))
+ (goto-char (match-end 1))
+ (insert "," new1))))
((looking-at diff-context-mid-hunk-header-re)
(when (> (+ space bang plus) 0)
(let* ((old1 (match-string 1))
;;;###autoload
(define-minor-mode diff-minor-mode
- "Minor mode for viewing/editing context diffs.
+ "Toggle Diff minor mode.
+With a prefix argument ARG, enable Diff minor mode if ARG is
+positive, and disable it otherwise. If called from Lisp, enable
+the mode if ARG is omitted or nil.
+
\\{diff-minor-mode-map}"
:group 'diff-mode :lighter " Diff"
;; FIXME: setup font-lock
(replace-match (cdr (assq (char-before) '((?+ . "-") (?> . "<"))))))
)
+(declare-function smerge-refine-subst "smerge-mode"
+ (beg1 end1 beg2 end2 props &optional preproc))
+
(defun diff-refine-hunk ()
"Highlight changes of hunk at point at a finer granularity."
(interactive)
- (eval-and-compile (require 'smerge-mode))
+ (require 'smerge-mode)
(save-excursion
(diff-beginning-of-hunk 'try-harder)
(let* ((start (point))