Mercurial > dotfiles
comparison .elisp/diff-mode-.el @ 32:dc1c584707e6
Add some colorized diff stuff to emacs.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Fri, 09 Jan 2009 11:28:24 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
31:a5691a22c92b | 32:dc1c584707e6 |
---|---|
1 ;;; diff-mode-.el --- Extensions to `diff-mode.el'. | |
2 ;; | |
3 ;; Filename: diff-mode-.el | |
4 ;; Description: Extensions to `diff-mode.el'. | |
5 ;; Author: Drew Adams | |
6 ;; Maintainer: Drew Adams | |
7 ;; Copyright (C) 2004-2009, Drew Adams, all rights reserved. | |
8 ;; Created: Mon Nov 08 16:36:09 2004 | |
9 ;; Version: 21.0 | |
10 ;; Last-Updated: Sat Dec 27 10:19:33 2008 (-0800) | |
11 ;; By: dradams | |
12 ;; Update #: 646 | |
13 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/diff-mode-.el | |
14 ;; Keywords: data, matching, tools, unix, local, font, face | |
15 ;; Compatibility: GNU Emacs 21.x, GNU Emacs 22.x | |
16 ;; | |
17 ;; Features that might be required by this library: | |
18 ;; | |
19 ;; None | |
20 ;; | |
21 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
22 ;; | |
23 ;;; Commentary: | |
24 ;; | |
25 ;; Extensions to `diff-mode.el'. | |
26 ;; | |
27 ;; "*Diff*" buffer is highlighted differently. | |
28 ;; | |
29 ;; NOTE: The faces defined here look best on a medium-dark | |
30 ;; background, because some are light and some are dark. | |
31 ;; Try, for example, setting the background to "LightSteelBlue" | |
32 ;; in your `~/.emacs' file: You can do this is via | |
33 ;; `special-display-buffer-names': | |
34 ;; | |
35 ;; (setq special-display-buffer-names | |
36 ;; (cons '("*Diff*" (background-color . "LightSteelBlue")) | |
37 ;; special-display-buffer-names)) | |
38 ;; | |
39 ;; You can alternatively change the background value of | |
40 ;; `special-display-frame-alist' and set | |
41 ;; `special-display-regexps' to something matching "*info*": | |
42 ;; | |
43 ;; (setq special-display-frame-alist | |
44 ;; (cons '(background-color . "LightSteelBlue") | |
45 ;; special-display-frame-alist)) | |
46 ;; (setq special-display-regexps '("[ ]?[*][^*]+[*]")) | |
47 ;; | |
48 ;; | |
49 ;; New faces defined here: | |
50 ;; | |
51 ;; `diff-file1-hunk-header', `diff-file2-hunk-header'. | |
52 ;; | |
53 ;; New user options defined here: | |
54 ;; | |
55 ;; `diff-file1-hunk-header-face', `diff-file2-hunk-header-face'. | |
56 ;; | |
57 ;; | |
58 ;; ***** NOTE: The following faces defined in `diff-mode.el' have | |
59 ;; been REDEFINED HERE: | |
60 ;; | |
61 ;; `diff-added', `diff-changed', `diff-context', | |
62 ;; `diff-file-header', `diff-header', `diff-hunk-header', | |
63 ;; `diff-index', `diff-indicator-added', `diff-indicator-changed', | |
64 ;; `diff-indicator-removed', `diff-nonexistent', `diff-removed'. | |
65 ;; | |
66 ;; | |
67 ;; ***** NOTE: The following variable defined in `diff-mode.el' has | |
68 ;; been REDEFINED HERE: | |
69 ;; | |
70 ;; `diff-font-lock-keywords'. | |
71 ;; | |
72 ;; | |
73 ;; This library should be loaded *before* library `diff-mode.el'. | |
74 ;; Put this in your initialization file, `~/.emacs': | |
75 ;; (require 'diff-mode-) | |
76 ;; | |
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
78 ;; | |
79 ;;; Change log: | |
80 ;; | |
81 ;; 2008/01/01 dadams | |
82 ;; Added :group for deffaces. | |
83 ;; 2006/01/04 dadams | |
84 ;; Updated to use new Emacs 22 face names for indicator faces. | |
85 ;; Thanks to Juri Linkov for the letting me know about the new faces. | |
86 ;; Updated diff-font-lock-keywords to be = Emacs 22, except for file name. | |
87 ;; 2006/01/01 dadams | |
88 ;; Renamed faces, without "-face". | |
89 ;; | |
90 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
91 ;; | |
92 ;; This program is free software; you can redistribute it and/or modify | |
93 ;; it under the terms of the GNU General Public License as published by | |
94 ;; the Free Software Foundation; either version 2, or (at your option) | |
95 ;; any later version. | |
96 | |
97 ;; This program is distributed in the hope that it will be useful, | |
98 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
99 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
100 ;; GNU General Public License for more details. | |
101 | |
102 ;; You should have received a copy of the GNU General Public License | |
103 ;; along with this program; see the file COPYING. If not, write to | |
104 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth | |
105 ;; Floor, Boston, MA 02110-1301, USA. | |
106 ;; | |
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
108 ;; | |
109 ;;; Code: | |
110 | |
111 ;;;;;;;;;;;;;;;;;;;;;;;; | |
112 | |
113 | |
114 ;;; Define some additional faces. | |
115 (defface diff-file1-hunk-header | |
116 '((t (:foreground "Blue" :background "DarkSeaGreen1"))) | |
117 "Face used to highlight a diff hunk for the first `diff' argument." | |
118 :group 'diff-mode) | |
119 (defvar diff-file1-hunk-header-face 'diff-file1-hunk-header) | |
120 | |
121 (defface diff-file2-hunk-header | |
122 '((t (:foreground "Red" :background "PaleGoldenrod"))) | |
123 "Face used to highlight a diff hunk for the second `diff' argument." | |
124 :group 'diff-mode) | |
125 (defvar diff-file2-hunk-header-face 'diff-file2-hunk-header) | |
126 | |
127 ;;; These faces are standard in Emacs 22, but they are new for Emacs 21. | |
128 (defface diff-indicator-changed | |
129 '((t (:foreground "PaleGoldenrod" :background "MediumBlue"))) | |
130 "*Face used to highlight the line-start indicator of a modified line." | |
131 :group 'diff-mode) | |
132 (defvar diff-indicator-changed-face 'diff-indicator-changed) | |
133 | |
134 (defface diff-indicator-added | |
135 '((t (:foreground "PaleGoldenrod" :background "DarkGreen"))) | |
136 "*Face used to highlight the line-start indicator of an inserted line." | |
137 :group 'diff-mode) | |
138 (defvar diff-indicator-added-face 'diff-indicator-added) | |
139 | |
140 (defface diff-indicator-removed | |
141 '((t (:foreground "PaleGoldenrod" :background "DarkMagenta"))) | |
142 "*Face used to highlight the line-start indicator of a removed line." | |
143 :group 'diff-mode) | |
144 (defvar diff-indicator-removed-face 'diff-indicator-removed) | |
145 | |
146 ;;; Change existing `diff-mode' faces too. | |
147 (custom-set-faces | |
148 '(diff-added ((t (:foreground "DarkGreen"))) 'now) | |
149 '(diff-changed ((t (:foreground "MediumBlue"))) 'now) | |
150 '(diff-context ((t (:foreground "LightSteelBlue"))) 'now) | |
151 '(diff-file-header ((t (:foreground "White"))) 'now) | |
152 '(diff-header ((t (:foreground "White"))) 'now) | |
153 '(diff-hunk-header ((t (:foreground "White"))) 'now) | |
154 '(diff-index ((t (:foreground "Green"))) 'now) | |
155 '(diff-nonexistent ((t (:foreground "DarkBlue"))) 'now) | |
156 '(diff-removed ((t (:foreground "Red"))) 'now) | |
157 ) | |
158 | |
159 ;;; The only real difference here now from the standard Emacs 22 version is the | |
160 ;;; use of diff-file1* and diff-file2*. | |
161 (defvar diff-font-lock-keywords | |
162 `( | |
163 ("^\\(@@ -[0-9,]+ \\+[0-9,]+ @@\\)\\(.*\\)$" ;unified | |
164 (1 diff-hunk-header-face) (2 diff-function-face)) | |
165 ("^\\(\\*\\{15\\}\\)\\(.*\\)$" ;context | |
166 (1 diff-hunk-header-face) (2 diff-function-face)) | |
167 ("^\\*\\*\\* .+ \\*\\*\\*\\*". diff-file1-hunk-header-face) ;context | |
168 ("^--- .+ ----$" . diff-file2-hunk-header-face) ;context | |
169 ("^[0-9,]+[acd][0-9,]+$" . diff-hunk-header-face) ; normal | |
170 ("^---$" . diff-hunk-header-face) ;normal | |
171 ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) \\(\\S-+\\)\\(.*[^*-]\\)?\n" | |
172 (0 diff-header-face) (2 diff-file-header-face prepend)) | |
173 ("^\\([-<]\\)\\(.*\n\\)" (1 diff-indicator-removed-face) (2 diff-removed-face)) | |
174 ("^\\([+>]\\)\\(.*\n\\)" (1 diff-indicator-added-face) (2 diff-added-face)) | |
175 ("^\\(!\\)\\(.*\n\\)" (1 diff-indicator-changed-face) (2 diff-changed-face)) | |
176 ("^Index: \\(.+\\).*\n" (0 diff-header-face) (1 diff-index-face prepend)) | |
177 ("^Only in .*\n" . diff-nonexistent-face) | |
178 ("^\\(#\\)\\(.*\\)" | |
179 (1 (if (facep 'font-lock-comment-delimiter-face) | |
180 'font-lock-comment-face)) | |
181 (2 font-lock-comment-face)) | |
182 ("^[^-=+*!<>#].*\n" (0 diff-context-face)))) | |
183 | |
184 ;;;;;;;;;;;;;;;;;;;;;;; | |
185 | |
186 (provide 'diff-mode-) | |
187 | |
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
189 ;;; diff-mode-.el ends here |