aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/diff-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/diff-mode.el')
-rw-r--r--lisp/diff-mode.el54
1 files changed, 33 insertions, 21 deletions
diff --git a/lisp/diff-mode.el b/lisp/diff-mode.el
index f6b2520a112..26ff5441baf 100644
--- a/lisp/diff-mode.el
+++ b/lisp/diff-mode.el
@@ -48,7 +48,6 @@
48;; 48;;
49;; - Refine hunk on a word-by-word basis. 49;; - Refine hunk on a word-by-word basis.
50;; 50;;
51;; - Use the new next-error-function to allow C-x `.
52;; - Handle `diff -b' output in context->unified. 51;; - Handle `diff -b' output in context->unified.
53 52
54;;; Code: 53;;; Code:
@@ -170,27 +169,27 @@ when editing big diffs)."
170;;;; 169;;;;
171 170
172(defface diff-header-face 171(defface diff-header-face
173 '((((type tty pc) (class color) (background light)) 172 '((((class color) (min-colors 88) (background light))
174 (:foreground "blue1" :weight bold))
175 (((type tty pc) (class color) (background dark))
176 (:foreground "green" :weight bold))
177 (((class color) (background light))
178 (:background "grey85")) 173 (:background "grey85"))
179 (((class color) (background dark)) 174 (((class color) (min-colors 88) (background dark))
180 (:background "grey45")) 175 (:background "grey45"))
176 (((class color) (background light))
177 (:foreground "blue1" :weight bold))
178 (((class color) (background dark))
179 (:foreground "green" :weight bold))
181 (t (:weight bold))) 180 (t (:weight bold)))
182 "`diff-mode' face inherited by hunk and index header faces.") 181 "`diff-mode' face inherited by hunk and index header faces.")
183(defvar diff-header-face 'diff-header-face) 182(defvar diff-header-face 'diff-header-face)
184 183
185(defface diff-file-header-face 184(defface diff-file-header-face
186 '((((type tty pc) (class color) (background light)) 185 '((((class color) (min-colors 88) (background light))
187 (:foreground "yellow" :weight bold))
188 (((type tty pc) (class color) (background dark))
189 (:foreground "cyan" :weight bold))
190 (((class color) (background light))
191 (:background "grey70" :weight bold)) 186 (:background "grey70" :weight bold))
192 (((class color) (background dark)) 187 (((class color) (min-colors 88) (background dark))
193 (:background "grey60" :weight bold)) 188 (:background "grey60" :weight bold))
189 (((class color) (background light))
190 (:foreground "yellow" :weight bold))
191 (((class color) (background dark))
192 (:foreground "cyan" :weight bold))
194 (t (:weight bold))) ; :height 1.3 193 (t (:weight bold))) ; :height 1.3
195 "`diff-mode' face used to highlight file header lines.") 194 "`diff-mode' face used to highlight file header lines.")
196(defvar diff-file-header-face 'diff-file-header-face) 195(defvar diff-file-header-face 'diff-file-header-face)
@@ -305,7 +304,11 @@ when editing big diffs)."
305(defvar diff-narrowed-to nil) 304(defvar diff-narrowed-to nil)
306 305
307(defun diff-end-of-hunk (&optional style) 306(defun diff-end-of-hunk (&optional style)
308 (if (looking-at diff-hunk-header-re) (goto-char (match-end 0))) 307 (when (looking-at diff-hunk-header-re)
308 (unless style
309 ;; Especially important for unified (because headers are ambiguous).
310 (setq style (cdr (assq (char-after) '((?@ . unified) (?* . context))))))
311 (goto-char (match-end 0)))
309 (let ((end (and (re-search-forward (case style 312 (let ((end (and (re-search-forward (case style
310 ;; A `unified' header is ambiguous. 313 ;; A `unified' header is ambiguous.
311 (unified (concat "^[^-+# \\]\\|" 314 (unified (concat "^[^-+# \\]\\|"
@@ -882,9 +885,14 @@ See `after-change-functions' for the meaning of BEG, END and LEN."
882 (diff-fixup-modifs (point) (cdr diff-unhandled-changes))))) 885 (diff-fixup-modifs (point) (cdr diff-unhandled-changes)))))
883 (setq diff-unhandled-changes nil))) 886 (setq diff-unhandled-changes nil)))
884 887
885;;;; 888(defun diff-next-error (arg reset)
886;;;; The main function 889 ;; Select a window that displays the current buffer so that point
887;;;; 890 ;; movements are reflected in that window. Otherwise, the user might
891 ;; never see the hunk corresponding to the source she's jumping to.
892 (pop-to-buffer (current-buffer))
893 (if reset (goto-char (point-min)))
894 (diff-hunk-next arg)
895 (diff-goto-source))
888 896
889;;;###autoload 897;;;###autoload
890(define-derived-mode diff-mode fundamental-mode "Diff" 898(define-derived-mode diff-mode fundamental-mode "Diff"
@@ -912,6 +920,7 @@ a diff with \\[diff-reverse-direction]."
912 ;; (set (make-local-variable 'paragraph-separate) paragraph-start) 920 ;; (set (make-local-variable 'paragraph-separate) paragraph-start)
913 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t") 921 ;; (set (make-local-variable 'page-delimiter) "--- [^\t]+\t")
914 ;; compile support 922 ;; compile support
923 (set (make-local-variable 'next-error-function) 'diff-next-error)
915 924
916 (when (and (> (point-max) (point-min)) diff-default-read-only) 925 (when (and (> (point-max) (point-min)) diff-default-read-only)
917 (toggle-read-only t)) 926 (toggle-read-only t))
@@ -967,7 +976,7 @@ a diff with \\[diff-reverse-direction]."
967 "Turn context diffs into unified diffs if applicable." 976 "Turn context diffs into unified diffs if applicable."
968 (if (save-excursion 977 (if (save-excursion
969 (goto-char (point-min)) 978 (goto-char (point-min))
970 (looking-at "\\*\\*\\* ")) 979 (and (looking-at diff-hunk-header-re) (eq (char-after) ?*)))
971 (let ((mod (buffer-modified-p))) 980 (let ((mod (buffer-modified-p)))
972 (unwind-protect 981 (unwind-protect
973 (diff-context->unified (point-min) (point-max)) 982 (diff-context->unified (point-min) (point-max))
@@ -1239,9 +1248,12 @@ If the prefix arg is bigger than 8 (for example with \\[universal-argument] \\[u
1239(defun diff-current-defun () 1248(defun diff-current-defun ()
1240 "Find the name of function at point. 1249 "Find the name of function at point.
1241For use in `add-log-current-defun-function'." 1250For use in `add-log-current-defun-function'."
1242 (destructuring-bind (buf line-offset pos src dst &optional switched) 1251 (save-excursion
1243 (diff-find-source-location) 1252 (when (looking-at diff-hunk-header-re)
1244 (save-excursion 1253 (forward-line 1)
1254 (while (and (looking-at " ") (not (zerop (forward-line 1))))))
1255 (destructuring-bind (buf line-offset pos src dst &optional switched)
1256 (diff-find-source-location)
1245 (beginning-of-line) 1257 (beginning-of-line)
1246 (or (when (memq (char-after) '(?< ?-)) 1258 (or (when (memq (char-after) '(?< ?-))
1247 ;; Cursor is pointing at removed text. This could be a removed 1259 ;; Cursor is pointing at removed text. This could be a removed