tracking changes





It's sometimes nice to see the changes you've made to a file. If the file is
under version control, you can use the 'diff'-features of the version
control system of course; or you can use diff-buffer-with-file to compare
your buffer with the version on disk. That obviously only. works when you
haven't saved the file yet.



Anyway, a bit easier, straighforward way may be to use
highlight-changes-mode. With that mode, emacs can give a special color to
parts of the text that you have changed.






;; higlight changes in documents
(global-highlight-changes-mode t)
(setq highlight-changes-visibility-initial-state nil); initially hide







The last line tells me that the changes should not be visible unless I want
to see them.



I defined a key binding (F6) so I can easily toggle between
visible/invisible changes:





;; toggle visibility
(global-set-key (kbd "<f6>") 'highlight-changes-visible-mode) ;; changes
;; remove the change-highlight in region
(global-set-key (kbd "S-<f6>") 'highlight-changes-remove-highlight)







With this last keybinding S-<f6> (Shift-F6), I can remove the
change-indication of the current region (selection). Here are some other
useful keybindings to quickly jump between various changes:






;; alt-pgup/pgdown jump to the previous/next change

;; if you're not already using it for something else...
(global-set-key (kbd "<M-prior>") 'highlight-changes-next-change)
(global-set-key (kbd "<M-next>") 'highlight-changes-previous-change)







Another interesting thing you can do is M-x highlight-compare-with-file.



The only remaining problem with highlight-changes-mode is that the default
colors are, well, hideous. But of course, that can easily be fixed by changing
the faces:






(set-face-foreground 'highlight-changes nil)
(set-face-background 'highlight-changes "#382f2f")
(set-face-foreground 'highlight-changes-delete nil)
(set-face-background 'highlight-changes-delete "#916868")







Or adding to your color-scheme:






(highlight-changes ((t (:foreground nil :background "#382f2f"))))
(highlight-changes-delete ((t (:foreground nil :background "#916868"))))







Now, with these color changes, the foreground stays the same, only the
background changes a bit. I am using a dark theme, you might want to change
the colors to fit in with your theme.



There are some more features - for example, to rotate through changes of
different age. For such things I prefer to use a version control system, but
you might want to check it out.



Tracking changes can be quite useful. And, unlike some word-processing
software, emacs does not hide your highly embarrassing modifications somewhere
in your document…


No comments:

Post a Comment

Followers

Popular Posts