emacs-devel
[Top][All Lists]
Advanced

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

Re: buffer is modified after commit


From: Stefan Monnier
Subject: Re: buffer is modified after commit
Date: Thu, 14 Feb 2008 09:57:26 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

>> edit
>> save
>> rotate
>> edit
>> save
>> undo undo undo...

> Maybe define

> (defun restore-buffer-unmodified-unless-saved (arg)
>   (when (or (and (not (buffer-file-name)) (not arg))
>           (and (file-exists-p (buffer-file-name))
>                (equal arg (nth 5 (file-attributes (buffer-file-name))))))
>     (restore-buffer-modified nil)))

> and add

> (setq buffer-undo-list
>       (cons '(apply restore-buffer-unmodified-unless-saved
>                   (when (and (buffer-file-name)
>                              (file-exists-p (buffer-file-name)))
>                     (nth 5 (file-attributes (buffer-file-name)))))
>           buffer-undo-list))

> to `highlight-changes-rotate-faces', but that would constitute yet
> another ugly hack.

> What's really needed is a new entry type for `buffer-undo-list' like the
> (nil PROPERTY VALUE BEG . END) one but when applied not causing a change
> in the buffer-modified status.

There's no such need.  The `apply' entry is all-powerful.
What hilit-chg needs to do is something like:

   (defun hilit-chg-undo-nomodify (undo-list)
     (let ((modified (buffer-modified-p)))
       (while undo-list
         (setq undo-list (primitive-undo 1 undo-list)))
       (unless modified (restore-buffer-modified-p nil))))

and then use something like:

   (push
    (let* ((buffer-undo-list nil))
      ...do your thing...
      `(apply 'hilit-chg-undo-nomodify ,buffer-undo-list))
    buffer-undo-list)

Of course, another option is to define a reverse function from
(unrotate) and put that one on the undo-list (that's what I (try to) do
with diff-reverse-direction, diff-context->unified, and
diff-unified->context).


        Stefan




reply via email to

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