File: hilit-chg.el.html
A minor mode: "Highlight Changes mode".
When Highlight Changes mode is enabled changes to the buffer are recorded with a text property. Normally these ranges of text are displayed in a distinctive face. However, sometimes it is desirable to temporarily not see these changes. Instead of disabling Highlight Changes mode (which would remove the text property) use the command highlight-changes-visible-mode.
Two faces are supported: one for changed or inserted text and another for the first character after text has been deleted.
When Highlight Changes mode is on (even if changes are not visible)
you can go to the next or previous change with
highlight-changes-next-change or highlight-changes-previous-change.
Command highlight-compare-with-file shows changes in this file compared with another file (by default the previous version of the file).
The command highlight-compare-buffers compares two buffers by highlighting their differences.
You can "age" different sets of changes by using
highlight-changes-rotate-faces. This rotates through a series
of different faces, so you can distinguish "new" changes from "older"
changes. You can customize these "rotated" faces in two ways. You can
either explicitly define each face by customizing
highlight-changes-face-list. If, however, the faces differ from
highlight-changes-face only in the foreground color, you can simply set
highlight-changes-colors. If highlight-changes-face-list is nil when
the faces are required they will be constructed from
highlight-changes-colors.
You can automatically rotate faces when the buffer is saved;
see function highlight-changes-rotate-faces for how to do this.
The hook highlight-changes-mode-hook is called when
Highlight Changes mode is turned on or off.
When it called, variable highlight-changes-mode(var)/highlight-changes-mode(fun) has been updated
to the new value.
Example usage:
(defun my-highlight-changes-mode-hook ()
(if highlight-changes-mode
(add-hook 'write-file-functions 'highlight-changes-rotate-faces nil t)
(remove-hook 'write-file-functions 'highlight-changes-rotate-faces t)))
Automatically enabling Highlight Changes mode
Normally, Highlight Changes mode is turned on explicitly in a buffer.
If you prefer to have it automatically invoked you can do it as follows.
1. Most modes have a major-hook, typically called MODE-hook. You
can use add-hook to call highlight-changes-mode(var)/highlight-changes-mode(fun).
Example:
(add-hook 'c-mode-hook 'highlight-changes-mode)
However, this cannot be done for Fundamental mode for there is no such hook.
2. You can use the function global-highlight-changes-mode(var)/global-highlight-changes-mode(fun)
This function, which is fashioned after the way global-font-lock works,
toggles on or off global Highlight Changes mode. When activated, it turns
on Highlight Changes mode in all "suitable" existing buffers and will turn
it on in new "suitable" buffers to be created.
A buffer's "suitability" is determined by variable
highlight-changes-global-modes, as follows. If it is
* nil -- then no buffers are suitable;
* a function -- this function is called and the result is used. As
an example, if the value is buffer-file-name(var)/buffer-file-name(fun) then all buffers
who are visiting files are suitable, but others (like Dired
buffers) are not;
* a list -- then the buffer is suitable if and only if its mode is in the
list, except if the first element is not, in which case the test
is reversed (i.e. it is a list of unsuitable modes).
* Otherwise, the buffer is suitable if its name does not begin with
or * and if buffer-file-name(var)/buffer-file-name(fun) returns true.
To enable it for future sessions put this in your ~/.emacs file:
(global-highlight-changes-mode t)
Possible bindings:
(keymap-global-set "C-<right>" #'highlight-changes-next-change)
(keymap-global-set "C-<left>" #'highlight-changes-previous-change)
Other interactive functions (that could be bound if desired):
highlight-changes-mode(var)/highlight-changes-mode(fun)
highlight-changes-remove-highlight
highlight-compare-with-file
highlight-compare-buffers
highlight-changes-rotate-faces
Defined variables (13)
global-highlight-changes-mode | Non-nil if Global Highlight-Changes mode is enabled. |
global-highlight-changes-mode-hook | Hook run after entering or leaving ‘global-highlight-changes-mode’. |
highlight-changes-colors | Colors used by ‘highlight-changes-rotate-faces’. |
highlight-changes-face-list | A list of faces used when rotating changes. |
highlight-changes-global-changes-existing-buffers | If non-nil, toggling global Highlight Changes mode affects existing buffers. |
highlight-changes-global-modes | Determine whether a buffer is suitable for global Highlight Changes mode. |
highlight-changes-invisible-string | The string used when in Highlight Changes mode and changes are hidden. |
highlight-changes-mode | Non-nil if Highlight-Changes mode is enabled. |
highlight-changes-mode-hook | Hook run after entering or leaving ‘highlight-changes-mode’. |
highlight-changes-visibility-initial-state | Controls whether changes are initially visible in Highlight Changes mode. |
highlight-changes-visible-mode | Non-nil if Highlight-Changes-Visible mode is enabled. |
highlight-changes-visible-mode-hook | Hook run after entering or leaving ‘highlight-changes-visible-mode’. |
highlight-changes-visible-string | The string used when in Highlight Changes mode and changes are visible. |
Defined functions (26)
Defined faces (2)
highlight-changes | Face used for highlighting changes. |
highlight-changes-delete | Face used for highlighting deletions. |