X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/8546720e6f25eb988e8215de6678798053031440..9a0115abd18f219f234d6dd460cf7f5ed3c0332f:/lisp/vc/diff-mode.el diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 50f20cea77..7de9d17e3f 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -1,6 +1,6 @@ ;;; 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 ;; Keywords: convenience patch diff vc @@ -146,7 +146,7 @@ when editing big diffs)." ;; but not all since they may hide useful M- 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. @@ -225,9 +225,16 @@ when editing big diffs)." "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)))) @@ -295,9 +302,14 @@ try to refine the current hunk, as well." (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) @@ -803,9 +815,11 @@ PREFIX is only used internally: don't use it." (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)))))) @@ -1136,12 +1150,14 @@ else cover the whole buffer." (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)) @@ -1299,7 +1315,11 @@ a diff with \\[diff-reverse-direction]. ;;;###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 @@ -1825,10 +1845,13 @@ For use in `add-log-current-defun-function'." (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))