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