diff options
| author | Juri Linkov | 2012-05-25 03:55:40 +0300 |
|---|---|---|
| committer | Juri Linkov | 2012-05-25 03:55:40 +0300 |
| commit | bc1b21bb4e3594708570a1f503f69b8acc1e6814 (patch) | |
| tree | 37a4e07a7c186ee88c3d86caa0c3ebdb4052bc66 /lisp/vc/diff-mode.el | |
| parent | 532f361c96162f1a90756b2276f3091b1c273f23 (diff) | |
| download | emacs-bc1b21bb4e3594708570a1f503f69b8acc1e6814.tar.gz emacs-bc1b21bb4e3594708570a1f503f69b8acc1e6814.zip | |
Use the same diff color scheme as in modern VCSes (bug#10181).
* lisp/vc/diff-mode.el (diff-header, diff-file-header): Remove "green"
to avoid confusion with `diff-added' that now uses green colors.
(diff-removed): Use shades of red.
(diff-added): Use shades of green.
(diff-changed): Leave just the yellow color.
(diff-use-changed-face): New variable.
(diff-font-lock-keywords): Use `diff-use-changed-face' to decide
how to highlight context diff changes.
(diff-refine-change): Use shades of yellow.
(diff-refine-removed): New face that uses shades of red.
(diff-refine-added): New face that uses shades of green.
(diff-refine-hunk): Use `diff-refine-change', `diff-refine-added',
`diff-refine-removed' in the call to `smerge-refine-subst'
depending on the value of `diff-use-changed-face'.
* lisp/vc/ediff-init.el (ediff-current-diff-A, ediff-fine-diff-A):
Add face condition `min-colors 88' with shades of red.
(ediff-current-diff-B, ediff-fine-diff-B): Add face condition
`min-colors 88' with shades of green.
(ediff-current-diff-C, ediff-fine-diff-C): Add face condition
`min-colors 88' with shades of yellow.
* lisp/vc/smerge-mode.el (smerge-mine): Use shades of red.
(smerge-other): Use shades of green.
(smerge-base): Use shades of yellow.
(smerge-refined-change): Empty face.
(smerge-refined-removed): New face that uses shades of red.
(smerge-refined-added): New face that uses shades of green.
(smerge-refine-subst): Rename arg `props' to `props-c'. Add new
args `props-r' and `props-a', and use them. Doc fix.
(smerge-refine): Evaluate `smerge-use-changed-face' and depending
on its value use different faces `smerge-refined-change',
`smerge-refined-removed', `smerge-refined-added' in the call to
`smerge-refine-subst'.
Diffstat (limited to 'lisp/vc/diff-mode.el')
| -rw-r--r-- | lisp/vc/diff-mode.el | 107 |
1 files changed, 81 insertions, 26 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index f3f7d8ce61b..9034ffe520f 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -237,10 +237,8 @@ well." | |||
| 237 | :background "grey80") | 237 | :background "grey80") |
| 238 | (((class color) (min-colors 88) (background dark)) | 238 | (((class color) (min-colors 88) (background dark)) |
| 239 | :background "grey45") | 239 | :background "grey45") |
| 240 | (((class color) (background light)) | 240 | (((class color)) |
| 241 | :foreground "blue1" :weight bold) | 241 | :foreground "blue1" :weight bold) |
| 242 | (((class color) (background dark)) | ||
| 243 | :foreground "green" :weight bold) | ||
| 244 | (t :weight bold)) | 242 | (t :weight bold)) |
| 245 | "`diff-mode' face inherited by hunk and index header faces." | 243 | "`diff-mode' face inherited by hunk and index header faces." |
| 246 | :group 'diff-mode) | 244 | :group 'diff-mode) |
| @@ -252,9 +250,7 @@ well." | |||
| 252 | :background "grey70" :weight bold) | 250 | :background "grey70" :weight bold) |
| 253 | (((class color) (min-colors 88) (background dark)) | 251 | (((class color) (min-colors 88) (background dark)) |
| 254 | :background "grey60" :weight bold) | 252 | :background "grey60" :weight bold) |
| 255 | (((class color) (background light)) | 253 | (((class color)) |
| 256 | :foreground "green" :weight bold) | ||
| 257 | (((class color) (background dark)) | ||
| 258 | :foreground "cyan" :weight bold) | 254 | :foreground "cyan" :weight bold) |
| 259 | (t :weight bold)) ; :height 1.3 | 255 | (t :weight bold)) ; :height 1.3 |
| 260 | "`diff-mode' face used to highlight file header lines." | 256 | "`diff-mode' face used to highlight file header lines." |
| @@ -277,14 +273,28 @@ well." | |||
| 277 | (defvar diff-hunk-header-face 'diff-hunk-header) | 273 | (defvar diff-hunk-header-face 'diff-hunk-header) |
| 278 | 274 | ||
| 279 | (defface diff-removed | 275 | (defface diff-removed |
| 280 | '((t :inherit diff-changed)) | 276 | '((default |
| 277 | :inherit diff-changed) | ||
| 278 | (((class color) (min-colors 88) (background light)) | ||
| 279 | :background "#ffdddd") | ||
| 280 | (((class color) (min-colors 88) (background dark)) | ||
| 281 | :background "#553333") | ||
| 282 | (((class color)) | ||
| 283 | :foreground "red")) | ||
| 281 | "`diff-mode' face used to highlight removed lines." | 284 | "`diff-mode' face used to highlight removed lines." |
| 282 | :group 'diff-mode) | 285 | :group 'diff-mode) |
| 283 | (define-obsolete-face-alias 'diff-removed-face 'diff-removed "22.1") | 286 | (define-obsolete-face-alias 'diff-removed-face 'diff-removed "22.1") |
| 284 | (defvar diff-removed-face 'diff-removed) | 287 | (defvar diff-removed-face 'diff-removed) |
| 285 | 288 | ||
| 286 | (defface diff-added | 289 | (defface diff-added |
| 287 | '((t :inherit diff-changed)) | 290 | '((default |
| 291 | :inherit diff-changed) | ||
| 292 | (((class color) (min-colors 88) (background light)) | ||
| 293 | :background "#ddffdd") | ||
| 294 | (((class color) (min-colors 88) (background dark)) | ||
| 295 | :background "#335533") | ||
| 296 | (((class color)) | ||
| 297 | :foreground "green")) | ||
| 288 | "`diff-mode' face used to highlight added lines." | 298 | "`diff-mode' face used to highlight added lines." |
| 289 | :group 'diff-mode) | 299 | :group 'diff-mode) |
| 290 | (define-obsolete-face-alias 'diff-added-face 'diff-added "22.1") | 300 | (define-obsolete-face-alias 'diff-added-face 'diff-added "22.1") |
| @@ -296,10 +306,8 @@ well." | |||
| 296 | '((((class color grayscale) (min-colors 88))) | 306 | '((((class color grayscale) (min-colors 88))) |
| 297 | ;; If the terminal lacks sufficient colors for shadowing, | 307 | ;; If the terminal lacks sufficient colors for shadowing, |
| 298 | ;; highlight changed lines explicitly. | 308 | ;; highlight changed lines explicitly. |
| 299 | (((class color) (background light)) | 309 | (((class color)) |
| 300 | :foreground "magenta" :weight bold :slant italic) | 310 | :foreground "yellow")) |
| 301 | (((class color) (background dark)) | ||
| 302 | :foreground "yellow" :weight bold :slant italic)) | ||
| 303 | "`diff-mode' face used to highlight changed lines." | 311 | "`diff-mode' face used to highlight changed lines." |
| 304 | :group 'diff-mode) | 312 | :group 'diff-mode) |
| 305 | (define-obsolete-face-alias 'diff-changed-face 'diff-changed "22.1") | 313 | (define-obsolete-face-alias 'diff-changed-face 'diff-changed "22.1") |
| @@ -374,6 +382,13 @@ well." | |||
| 374 | (defconst diff-context-mid-hunk-header-re | 382 | (defconst diff-context-mid-hunk-header-re |
| 375 | "--- \\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$") | 383 | "--- \\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? ----$") |
| 376 | 384 | ||
| 385 | (defvar diff-use-changed-face (and (face-differs-from-default-p diff-changed-face) | ||
| 386 | (not (face-equal diff-changed-face diff-added-face)) | ||
| 387 | (not (face-equal diff-changed-face diff-removed-face))) | ||
| 388 | "If non-nil, use the face `diff-changed' for changed lines in context diffs. | ||
| 389 | Otherwise, use the face `diff-removed' for removed lines, | ||
| 390 | and the face `diff-added' for added lines.") | ||
| 391 | |||
| 377 | (defvar diff-font-lock-keywords | 392 | (defvar diff-font-lock-keywords |
| 378 | `((,(concat "\\(" diff-hunk-header-re-unified "\\)\\(.*\\)$") | 393 | `((,(concat "\\(" diff-hunk-header-re-unified "\\)\\(.*\\)$") |
| 379 | (1 diff-hunk-header-face) (6 diff-function-face)) | 394 | (1 diff-hunk-header-face) (6 diff-function-face)) |
| @@ -393,8 +408,25 @@ well." | |||
| 393 | ("^\\([+>]\\)\\(.*\n\\)" | 408 | ("^\\([+>]\\)\\(.*\n\\)" |
| 394 | (1 diff-indicator-added-face) (2 diff-added-face)) | 409 | (1 diff-indicator-added-face) (2 diff-added-face)) |
| 395 | ("^\\(!\\)\\(.*\n\\)" | 410 | ("^\\(!\\)\\(.*\n\\)" |
| 396 | (1 diff-indicator-changed-face) (2 diff-changed-face)) | 411 | (1 (if diff-use-changed-face |
| 397 | ("^Index: \\(.+\\).*\n" | 412 | diff-indicator-changed-face |
| 413 | ;; Otherwise, search for `diff-context-mid-hunk-header-re' and | ||
| 414 | ;; if the line of context diff is above, use `diff-removed-face'; | ||
| 415 | ;; if below, use `diff-added-face'. | ||
| 416 | (save-match-data | ||
| 417 | (let ((limit (save-excursion (diff-beginning-of-hunk)))) | ||
| 418 | (if (save-excursion (re-search-backward diff-context-mid-hunk-header-re limit t)) | ||
| 419 | diff-indicator-added-face | ||
| 420 | diff-indicator-removed-face))))) | ||
| 421 | (2 (if diff-use-changed-face | ||
| 422 | diff-changed-face | ||
| 423 | ;; Otherwise, use the same method as above. | ||
| 424 | (save-match-data | ||
| 425 | (let ((limit (save-excursion (diff-beginning-of-hunk)))) | ||
| 426 | (if (save-excursion (re-search-backward diff-context-mid-hunk-header-re limit t)) | ||
| 427 | diff-added-face | ||
| 428 | diff-removed-face)))))) | ||
| 429 | ("^\\(?:Index\\|revno\\): \\(.+\\).*\n" | ||
| 398 | (0 diff-header-face) (1 diff-index-face prepend)) | 430 | (0 diff-header-face) (1 diff-index-face prepend)) |
| 399 | ("^Only in .*\n" . diff-nonexistent-face) | 431 | ("^Only in .*\n" . diff-nonexistent-face) |
| 400 | ("^\\(#\\)\\(.*\\)" | 432 | ("^\\(#\\)\\(.*\\)" |
| @@ -1847,17 +1879,35 @@ For use in `add-log-current-defun-function'." | |||
| 1847 | 1879 | ||
| 1848 | (defface diff-refine-change | 1880 | (defface diff-refine-change |
| 1849 | '((((class color) (min-colors 88) (background light)) | 1881 | '((((class color) (min-colors 88) (background light)) |
| 1850 | :background "grey85") | 1882 | :background "#ffff55") |
| 1851 | (((class color) (min-colors 88) (background dark)) | 1883 | (((class color) (min-colors 88) (background dark)) |
| 1852 | :background "grey60") | 1884 | :background "#aaaa22") |
| 1853 | (((class color) (background light)) | 1885 | (t :inverse-video t)) |
| 1854 | :background "yellow") | ||
| 1855 | (((class color) (background dark)) | ||
| 1856 | :background "green") | ||
| 1857 | (t :weight bold)) | ||
| 1858 | "Face used for char-based changes shown by `diff-refine-hunk'." | 1886 | "Face used for char-based changes shown by `diff-refine-hunk'." |
| 1859 | :group 'diff-mode) | 1887 | :group 'diff-mode) |
| 1860 | 1888 | ||
| 1889 | (defface diff-refine-removed | ||
| 1890 | '((default | ||
| 1891 | :inherit diff-refine-change) | ||
| 1892 | (((class color) (min-colors 88) (background light)) | ||
| 1893 | :background "#ffaaaa") | ||
| 1894 | (((class color) (min-colors 88) (background dark)) | ||
| 1895 | :background "#aa2222")) | ||
| 1896 | "Face used for removed characters shown by `diff-refine-hunk'." | ||
| 1897 | :group 'diff-mode | ||
| 1898 | :version "24.2") | ||
| 1899 | |||
| 1900 | (defface diff-refine-added | ||
| 1901 | '((default | ||
| 1902 | :inherit diff-refine-change) | ||
| 1903 | (((class color) (min-colors 88) (background light)) | ||
| 1904 | :background "#aaffaa") | ||
| 1905 | (((class color) (min-colors 88) (background dark)) | ||
| 1906 | :background "#22aa22")) | ||
| 1907 | "Face used for added characters shown by `diff-refine-hunk'." | ||
| 1908 | :group 'diff-mode | ||
| 1909 | :version "24.2") | ||
| 1910 | |||
| 1861 | (defun diff-refine-preproc () | 1911 | (defun diff-refine-preproc () |
| 1862 | (while (re-search-forward "^[+>]" nil t) | 1912 | (while (re-search-forward "^[+>]" nil t) |
| 1863 | ;; Remove spurious changes due to the fact that one side of the hunk is | 1913 | ;; Remove spurious changes due to the fact that one side of the hunk is |
| @@ -1871,7 +1921,7 @@ For use in `add-log-current-defun-function'." | |||
| 1871 | ) | 1921 | ) |
| 1872 | 1922 | ||
| 1873 | (declare-function smerge-refine-subst "smerge-mode" | 1923 | (declare-function smerge-refine-subst "smerge-mode" |
| 1874 | (beg1 end1 beg2 end2 props &optional preproc)) | 1924 | (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)) |
| 1875 | 1925 | ||
| 1876 | (defun diff-refine-hunk () | 1926 | (defun diff-refine-hunk () |
| 1877 | "Highlight changes of hunk at point at a finer granularity." | 1927 | "Highlight changes of hunk at point at a finer granularity." |
| @@ -1882,7 +1932,9 @@ For use in `add-log-current-defun-function'." | |||
| 1882 | (let* ((start (point)) | 1932 | (let* ((start (point)) |
| 1883 | (style (diff-hunk-style)) ;Skips the hunk header as well. | 1933 | (style (diff-hunk-style)) ;Skips the hunk header as well. |
| 1884 | (beg (point)) | 1934 | (beg (point)) |
| 1885 | (props '((diff-mode . fine) (face diff-refine-change))) | 1935 | (props-c '((diff-mode . fine) (face diff-refine-change))) |
| 1936 | (props-r '((diff-mode . fine) (face diff-refine-removed))) | ||
| 1937 | (props-a '((diff-mode . fine) (face diff-refine-added))) | ||
| 1886 | ;; Be careful to go back to `start' so diff-end-of-hunk gets | 1938 | ;; Be careful to go back to `start' so diff-end-of-hunk gets |
| 1887 | ;; to read the hunk header's line info. | 1939 | ;; to read the hunk header's line info. |
| 1888 | (end (progn (goto-char start) (diff-end-of-hunk) (point)))) | 1940 | (end (progn (goto-char start) (diff-end-of-hunk) (point)))) |
| @@ -1896,7 +1948,7 @@ For use in `add-log-current-defun-function'." | |||
| 1896 | end t) | 1948 | end t) |
| 1897 | (smerge-refine-subst (match-beginning 0) (match-end 1) | 1949 | (smerge-refine-subst (match-beginning 0) (match-end 1) |
| 1898 | (match-end 1) (match-end 0) | 1950 | (match-end 1) (match-end 0) |
| 1899 | props 'diff-refine-preproc))) | 1951 | nil 'diff-refine-preproc props-r props-a))) |
| 1900 | (context | 1952 | (context |
| 1901 | (let* ((middle (save-excursion (re-search-forward "^---"))) | 1953 | (let* ((middle (save-excursion (re-search-forward "^---"))) |
| 1902 | (other middle)) | 1954 | (other middle)) |
| @@ -1908,14 +1960,17 @@ For use in `add-log-current-defun-function'." | |||
| 1908 | (setq other (match-end 0)) | 1960 | (setq other (match-end 0)) |
| 1909 | (match-beginning 0)) | 1961 | (match-beginning 0)) |
| 1910 | other | 1962 | other |
| 1911 | props 'diff-refine-preproc)))) | 1963 | (if diff-use-changed-face props-c) |
| 1964 | 'diff-refine-preproc | ||
| 1965 | (unless diff-use-changed-face props-r) | ||
| 1966 | (unless diff-use-changed-face props-a))))) | ||
| 1912 | (t ;; Normal diffs. | 1967 | (t ;; Normal diffs. |
| 1913 | (let ((beg1 (1+ (point)))) | 1968 | (let ((beg1 (1+ (point)))) |
| 1914 | (when (re-search-forward "^---.*\n" end t) | 1969 | (when (re-search-forward "^---.*\n" end t) |
| 1915 | ;; It's a combined add&remove, so there's something to do. | 1970 | ;; It's a combined add&remove, so there's something to do. |
| 1916 | (smerge-refine-subst beg1 (match-beginning 0) | 1971 | (smerge-refine-subst beg1 (match-beginning 0) |
| 1917 | (match-end 0) end | 1972 | (match-end 0) end |
| 1918 | props 'diff-refine-preproc)))))))) | 1973 | nil 'diff-refine-preproc props-r props-a)))))))) |
| 1919 | 1974 | ||
| 1920 | (defun diff-undo (&optional arg) | 1975 | (defun diff-undo (&optional arg) |
| 1921 | "Perform `undo', ignoring the buffer's read-only status." | 1976 | "Perform `undo', ignoring the buffer's read-only status." |