;;; changes-mode.el --- Basic tools for highlighting changes in a buffer. ;; Copyright (C) 1995 Niels Möller ;; Author: Niels Möller ;; Created: 11 Dec 1995 ;; Version: 1.0 ;; Keywords: C lisp tools editing ;; This file is part of GNU Emacs. ;; GNU Emacs 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, or (at your option) ;; any later version. ;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ;;; Commentary: ;; CHANGES-MODE turns the minor mode on or off. ;; CHANGES-CLEAR forgets which parts of the buffer have been modified ;; CHANGES-MODE-PROPERTIES is an alist of properties and values that ;; should be set for text that is changed. ;;; Code: ;;; User parameters (defvar changes-mode-properties '(modified t face bold) "Alist of properties and values to be set on modified characters.") ;;; Minor mode definitions (defvar changes-mode nil "Non-nil if changes-mode is active.") (make-variable-buffer-local 'changes-mode) (or (assq 'changes-mode minor-mode-alist) (setq minor-mode-alist (cons '(changes-mode " Changes") minor-mode-alist))) ;;; For internal use only ;; Bound to non-nil locally in when modifying text properties, ;; to stop infinite recursion (defconst changes-mode-busy nil) ;; Hook to be called when buffer changes. (defun changes-hook-function (start end length) (and changes-mode (not changes-mode-busy) (let ((changes-mode-busy 'busy)) (add-text-properties start end changes-mode-properties)))) (defun changes-clear () "Removes text properties added by changes-mode." (interactive) (let ((changes-mode-busy 'busy)) (remove-text-properties (point-min) (point-max) changes-mode-properties))) ;; Turn on or off the changes minor mode (defun changes-mode (arg) "Adds the text properties in CHANGES-MODE-PROPERTIES to characters in the buffer as they are modified." (interactive "P") (setq changes-mode (if (null arg) (not changes-mode) (> (prefix-numeric-value arg) 0))) (if changes-mode (progn (make-local-variable 'after-change-function) (add-hook 'after-change-functions 'changes-hook-function )))) (provide 'changes-mode) ;;; changes-mode.el ends here