;;; code for diff output (defgroup diff-text-highlighting nil "No clue why I defined this, blindly copying hi-lock code." :group 'faces) (defgroup diff-faces nil "Faces for diff output." :group 'diff-text-highlighting) (defface diff-hide '((t (:weight bold :foreground "blue"))) "Face for diff output." :group 'diff-faces) (defface diff-less '((t (:weight bold :foreground "red"))) "Face for diff output." :group 'diff-faces) (defface diff-more '((t (:weight bold :foreground "green"))) "Face for diff output." :group 'diff-faces) (defface diff-head '((t (:weight bold :foreground "yellow"))) "Face for diff output." :group 'diff-faces) '(setq diff-removed-face 'diff-less diff-added-face 'diff-more diff-header-face 'diff-hide ;; diff-file-header-face 'diff-hide diff-hunk-header-face 'diff-hide ;; inheritance seems to not work diff-index-face 'diff-hide) (defun diff-colorize (swap) "Colorize diff output old/new text as red/green. Optional prefix arg SWAP to exchange red and green." ;; use text overlays because they work when read-only ;; color-regexp groups <---> color-faces items ;; diff-hide dark blue for boring details ;; diff-head bright yellow for file headers ;; char ?? depends on + or - initial char ;; diff-more green for new text ;; diff-less red for old text (interactive "P") (message "Colorizing ...") (dolist (face '(diff-hide diff-head diff-less diff-more)) (remove-overlays nil nil 'face face)) (save-excursion (goto-char (point-min)) (let ((color-regexp "^\\(\ \\(@@.*\\)\\|\ \\(\\(---\\|\\+\\+\\+\\) \\([^\t\n]*\\)\t\\(.*\\)\\)\\|\ \\(\\([-+]\\)\\(.*\\)\\)\ \\)$") (color-faces '(diff-hide nil diff-hide ?? diff-head nil diff-hide ??))) (while (search-forward-regexp color-regexp (point-max) t) (do ((n 2 (1+ n)) (color color-faces (cdr color))) ((null color)) (when (and (car color) (match-beginning n)) (overlay-put (make-overlay (match-beginning n) (match-end n)) 'face (if (symbolp (car color)) (car color) (when (cdr color) (message "Colorizing %s ..." (match-string-no-properties n))) (cadr (assq (char-after (match-beginning 0)) (if swap '((?+ diff-less) (?- diff-more)) '((?+ diff-more) (?- diff-less)))))))))))) (message "Colorizing Done.")) ;;; end code for diff output