; ; unidiff.el -- major mode for diff files in unified format. ; ; Copyright (c) Andrew W. Nosenko , 2000-2001 ; ; You can redistribute this file and/or modify it under the terms of ; the GNU General Public License as published by the Free Software ; Foundation; either version 2, or (at your option) any later version. ; ; How to add to auto-mode alist (example): insert next code ; into ~/.emacs file: ; ; (setq auto-mode-alist ; (append '(("diff$" . unidiff-mode) ; ("\\.patch$" . unidiff-mode) ; ("^patch-" . unidiff-mode)) ; auto-mode-alist)) ; (defvar unidiff-mode-map nil "Unidiff mode keymap") ; Create a mode-specific keymap. (if unidiff-mode-map () ; don't change mode-map if already set (setq unidiff-mode-map (make-sparse-keymap)) (define-key unidiff-mode-map "\M-p" 'unidiff-go-prev-chunk) (define-key unidiff-mode-map "\M-n" 'unidiff-go-next-chunk) (define-key unidiff-mode-map "\M-{" 'unidiff-go-prev-file) (define-key unidiff-mode-map "\M-}" 'unidiff-go-next-file) ) (defvar unidiff-mode-abbrev-table nil "Unidiff mode abbrev table") (defgroup unidiff-faces () ; initial members "Unidiff Mode Faces" :group 'faces ) (defface unidiff-minus-line-face '((((class color)) (:foreground "red4"))) "Face for \"minus\" lines" :group 'unidiff-faces ) (defface unidiff-plus-line-face '((((class color)) (:foreground "blue4"))) "Face for \"plus\" lines" :group 'unidiff-faces ) (defface unidiff-index-line-face '((((class color)) (:foreground "green4"))) "Face for \"Index:\" lines" :group 'unidiff-faces ) (defface unidiff-file-line-face '((((class color)) (:foreground "green4"))) "Face for file name lines" :group 'unidiff-faces ) (defface unidiff-begin-chunk-face '((((class color)) (:foreground "magenta4"))) "Face for begin of chunk lines" :group 'unidiff-faces ) (defface unidiff-ancor-line-face '((((class color)) (:foreground "gray50"))) "Face for ancor lines" :group 'unidiff-faces ) (defvar unidiff-font-lock-keywords '( ("^--- .*\n\\+\\+\\+ .*$" . unidiff-file-line-face) ("^@@.*$" . unidiff-begin-chunk-face) ("^\\(Index: .*\n\\(=*\nRCS file: .*\nretrieving revision.*\n\\(retrieving revision.*\n\\)?\\)?\\)?diff .*$" . unidiff-index-line-face) ("^\\+.*$" . unidiff-plus-line-face) ("^-.*$" . unidiff-minus-line-face) ("^ .*$" . unidiff-ancor-line-face) ) ) (defvar unidiff-begin-chunk-regexp "^@@.*$" "Regexp for catch begin of chunk. Not affect for font-lock." ) (defvar unidiff-begin-file-regexp "^--- .*\n\\+\\+\\+ .*$" "Regexp for catch begin of file. Not affect for font-lock." ) ;;;###autoload (defun unidiff-mode () "Major mode for view/edit unidiff files Key bindings: \\{unidiff-mode-map}" (interactive) (kill-all-local-variables) (setq major-mode 'unidiff-mode mode-name "Unidiff" local-abbrev-table unidiff-mode-abbrev-table ) (use-local-map unidiff-mode-map) (put 'unidiff-mode 'mode-class 'special) (set (make-local-variable 'font-lock-keywords-only) t) (run-hooks 'unidiff-mode-hook) ) (defun unidiff-go-next-chunk () (interactive) (make-local-variable 'unidiff-saved-position) (set 'unidiff-saved-position (point)) (goto-char (+ unidiff-saved-position 1)) (if (not (re-search-forward unidiff-begin-chunk-regexp nil t)) (progn (goto-char unidiff-saved-position) (message "no next chunk") (beep) ) (goto-char (match-beginning 0)) ) ) (defun unidiff-go-prev-chunk () (interactive) (make-local-variable 'unidiff-saved-position) (set 'unidiff-saved-position (point)) (goto-char (+ unidiff-saved-position 1)) (if (not (re-search-backward unidiff-begin-chunk-regexp nil t)) (progn (goto-char unidiff-saved-position) (message "no previous chunk") (beep) ) (goto-char (match-beginning 0)) ) ) (defun unidiff-go-next-file () (interactive) (make-local-variable 'unidiff-saved-position) (set 'unidiff-saved-position (point)) (goto-char (+ unidiff-saved-position 1)) (if (not (re-search-forward unidiff-begin-file-regexp nil t)) (progn (goto-char unidiff-saved-position) (message "no next file") (beep) ) (goto-char (match-beginning 0)) ) ) (defun unidiff-go-prev-file () (interactive) (make-local-variable 'unidiff-saved-position) (set 'unidiff-saved-position (point)) (goto-char (+ unidiff-saved-position 1)) (if (not (re-search-backward unidiff-begin-file-regexp nil t)) (progn (goto-char unidiff-saved-position) (message "no previous file") (beep) ) (goto-char (match-beginning 0)) ) )