Source

pcl-cvs / diff-mode.el

Full commit
;;; diff-mode.el

(defconst rcsid-diff-mode "@(#)$Name$:$Id$")

;; Copyright (C) 1998-1999  Stefan Monnier <monnier@cs.yale.edu>
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

(require 'cl)
(require 'pcl-cvs-compat)

;; Maybe I should try to merge that with Pavel Machek's patch-mode ?

(defface diff-file-header-face
  '((((class color) (background light))
     (:background "grey70" :bold t))
    (t (:bold t)))
  "diff-mode face used to highlight file header lines."
  :group 'diff-mode)
(defvar diff-file-header-face 'diff-file-header-face)
(defvar diff-index-face 'diff-file-header-face)

(defface diff-hunk-header-face
  '((((class color) (background light))
     (:background "grey85"))
    (t (:bold t)))
  "diff-mode face used to highlight hunk header lines."
  :group 'diff-mode)
(defvar diff-hunk-header-face 'diff-hunk-header-face)

(defface diff-changed-face
  '((t ()))
  "diff-mode face used to highlight changed lines."
  :group 'diff-mode)
(defvar diff-removed-face 'diff-changed-face)
(defvar diff-added-face 'diff-changed-face)
(defvar diff-changed-face 'diff-changed-face)


(defvar diff-font-lock-keywords
  '(("^@@ .+ @@$" . diff-hunk-header-face) ;unified
    ("^--- .+ ----$" . diff-hunk-header-face) ;context
    ("^\\*\\*\\*.+\\*\\*\\*\n" . diff-hunk-header-face) ;context
    ("^\\(---\\|\\+\\+\\+\\|\\*\\*\\*\\) .*\n" . diff-file-header-face)
    ("^!.*\n" . diff-changed-face)	;context
    ("^\\+.*\n" . diff-added-face)
    ("^-.*\n" . diff-removed-face)
    ("^Index: .*\n" . diff-index-face)
    ("^[^-=+*].*\n" . font-lock-comment-face)))

(defconst diff-font-lock-defaults
  '(diff-font-lock-keywords t nil nil nil))

(defvar diff-mode-map (make-sparse-keymap)
  "Keymap for diff-mode buffers.")

(defvar diff-mode-hook nil
  "Run after setting up the diff-mode major mode.")

(defvar diff-mode-load-hook nil
  "Run after loading diff-mode.")

;; to shut up the compiler
(defvar global-font-lock-mode)

;;;###autoload
(defun diff-mode ()
  "Major mode for context diffs.
\\{cvs-mode-map}"
  (interactive)
  (setq major-mode 'diff-mode)
  (setq mode-name "diff")
  (use-local-map diff-mode-map)
  (set (make-local-variable 'font-lock-defaults) diff-font-lock-defaults)
  (when (and (boundp 'global-font-lock-mode) global-font-lock-mode)
    (turn-on-font-lock))
  (run-hooks 'diff-mode-hook))

;; provide the package

(run-hooks 'diff-mode-load-hook)
(provide 'diff-mode)

;; diff-mode.el ends here