emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Diff mode faces


From: Juri Linkov
Subject: Diff mode faces
Date: Fri, 17 Jun 2005 14:47:05 +0300
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

The default diff face used to highlight changed lines on tty
(magenta/yellow bold italic) makes an indigestible fruit salad.
OTOH, the same face has no highlighting under X.  This makes
sense, because changed lines are the primary text in diff files
that doesn't need special highlighting.

I propose instead of highlighting whole lines on tty to use at least
the same approach as introduced recently for comments on tty to highlight
only comment delimiters in new face font-lock-comment-delimiter-face.
Similarly, only diff indicators (the first character of the line) could
be highlighted in diff buffers on tty.

The patch below adds three new faces for highlighting diff indicators.
On tty they inherit from font-lock-comment-delimiter-face, but on X
there is no highlighting which preserves the current default appearance.
These faces are useful not only on tty but even on window systems
where users might want to redefine them.

Also I noticed that unlike context hunk headers `--- 123 ---',
normal (i.e. neither context nor unified) hunk headers `---' are
not highlighted.  The same patch fixes that.

With -D option diff makes `#ifdef' format output with conditional
preprocessor directives.  Currently diff-mode.el uses hard-coded
font-lock-string-face to highlight them.  The patch adds a new face
to allow users to configure it.  By default, it inherits from
font-lock-preprocessor-face.

Index: lisp/diff-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/diff-mode.el,v
retrieving revision 1.75
diff -u -r1.75 diff-mode.el
--- lisp/diff-mode.el   14 Jun 2005 14:34:40 -0000      1.75
+++ lisp/diff-mode.el   17 Jun 2005 11:21:23 -0000
@@ -240,16 +240,34 @@
 (defvar diff-added-face 'diff-added)
 
 (defface diff-changed
-  '((((type tty pc) (class color) (background light))
-     :foreground "magenta" :weight bold :slant italic)
-    (((type tty pc) (class color) (background dark))
-     :foreground "yellow" :weight bold :slant italic))
+  nil
   "`diff-mode' face used to highlight changed lines."
   :group 'diff-mode)
 ;; backward-compatibility alias
 (put 'diff-changed-face 'face-alias 'diff-changed)
 (defvar diff-changed-face 'diff-changed)
 
+(defface diff-indicator-removed
+  '((t :inherit diff-indicator-changed))
+  "`diff-mode' face used to highlight indicator of removed lines (-, <)."
+  :group 'diff-mode
+  :version "22.1")
+(defvar diff-indicator-removed-face 'diff-indicator-removed)
+
+(defface diff-indicator-added
+  '((t :inherit diff-indicator-changed))
+  "`diff-mode' face used to highlight indicator of added lines (+, >)."
+  :group 'diff-mode
+  :version "22.1")
+(defvar diff-indicator-added-face 'diff-indicator-added)
+
+(defface diff-indicator-changed
+  '((((type tty pc) (class color)) :inherit font-lock-comment-delimiter-face))
+  "`diff-mode' face used to highlight indicator of changed lines."
+  :group 'diff-mode
+  :version "22.1")
+(defvar diff-indicator-changed-face 'diff-indicator-changed)
+
 (defface diff-function
   '((t :inherit diff-context))
   "`diff-mode' face used to highlight function names produced by \"diff -p\"."
@@ -274,6 +292,13 @@
 (put 'diff-nonexistent-face 'face-alias 'diff-nonexistent)
 (defvar diff-nonexistent-face 'diff-nonexistent)
 
+(defface diff-preprocessor
+  '((t :inherit  font-lock-preprocessor-face))
+  "`diff-mode' face used to highlight preprocessor lines staring with #."
+  :group 'diff-mode
+  :version "22.1")
+(defvar diff-preprocessor-face 'diff-preprocessor)
+
 (defconst diff-yank-handler '(diff-yank-function))
 (defun diff-yank-function (text)
   ;; FIXME: the yank-handler is now called separately on each piece of text
@@ -306,15 +331,16 @@
      (1 diff-hunk-header-face)
      (2 diff-function-face))
     ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-hunk-header-face) ;context
+    ("^---$" . diff-hunk-header-face) ; normal
     ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)\\(.*[^*-]\\)?\n"
      (0 diff-header-face) (2 diff-file-header-face prepend))
     ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face)
-    ("^!.*\n" (0 diff-changed-face))
-    ("^[+>].*\n" (0 diff-added-face))
-    ("^[-<].*\n" (0 diff-removed-face))
+    ("^\\([-<]\\)\\(.*\n\\)" (1 diff-indicator-removed-face) (2 
diff-removed-face))
+    ("^\\([+>]\\)\\(.*\n\\)" (1 diff-indicator-added-face) (2 diff-added-face))
+    ("^\\(!\\)\\(.*\n\\)" (1 diff-indicator-changed-face) (2 
diff-changed-face))
     ("^Index: \\(.+\\).*\n" (0 diff-header-face) (1 diff-index-face prepend))
     ("^Only in .*\n" . diff-nonexistent-face)
-    ("^#.*" . font-lock-string-face)
+    ("^#.*" . diff-preprocessor-face)
     ("^[^-=+*!<>].*\n" (0 diff-context-face))))
 
 (defconst diff-font-lock-defaults

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]