[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: highlight-changes-rotate-faces sets buffer modified flag

From: martin rudalics
Subject: Re: highlight-changes-rotate-faces sets buffer modified flag
Date: Wed, 09 May 2007 18:53:46 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> So this is an improved version of my advice:
> (defadvice highlight-changes-rotate-faces (around around-rotate-faces)
>   (let ((was-modified (buffer-modified-p))
>         (saved-undo-list buffer-undo-list)
>         (buffer-undo-list t))
>     ad-do-it
>     (setq buffer-undo-list saved-undo-list)
>     (unless was-modified
>       (set-buffer-modified-p nil))))
> (ad-activate 'highlight-changes-rotate-faces)

The following should be sufficient

(defadvice highlight-changes-rotate-faces (around around-rotate-faces)
  (let ((was-modified (buffer-modified-p))
        (buffer-undo-list t))
    (unless was-modified
      (set-buffer-modified-p nil))))
 (ad-activate 'highlight-changes-rotate-faces)

but please check whether undoing / redoing does assign the correct

Alternatively you could try to replace your version of
`highlight-changes-rotate-faces' with the one I attached.  Either you do
that directly in hilit-chg.el (recompiling that file) or you add it to
your .emacs preceded by a

(require 'hilit-chg)

(defun highlight-changes-rotate-faces ()
  "Rotate the faces used by Highlight Changes mode.

Current changes are displayed in the face described by the first element
of `highlight-changes-face-list', one level older changes are shown in
face described by the second element, and so on.  Very old changes remain
shown in the last face in the list.

You can automatically rotate colors when the buffer is saved by adding
this function to `write-file-functions' as a buffer-local value.  To do
this, eval the following in the buffer to be saved:

  \(add-hook 'write-file-functions 'highlight-changes-rotate-faces nil t)"
  ;; If not in active mode do nothing but don't complain because this
  ;; may be bound to a hook.
  (when (eq highlight-changes-mode 'active)
    (let ((modified (buffer-modified-p))
          (buffer-undo-list t)
          (inhibit-modification-hooks t))
            ;; ensure hilit-chg-list is made and up to date
            ;; remove our existing overlays
            ;; for each change text property, increment it
            (hilit-chg-map-changes 'hilit-chg-bump-change)
            ;; and display them all if active
            (if (eq highlight-changes-mode 'active)
        (unless modified (set-buffer-modified-p nil)))))
  ;; This always returns nil so it is safe to use in write-file-functions

reply via email to

[Prev in Thread] Current Thread [Next in Thread]