Mercurial > emacs
annotate lisp/hilit-chg.el @ 51188:283c294b88ea kfs_20030524_pre
*** empty log message ***
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Sat, 24 May 2003 20:18:13 +0000 |
parents | 37645a051842 |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
22957 | 1 ;;; hilit-chg.el --- minor mode displaying buffer changes with special face |
2 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
3 ;; Copyright (C) 1998, 2000 Free Software Foundation, Inc. |
22957 | 4 |
23614 | 5 ;; Author: Richard Sharman <rsharman@pobox.com> |
22957 | 6 ;; Keywords: faces |
7 | |
23101 | 8 ;; This file is part of GNU Emacs. |
9 | |
38401 | 10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
22957 | 11 ;; it under the terms of the GNU General Public License as published by |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
38401 | 15 ;; GNU Emacs is distributed in the hope that it will be useful, |
22957 | 16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; A minor mode: "Highlight Changes mode". | |
28 ;; | |
29 | |
30 ;; Highlight Changes mode has 2 submodes: active and passive. | |
31 ;; When active, changes to the buffer are displayed in a different face. | |
32 ;; When passive, any existing displayed changes are saved and new ones | |
33 ;; recorded but are not displayed differently. | |
34 ;; Why active and passive? Having the changes visible can be handy when you | |
35 ;; want the information but very distracting otherwise. So, you can keep | |
36 ;; Highlight Changes mode in passive state while you make your changes, toggle | |
37 ;; it on to active mode to see them, then toggle it back off to avoid | |
38 ;; distraction. | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
39 ;; |
22957 | 40 ;; When active, changes are displayed in `highlight-changes-face'. When |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
41 ;; text is deleted, the following character is displayed in |
22957 | 42 ;; `highlight-changes-delete-face' face. |
43 ;; | |
44 ;; | |
45 ;; You can "age" different sets of changes by using | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
46 ;; `highlight-changes-rotate-faces'. This rotates through a series |
22957 | 47 ;; of different faces, so you can distinguish "new" changes from "older" |
23046 | 48 ;; changes. You can customize these "rotated" faces in two ways. You can |
22957 | 49 ;; either explicitly define each face by customizing |
50 ;; `highlight-changes-face-list'. If, however, the faces differ from | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
51 ;; `highlight-changes-face' only in the foreground color, you can simply set |
22957 | 52 ;; `highlight-changes-colours'. If `highlight-changes-face-list' is nil when |
53 ;; the faces are required they will be constructed from | |
54 ;; `highlight-changes-colours'. | |
55 ;; | |
56 ;; | |
57 ;; When a Highlight Changes mode is on (either active or passive) you can go | |
58 ;; to the next or previous change with `highlight-changes-next-change' and | |
59 ;; `highlight-changes-previous-change'. | |
60 ;; | |
61 ;; | |
23289 | 62 ;; You can also use the command highlight-compare-with-file to show changes |
63 ;; in this file compared with another file (typically the previous version | |
64 ;; of the file). | |
22957 | 65 ;; |
66 ;; | |
67 ;; There are currently three hooks run by `highlight-changes-mode': | |
68 ;; `highlight-changes-enable-hook' - is run when Highlight Changes mode | |
69 ;; is initially enabled for a buffer. | |
70 ;; `highlight-changes-disable-hook' - is run when Highlight Changes mode | |
71 ;; is turned off. | |
72 ;; `highlight-changes-toggle-hook' - is run each time `highlight-changes-mode' | |
73 ;; is called. Typically this is when | |
74 ;; toggling between active and passive | |
75 ;; modes. The variable | |
76 ;; `highlight-changes-mode' contains the new | |
77 ;; state (`active' or `passive'.) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
78 ;; |
22957 | 79 ;; |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
80 ;; |
22957 | 81 ;; Example usage: |
82 ;; (defun my-highlight-changes-enable-hook () | |
83 ;; (add-hook 'local-write-file-hooks 'highlight-changes-rotate-faces) | |
84 ;; ) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
85 ;; |
22957 | 86 ;; (defun my-highlight-changes-disable-hook () |
87 ;; (remove-hook 'local-write-file-hooks 'highlight-changes-rotate-faces) | |
88 ;; ) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
89 ;; |
22957 | 90 ;; (add-hook 'highlight-changes-enable-hook 'my-highlight-changes-enable-hook) |
91 ;; (add-hook 'highlight-changes-disable-hook | |
92 ;; 'my-highlight-changes-disable-hook) | |
93 | |
94 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
95 ;; Explicit vs. Implicit |
22957 | 96 ;; |
97 | |
98 ;; Normally, Highlight Changes mode is turned on explicitly in a buffer. | |
99 ;; | |
100 ;; If you prefer to have it automatically invoked you can do it as | |
101 ;; follows. | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
102 ;; |
22957 | 103 ;; 1. Most modes have a major-hook, typically called MODE-hook. You |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
104 ;; can use `add-hook' to call `highlight-changes-mode'. |
22957 | 105 ;; |
106 ;; Example: | |
107 ;; (add-hook 'c-mode-hook 'highlight-changes-mode) | |
108 ;; | |
109 ;; If you want to make it start up in passive mode (regardless of the | |
110 ;; setting of highlight-changes-initial-state): | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
111 ;; (add-hook 'emacs-lisp-mode-hook |
22957 | 112 ;; (lambda () |
113 ;; (highlight-changes-mode 'passive))) | |
114 ;; | |
115 ;; However, this cannot be done for Fundamental mode for there is no | |
116 ;; such hook. | |
117 ;; | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
118 ;; 2. You can use the function `global-highlight-changes' |
22957 | 119 ;; |
120 ;; This function, which is fashioned after the way `global-font-lock' works, | |
121 ;; toggles on or off global Highlight Changes mode. When activated, it turns | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
122 ;; on Highlight Changes mode in all "suitable" existing buffers and will turn |
22957 | 123 ;; it on in new "suitable" buffers to be created. |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
124 ;; |
22957 | 125 ;; A buffer's "suitability" is determined by variable |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
126 ;; `highlight-changes-global-modes', as follows. If the variable is |
22957 | 127 ;; * nil -- then no buffers are suitable; |
128 ;; * a function -- this function is called and the result is used. As | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
129 ;; an example, if the value is `buffer-file-name' then all buffers |
22957 | 130 ;; who are visiting files are suitable, but others (like dired |
131 ;; buffers) are not; | |
30924 | 132 ;; * a list -- then the buffer is suitable iff its mode is in the |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
133 ;; list, except if the first element is `not', in which case the test |
22957 | 134 ;; is reversed (i.e. it is a list of unsuitable modes). |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
135 ;; * Otherwise, the buffer is suitable if its name does not begin with |
22957 | 136 ;; ` ' or `*' and if `buffer-file-name' returns true. |
137 ;; | |
138 | |
139 | |
140 | |
141 ;; Possible bindings: | |
142 ;; (global-set-key '[C-right] 'highlight-changes-next-change) | |
143 ;; (global-set-key '[C-left] 'highlight-changes-previous-change) | |
144 ;; | |
145 ;; Other interactive functions (which could be bound if desired): | |
146 ;; highlight-changes-mode | |
147 ;; highlight-changes-remove-highlight | |
148 ;; highlight-changes-rotate-faces | |
23289 | 149 ;; highlight-compare-with-file |
22957 | 150 |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
151 ;; |
22957 | 152 ;; You can automatically rotate faces when the buffer is saved; |
153 ;; see function `highlight-changes-rotate-faces' for how to do this. | |
154 ;; | |
155 | |
156 | |
157 ;;; Bugs: | |
158 | |
159 ;; - the next-change and previous-change functions are too literal; | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
160 ;; they should find the next "real" change, in other words treat |
22957 | 161 ;; consecutive changes as one. |
162 | |
163 | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
164 ;;; To do (maybe), notes, ... |
22957 | 165 |
166 ;; - having different faces for deletion and non-deletion: is it | |
167 ;; really worth the hassle? | |
168 ;; - should have better hooks: when should they be run? | |
23289 | 169 ;; - highlight-compare-with-file should allow RCS files - e.g. nice to be |
170 ;; able to say show changes compared with version 2.1. | |
22957 | 171 ;; - Maybe we should have compare-with-buffer as well. (When I tried |
172 ;; a while back I ran into a problem with ediff-buffers-internal.) | |
173 | |
174 | |
175 ;;; History: | |
176 | |
177 ;; R Sharman (rsharman@magma.ca) Feb 1998: | |
178 ;; - initial release as change-mode. | |
179 ;; Jari Aalto <jari.aalto@ntc.nokia.com> Mar 1998 | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
180 ;; - fixes for byte compile errors |
22957 | 181 ;; - use eval-and-compile for autoload |
182 ;; Marijn Ros <J.M.Ros@fys.ruu.nl> Mar 98 | |
183 ;; - suggested turning it on by default | |
184 ;; Eric Ludlam <zappo@gnu.org> Suggested using overlays. | |
185 ;; July 98 | |
186 ;; - global mode and various stuff added | |
187 ;; - Changed to use overlays | |
188 ;; August 98 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
189 ;; - renamed to Highlight Changes mode. |
22957 | 190 |
191 | |
192 ;;; Code: | |
193 | |
194 (require 'wid-edit) | |
195 | |
196 ;; ====================== Customization ======================= | |
197 (defgroup highlight-changes nil | |
198 "Highlight Changes mode." | |
24554
9a9a307e9a57
(highlight-changes): Add defgroup :version.
Dave Love <fx@gnu.org>
parents:
23614
diff
changeset
|
199 :version "20.4" |
22957 | 200 :group 'faces) |
201 | |
202 | |
203 ;; Face information: How the changes appear. | |
204 | |
205 ;; Defaults for face: red foreground, no change to background, | |
206 ;; and underlined if a change is because of a deletion. | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
207 ;; Note: underlining is helpful in that it shows up changes in white space. |
22957 | 208 ;; However, having it set for non-delete changes can be annoying because all |
209 ;; indentation on inserts gets underlined (which can look pretty ugly!). | |
210 | |
211 (defface highlight-changes-face | |
212 '((((class color)) (:foreground "red" )) | |
213 (t (:inverse-video t))) | |
214 "Face used for highlighting changes." | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
215 :group 'highlight-changes) |
22957 | 216 |
217 ;; This looks pretty ugly, actually. Maybe the underline should be removed. | |
218 (defface highlight-changes-delete-face | |
219 '((((class color)) (:foreground "red" :underline t)) | |
220 (t (:inverse-video t))) | |
221 "Face used for highlighting deletions." | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
222 :group 'highlight-changes) |
22957 | 223 |
224 | |
225 | |
226 ;; A (not very good) default list of colours to rotate through. | |
227 ;; | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
228 (defcustom highlight-changes-colours |
22957 | 229 (if (eq (frame-parameter nil 'background-mode) 'light) |
230 ;; defaults for light background: | |
231 '( "magenta" "blue" "darkgreen" "chocolate" "sienna4" "NavyBlue") | |
232 ;; defaults for dark background: | |
233 '("yellow" "magenta" "blue" "maroon" "firebrick" "green4" "DarkOrchid")) | |
234 "*Colours used by `highlight-changes-rotate-faces'. | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
235 The newest rotated change will be displayed in the first element of this list, |
22957 | 236 the next older will be in the second element etc. |
237 | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
238 This list is used if `highlight-changes-face-list' is nil, otherwise that |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
239 variable overrides this list. If you only care about foreground |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
240 colours then use this, if you want fancier faces then set |
22957 | 241 `highlight-changes-face-list'." |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
242 :type '(repeat color) |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
243 :group 'highlight-changes) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
244 |
22957 | 245 |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
246 ;; If you invoke highlight-changes-mode with no argument, should it start in |
22957 | 247 ;; active or passive mode? |
248 ;; | |
249 (defcustom highlight-changes-initial-state 'active | |
250 "*What state (active or passive) `highlight-changes' should start in. | |
251 This is used when `highlight-changes' is called with no argument. | |
252 This variable must be set to one of the symbols `active' or `passive'." | |
253 :type '(choice (const :tag "Active" active) | |
254 (const :tag "Passive" passive)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
255 :group 'highlight-changes) |
22957 | 256 |
257 (defcustom highlight-changes-global-initial-state 'passive | |
258 "*What state `global-highlight-changes' should start in. | |
259 This is used if `global-highlight-changes' is called with no argument. | |
260 This variable must be set to either `active' or `passive'" | |
261 :type '(choice (const :tag "Active" active) | |
262 (const :tag "Passive" passive)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
263 :group 'highlight-changes) |
22957 | 264 |
265 ;; The strings displayed in the mode-line for the minor mode: | |
43132
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
266 (defcustom highlight-changes-active-string " +Chg" |
22957 | 267 "*The string used when Highlight Changes mode is in the active state. |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
268 This should be set to nil if no indication is desired, or to |
22957 | 269 a string with a leading space." |
270 :type '(choice string | |
271 (const :tag "None" nil)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
272 :group 'highlight-changes) |
22957 | 273 |
43132
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
274 (defcustom highlight-changes-passive-string " -Chg" |
22957 | 275 "*The string used when Highlight Changes mode is in the passive state. |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
276 This should be set to nil if no indication is desired, or to |
22957 | 277 a string with a leading space." |
278 :type '(choice string | |
279 (const :tag "None" nil)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
280 :group 'highlight-changes) |
22957 | 281 |
282 (defcustom highlight-changes-global-modes t | |
283 "*Determine whether a buffer is suitable for global Highlight Changes mode. | |
284 | |
43132
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
285 A function means call that function to decide: if it returns non-nil, |
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
286 the buffer is suitable. |
22957 | 287 |
43132
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
288 A list means the elements are major modes suitable for Highlight |
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
289 Changes mode, or a list whose first element is `not' followed by major |
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
290 modes which are not suitable. |
22957 | 291 |
43132
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
292 t means the buffer is suitable if it is visiting a file and its name |
0dd2ebecd217
(highlight-changes-active-string): Default to +Chg.
Richard M. Stallman <rms@gnu.org>
parents:
43030
diff
changeset
|
293 does not begin with ` ' or `*'. |
22957 | 294 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
295 A value of nil means no buffers are suitable for `global-highlight-changes' |
41701 | 296 \(effectively disabling the mode). |
22957 | 297 |
298 Examples: | |
299 (c-mode c++-mode) | |
300 means that Highlight Changes mode is turned on for buffers in C and C++ | |
301 modes only." | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
302 :type '(choice |
22957 | 303 (const :tag "all non-special buffers visiting files" t) |
304 (set :menu-tag "specific modes" :tag "modes" | |
305 :value (not) | |
306 (const :tag "All except these" not) | |
307 (repeat :tag "Modes" :inline t (symbol :tag "mode"))) | |
308 (function :menu-tag "determined by function" | |
309 :value buffer-file-name) | |
310 (const :tag "none" nil) | |
311 ) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
312 :group 'highlight-changes) |
22957 | 313 |
314 (defvar global-highlight-changes nil) | |
315 | |
316 (defcustom highlight-changes-global-changes-existing-buffers nil | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
317 "*If non-nil, toggling global Highlight Changes mode affects existing buffers. |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
318 Normally, `global-highlight-changes' affects only new buffers (to be |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
319 created). However, if `highlight-changes-global-changes-existing-buffers' |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
320 is non-nil, then turning on `global-highlight-changes' will turn on |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
321 Highlight Changes mode in suitable buffers, and turning the mode off will |
22957 | 322 remove it from existing buffers." |
323 :type 'boolean | |
324 :group 'highlight-changes) | |
325 | |
326 (defun hilit-chg-cust-fix-changes-face-list (w wc &optional event) | |
327 ;; When customization function `highlight-changes-face-list' inserts a new | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
328 ;; face it uses the default face. We don't want the user to modify this |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
329 ;; face, so we rename the faces in the list on an insert. The rename is |
22957 | 330 ;; actually done by copying the faces so user-defined faces still remain |
331 ;; in the same order. | |
332 ;; The notifying the parent is needed because without it changes to the | |
333 ;; faces are saved but not to the actual list itself. | |
334 (let ((old-list (widget-value w))) | |
335 (if (member 'default old-list) | |
336 (let | |
337 ((p (reverse old-list)) | |
338 (n (length old-list)) | |
339 new-name old-name | |
340 (new-list nil) | |
341 ) | |
342 (while p | |
343 (setq old-name (car p)) | |
344 (setq new-name (intern (format "highlight-changes-face-%d" n))) | |
345 (if (eq old-name new-name) | |
346 nil | |
347 ;; A new face has been inserted: we don't want to modify the | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
348 ;; default face so copy it. Better, though, (I think) is to |
22957 | 349 ;; make a new face have the same attributes as |
350 ;; highlight-changes-face . | |
351 (if (eq old-name 'default) | |
352 (copy-face 'highlight-changes-face new-name) | |
353 (copy-face old-name new-name) | |
354 )) | |
355 (setq new-list (append (list new-name) new-list)) | |
356 (setq n (1- n)) | |
357 (setq p (cdr p))) | |
358 (if (equal new-list (widget-value w)) | |
359 nil ;; (message "notify: no change!") | |
360 (widget-value-set w new-list) | |
361 (widget-setup) | |
362 ) | |
363 ) | |
364 ;; (message "notify: no default here!") | |
365 )) | |
366 (let ((parent (widget-get w :parent))) | |
367 (when parent | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
368 (widget-apply parent :notify w event)))) |
22957 | 369 |
370 | |
371 (defcustom highlight-changes-face-list nil | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
372 "*A list of faces used when rotating changes. |
22957 | 373 Normally the variable is initialized to nil and the list is created from |
374 `highlight-changes-colours' when needed. However, you can set this variable | |
375 to any list of faces. You will have to do this if you want faces which | |
376 don't just differ from `highlight-changes-face' by the foreground colour. | |
377 Otherwise, this list will be constructed when needed from | |
378 `highlight-changes-colours'." | |
379 :type '(choice | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
380 (repeat |
22957 | 381 :notify hilit-chg-cust-fix-changes-face-list |
382 face ) | |
383 (const :tag "Derive from highlight-changes-colours" nil) | |
384 ) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
385 :group 'highlight-changes) |
22957 | 386 |
387 ;; ======================================================================== | |
388 | |
389 ;; These shouldn't be changed! | |
390 | |
25533
121060238dc8
(highlight-changes-mode): Add autoload cookie for variable.
Dave Love <fx@gnu.org>
parents:
24554
diff
changeset
|
391 ;; Autoload for the benefit of `make-mode-line-mouse-sensitive'. |
121060238dc8
(highlight-changes-mode): Add autoload cookie for variable.
Dave Love <fx@gnu.org>
parents:
24554
diff
changeset
|
392 ;;;###autoload |
22957 | 393 (defvar highlight-changes-mode nil) |
394 (defvar hilit-chg-list nil) | |
395 (defvar hilit-chg-string " ??") | |
396 (or (assq 'highlight-changes-mode minor-mode-alist) | |
397 (setq minor-mode-alist | |
398 (cons '(highlight-changes-mode hilit-chg-string) minor-mode-alist) | |
399 )) | |
400 (make-variable-buffer-local 'highlight-changes-mode) | |
401 (make-variable-buffer-local 'hilit-chg-string) | |
402 | |
403 | |
404 | |
405 (eval-and-compile | |
23289 | 406 ;; For highlight-compare-with-file |
22957 | 407 (defvar ediff-number-of-differences) |
408 (autoload 'ediff-setup "ediff") | |
409 (autoload 'ediff-with-current-buffer "ediff") | |
410 (autoload 'ediff-really-quit "ediff") | |
411 (autoload 'ediff-make-fine-diffs "ediff") | |
412 (autoload 'ediff-get-fine-diff-vector "ediff") | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
413 (autoload 'ediff-get-difference "ediff")) |
22957 | 414 |
415 | |
416 | |
417 ;;; Functions... | |
418 | |
419 (defun hilit-chg-map-changes (func &optional start-position end-position) | |
420 "Call function FUNC for each region used by Highlight Changes mode." | |
421 ;; if start-position is nil, (point-min) is used | |
422 ;; if end-position is nil, (point-max) is used | |
423 ;; FUNC is called with 3 params: property start stop | |
424 (let ((start (or start-position (point-min))) | |
425 (limit (or end-position (point-max))) | |
426 prop end) | |
427 (while (and start (< start limit)) | |
428 (setq prop (get-text-property start 'hilit-chg)) | |
429 (setq end (text-property-not-all start limit 'hilit-chg prop)) | |
430 (if prop | |
431 (funcall func prop start (or end limit))) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
432 (setq start end)))) |
22957 | 433 |
434 | |
435 (defun hilit-chg-display-changes (&optional beg end) | |
436 "Display face information for Highlight Changes mode. | |
437 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
438 An overlay containing a change face is added from the information |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
439 in the text property of type `hilit-chg'. |
22957 | 440 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
441 This is the opposite of `hilit-chg-hide-changes'." |
22957 | 442 (hilit-chg-map-changes 'hilit-chg-make-ov beg end)) |
443 | |
444 | |
445 (defun hilit-chg-make-ov (prop start end) | |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
446 (or prop |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
447 (error "hilit-chg-make-ov: prop is nil")) |
22957 | 448 ;; for the region make change overlays corresponding to |
449 ;; the text property 'hilit-chg | |
450 (let ((ov (make-overlay start end)) | |
451 face) | |
452 (if (eq prop 'hilit-chg-delete) | |
453 (setq face 'highlight-changes-delete-face) | |
454 (setq face (nth 1 (member prop hilit-chg-list)))) | |
455 (if face | |
456 (progn | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
457 ;; We must mark the face, that is the purpose of the overlay |
22957 | 458 (overlay-put ov 'face face) |
459 ;; I don't think we need to set evaporate since we should | |
460 ;; be controlling them! | |
461 (overlay-put ov 'evaporate t) | |
462 ;; We set the change property so we can tell this is one | |
463 ;; of our overlays (so we don't delete someone else's). | |
464 (overlay-put ov 'hilit-chg t) | |
465 ) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
466 (error "hilit-chg-make-ov: no face for prop: %s" prop)))) |
22957 | 467 |
468 (defun hilit-chg-hide-changes (&optional beg end) | |
469 "Remove face information for Highlight Changes mode. | |
470 | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
471 The overlay containing the face is removed, but the text property |
22957 | 472 containing the change information is retained. |
473 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
474 This is the opposite of `hilit-chg-display-changes'." |
22957 | 475 (let ((start (or beg (point-min))) |
476 (limit (or end (point-max))) | |
477 p ov) | |
478 (setq p (overlays-in start limit)) | |
479 (while p | |
480 ;; don't delete the overlay if it isn't ours! | |
481 (if (overlay-get (car p) 'hilit-chg) | |
482 (delete-overlay (car p))) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
483 (setq p (cdr p))))) |
22957 | 484 |
485 (defun hilit-chg-fixup (beg end) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
486 "Fix change overlays in region between BEG and END. |
22957 | 487 |
488 Ensure the overlays agree with the changes as determined from | |
489 the text properties of type `hilit-chg' ." | |
490 ;; Remove or alter overlays in region beg..end | |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
491 (let (ov-start ov-end props q) |
22957 | 492 ;; temp for debugging: |
493 ;; (or (eq highlight-changes-mode 'active) | |
494 ;; (error "hilit-chg-fixup called but Highlight Changes mode not active")) | |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
495 (dolist (ov (overlays-in beg end)) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
496 ;; Don't alter overlays that are not ours. |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
497 (when (overlay-get ov 'hilit-chg) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
498 (let ((ov-start (overlay-start ov)) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
499 (ov-end (overlay-end ov))) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
500 (if (< ov-start beg) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
501 (progn |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
502 (move-overlay ov ov-start beg) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
503 (if (> ov-end end) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
504 (progn |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
505 (setq props (overlay-properties ov)) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
506 (setq ov (make-overlay end ov-end)) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
507 (while props |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
508 (overlay-put ov (car props)(car (cdr props))) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
509 (setq props (cdr (cdr props))))))) |
22957 | 510 (if (> ov-end end) |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
511 (move-overlay ov end ov-end) |
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
512 (delete-overlay ov)))))) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
513 (hilit-chg-display-changes beg end))) |
22957 | 514 |
515 ;;;###autoload | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
516 (defun highlight-changes-remove-highlight (beg end) |
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
517 "Remove the change face from the region between BEG and END. |
22957 | 518 This allows you to manually remove highlighting from uninteresting changes." |
519 (interactive "r") | |
520 (let ((after-change-functions nil)) | |
521 (remove-text-properties beg end '(hilit-chg nil)) | |
522 (hilit-chg-fixup beg end))) | |
523 | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
524 (defun hilit-chg-set-face-on-change (beg end leng-before |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
525 &optional no-property-change) |
22957 | 526 "Record changes and optionally display them in a distinctive face. |
527 `hilit-chg-set' adds this function to the `after-change-functions' hook." | |
528 ;; | |
529 ;; This function is called by the `after-change-functions' hook, which | |
530 ;; is how we are notified when text is changed. | |
23289 | 531 ;; It is also called from `highlight-compare-with-file'. |
22957 | 532 ;; |
533 ;; We do NOT want to simply do this if this is an undo command, because | |
534 ;; otherwise an undone change shows up as changed. While the properties | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
535 ;; are automatically restored by undo, we must fix up the overlay. |
22957 | 536 (save-match-data |
537 (let ((beg-decr 1) (end-incr 1) | |
538 (type 'hilit-chg) | |
539 old) | |
540 (if undo-in-progress | |
541 (if (eq highlight-changes-mode 'active) | |
542 (hilit-chg-fixup beg end)) | |
543 (if (and (= beg end) (> leng-before 0)) | |
544 ;; deletion | |
545 (progn | |
546 ;; The eolp and bolp tests are a kludge! But they prevent | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
547 ;; rather nasty looking displays when deleting text at the end |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
548 ;; of line, such as normal corrections as one is typing and |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
549 ;; immediately makes a correction, and when deleting first |
22957 | 550 ;; character of a line. |
551 ;;; (if (= leng-before 1) | |
552 ;;; (if (eolp) | |
553 ;;; (setq beg-decr 0 end-incr 0) | |
554 ;;; (if (bolp) | |
555 ;;; (setq beg-decr 0)))) | |
556 ;;; (setq beg (max (- beg beg-decr) (point-min))) | |
557 (setq end (min (+ end end-incr) (point-max))) | |
558 (setq type 'hilit-chg-delete)) | |
559 ;; Not a deletion. | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
560 ;; Most of the time the following is not necessary, but |
22957 | 561 ;; if the current text was marked as a deletion then |
562 ;; the old overlay is still in effect, so if we add some | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
563 ;; text then remove the deletion marking, but set it to |
22957 | 564 ;; changed otherwise its highlighting disappears. |
565 (if (eq (get-text-property end 'hilit-chg) 'hilit-chg-delete) | |
566 (progn | |
567 (remove-text-properties end (+ end 1) '(hilit-chg nil)) | |
568 (put-text-property end (+ end 1) 'hilit-chg 'hilit-chg) | |
569 (if (eq highlight-changes-mode 'active) | |
570 (hilit-chg-fixup beg (+ end 1)))))) | |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
571 (unless no-property-change |
22957 | 572 (put-text-property beg end 'hilit-chg type)) |
43030
90bce6424b8b
(hilit-chg-fixup): Don't alter overlay if not ours.
Richard M. Stallman <rms@gnu.org>
parents:
41701
diff
changeset
|
573 (if (or (eq highlight-changes-mode 'active) no-property-change) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
574 (hilit-chg-make-ov type beg end)))))) |
22957 | 575 |
576 (defun hilit-chg-set (value) | |
577 "Turn on Highlight Changes mode for this buffer." | |
578 (setq highlight-changes-mode value) | |
579 (remove-hook 'after-change-functions 'hilit-chg-set-face-on-change t) | |
580 (hilit-chg-make-list) | |
581 (if (eq highlight-changes-mode 'active) | |
582 (progn | |
583 (setq hilit-chg-string highlight-changes-active-string) | |
584 (or buffer-read-only | |
585 (hilit-chg-display-changes))) | |
586 ;; mode is passive | |
587 (setq hilit-chg-string highlight-changes-passive-string) | |
588 (or buffer-read-only | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
589 (hilit-chg-hide-changes))) |
22957 | 590 (force-mode-line-update) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
591 (add-hook 'after-change-functions 'hilit-chg-set-face-on-change nil t)) |
22957 | 592 |
593 (defun hilit-chg-clear () | |
594 "Remove Highlight Changes mode for this buffer. | |
595 This removes all saved change information." | |
596 (if buffer-read-only | |
597 ;; We print the buffer name because this function could be called | |
598 ;; on many buffers from `global-highlight-changes'. | |
599 (message "Cannot remove highlighting from read-only mode buffer %s" | |
600 (buffer-name)) | |
601 (remove-hook 'after-change-functions 'hilit-chg-set-face-on-change t) | |
602 (let ((after-change-functions nil)) | |
603 (hilit-chg-hide-changes) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
604 (hilit-chg-map-changes |
22957 | 605 '(lambda (prop start stop) |
606 (remove-text-properties start stop '(hilit-chg nil)))) | |
607 ) | |
608 (setq highlight-changes-mode nil) | |
609 (force-mode-line-update) | |
610 ;; If we type: C-u -1 M-x highlight-changes-mode | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
611 ;; we want to turn it off, but hilit-chg-post-command-hook |
22957 | 612 ;; runs and that turns it back on! |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
613 (remove-hook 'post-command-hook 'hilit-chg-post-command-hook))) |
22957 | 614 |
615 ;;;###autoload | |
616 (defun highlight-changes-mode (&optional arg) | |
617 "Toggle (or initially set) Highlight Changes mode. | |
618 | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
619 Without an argument: |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
620 If Highlight Changes mode is not enabled, then enable it (in either active |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
621 or passive state as determined by the variable |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
622 `highlight-changes-initial-state'); otherwise, toggle between active |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
623 and passive state. |
22957 | 624 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
625 With an argument ARG: |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
626 If ARG is positive, set state to active; |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
627 If ARG is zero, set state to passive; |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
628 If ARG is negative, disable Highlight Changes mode completely. |
22957 | 629 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
630 Active state - means changes are shown in a distinctive face. |
22957 | 631 Passive state - means changes are kept and new ones recorded but are |
632 not displayed in a different face. | |
633 | |
634 Functions: | |
635 \\[highlight-changes-next-change] - move point to beginning of next change | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
636 \\[highlight-changes-previous-change] - move to beginning of previous change |
23289 | 637 \\[highlight-compare-with-file] - mark text as changed by comparing this |
638 buffer with the contents of a file | |
22957 | 639 \\[highlight-changes-remove-highlight] - remove the change face from the region |
640 \\[highlight-changes-rotate-faces] - rotate different \"ages\" of changes \ | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
641 through |
22957 | 642 various faces. |
643 | |
644 Hook variables: | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
645 `highlight-changes-enable-hook' - when enabling Highlight Changes mode. |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
646 `highlight-changes-toggle-hook' - when entering active or passive state |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
647 `highlight-changes-disable-hook' - when turning off Highlight Changes mode." |
22957 | 648 (interactive "P") |
29204
d38a98cddcec
(highlight-changes-mode): Ask about color or
Eli Zaretskii <eliz@gnu.org>
parents:
25533
diff
changeset
|
649 (if (or (display-color-p) |
d38a98cddcec
(highlight-changes-mode): Ask about color or
Eli Zaretskii <eliz@gnu.org>
parents:
25533
diff
changeset
|
650 (and (fboundp 'x-display-grayscale-p) (x-display-grayscale-p))) |
22957 | 651 (let ((was-on highlight-changes-mode) |
652 (new-highlight-changes-mode | |
653 (cond | |
654 ((null arg) | |
655 ;; no arg => toggle (or set to active initially) | |
656 (if highlight-changes-mode | |
657 (if (eq highlight-changes-mode 'active) 'passive 'active) | |
658 highlight-changes-initial-state)) | |
659 ;; an argument is given | |
660 ((eq arg 'active) | |
661 'active) | |
662 ((eq arg 'passive) | |
663 'passive) | |
664 ((> (prefix-numeric-value arg) 0) | |
665 'active) | |
666 ((< (prefix-numeric-value arg) 0) | |
667 nil) | |
668 (t | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
669 'passive)))) |
22957 | 670 (if new-highlight-changes-mode |
671 ;; mode is turned on -- but may be passive | |
672 (progn | |
673 (hilit-chg-set new-highlight-changes-mode) | |
674 (or was-on | |
675 ;; run highlight-changes-enable-hook once | |
676 (run-hooks 'highlight-changes-enable-hook)) | |
677 (run-hooks 'highlight-changes-toggle-hook)) | |
678 ;; mode is turned off | |
679 (run-hooks 'highlight-changes-disable-hook) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
680 (hilit-chg-clear))) |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
681 (message "Highlight Changes mode requires color or grayscale display"))) |
22957 | 682 |
683 ;;;###autoload | |
684 (defun highlight-changes-next-change () | |
685 "Move to the beginning of the next change, if in Highlight Changes mode." | |
686 (interactive) | |
687 (if highlight-changes-mode | |
688 (let ((start (point)) | |
689 prop) | |
690 (setq prop (get-text-property (point) 'hilit-chg)) | |
691 (if prop | |
692 ;; we are in a change | |
693 (setq start (next-single-property-change (point) 'hilit-chg))) | |
694 (if start | |
695 (setq start (next-single-property-change start 'hilit-chg))) | |
696 (if start | |
697 (goto-char start) | |
698 (message "no next change"))) | |
699 (message "This buffer is not in Highlight Changes mode."))) | |
700 | |
701 | |
702 ;;;###autoload | |
703 (defun highlight-changes-previous-change () | |
704 "Move to the beginning of the previous change, if in Highlight Changes mode." | |
705 (interactive) | |
706 (if highlight-changes-mode | |
707 (let ( (start (point)) (prop nil) ) | |
708 (or (bobp) | |
709 (setq prop (get-text-property (1- (point)) 'hilit-chg))) | |
710 (if prop | |
711 ;; we are in a change | |
712 (setq start (previous-single-property-change (point) 'hilit-chg))) | |
713 (if start | |
714 (setq start (previous-single-property-change start 'hilit-chg))) | |
715 ;; special handling for the case where (point-min) is a change | |
716 (if start | |
717 (setq start (or (previous-single-property-change start 'hilit-chg) | |
718 (if (get-text-property (point-min) 'hilit-chg) | |
719 (point-min))))) | |
720 (if start | |
721 (goto-char start) | |
722 (message "no previous change"))) | |
723 (message "This buffer is not in Highlight Changes mode."))) | |
724 | |
725 ;; ======================================================================== | |
726 | |
727 (defun hilit-chg-make-list (&optional force) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
728 "Construct `hilit-chg-list' and `highlight-changes-face-list'." |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
729 ;; Constructs highlight-changes-face-list if necessary, |
22957 | 730 ;; and hilit-chg-list always: |
731 ;; Maybe this should always be called when rotating a face | |
732 ;; so we pick up any changes? | |
733 (if (or (null highlight-changes-face-list) ; Don't do it if it | |
734 force) ; already exists unless FORCE non-nil. | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
735 (let ((p highlight-changes-colours) |
22957 | 736 (n 1) name) |
737 (setq highlight-changes-face-list nil) | |
738 (while p | |
739 (setq name (intern (format "highlight-changes-face-%d" n))) | |
740 (copy-face 'highlight-changes-face name) | |
741 (set-face-foreground name (car p)) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
742 (setq highlight-changes-face-list |
22957 | 743 (append highlight-changes-face-list (list name))) |
744 (setq p (cdr p)) | |
745 (setq n (1+ n))))) | |
746 (setq hilit-chg-list (list 'hilit-chg 'highlight-changes-face)) | |
747 (let ((p highlight-changes-face-list) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
748 (n 1) |
22957 | 749 last-category last-face) |
750 (while p | |
751 (setq last-category (intern (format "change-%d" n))) | |
752 ;; (setq last-face (intern (format "highlight-changes-face-%d" n))) | |
753 (setq last-face (car p)) | |
754 (setq hilit-chg-list | |
755 (append hilit-chg-list | |
756 (list last-category last-face))) | |
757 (setq p (cdr p)) | |
758 (setq n (1+ n))) | |
759 (setq hilit-chg-list | |
760 (append hilit-chg-list | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
761 (list last-category last-face))))) |
22957 | 762 |
763 (defun hilit-chg-bump-change (prop start end) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
764 "Increment (age) the Highlight Changes mode text property." |
22957 | 765 (let ( new-prop ) |
766 (if (eq prop 'hilit-chg-delete) | |
767 (setq new-prop (nth 2 hilit-chg-list)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
768 (setq new-prop (nth 2 (member prop hilit-chg-list)))) |
22957 | 769 (if prop |
770 (put-text-property start end 'hilit-chg new-prop) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
771 (message "%d-%d unknown property %s not changed" start end prop)))) |
22957 | 772 |
773 ;;;###autoload | |
774 (defun highlight-changes-rotate-faces () | |
775 "Rotate the faces used by Highlight Changes mode. | |
776 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
777 Current changes are displayed in the face described by the first element |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
778 of `highlight-changes-face-list', one level older changes are shown in |
22957 | 779 face described by the second element, and so on. Very old changes remain |
780 shown in the last face in the list. | |
781 | |
782 You can automatically rotate colours when the buffer is saved | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
783 by adding the following to `local-write-file-hooks', by evaling it in the |
22957 | 784 buffer to be saved): |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
785 |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
786 \(add-hook 'local-write-file-hooks 'highlight-changes-rotate-faces)" |
22957 | 787 (interactive) |
788 ;; If not in active mode do nothing but don't complain because this | |
789 ;; may be bound to a hook. | |
790 (if (eq highlight-changes-mode 'active) | |
791 (let ((after-change-functions nil)) | |
792 ;; ensure hilit-chg-list is made and up to date | |
793 (hilit-chg-make-list) | |
794 ;; remove our existing overlays | |
795 (hilit-chg-hide-changes) | |
796 ;; for each change text property, increment it | |
797 (hilit-chg-map-changes 'hilit-chg-bump-change) | |
798 ;; and display them all if active | |
799 (if (eq highlight-changes-mode 'active) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
800 (hilit-chg-display-changes)))) |
22957 | 801 ;; This always returns nil so it is safe to use in |
802 ;; local-write-file-hook | |
803 nil) | |
804 | |
805 ;; ======================================================================== | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
806 ;; Comparing with an existing file. |
22957 | 807 ;; This uses ediff to find the differences. |
808 | |
809 ;;;###autoload | |
23288
17dd9ecf84f1
(highlight-compare-with-file): Renamed from
Karl Heuer <kwzh@gnu.org>
parents:
23101
diff
changeset
|
810 (defun highlight-compare-with-file (file-b) |
17dd9ecf84f1
(highlight-compare-with-file): Renamed from
Karl Heuer <kwzh@gnu.org>
parents:
23101
diff
changeset
|
811 "Compare this buffer with a file, and highlight differences. |
22957 | 812 |
813 The current buffer must be an unmodified buffer visiting a file, | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
814 and must not be read-only. |
22957 | 815 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
816 If the buffer has a backup filename, it is used as the default when |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
817 this function is called interactively. |
22957 | 818 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
819 If the current buffer is visiting the file being compared against, it |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
820 also will have its differences highlighted. Otherwise, the file is |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
821 read in temporarily but the buffer is deleted. |
22957 | 822 |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
823 If the buffer is read-only, differences will be highlighted but no property |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
824 changes are made, so \\[highlight-changes-next-change] and |
22957 | 825 \\[highlight-changes-previous-change] will not work." |
826 (interactive (list | |
827 (read-file-name | |
828 "File to compare with? " ;; prompt | |
829 "" ;; directory | |
830 nil ;; default | |
831 'yes ;; must exist | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
832 (let ((f (make-backup-file-name |
22957 | 833 (or (buffer-file-name (current-buffer)) |
834 (error "no file for this buffer"))))) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
835 (if (file-exists-p f) f ""))))) |
22957 | 836 |
837 (let* ((buf-a (current-buffer)) | |
838 (buf-a-read-only buffer-read-only) | |
839 (orig-pos (point)) | |
840 (file-a (buffer-file-name)) | |
841 (existing-buf (get-file-buffer file-b)) | |
842 (buf-b (or existing-buf | |
843 (find-file-noselect file-b))) | |
844 (buf-b-read-only (with-current-buffer buf-b buffer-read-only)) | |
845 xy xx yy p q | |
846 a-start a-end len-a | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
847 b-start b-end len-b) |
22957 | 848 |
849 ;; We use the fact that the buffer is not marked modified at the | |
850 ;; end where we clear its modified status | |
851 (if (buffer-modified-p buf-a) | |
852 (if (y-or-n-p (format "OK to save %s? " file-a)) | |
853 (save-buffer buf-a) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
854 (error "Buffer must be saved before comparing with a file"))) |
22957 | 855 (if (and existing-buf (buffer-modified-p buf-b)) |
856 (if (y-or-n-p (format "OK to save %s? " file-b)) | |
857 (save-buffer buf-b) | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
38401
diff
changeset
|
858 (error "Cannot compare with a file in an unsaved buffer"))) |
22957 | 859 (highlight-changes-mode 'active) |
860 (if existing-buf (with-current-buffer buf-b | |
861 (highlight-changes-mode 'active))) | |
862 (save-window-excursion | |
863 (setq xy (hilit-chg-get-diff-info buf-a file-a buf-b file-b))) | |
864 (setq xx (car xy)) | |
865 (setq p xx) | |
866 (setq yy (car (cdr xy))) | |
867 (setq q yy) | |
868 (hilit-chg-make-list) | |
869 (while p | |
870 (setq a-start (nth 0 (car p))) | |
871 (setq a-end (nth 1 (car p))) | |
872 (setq b-start (nth 0 (car q))) | |
873 (setq b-end (nth 1 (car q))) | |
874 (setq len-a (- a-end a-start)) | |
875 (setq len-b (- b-end b-start)) | |
876 (set-buffer buf-a) | |
877 (hilit-chg-set-face-on-change a-start a-end len-b buf-a-read-only) | |
878 (set-buffer-modified-p nil) | |
879 (goto-char orig-pos) | |
880 (if existing-buf | |
881 (with-current-buffer buf-b | |
882 (hilit-chg-set-face-on-change b-start b-end len-a | |
883 buf-b-read-only ) | |
884 )) | |
885 (setq p (cdr p)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
886 (setq q (cdr q))) |
22957 | 887 (if existing-buf |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
888 (set-buffer-modified-p nil) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
889 (kill-buffer buf-b)))) |
22957 | 890 |
891 | |
892 (defun hilit-chg-get-diff-info (buf-a file-a buf-b file-b) | |
893 (let ((e nil) x y) ;; e is set by function hilit-chg-get-diff-list-hk | |
894 (ediff-setup buf-a file-a buf-b file-b | |
895 nil nil ; buf-c file-C | |
896 'hilit-chg-get-diff-list-hk | |
897 (list (cons 'ediff-job-name 'something)) | |
898 ) | |
899 (ediff-with-current-buffer e (ediff-really-quit nil)) | |
900 (list x y))) | |
901 | |
902 | |
903 (defun hilit-chg-get-diff-list-hk () | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
904 ;; x and y are dynamically bound by hilit-chg-get-diff-info |
22957 | 905 ;; which calls this function as a hook |
906 (defvar x) ;; placate the byte-compiler | |
907 (defvar y) | |
908 (setq e (current-buffer)) | |
909 (let ((n 0) extent p va vb a b) | |
910 (setq x nil y nil) ;; x and y are bound by hilit-chg-get-diff-info | |
911 (while (< n ediff-number-of-differences) | |
912 (ediff-make-fine-diffs n) | |
913 (setq va (ediff-get-fine-diff-vector n 'A)) | |
914 ;; va is a vector if there are fine differences | |
915 (if va | |
916 (setq a (append va nil)) | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
917 ;; if not, get the unrefined difference |
22957 | 918 (setq va (ediff-get-difference n 'A)) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
919 (setq a (list (elt va 0)))) |
22957 | 920 ;; a list a list |
921 (setq p a) | |
922 (while p | |
923 (setq extent (list (overlay-start (car p)) | |
924 (overlay-end (car p)))) | |
925 (setq p (cdr p)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
926 (setq x (append x (list extent) )));; while p |
22957 | 927 ;; |
928 (setq vb (ediff-get-fine-diff-vector n 'B)) | |
929 ;; vb is a vector | |
930 (if vb | |
931 (setq b (append vb nil)) | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
932 ;; if not, get the unrefined difference |
22957 | 933 (setq vb (ediff-get-difference n 'B)) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
934 (setq b (list (elt vb 0)))) |
22957 | 935 ;; b list a list |
936 (setq p b) | |
937 (while p | |
938 (setq extent (list (overlay-start (car p)) | |
939 (overlay-end (car p)))) | |
940 (setq p (cdr p)) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
941 (setq y (append y (list extent) ))) |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
942 (setq n (1+ n)));; while |
22957 | 943 ;; ediff-quit doesn't work here. |
944 ;; No point in returning a value, since this is a hook function. | |
945 )) | |
946 | |
947 ;; ======================= automatic stuff ============== | |
948 | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
949 ;; Global Highlight Changes mode is modeled after Global Font-lock mode. |
22957 | 950 ;; Three hooks are used to gain control. When Global Changes Mode is |
951 ;; enabled, `find-file-hooks' and `change-major-mode-hook' are set. | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
952 ;; `find-file-hooks' is called when visiting a file, the new mode is |
22957 | 953 ;; known at this time. |
954 ;; `change-major-mode-hook' is called when a buffer is changing mode. | |
955 ;; This could be because of finding a file in which case | |
956 ;; `find-file-hooks' has already been called and has done its work. | |
957 ;; However, it also catches the case where a new mode is being set by | |
958 ;; the user. However, it is called from `kill-all-variables' and at | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
959 ;; this time the mode is the old mode, which is not what we want. |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
960 ;; So, our function temporarily sets `post-command-hook' which will |
22957 | 961 ;; be called after the buffer has been completely set up (with the new |
962 ;; mode). It then removes the `post-command-hook'. | |
963 ;; One other wrinkle - every M-x command runs the `change-major-mode-hook' | |
964 ;; so we ignore this by examining the buffer name. | |
965 | |
966 | |
967 (defun hilit-chg-major-mode-hook () | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
968 (add-hook 'post-command-hook 'hilit-chg-post-command-hook)) |
22957 | 969 |
970 (defun hilit-chg-post-command-hook () | |
971 ;; This is called after changing a major mode, but also after each | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
972 ;; M-x command, in which case the current buffer is a minibuffer. |
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
973 ;; In that case, do not act on it here, but don't turn it off |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
974 ;; either, we will get called here again soon-after. |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
975 ;; Also, don't enable it for other special buffers. |
22957 | 976 (if (string-match "^[ *]" (buffer-name)) |
977 nil ;; (message "ignoring this post-command-hook") | |
978 (remove-hook 'post-command-hook 'hilit-chg-post-command-hook) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
979 ;; The following check isn't necessary, since |
22957 | 980 ;; hilit-chg-turn-on-maybe makes this check too. |
981 (or highlight-changes-mode ;; don't turn it on if it already is | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
982 (hilit-chg-turn-on-maybe highlight-changes-global-initial-state)))) |
22957 | 983 |
984 (defun hilit-chg-check-global () | |
985 ;; This is called from the find file hook. | |
986 (hilit-chg-turn-on-maybe highlight-changes-global-initial-state)) | |
987 | |
988 | |
989 ;;;###autoload | |
990 (defun global-highlight-changes (&optional arg) | |
991 "Turn on or off global Highlight Changes mode. | |
992 | |
993 When called interactively: | |
994 - if no prefix, toggle global Highlight Changes mode on or off | |
995 - if called with a positive prefix (or just C-u) turn it on in active mode | |
996 - if called with a zero prefix turn it on in passive mode | |
997 - if called with a negative prefix turn it off | |
998 | |
999 When called from a program: | |
1000 - if ARG is nil or omitted, turn it off | |
47259
08b8c2bc2e81
(highlight-changes-colours, highlight-changes-active-string,
Juanma Barranquero <lekktu@gmail.com>
parents:
44740
diff
changeset
|
1001 - if ARG is `active', turn it on in active mode |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1002 - if ARG is `passive', turn it on in passive mode |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1003 - otherwise just turn it on |
22957 | 1004 |
1005 When global Highlight Changes mode is enabled, Highlight Changes mode is turned | |
1006 on for future \"suitable\" buffers (and for \"suitable\" existing buffers if | |
1007 variable `highlight-changes-global-changes-existing-buffers' is non-nil). | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1008 \"Suitability\" is determined by variable `highlight-changes-global-modes'." |
22957 | 1009 |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1010 (interactive |
22957 | 1011 (list |
1012 (cond | |
1013 ((null current-prefix-arg) | |
1014 ;; no arg => toggle it on/off | |
1015 (setq global-highlight-changes (not global-highlight-changes))) | |
1016 ;; positive interactive arg - turn it on as active | |
1017 ((> (prefix-numeric-value current-prefix-arg) 0) | |
1018 (setq global-highlight-changes t) | |
1019 'active) | |
1020 ;; zero interactive arg - turn it on as passive | |
1021 ((= (prefix-numeric-value current-prefix-arg) 0) | |
1022 (setq global-highlight-changes t) | |
1023 'passive) | |
1024 ;; negative interactive arg - turn it off | |
1025 (t | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1026 (setq global-highlight-changes nil) |
22957 | 1027 nil)))) |
1028 | |
1029 (if arg | |
1030 (progn | |
1031 (if (eq arg 'active) | |
1032 (setq highlight-changes-global-initial-state 'active) | |
1033 (if (eq arg 'passive) | |
1034 (setq highlight-changes-global-initial-state 'passive))) | |
1035 (setq global-highlight-changes t) | |
44740
385762249723
(global-highlight-changes): Capitalize status texts.
Pavel Janík <Pavel@Janik.cz>
parents:
43132
diff
changeset
|
1036 (message "Turning ON Global Highlight Changes mode in %s state" |
22957 | 1037 highlight-changes-global-initial-state) |
1038 (add-hook 'hilit-chg-major-mode-hook 'hilit-chg-major-mode-hook) | |
1039 (add-hook 'find-file-hooks 'hilit-chg-check-global) | |
1040 (if highlight-changes-global-changes-existing-buffers | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1041 (hilit-chg-update-all-buffers |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1042 highlight-changes-global-initial-state))) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1043 |
44740
385762249723
(global-highlight-changes): Capitalize status texts.
Pavel Janík <Pavel@Janik.cz>
parents:
43132
diff
changeset
|
1044 (message "Turning OFF global Highlight Changes mode") |
22957 | 1045 (remove-hook 'hilit-chg-major-mode-hook 'hilit-chg-major-mode-hook) |
1046 (remove-hook 'find-file-hooks 'hilit-chg-check-global) | |
1047 (remove-hook 'post-command-hook | |
1048 'hilit-chg-post-command-hook) | |
1049 (remove-hook 'find-file-hooks 'hilit-chg-check-global) | |
1050 (if highlight-changes-global-changes-existing-buffers | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1051 (hilit-chg-update-all-buffers nil)))) |
22957 | 1052 |
1053 | |
1054 (defun hilit-chg-turn-on-maybe (value) | |
1055 "Turn on Highlight Changes mode if it is appropriate for this buffer. | |
1056 | |
1057 A buffer is appropriate for Highlight Changes mode if all these are true: | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1058 - the buffer is not a special buffer (one whose name begins with |
22957 | 1059 `*' or ` ') |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1060 - the buffer's mode is suitable as per variable |
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1061 `highlight-changes-global-modes' |
22957 | 1062 - Highlight Changes mode is not already on for this buffer. |
1063 | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1064 This function is called from `hilit-chg-update-all-buffers' or |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1065 from `global-highlight-changes' when turning on global Highlight Changes mode." |
22957 | 1066 (or highlight-changes-mode ; do nothing if already on |
1067 (if | |
1068 (cond | |
1069 ((null highlight-changes-global-modes) | |
1070 nil) | |
1071 ((functionp highlight-changes-global-modes) | |
1072 (funcall highlight-changes-global-modes)) | |
1073 ((listp highlight-changes-global-modes) | |
1074 (if (eq (car-safe highlight-changes-global-modes) 'not) | |
1075 (not (memq major-mode (cdr highlight-changes-global-modes))) | |
1076 (memq major-mode highlight-changes-global-modes))) | |
1077 (t | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1078 (and |
22957 | 1079 (not (string-match "^[ *]" (buffer-name))) |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1080 (buffer-file-name)))) |
22957 | 1081 (progn |
1082 (hilit-chg-set value) | |
30962
b309b17a6025
General cleanup of doc strings, comments and
Gerd Moellmann <gerd@gnu.org>
parents:
30924
diff
changeset
|
1083 (run-hooks 'highlight-changes-enable-hook))))) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1084 |
22957 | 1085 |
1086 (defun hilit-chg-turn-off-maybe () | |
1087 (if highlight-changes-mode | |
1088 (progn | |
1089 (run-hooks 'highlight-changes-disable-hook) | |
1090 (hilit-chg-clear)))) | |
1091 | |
1092 | |
1093 (defun hilit-chg-update-all-buffers (value) | |
1094 (mapcar | |
1095 (function (lambda (buffer) | |
1096 (with-current-buffer buffer | |
1097 (if value | |
1098 (hilit-chg-turn-on-maybe value) | |
1099 (hilit-chg-turn-off-maybe)) | |
1100 ))) | |
1101 (buffer-list))) | |
1102 | |
1103 ;; ===================== debug ================== | |
1104 ;; For debug & test use: | |
1105 ;; | |
1106 ;; (defun hilit-chg-debug-show (&optional beg end) | |
1107 ;; (interactive) | |
1108 ;; (message "--- hilit-chg-debug-show ---") | |
1109 ;; (hilit-chg-map-changes '(lambda (prop start end) | |
1110 ;; (message "%d-%d: %s" start end prop) | |
1111 ;; ) | |
1112 ;; beg end | |
1113 ;; )) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47259
diff
changeset
|
1114 ;; |
22957 | 1115 ;; ================== end of debug =============== |
1116 | |
1117 (provide 'hilit-chg) | |
22958
cd50dfa70bb2
Delete the undo-in-progress compatibility code.
Richard M. Stallman <rms@gnu.org>
parents:
22957
diff
changeset
|
1118 |
22957 | 1119 ;;; hilit-chg.el ends here |